Search code examples
listlispelisp

Make list into symbol


I was trying to pop an element of a list in elisp as follows,

(pop '(1 2))

but, due to my misunderstanding, that doesn't work b/c the list hasn't been internalized as a symbol. Is there an idiomatic way to do the above, or is that not a proper approach? Messing around a bit further I found I could do

(pop (progn (setq tmp '(1 2)) tmp))

but it doesn't seem right. Is there a way to make anonymous lists and modify them in place like I was trying to do?


Solution

  • pop is a macro which modifies the value of its argument, a place.

    E.g.,

    (defparameter *var* '(1 2 3))
    (pop *var*)
    ==> 1
    *var*
    ==> (2 3)
    

    Note that what gets modified is the value of the place, not the object contained in the place.

    E.g.,

    (defparameter *var-1* '(1 2 3))
    (defparameter *var-2* *var-1*)
    (pop *var-1*)
    ==> 1
    *var-1*
    ==> (2 3)
    *var-2*
    ==> (1 2 3)
    

    IOW, the list (1 2 3) is not modified, only the value of the variable is.

    What exactly are you trying to do?