MathGroup Archive 2003

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

Search the Archive

RE: Part assignment

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44984] RE: [mg44972] Part assignment
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Fri, 12 Dec 2003 04:41:21 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Wolf, Hartmut 
To: mathgroup at smc.vnet.net
>Sent: Thursday, December 11, 2003 1:48 PM
>To: 'Maxim'; mathgroup at smc.vnet.net
>Subject: [mg44984] RE: [mg44972] Part assignment
>
>
>
>>-----Original Message-----
>>From: Maxim [mailto:dontsendhere@.]
To: mathgroup at smc.vnet.net
>>Sent: Thursday, December 11, 2003 11:28 AM
>>To: mathgroup at smc.vnet.net
>>Subject: [mg44984] [mg44972] Part assignment
>>
>>
>>Consider
>>
>>In[1]:=
>>Module[
>>  {L={0,0}},
>>  L[[1]]=Sequence[1,1];
>>  L[[2]]=2;
>>  L[[2]]
>>]
>>
>>Out[1]=
>>1
>>
>>The first part assignment constructs a list {Sequence[1,1],0}. Then an
>>interesting thing happens: part extraction functions (Part and others)
>>think that the second element of this list is 1, while part assignment
>>(Set) decides that the second element is 0.
>>
>>Maxim Rytin
>>m.r at prontomail.com
>>
>>
>
>Maxim,
>
>obviously you like to live on the edge. Unless you complain, 
>this is a bold way to learn. Observe:
>
>In[32]:= L = {0, 0};
>         L[[1]] = Sequence[1, 1];
>         L[[2]] = 2;
>         L[[2]]
>Out[35]= 1
>
>In[36]:= ?L
>
>         Global`L
>
>         L = {Sequence[1, 1], 2}
>
>In[48]:= Attributes[Set]
>Out[48]= {HoldFirst, Protected, SequenceHold}
>
>(Look up what SequenceHold means!)
>
>
>
>As mostly, you do have alternatives:
>
>In[38]:= L = {0, 0};
>         L = ReplacePart[L, Unevaluated[Sequence[1, 1]], 1];
>         L[[2]] = 2;
>         L[[2]]
>
>Out[41]= 2
>
>In[42]:= ?L
>
>         Global`L
>
>         L = {1, 2, 0}
>
>
>--
>Hartmut Wolf
>

a corollary, this simple trick:

In[49]:= L = {0, 0};
         L[[1]] = Sequence[1, 1];
         L = L;
         L[[2]] = 2;
         L[[2]]
Out[53]= 2

--
Hartmut


  • Prev by Date: RE: how to change arguments of standard functions ?
  • Next by Date: RE: log-log plot with error bars, different data markers
  • Previous by thread: RE: Part assignment
  • Next by thread: Re: Part assignment