[英]Referencing unbounded function in Clojure REPL
In the Common Lisp REPL I can do that: 在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)
If I try the same in Clojure the result is this: 如果我在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!
Why? 为什么?
in clojure use declare
to create forward references. Clojure中使用declare
创建向前引用。
(declare sq)
(defn sos [x y] (+ (sq x) (sq y)))
This part of the one-pass compiler design decision. 这部分是一遍式编译器设计的决定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.