In the original version, verification (if (not ...)) occurred at compile time; you included it in the extended code instead. So, here is the minimal change that will make it act the way you want - itโs actually the same as the original, but it โflipsโ what is quoted and what is not.
(defmacro my-recursive-infix [form] (let [third (nth form 2)] `(~(second form) ~(first form) ~(if (not (seq? third)) third `(my-recursive-infix ~third)))))
However, it is slightly better to use destructuring to pull out fragments of the form ahead of time, and not in place:
(defmacro my-recursive-infix [form] (let [[x op y] form] `(~op ~x ~(if (not (seq? y)) y `(my-recursive-infix ~y)))))
And even better - move the non-recursive case outside so that (a) it works for alphabetic numbers and (b) the code is more like expanding:
(defmacro my-recursive-infix [form] (if-not (seq? form) form (let [[x op y] form] `(~op ~x (my-recursive-infix ~y)))))
source share