【问题标题】:Clojure: documentationClojure:文档
【发布时间】:2013-04-09 01:41:54
【问题描述】:

我正在学习本教程:http://moxleystratton.com/clojure/clojure-tutorial-for-the-non-lisp-programmer

遇到了这个sn-p:

user=> (loop [i 0]
  (when (< i 5)
    (println "i:" i)
    (recur (inc i))))
i: 0
i: 1
i: 2
i: 3
i: 4
nil

在我的解释器上效果很好!

❯ lein repl
nREPL server started on port 50974
REPL-y 0.1.10
Clojure 1.5.1

现在我正在寻找一些关于 recur 是什么的文档。

这里不存在! http://clojure.github.io/clojure/api-index.html

我花了一段时间才弄清楚它是一种“特殊形式”,因此在this page 中进行了描述。

那里有没有一个具有单一连贯索引的汇编?

【问题讨论】:

    标签: clojure


    【解决方案1】:

    尝试使用 REPL 中的内置文档:

    user=> (doc recur)
    -------------------------
    recur
      (recur exprs*)
    Special Form
      Evaluates the exprs in order, then, in parallel, rebinds
      the bindings of the recursion point to the values of the exprs.
      Execution then jumps back to the recursion point, a loop or fn method.
    
      Please see http://clojure.org/special_forms#recur
    

    它适用于函数、宏、特殊形式、变量——几乎所有东西。

    【讨论】:

    • (使用 'clojure.repl)在除 'user 之外的命名空间中使用它
    【解决方案2】:

    clojuredocs.org 上的搜索框是一个很好的起点,它们提供了非常 complete list 的表单和功能。请注意,目前 Clojure Docs 尚未与最新版本的 clojure 保持同步,因此存在一些细微差别。在实践中,official api page 已经足够完整并且是最新的。它没有所有的特殊形式,尽管 clojure 中的特殊形式很少,所以这通常不是问题

    【讨论】:

    • 我也一直在使用 clojuredocs.org。但例如,在搜索中没有找到for。我想在这两个站点中的至少一个站点中至少会有一个针对任何特定表单/func/var 的条目。
    • clojuredocs 搜索有点奇怪。 'for' 不返回 for 的结果,但如果您在搜索框中输入 for 并稍等片刻,您将看到 for 的条目。或者,您可以直接使用clojuredocs.org/clojure_core/clojure.core/for 访问资源——根据需要替换术语。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 1970-01-01
    • 2011-07-17
    • 2012-07-21
    相关资源
    最近更新 更多