I only bound it to a var to be clear; the intent was that it would be
called directly for the first arg to apply, thus (memfn divide x) may
end up being fewer chars and more informational than #(.divide %1
%2).  But yeah, not a huge thing.  It very well may precede
the .prefix notation.

On Feb 5, 6:44 pm, nchubrich <nicholas.chubr...@gmail.com> wrote:
> Is there ever any reason to use memfn as opposed to ordinary
> functions, i.e.
>
> (def div (fn [x y] (.divide x y)))
>
> On Feb 5, 4:20 pm, ataggart <alex.tagg...@gmail.com> wrote:
>
>
>
> > On Feb 5, 12:34 pm, Nicolas Buduroi <nbudu...@gmail.com> wrote:
>
> > > Hi, I'm searching for a way of applying a sequence of arguments to a
> > > Java method, but haven't found anything yet. Tried to write a macro
> > > for it and don't even see how that would be possible. Is there a way
> > > to do that?
>
> > > Thanks
>
> > > - budu
>
> > You could also use memfn.
>
> > user=> (def div (memfn divide val))
> > #'user/div
> > user=> (def x (BigInteger. "6"))
> > #'user/x
> > user=> (def y (BigInteger. "2"))
> > #'user/y
> > user=> (div x y)
> > 3
> > user=> (apply div [x y])
> > 3
>
> > Though it requires reflection.  To deal with that you could make your
> > own type-hinted function:
>
> > user=> (defn div [#^BigInteger x #^BigInteger y] (.divide x
> > y))
> > #'user/div
> > user=> (apply div [x y])
> > 3

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