Mismatched argument count to recur in syntax quoted macro

不问归期 提交于 2019-12-25 07:49:09

问题


I'm creating a macro that will accept a sum in infix notation and return an equivalent list in prefix notation. Whilst the code probably isn't logically correct yet, I've run into the following error when calling the macro:

CompilerException java.lang.IllegalArgumentException: Mismatched argument count to recur, expected: 0 args, got: 5, compiling:(/tmp/form-init1201331851685991945.clj:1:1)

Here's the macro's code:

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

I'm using the following to test it, after which the above error is thrown:

(def s1 '(1 + 3 * 2 / 2 * 5 - 3))
(infixer * () (first s1)(second s1)(rest (rest s1)))

I can't see any recur targets, so shouldn't recur be seeing the five arguments after the macro name? I haven't used syntax quoting before, so my suspicions are that I've misunderstood how to use it. Please can someone explain why the error is being thrown?

Also, if I'm way off on the logic of trying to convert infix to prefix, feel free to point me in the right direction! I'm new to Clojure and FP so any guidance is extremely appreciated - thanks in advance.

来源:https://stackoverflow.com/questions/41555991/mismatched-argument-count-to-recur-in-syntax-quoted-macro

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!