什么是亚历山大:保证符号?

时间:2017-02-03 17:40:09

标签: common-lisp

似乎做了intern所做的事情。也许是(intern (read sym))。但这是为了什么?我看到它被用作:

(if (keywordp x)
  (alexandria:ensure-symbol x)
  x)

在什么情况下可能是某个关键字但不是符号?

1 个答案:

答案 0 :(得分:2)

keyword当然总是symbol

有问题的函数是defined

(declaim (inline ensure-symbol))
(defun ensure-symbol (name &optional (package *package*))
  "Returns a symbol with name designated by NAME, accessible in package
designated by PACKAGE. If symbol is not already accessible in PACKAGE, it is
interned there. Returns a secondary value reflecting the status of the symbol
in the package, which matches the secondary return value of INTERN.
Example:
  (ensure-symbol :cons :cl) => cl:cons, :external
"
  (intern (string name) package))

即,您的代码段执行此操作:如果xkeyword(在symbol包中实习KEYWORD),则会返回"普通& #34;当前包*package*中具有相同名称的符号(否则返回x)。