Welcome! Please see the About page for a little more info on how this works.

0 votes
in core.match by

The following function fails to compile. If I change the row

(link: :context _ _)   formula

to

(link: :context _)   formula

it works.

(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 Answers

0 votes
by

Comment made by: glchapman

A fix for this is to replace the two {{recur}} s with recursive calls to {{terms}}. When recur is present, core.match generates code which ensures the recur is in tail position. However, the amount of code generated is much larger than code without recur (which uses a backtrack exception to handle non-matches).

0 votes
by
Reference: https://clojure.atlassian.net/browse/MATCH-114 (reported by alex+import)
...