Search code examples
lispelispcommon-lisp

How to delete variable/forms in Lisp?


In Python we have the del statement for deleting variables.

E.g:

a = 1
del a

What the equivalent of this in Lisp?

(setq foo 1)
;; (del foo) ?

Solution

  • In Common Lisp.

    For symbols as variables:

    CL-USER 7 > (setf foo 42)
    42
    
    CL-USER 8 > foo
    42
    
    CL-USER 9 > (makunbound 'foo)
    FOO
    
    CL-USER 10 > foo
    
    Error: The variable FOO is unbound.
    

    See:

    • MAKUNBOUND (defined)
    • SLOT-MAKUNBOUND (defined)
    • FMAKUNBOUND (defined)