为什么不能在Clojure REPL中更改clojure.repl/print-doc绑定?
这按预期工作:为什么不能在Clojure REPL中更改clojure.repl/print-doc绑定?
java -jar clojure-1.4.0.jar -e "(do (require 'clojure.repl) (.setDynamiC#'clojure.repl/print-doc) (with-bindings {#'clojure.repl/print-doc str} (eval '(clojure.repl/doc println))))"
输出:
"{:ns #<Namespace clojure.core>, :name println, :arglists ([& more]), :added \"1.0\", :static true, :doc \"Same as print followed by (newline)\", :line 3325, :file \"clojure/core.clj\"}"
但同样在REPL不起作用:
输出(doc println)
的
java -jar clojure-1.4.0.jar -e "(do (require 'clojure.repl) (.setDynamiC#'clojure.repl/print-doc) (clojure.main/repl :init (fn [] {#'clojure.repl/print-doc str}))))"
:
user=> (doc println) -------------------------
clojure.core/println
([& more])
Same as print followed by (newline)
nil
user=>
我不知道我在做什么错。
回答:
找到答案潜入逆时针和nrepl代码之后:
java -jar clojure-1.4.0.jar -e "(do (require 'clojure.repl) (.setDynamiC#'clojure.repl/print-doc) (with-bindings {#'clojure.repl/print-doc str} (clojure.main/repl)))))"
的输出是与上述相同的:
"{:ns #<Namespace clojure.core>, :name println, :arglists ([& more]), :added \"1.0\", :static true, :doc \"Same as print followed by (newline)\", :line 3325, :file \"clojure/core.clj\"}"
诀窍是调用repl
前使用with-bindings
:
(with-bindings {#'clojure.repl/print-doc str} (repl))
以上是 为什么不能在Clojure REPL中更改clojure.repl/print-doc绑定? 的全部内容, 来源链接: utcz.com/qa/257860.html