Re: odd behaviour in rule delayed

• To: mathgroup at smc.vnet.net
• Subject: [mg21506] Re: odd behaviour in rule delayed
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Fri, 14 Jan 2000 02:43:26 -0500 (EST)
• References: <851dn1\$43k@smc.vnet.net> <200001070520.AAA08503@smc.vnet.net> <85i124\$1qh@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Francisco:

Your example (edited)
list = {1, 0, 1, 0, 0, 1}

{1, 0, 1, 0, 0, 1}

k = 0;
{1, 0, 1, 0, 0, 1} /.1 :> ++k

{10., 0, 10., 0, 0, 10.} :> ++k

This is because {1, 0, 1, 0, 0, 1} /.1 :> ++k is parsed as
({1, 0, 1, 0, 0, 1} /(.1)) :> ++k
So / gives division by 0.1.

Solutions: add space between /. and 1

k = 0;
{1, 0, 1, 0, 0, 1} /. 1 :> ++k

{1, 0, 2, 0, 0, 3}

Or, clearer,

k = 0;
{1, 0, 1, 0, 0, 1} /. (1 :> ++k)

{1, 0, 2, 0, 0, 3}

k = 0;
{1, 0, 1, 0, 0, 1} /. {1 :> ++k}

{1, 0, 2, 0, 0, 3}

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Francisco Gutierrez" <rpena at impsat.net.co> wrote in message
news:85i124\$1qh at smc.vnet.net...
> 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?
>
> Francisco Gutierrez
>
>

```

• Prev by Date: Re: Limit problem from analysis
• Next by Date: Alternative cf format.
• Previous by thread: Re: odd behaviour in rule delayed
• Next by thread: Size of a Text[] Graphics primitive