[chicago-lisp] quoted list modification-- "let" does not protect values

David Riggs dariggs at humnet.ucla.edu
Sun Dec 3 01:33:38 UTC 2006


Dear Lispers,

I want to have an alist to keep track of occurances of items in a buffer 
I am searching. So I define a function to do that, and start off with a 
"let" to set an alist with the strings I am searching for, setting the 
crd to zero for each. But each time I invoke the function, the old 
values of the cdr are remembered.


For example

(defun mytest () (interactive)
  (let ((dot '("a" .  0)) (n 0))
(setcdr dot (1+ (cdr dot)))
  (setq n (1+ n))
(print  dot)(print n)  ))

Will increase output ("a" . 1) 1, then ("a" . 2) 1 etc, increasing by 
one each call (though the "n" value is always reset to 0).

If I change the let to be

(let ((dot (cons "a"   0)) (n 0))

Then it works as expected, resetting to zero each time.

Why does a function which sets a let declaired variable to a quoted 
alist not reset to inittial value each time it is called?

Clearly I am quite unclear about something very fundamental. Would 
anyone like to straighten me out?

Thanks,

David Riggs, Oberlin Ohio




More information about the Chicago-lisp mailing list