14
Il codice seguente non si comporta come mi aspetterei.Come creare una macro per definire due funzioni in clojure
; given a function name, its args and body, create 2 versions:
; i.e., (double-it foo []) should create 2 functions: foo and foo*
(defmacro double-it
[fname args & body]
`(defn ~fname ~args [email protected])
`(defn ~(symbol (str fname "*")) ~args [email protected]))
Il codice sopra non crea due funzioni come mi aspetterei. Crea solo l'ultimo.
user=> (double-it deez [a b] (str b a))
#'user/deez*
Come è possibile ottenere una singola macro per definire due funzioni?