2013-02-21 43 views

回答

7
=> (defmacro string-it [x] (str x)) 
#'user/string-it 
=> (string-it (+ 1 2)) 
"(+ 1 2)" 
2

你可以這樣做:

(str '(and (f 1) (g 3))) 

編輯

如果你不熟悉它,在'(「報價「)字符是一個閱讀器宏字符(more),用於轉義代碼 - 即避免被評估。

你也可以設置一個變量:

(def x '(and (f 1) (g 3))) 
(str x) 

,然後如果你想運行的代碼,你可以EVAL它。

3

Alternativly,如果你不知道你在動手之前可以做的形式,

(defmacro to-str [f] 
    (str f)) 

(to-str (and (f 1) (g 3))) 

,並得到,

"(and (f 1) (g 3))"