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 的代码量大得多(没有 recur 的代码使用回溯异常来处理不匹配)。

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