[英]In Clojure: Error executing a Java call with let inside a function but not in REPL
[英]Referencing unbounded function in Clojure REPL
在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!
为什么?
Clojure中使用declare
创建向前引用。
(declare sq)
(defn sos [x y] (+ (sq x) (sq y)))
这部分是一遍式编译器设计的决定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.