       Re: Lists

• To: mathgroup at yoda.physics.unc.edu
• Subject: Re: Lists
• From: John Lee <lee at math.washington.edu>
• Date: Fri, 29 Jan 93 12:48:49 -0800

```neilb at physics.su.oz.au (RiemannZeta(s)) write:

> >In:= l={x,z,y,0,0}
> >
> >Out= {x, z, y, 0, 0}
> >
> >In:=  l/.l[[Length[l] ]]->l[[Length[l] ]]+1
> >
> >Out= {x, z, y, 1, 1}
> >
> which is curious. Does anybody know why
> this doesn't produce
> {x,y,z,0,1}?

Since the construct l/.b->c evaluates b and c before applying the rule, and
since l[[ Length[l] ]] has the value 0, your expression In is equivalent
to

l /. 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:= l={x,z,y,0,0}

Out= {x, z, y, 0, 0}

In:= l[[ Length[l]] ] += 1

Out= 1

In:= l

Out= {x, z, y, 0, 1}

If you're always adding exactly 1, you might also look at the functions
Increment and PreIncrement.

Jack Lee
Dept. of Mathematics
University of Washington
Seattle, WA

```

• Prev by Date: Re: Bug in ANIMATION???
• Next by Date: Re: Lists