Clojure China

Clojure-koans 里的某个宏怎么写?

#1

中缀表达式 转前缀的那个宏

(defmacro infix-better [form]
   `(~(second form)
     ~(first form)
     ~(let [thrd (nth form 2)]
             (if (seq? thrd)
                 (infix-better thrd)
                 thrd))))

这么写各种报错 。。。

#2
(defmacro infix-better [form]
  `(~(second form) ; Note the syntax-quote (`) and unquote (~) characters!
    ~(first form)
    ~(nth form 2)))
#3

看到微博,就过来回答了。:grin:

#4

不知道你想要什么结果,请给出相应的输入输出

#5

来个稍微好一点的版本:

https://gist.github.com/gfZeng/89ff54b9531a86c294da

支持优先级, 甚至括号

(infix 2 + 3 * 4 *  (7 + 8 * 2))
#6

输入输出的话,找https://github.com/functional-koans/clojure-koans/blob/master/src/koans/18_macros.clj

#7

https://github.com/functional-koans/clojure-koans/blob/master/src/koans/18_macros.clj
这是原题
考虑一下 有括号怎么办