MathGroup Archive 2013

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

Search the Archive

list mutability (very basic question)

  • To: mathgroup at
  • Subject: [mg131695] list mutability (very basic question)
  • From: Alan <alan.isaac at>
  • Date: Sat, 21 Sep 2013 04:38:30 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:

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

  • Prev by Date: Re: apply rule to Partition
  • Next by Date: Re: Extract columns based on their the title in header
  • Previous by thread: Re: DDFLink
  • Next by thread: Re: list mutability (very basic question)