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