Open GoogleCodeExporter opened 8 years ago
I think that method 2 can be discarded since it isn't idiomatic Clojure and
working with "host" objects is supported for low-level stuff like
Clojure-on-Clojure. Notice that you'd need to add (HelloWorld) at the end to
get the object. I can see that's like the description in the spec: "using the
methods of object X".
I realize that the spec talks about top-level functions and the option of the
proxy class with a handler that delegates to invokable functions. But since
there's no interpreter, an object implementing interface X must be created
either by the intermediary call #getInterface() out of metadata from the
Clojure runtime through Java reflection, or else come from the script itself
taking advantage that Clojure lets you create exactly such a thing.
Under the current scheme, once the code is evaluated (ie, compiled), getting an
interface and using it is Java all the way; there's no invocation roundtrip to
Clojure per method call. This efficiency comes at what seems to me the very
little cost of composing a (proxy) s-expression. The naming convention may seem
arbitrary but it saves having to somehow map your vars to classes somewhere.
I'll also add that (proxy) lets you implement any number of interfaces in a
single script without name collisions.
Top-level functions is a convenience that is expensive in terms of implementing
an interface on the fly, and later for each method call.
Original comment by abm221...@gmail.com
on 13 Jan 2011 at 9:21
Original issue reported on code.google.com by
romain.r...@gmail.com
on 13 Jan 2011 at 3:38