2013-05-04 34 views
1

所以試圖製造類似Haskell的lambda語法,以及與此宏是我的本錢:宏想Clojure中使用的符號,而不是字符串的

(defmacro/[& all] 
    (let [args (take-while #(not (= %1 "=>")) all) 
     argCount (count args) 
     expr (last (split-at (+ argCount 1) all))] 
    `(fn ~(vec args) ([email protected])))) 

(reduce (/ x y "=>" + x y) [1 2 3]) 

這工作做得不夠好,但我想要做的最後一件事就是讓它,所以我不需要"=>"但可以只使用=>

任何提示我怎麼可能讓=>有效的符號,我可以只解析在上下文我推薦呢?

回答

1

比較符號的name對字符串:

(defmacro/[& all] 
    (let [args (take-while #(not (= (name %1) "=>")) all) 
     argCount (count args) 
     expr (last (split-at (+ argCount 1) all))] 
    `(fn ~(vec args) ([email protected])))) 
+0

是的!這甚至讓我使用 - >而不是=>!可愛!謝謝! – 2013-05-04 18:47:40

相關問題