中缀表达式 转前缀的那个宏
(defmacro infix-better [form] `(~(second form) ~(first form) ~(let [thrd (nth form 2)] (if (seq? thrd) (infix-better thrd) thrd))))
这么写各种报错 。。。
中缀表达式 转前缀的那个宏
(defmacro infix-better [form] `(~(second form) ~(first form) ~(let [thrd (nth form 2)] (if (seq? thrd) (infix-better thrd) thrd))))
这么写各种报错 。。。
(defmacro infix-better [form]
`(~(second form) ; Note the syntax-quote (`) and unquote (~) characters!
~(first form)
~(nth form 2)))
来个稍微好一点的版本:
https://gist.github.com/gfZeng/89ff54b9531a86c294da
支持优先级, 甚至括号
(infix 2 + 3 * 4 * (7 + 8 * 2))
输入输出的话,找https://github.com/functional-koans/clojure-koans/blob/master/src/koans/18_macros.clj