MathGroup Archive 1998

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

Search the Archive

Re: Re: list assignment problem



Sorry Bob,
I don't agree with your explanation. With your arguments, the following
also could not work:

klist={1,2};

klist[[1]]=2;

If you do it step by step, you assign 1=2.

Ok, I think it's only fair I put my bet:

The error message says

Set::setps: jlist[[1]] in assignment of part is not a symbol.

and that's it. Like in old days with Turbo C, there are limits to what
is allowed as a left-hand value. I would call that a design decision.

Now to the question

>>Is there any
>>difference between the two stmts ?

I would say one of the stmts produces a error message and the other one
the desired result, so they are indeed different. Neverthless I can
understand why one would still like to ask: The bible of Mathematica
(Third edition, 1996) says (page 119, second paragraph from below)

"This is equivalent to t[[1, 2]], but is clumsier to write.
 In[14]:= t[[1]][[2]]
 Out[14]= b"

and that's what I told my students before I knew the example.

Ok, now we know better.

Jürgen


-----Original Message-----
From: Bob Hanlon <BobHanlon@aol.com> To: mathgroup@smc.vnet.net
Subject: [mg12542] [mg12495] Re: [mg12434] list assignment problem


>jlist = {{1, 2}, {3, 4}};
>
>To understand what happens with jlist[[1]][[2]], implement it a step at
>a time the way it would be interpretted.
>
>jlist[[1]]
>
>{1, 2}
>
>This is the first row of the matrix.
>
>%[[2]]
>
>2
>
>This is the second element of the two element list.
>
>% = 6
>
>Set::write: Tag Out in % is Protected.
>
>6
>
>That is you asked for it to make the assignment 2 = 6.  This assignment
>couldn't be made and it returned the last meaningful value which it
>has, the 6
> from the attempted assignment.
>
>jlist[[1]][[2]] = 6
>
>Set::setps: jlist[[1]] in assignment of part is not a symbol.
>
>6
>
>When this is all done on one line, Mathematica concludes that there is
>no  symbol involved in the assignment slightly earlier and gives you a
>different  error message.  The 6 does not reflect the result of an
>assignment since no assignment can be made.
>
>Bob Hanlon
>
>In a message dated 5/15/98 12:21:26 PM, you wrote:
>
>>I would like to thank everyone who responded to my question.
>>I know now how to do it right and it works in my program fine
>>but I still dont know really the difference between these two
>>stmts:
>>
>>jlist[[1]][[2]]=6 which is wrong
>>and
>>jlist[[1,2]]=6 which is right.
>>To read the values of index 1 and 2
>>both will give 6 but in the assignment
>>only the 2nd one works. Is there any
>>difference between the two stmts ?
>




  • Prev by Date: Re: RenderAll crash
  • Next by Date: About plotting a surface
  • Prev by thread: Re: list assignment problem
  • Next by thread: bivariate normal probability