MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ReadListBinary question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49883] Re: [mg49861] ReadListBinary question
  • From: Yasvir Tesiram <yat at omrf.ouhsc.edu>
  • Date: Thu, 5 Aug 2004 09:20:54 -0400 (EDT)
  • References: <200408041446.KAA20192@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,
ReadListBinary has attribute "HoldRest"

You can use ClearAttributes for ReadListBinary to pass the value of 
nval to it. But I don't know what the side effects would be.

Instead I would recast reading using SetDelayed

fread[nval_] := ReadListBinary["filename", type, nval]


In[1]:=
<<Utilities`BinaryFiles`

In[2]:=
strmOut=OpenWriteBinary["test"]

Out[2]=
OutputStream[test,4]

In[3]:=
d=Table[i,{i,1,10}]

Out[3]=
{1,2,3,4,5,6,7,8,9,10}

In[4]:=
WriteBinary[strmOut,d]

In[5]:=
Close[strmOut]

Out[5]=
test

In[6]:=
fread[nval_]:=ReadListBinary["test",Int16,nval]

In[7]:=
fread[5]

Out[7]=
{1,2,3,4,5}

In[9]:=
Attributes[ReadListBinary]

Out[9]=
{HoldRest}

In[10]:=
ClearAttributes[ReadListBinary,HoldRest]

In[11]:=
nval=5
ReadListBinary["test",Int16,nval]

Out[11]=
5

Out[12]=
{1,2,3,4,5}

Cheers
Yas

On Aug 4, 2004, at 9:46 AM, Jonathan Greenberg wrote:

> Is there any reason why ReadListBinary[stream,type,n] doesn't let me 
> use a
> variable for "n" (e.g. If I set nval=5, and 
> ReadListBinary[stream,type,nval]
> -- it won't work)?  Are there any workarounds for this?
>
> --j


  • Prev by Date: Re: Does anybody?
  • Next by Date: Re: Forcing Argument Evaluation
  • Previous by thread: ReadListBinary question
  • Next by thread: Re: ReadListBinary question