makunbound
makunbound Function
Syntax:
makunbound symbol → symbol
Arguments and Values:
symbol—a symbol
Description:
Makes the symbol be unbound, regardless of whether it was previously bound.
Examples:
(setf (symbol-value ’a) 1)
(boundp ’a) → true
a → 1
(makunbound ’a) → A
(boundp ’a) → false
Side Effects:
The value cell of symbol is modified.
Exceptional Situations:
Should signal an error of type type-error if symbol is not a symbol.
See Also:
boundp, fmakunbound
Expanded Reference: makunbound
Basic usage
makunbound removes the value from a symbol's value cell, making it unbound. It returns the symbol.
(setf (symbol-value 'temp) 42)
(boundp 'temp)
=> T
(makunbound 'temp)
=> TEMP
(boundp 'temp)
=> NIL
Accessing an unbound symbol signals an error
After makunbound, attempting to read the symbol's value signals an unbound-variable error.
(setf (symbol-value 'doomed) 99)
(makunbound 'doomed)
(handler-case (symbol-value 'doomed)
(unbound-variable () :caught))
=> :CAUGHT
makunbound on an already unbound symbol
Calling makunbound on a symbol that is already unbound is harmless.
(let ((sym (gensym)))
(boundp sym)
(makunbound sym)
(boundp sym))
=> NIL
makunbound does not affect lexical bindings
makunbound only affects the global dynamic binding, not any lexical bindings in scope.
(setf (symbol-value 'outer) :global)
(let ((outer :lexical))
(makunbound 'outer)
outer)
=> :LEXICAL
Round-trip with boundp
makunbound and setf/symbol-value form a complementary pair for managing symbol bindings.
(let ((sym (gensym)))
(values
(boundp sym)
(progn (setf (symbol-value sym) 1)
(boundp sym))
(progn (makunbound sym)
(boundp sym))))
=> NIL
=> T
=> NIL