Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #15507
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: list mutability (very basic question) |
| Date | 2013-09-22 06:24 +0000 |
| Message-ID | <l1m2f1$cao$1@smc.vnet.net> (permalink) |
| References | <20130921083830.751226A65@smc.vnet.net> |
| Organization | Time-Warner Telecom |
You are missing part of the quote. It reads:
"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 m[[...]] = val does."
Set has attribute HoldFirst which prevents x[[1]] in your second example
from turning into {0}[[1]] (your first example) and causing the error
Set::setps: {0} in the part assignment is not a symbol. >>
Attributes[Set]
{HoldFirst, Protected, SequenceHold}
Bob Hanlon
On Sat, Sep 21, 2013 at 4:38 AM, Alan <alan.isaac@gmail.com> wrote:
> I just realized that I am unclear on a very basic point: in what ways are
> lists mutable?
>
> Example:
> {0}[[1]]=1; (* a. this is an error *)
> x={0}
> x[[1]]=1 (* b. this is not an error *)
> ReplacePart[x, 1 -> 2] (* c. this is differently not an error *)
>
>
> http://reference.wolfram.com/mathematica/tutorial/ManipulatingListsByTheirIndices.html
> 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.)
>
> Thanks,
> Alan Isaac
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: list mutability (very basic question) Bob Hanlon <hanlonr357@gmail.com> - 2013-09-22 06:24 +0000
csiph-web