The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: list mutability (very basic question)
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  

Posts: 95
Registered: 3/29/11
list mutability (very basic question)
Posted: Sep 21, 2013 4:21 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I just realized that I am unclear on a very basic point: in what ways are lists mutable?

{0}[[1]]=1; (* a. this is an error *)
x[[1]]=1 (* b. this is not an error *)
ReplacePart[x, 1 -> 2] (* c. this is differently not an error *)
It is important to understand that ReplacePart always creates a new list. It does not modify a list that has already been assigned to a symbol the way does.

I think this means that after b. (i.e., Set[Part[x,1],1]) that x still references the same location in memory. If so, why is a. an error? (I realize that someone will think that saying that {0} is not a L-value will be a helpful answer, and perhaps it should be, but I'm looking for a different angle on the answer.)

Alan Isaac

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.