MathGroup Archive 2003

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

Search the Archive

Re: Simple List question. HELP.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39445] Re: Simple List question. HELP.
  • From: Bill Rowe <listuser at earthlink.net>
  • Date: Sat, 15 Feb 2003 01:43:21 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 2/14/03 at 3:24 AM, MarkCWestwood at compuserve.com (Mark Westwood)
wrote:

>Far better to use Append all the time.  Note too that, like many a
>functional programming language Append[list, value] does NOT change
>list !  It returns the list made by appending value to list.  What you
>probably want is:

>list = Append[list, value]

>that is, make an explicit assignment which causes the old version of
>list to be replaced by its new version, with value added.  If you
>continue to Append in this way you'll probably notice a piling up of
>curly brackets.  

No, Append will not cause "a piling up of curly brackets". Try for example

In[1]:=
lst={};
lst=Nest[Append[#,{Random[],Random[]}]&,lst,5];
Depth[lst]

Out[3]=
3

But it is also true building up lists in this manner is not the fastest way to do things.  A faster way to build up a list would be lst = {lst,next element} which will cause "a piling up of curly brackets" For example,

In[4]:=
lst={};
Timing[lst=Nest[Append[#,{Random[]}]&,lst,10000];]

Out[5]=
{25.02 Second,Null}

In[6]:=
lst={};
Timing[lst=Flatten[Nest[{#,Random[]}&,lst,10000]];]

Out[7]=
{0.08 Second,Null}


  • Prev by Date: Guilloche patterns --- slightly off group topic
  • Next by Date: Re: Porting Mathematica graphics to MicroSoft Point, with quality
  • Previous by thread: Re: Simple List question. HELP.
  • Next by thread: Bug in ColorFunctionScaling ???