Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: list mutability (very basic question)
Replies: 11   Last Post: Sep 24, 2013 4:15 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Murray Eisenberg

Posts: 2,105
Registered: 12/6/04
Re: list mutability (very basic question)
Posted: Sep 23, 2013 2:44 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I missed the beginning of this thread, but I just wanted to note that the confusion is deepened when you contrast evaluating

{0}[[1]]

which causes an error, with evaluating each of the following two sequences of inputs:

x = {0};
x[[1]] = "Hello"'
x
{Hello}

{0}[[1]]
0


On Sep 22, 2013, at 2:47 AM, Alan G Isaac <alan.isaac@gmail.com> wrote:

> On 9/21/2013 10:15 AM, Bob Hanlon wrote:
>> Attributes[Set]
>> {HoldFirst, Protected, SequenceHold}

>
>
> Thanks, but I'm still unclear:
> why does ``{0}[[1]]=1`` raise an error?
>
> As a point of reference for my confusion,
> Python behaves in a way I find more intuitive:
> ``[0,1][1]=0`` does not raise an error.
> (This becomes an interesting difference when
> we get to argument passing in Mathematica, where HoldFirst
> becomes useful as a way to allow "in place" modification.)
>
> Back to Mathematica, am I understanding correctly that after
> ``Set[Part[x,1],1])`` that x still references the
> same location in memory? How can I easily see that?
> (E.g., in Python, I would us the ``id`` function.)
>
> Thanks,
> Alan Isaac


---
Murray Eisenberg =
murray@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower
University of Massachusetts
710 North Pleasant Street
Amherst, MA 01003-9305









Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.