【发布时间】:2019-09-16 04:23:28
【问题描述】:
在下面的实验中,我对 REPL 返回错误的位置进行了缩写,并添加了 [num],以便在讨论中引用这些内容。
我有点困惑,为什么我尝试调用存储在变量中的函数失败了。在我看来,语法比它需要的更复杂。
为什么我既不能发出(f 3),也不能发出(#'f 3)?
不允许尖锐的引号作为表单的第一个元素吗?
为什么这里需要funcall?
[235]> (setf f #'abs) ; I'm ok with this
#<SYSTEM-FUNCTION ABS>
[236]> (abs 3) ; This is fine
3
[237]> (f 3) ; Err due to sep. fn namespace. OK.
-- Err[1]: "Undefined function f" --
[238]> (#'f 3) ; Don't get what this err is telling me...
-- Err[2]: "#'F is not a function name, try using a symbol instead"
[239]> (funcall #'f 3) ; seems very long winded...!
3
这是否意味着系统函数的处理方式与用户定义的函数不同?
为了完整性:
[240]> (funcall abs 3)
-- Err[3]: variable ABS has no value -- ; I get why this is an error.
[241]> (funcall #'abs 3) ; Isn't this verbose... ?
3
我还没有阅读 ANSI Common Lisp 中的符号章节,也许这会有所帮助...感谢任何提示。
【问题讨论】:
标签: common-lisp