Hi,

Not sure if it makes sense, but I thought I'd ask anyway. Why are type
hints in a macro not passed to a body of code executed inside?

user=> (set! *warn-on-reflection* true)
true
user=> (def s "Hello world")
#'user/s
user=> (.length s)
Reflection warning, NO_SOURCE_PATH:28 - reference to field length
can't be resolved.
11
user=> (defmacro in-macro [[x y] & body] `(let [^String ~x ~y]
~...@body))
#'user/in-macro
user=> (in-macro [x s] (.length x))
Reflection warning, NO_SOURCE_PATH:30 - reference to field length
can't be resolved.
11
user=> (defmacro in-macro [[x y] & body] `(let [^String ~x (str ~y)]
~...@body))
#'user/in-macro
user=> (in-macro [x s] (.length x))
11

As you can see above, when I wrap ~y as (str ~y), it avoids
reflection.

Regards,
Shantanu

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to