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

Common Lisp noob problem

Name: Anonymous 2011-08-27 23:17

(defvar *beep* '((A . Apple) (B . Ball) (C . Carrot)))

(defun apply-change (state k v)
  (let ((my-state state))
    (setf (rest (assoc k my-state)) v)
    my-state))


I want to take an a-list as input, create a temporary copy local to this function and modify one of the values (given a key) of the copy, and then return the copy.  But when I try this, it also modifies *beep* itself.

[1]>(apply-change *beep* 'C 'COCKS)
((A . APPLE) (B . BITCH) (C . COCKS))
[2]> *beep*
((A . APPLE) (B . BITCH) (C . COCKS))


How do I copy the alist in apply-change, instead of making my-state refer to the original?  And you can tell me the correct vocabulary I should be using here, too.

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