Tassilo Horn <[email protected]> writes:

> I'm facing the same issue.  I have this macro for java interop:
>
> (defmacro with-traversal-context
>   [[g tc] & body]
>   `(let [old-tc# (.getTraversalContext ^Graph ~g)]
>      (try
>        (.setTraversalContext ^Graph ~g ^TraversalContext ~tc)
>        ~@body
>        (finally (.setTraversalContext ^Graph ~g ^TraversalContext old-tc#)))))
>
> But the type hints are gone in the macro expansion, thus I have 3
> reflection warnings per macro application, and real, performance
> critical reflection warnings get lost in the shuffle.

What you appear to be having is actually the different, but
conceptually-related problem of the metadata reader macro and unquote
operations interacting in a way which is consistent, but potentially not
optimal.  Fortunately in your sort of situation, you can work around the
problem by replacing the metadata reader macro with explicit metadata
operations.  Something like the following should work:

  (defn assoc-meta [x & kvs]
    (with-meta x (apply assoc (meta x) kvs)))

  (defmacro with-traversal-context
    [[g tc] & body]
    (let [g (assoc-meta g :tag Graph)
          tc (assoc-meta tc :tag TraversalContext)]
      `(let [^TraversalContext old-tc# (.getTraversalContext ~g)]
         (try
           (.setTraversalContext ~g ~tc)
           ~@body
           (finally (.setTraversalContext ~g old-tc#))))))

-Marshall

-- 
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

Reply via email to