Hi all,
I've stumbled upon some interesting behaviour regarding macros and
anonymous functions. I couldn't find doco anywhere on this so if you
have any pointers please let me know.
Considering the macro:
(defmacro splicer [a] `(list ~@ a))
What's the expected result of:
(macroexpand-1 '(splicer #(true)))
?
What I am getting now is:
behaviors.t-canary> (macroexpand-1 '(splicer #(true)))
(clojure.core/list fn* [] (true))
behaviors.t-canary> (macroexpand-1 '(splicer (list true)))
(clojure.core/list list true)
I've found this issue while using Midje to test my code. This simple test case:
(fact "splice for lambdas"
(let [a #(true)]
(a) => true))
Expands to:
behaviors.t-canary> (macroexpand-1 '(fact "splice is broken for lambdas"
(let [a #(true)]
(a) => true)))
(midje.util.wrapping/midje-wrapped (clojure.core/every?
clojure.core/true? (clojure.core/list "splice is broken for lambdas"
(let [a (fn* [] (true))] (midje.util.wrapping/midje-wrapped
(midje.semi-sweet/expect (a) midje.semi-sweet/=> true :file-position
(midje.util.file-position/line-number-known 1)))))))
And results in:
;.;. FAIL at (NO_SOURCE_FILE:1)
;.;. Expected: true
;.;. Actual: java.lang.ClassCastException: java.lang.Boolean
cannot be cast to clojure.lang.IFn
;.;. behaviors.t_canary$eval7514$a__7515.invoke(NO_SOURCE_FILE:1)
;.;. behaviors.t_canary$eval7514$fn__7517.invoke(NO_SOURCE_FILE:1)
Can anyone shed a light on this? Expected behaviour, bug or am I
missing something?
Cheers
--
Phil Calçado
http://fragmental.tw
http://www.fragmental.com.br
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en