On Apr 27, 10:04 pm, Boris Mizhen <bo...@boriska.com> wrote:
> Thanks to all who replied.
>
> To summarize what I learned - Clojure has a special form (. ) to
> *call* java functions, but does not have concept of a *value*
> corresponding to a java function.
> This makes Java functions a second class citizen :)
>
Java was born a second-class citizen, Clojure doesn't make it so. In
particular, Java doesn't have proper functions, it has methods. They
are not first class values in Java, and Clojure can't fix that. You
can't pass Java methods by value and you can't apply them. While it
would be possible to automatically generate wrapper fns for Java
methods that would let you *pretend* they were functions, Clojure
currently doesn't do that, since doing so would often mean silently
generating code that uses reflection, and by the time you add
sufficient syntax to allow type hints, there's little benefit over #
().
> In addition special forms are expanded in the first position of the
> list, but not on other positions, thus in (foo Math/abs) Math/abs is
> no longer a syntax for a static method, but a lookup of a var 'abs' in
> a namespace Math.
>
> Correct?
>
What's correct is what is documented here:
http://clojure.org/java_interop
Rich
> On Apr 27, 7:28 pm, Timothy Pratley <timothyprat...@gmail.com> wrote:
>
> > > How can I pass a static java function to another function?
>
> > There is also memfn:
> > (memfn name & args)
> > Macro
> > Expands into code that creates a fn that expects to be passed an
> > object and any args and calls the named instance method on the object
> > passing the args. Use when you want to treat a Java method as a first-
> > class fn.
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---