在Common Lisp REPL中,我可以这样做:
>(DEFUN SOS (x y) (+ (sq x) (sq y)))
SOS
>(sos 5 4)
Error in SOS [or a callee]: The function SQ is undefined.
Fast links are on: do (use-fast-links nil) for debugging
Broken at +. Type :H for Help.
1 (Abort) Return to top level.
dbl:>>1
Top level.
>(DEFUN sq (x) (* x x))
SQ
>(sos 5 4)
41
>(quit)
如果我在Clojure中尝试相同的结果是这样的:
user=> (defn sos [x y] (+ (sq x) (sq y)))
CompilerException java.lang.RuntimeException: Unable to resolve symbol: sq in this context, compiling:(NO_SOURCE_PATH:1:20)
user=> (quit)
Bye for now!
为什么?
答案 0 :(得分:4)
在clojure中使用declare
来创建前向引用。
(declare sq)
(defn sos [x y] (+ (sq x) (sq y)))
这部分一次性编译器设计决定。