MathGroup Archive 1993

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

Search the Archive

Re: Lists


On Fri, 29 Jan 93 12:48:49 -0800, "John Lee" <lee at math.washington.EDU> wrote:
> neilb at physics.su.oz.au (RiemannZeta(s)) write:
> > >In[5]:= l={x,z,y,0,0}
> > >
> > >Out[5]= {x, z, y, 0, 0}
> > >
> > >In[6]:=  l/.l[[Length[l] ]]->l[[Length[l] ]]+1
> > >
> > >Out[6]= {x, z, y, 1, 1}
> > >
> > which is curious. Does anybody know why
> > this doesn't produce
> > {x,y,z,0,1}?

> This explains why you got the result you did.  One function you might use
> here is AddTo (which can be abbreviated +=).  For example:
> 
>   In[4]:= l={x,z,y,0,0}
> 
>   Out[4]= {x, z, y, 0, 0}
> 
>   In[5]:= l[[ Length[l]] ] += 1

Why fuss with using Length[] to find the end of the list?  What about
Last[l], Part[l, -1], or even ReplacePart[l, ++#&, -1]?  

I'm not sure the syntax for ReplacePart is right, since I don't have
Mma running at the moment, but it looks like using it in some way is
probably the most efficient (and easiest to read).

Katherine
-- 
Katherine (Williams) Derbyshire
kewms at kew.com

A mouse is an elephant designed by the Japanese.





  • Prev by Date: Mathematica Help
  • Next by Date: Re: Interpolation
  • Previous by thread: re: Lists
  • Next by thread: Symposium on QE & CAD