符号的含义
lisp中符号的类型是SYMBOL,一个符号就是这一类型的值.符号和整数其实差不多,只不过一个是数字表示的一个可以用字母表示.
* (type-of 'aaa)
SYMBOL
*
相同的符号总是EQ的
* (eq 'a 'a)
T
符号绑定
一个符号可以同时绑定到变量 函数 类上,
CL-USER> (find "A" (map 'list #'symbol-name (loop for s being the symbol collect s)) :test #'string=)
NIL
CL-USER> (setf a "ddd")
; in: SETF A
; (SETF A "ddd")
; ==>
; (SETQ A "ddd")
;
; caught WARNING:
; undefined variable: A
;
; compilation unit finished
; Undefined variable:
; A
; caught 1 WARNING condition
"ddd"
CL-USER> (find "A" (map 'list #'symbol-name (loop for s being the symbol collect s)) :test #'string=)
"A"
CL-USER> (boundp 'a)
T
CL-USER> (defun a () ())
A
CL-USER> (fboundp 'a)
T
CL-USER> (defclass a () ())
#<STANDARD-CLASS COMMON-LISP-USER::A>
CL-USER> (find-class 'a)
#<STANDARD-CLASS COMMON-LISP-USER::A>
但结构和类不能绑定到同一个符号上
CL-USER> (defstruct a x y)
A
CL-USER> (defclass a () ())
; Evaluation aborted on #<SB-PCL::METAOBJECT-INITIALIZATION-VIOLATION "~@<Cannot ~S~@[ ~S~] objects into ~S metaobjects.~@:>" {1004D44943}>.
CL-USER>