Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15506

Re: list mutability (very basic question)

From Bob Hanlon <hanlonr357@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: list mutability (very basic question)
Date 2013-09-22 06:23 +0000
Message-ID <l1m2cl$cag$1@smc.vnet.net> (permalink)
References <20130921083830.751226A65@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


In the statement {0}[[1]]=1 there is no memory location being referenced to
be set. And, if one were created, how would you subsequently reference it?

In Set[Part[x,1],1] I do not know if it is the same memory location but
probably not since the new value may not occupy the same amount of memory
(e.g., you could be changing amongst integers, reals, complexes, strings,
lists, =85). Whether it is the same location or not is immaterial to its
value and the ability to reference its value.


Bob Hanlon


On Sat, Sep 21, 2013 at 11:05 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
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: list mutability (very basic question) Bob Hanlon <hanlonr357@gmail.com> - 2013-09-22 06:23 +0000

csiph-web