2024 Clojure 状态调查!分享您的想法。

欢迎!请查看关于页面了解如何使用本站。

0
core.match

以下函数无法编译。如果我把这一行

(link: :context _ _)   formula

改为

(link: :context _)   formula

它就可以工作了。

(defn terms (link: formula)
(match formula

(link: :root r)      (recur r)
(link: :expr e)      (recur e)
(link: :call f [:args & args]] (for [arg args) (terms arg))
(link: :refer _ _)   formula
(link: :float _)     formula
(link: :context _ _)   formula
(link: :string _)    formula
(link: :eq e1 _ e2)  (concat (terms e1) (terms e2))
(link: :add & args ) (for (link: arg args) (terms arg))
(link: :sub & args ) (for (link: arg args) (terms arg))
(link: :div & args ) (for (link: arg args) (terms arg))
(link: :mul & args ) (for (link: arg args) (terms arg))

))

2 个答案

0

评论者:glchapman

此问题的解决方案是将两个 {{recur}} 替换为对 {{terms}} 的递归调用。当存在 recur 时,core.match 生成的代码将确保 recur 处于尾部位置。然而,生成的代码量比没有 recur(使用回溯异常来处理不匹配)的代码量大得多。

0
参考:https://clojure.atlassian.net/browse/MATCH-114(由 alex+import 报告)
...