[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lisp Question



This is a common (well, not totally obscure, at any rate) confusion
with Common Lisp. MCL is performing correctly here.

The '(1 2 3) list in your code is not freshly consed every time
you run foo; if you wanted this behavior instead you need to say
 (let ((ted (list 1 2 3))) ...), which creates a new list each time.

The first time you call rplacd, you bash this value and there's
never any reason for it to be reset back to (1 2 3).


 > Date: Thu, 27 Oct 94 13:50:31 CDT
 > From: paul_hasse@NSDGATE3.nsd.fmc.com (paul hasse)
 > Encoding: 939 Text
 > To: info-mcl@cambridge.apple.com
 > Subject: Lisp Question
 > Sender: owner-info-mcl@cambridge.apple.com
 > 
 > I have noticed the following behavior with respect to the scope of local 
 > variables, their initialization, and their destructive modification.  In the 
 > following example, the function foo behaves differently on the second run.  
 > Obviously, the memory containing foos initialization is being modified.  I also 
 > assume this in not a bug in MCL.  Could someone direct be to the portion of 
 > Steels lisp book (2nd edition) which refers to this behavior.  Also, what 
 > should happen if foo were loaded from a compiled file.
 > 
 > ? (defun foo ()
 >     (let ((ted '(1 2 3)))
 >       (print ted)
 >       (rplacd ted 'bill)
 >       (print ted)))
 > FOO
 > ? (FOO)
 > 
 > (1 2 3) 
 > (1 . BILL) 
 > (1 . BILL)
 > ? (FOO)
 > 
 > (1 . BILL) 
 > (1 . BILL) 
 > (1 . BILL)
 > ? 
 > 
 > Second question, I remember hearing about a company which offered a translator 
 > from Lisp to C.  Any info on this company or product (in particular, an 
 > internet address).
 > 
 > Thanks in advance!