Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

It's Lisping Time!!

Name: None 2012-03-17 15:12

As I know most of you love Lisp I have a question for you:

What is the difference between


(setf mylist '(1 2 3))
(setf another mylist)


and



(setf mylist '(1 2 3))
(setf another (copy-list mylist))


?

Name: Anonymous 2012-03-17 15:24

The between the two is mutability. In most Lisp dialects, the regular lists for which there are literals are not immutable, so you run into the same problem (or not, depending on how you see it) that as in arrays or any other mutable object, i.e. if you have two variables, a and b, and you set b to the same list object referred by a, if you modify it you'll see the changes reflected in both variables.

Not so in the second examples, as the list set in another is a fresh, independent copy.

Name: Anonymous 2012-03-17 15:41

>>2
Crap. That was some shitty proof reading on my part.

Name: Anonymous 2012-03-17 15:45

cons should be immutable by default.

Don't change these.
Name: Email:
Entire Thread Thread List