Re: how come ?
- To: mathgroup at smc.vnet.net
- Subject: [mg41121] Re: [mg41115] how come ?
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sun, 4 May 2003 03:55:07 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
The reason is that Set (=) with Part behave in a somewhat peculiar way when used together. When you evaluate Part[l,1,2]=3 Mathematica first checks if l is a Symbol, and if it is not, then produces the error message you got. If, on the other hand, it is a Symbol than it looks for a "part" of l corresponding to Part[l,1,2] and replaces it by 3 (without evaluating the new expression!). If such a part does not exist you will get a different error message. So when you enter Part[Part[l,1],2]=3 Mathematica simply sees that Part[l,1] is not a Symbol and produces your error message. Part[l,1] itself is never evaluated, and if you try force evaluation of the left hand side you will end up with an attempt at an impossible assignment 2 = 3: Evaluate[l[[1]][[2]]] = 3 Set::setraw:Cannot assign to raw object 2. Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ On Saturday, May 3, 2003, at 04:30 pm, Phuong wrote: > Hi everybody, > > I am a newbie in Mathematica and began programming with it. Could > anyone explain this problem to me ? > > why mathematica can't deal with > > l={{1,2,3},{2,4,5}} > > l[[1]][[2]]=3 > > and here is its error message : > Set::"setps": "\!\(l \[LeftDoubleBracket] 1 \[RightDoubleBracket]\) in > \ > assignment of part is not a symbol." > > but it can with > > Part[l,1,2]=3 > > > >