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

欢迎!请参阅关于页面以获取更多关于如何操作的信息。

0 点赞
core.match

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

(link: :context _ _)   formula

改为

(link: :context _)   formula

它就正常工作了。

(defn terms (link: 公式)
(match 公式

(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 报告)
...