我正在创建一个宏,它将接受中缀表示法中的和并返回前缀表示法中的等效列表。虽然代码可能在逻辑上还不正确,但在调用宏时我遇到了以下错误:
CompilerException java.lang.IllegalArgumentException: Mismatched argument count to recur, expected: 0 args, got: 5, compiling:(/tmp/form-init1201331851685991945.clj:1:1)
这是宏观代码:
(defmacro infixer [o1 outlist i1 i2 i3]
`(if (empty? ~i3)
(concat ~i1 ~i2)
(if (= ~i2 ~o1)
;then recur list of i2 i1 i3 at outlist tail
(recur ~o1
(concat ~outlist (~i2 ~i1 ~(first i3)))
()
~(second i3)
~(rest (rest i3)))
;else recur i1 at outlist tail
(recur ~o1
(concat ~outlist ~i1)
~i2
~i3
~(rest i3)
))))
我使用以下内容对其进行测试,然后抛出上述错误:
(def s1 '(1 + 3 * 2 / 2 * 5 - 3))
(infixer * () (first s1)(second s1)(rest (rest s1)))
我看不到任何recur
个目标,所以不应该{1}}看到宏名后面的五个参数吗?我之前没有使用过语法引用,所以我怀疑是我误解了如何使用它。有人可以解释为什么会抛出错误吗?
此外,如果我试图将中缀转换为前缀的逻辑,请随意指出我正确的方向!我是Clojure和FP的新手,所以任何指导都非常感谢 - 提前感谢。