是否可以将 Common Lisp 的 getf 函数默认值更改为 NIL 以外的其他值?
Is it possible to change Common Lisp's `getf` function default value to something else than NIL?
函数getf
的工作原理是这样的:
CL-USER> (getf '(:name "pedro") :name)
"pedro"
CL-USER> (getf '(:name "pedro") :whatever)
NIL
NIL
是默认值。可以改吗?
是的。文档defines这种可能性:
(getf place indicator &optional default)
因此,默认值实际上是一个可选参数。使用它的一个例子是:
CL-USER> (getf '(:name "pedro") :name "no-answer")
"pedro"
CL-USER> (getf '(:name "pedro") :whatever "no-answer")
"no-answer"
函数getf
的工作原理是这样的:
CL-USER> (getf '(:name "pedro") :name)
"pedro"
CL-USER> (getf '(:name "pedro") :whatever)
NIL
NIL
是默认值。可以改吗?
是的。文档defines这种可能性:
(getf place indicator &optional default)
因此,默认值实际上是一个可选参数。使用它的一个例子是:
CL-USER> (getf '(:name "pedro") :name "no-answer")
"pedro"
CL-USER> (getf '(:name "pedro") :whatever "no-answer")
"no-answer"