MathGroup Archive 2000

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

Search the Archive

Re: odd behaviour in rule delayed

  • To: mathgroup at
  • Subject: [mg21543] Re: [mg21499] odd behaviour in rule delayed
  • From: "Tomas Garza" <tgarza at>
  • Date: Fri, 14 Jan 2000 02:44:02 -0500 (EST)
  • Sender: owner-wri-mathgroup at

Francisco Gutierrez [rpena at] wrote:

> I have M 4.0, window 95.
> I have a list of 0's and 1's, and I want the one's to perform a
> consecutive
> numeration. For example, transform {1,0,1,0,0,1} into {1,0,2,0,0,3}.
> The easiest (and most elegant, I think) way to do it is with a counter and
> rule delayed:
> list={1,0,1,0,0,1}
> kk=0; newlist={1,0,1,0,0,1} /.1:>++k
> However, the answer I get from this operation is completely
> odd:{10.,0,10.,0,0,10.}:>++k.  I closed my session and re-started my
> computer, but I keep getting the same stuff.  I don't understand what is
> happening. By the way, this problem didn't appear in M3.0.
> Can somebody help me?

I tried your code in Mathematica 3.0 and it gives the same result as in
Version 4. For one thing, newlist is obtained by dividing list by 0.1, so
that the first part of the result is definitely OK: {10.,0,10.,0,0,10.}.
Second, k is not defined (you have kk = 0, not k), but I guess it's only a
Try enclosing the rule into parenthesis so as to avoid the confusion between
a decimal point and a part of the rule symbol:

kk = 0; newlist = {1, 0, 1, 0, 0, 1} /. (1 :> ++kk)
{1, 0, 2, 0, 0, 3}

Tomas Garza
Mexico City

  • Prev by Date: Re: "mma" becomes "Mathematica"
  • Next by Date: Re: "mma" becomes "Mathematica"
  • Previous by thread: Re: odd behaviour in rule delayed
  • Next by thread: RE: odd behaviour in rule delayed