Guys,

I seem to have thrown myself in at the deep end here !

I'm writing some clojure which interacts very heavily with some pojos,
making, hopefully, millions of method invocations a second.

I tried :

Clojure 1.1.0-new-SNAPSHOT
user=> (set! *warn-on-reflection* true)
true
user=> (defn fn1 [s] (.length s))
Reflection warning, NO_SOURCE_PATH:15 - reference to field length
can't be resolved.
#'user/fn1
user=> (time (dotimes [x 100000] (fn1 "foo")))
"Elapsed time: 2424.1015 msecs"
nil
user=> (defn fn2 [#^String s] (.length s))
#'user/fn2
user=> (time (dotimes [x 100000] (fn2 "foo")))
"Elapsed time: 63.462 msecs"
nil

and found that I really needed to take notice of the reflection
warnings for perfomance's sake !

My problem is, that I need to produce functions like the one above, on-
the-fly, from java-side metadata, where both the method name and arg
type are parameterised.

I've spent some time messing around with eval and defmacro and then
found that I was being defeated by the #^ reader macro at every turn,
so I tried switching to using with-meta, but I cannot figure out how
to place metadata correctly on the symbols in the arglist - e.g. :

user=> (fn [(with-meta 's {:tag String})] (.length s))
java.lang.Exception: Unsupported binding form: (with-meta (quote s)
{:tag String}) (NO_SOURCE_FILE:30)

most probably because 'fn is a macro and arglist is not expanded as
you might expect, and:

user=> (let [arg (with-meta 's {:tag String}) arglist [arg] body (list
'.length arg)] (eval (list 'fn arglist body)))
Reflection warning, NO_SOURCE_PATH:40 - reference to field length
can't be resolved.
#<user$eval__168$fn__170 user$eval__168$fn__...@3a1834>
user=> (*1 "foo")
3

The above looks like it worked - but the metadata has been ignored by
the compiler - aaargh !

There must be a way to put together a list/tree of code, at runtime,
that, when evaluated, gives me what I want, by flying beneath the 'fn
macro and/or the #^ reader macro, but at this point I run out of doc
and google-hits :-(

I'd really appreciate some help with this.

thanks,

Jules

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