【问题标题】:Clojure macroexpandClojure 宏展开
【发布时间】:2010-11-29 13:56:47
【问题描述】:

为什么

(macroexpand '(.. arm getHand getFinger))

展开到

(. (. arm getHand) getFinger)

同时

(macroexpand '(-> arm getHand getFinger))

扩展到

(getFinger (clojure.core/-> arm getHand))

换句话说,为什么-> 在第二个例子中没有完全展开?

【问题讨论】:

    标签: macros clojure


    【解决方案1】:

    macroexpand 只扩展表单,直到函数位置的符号不是宏。在 -> 的情况下您注意到这一点的原因是因为 -> 宏是递归的。

    在你的情况下,你想要macroexpand-all form clojure.walk

    【讨论】:

    • 这就是我问的原因。 macroexpand 不应该扩展 -> 直到它不是宏吗?我查看了-> 的源代码,它似乎最终解析为 "([x form] (if (seq?form) (with-meta `(~(first form) ~x ~@(next form)) (元形式))(列表形式x)))“也许我没有正确理解它。
    • @Ralph: macroexpand 不会在子表单中扩展宏,所以(-> arm getHand getFinger) 会扩展为(clojure.core/-> (clojure.core/-> arm getHand) getFinger),而(clojure.core/-> (clojure.core/-> arm getHand) getFinger) 会扩展(因为-> 是一个宏)为(getFinger (clojure.core/-> arm getHand))。扩展在这里停止,因为getFinger 不是宏。
    猜你喜欢
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2016-11-20
    • 1970-01-01
    相关资源
    最近更新 更多