User Tools


Accessor SYMBOL-VALUE

Syntax

  • symbol-value symbolvalue
  • (setf (symbol-value symbol) new-value)

Arguments and Values

Description

Examples

(setf (symbol-value 'a) 1)

1

(symbol-value 'a)

1

;;; SYMBOL-VALUE cannot see lexical variables. (let ((a 2)) (symbol-value 'a))

1

(let ((a 2)) (setf a 3) (symbol-value 'a))

1

;; SYMBOL-VALUE can see dynamic variables. (let ((a 2)) (declare (special a)) (symbol-value 'a))

2

(let ((a 2)) (declare (special a)) (setf a 3) (symbol-value 'a))

3

(let ((a 2)) (setf (symbol-value 'a) 3) a)

2

a

3

(symbol-value 'a)

3

(let ((a 4)) (declare (special a)) (let ((b (symbol-value 'a))) (setf (symbol-value 'a) 5) (values a b)))

5 4

a

3

(symbol-value :any-keyword)

:ANY-KEYWORD

(symbol-value 'nil)

NIL

(symbol-value '())

NIL

;; The precision of this next one is implementation-dependent. (symbol-value 'pi)

3.141592653589793d0

Side Effects

None.

Affected By

Exceptional Situations

Should signal an error of type type-error if symbol is not a symbol.

Should signal unbound-variable if symbol is unbound and an attempt is made to read its value. (No such error is signaled on an attempt to write its value.)

See Also

Notes

symbol-value can be used to get the value of a constant variable.

symbol-value cannot access the value of a lexical variable.