Re: apply-ing Java methods

2010-03-09 Thread Michael Gardner
On Mar 8, 2010, at 11:20 PM, Michał Marczyk wrote: > It's simple to write this way... And if you provide type hints, I'd > expect the resulting function to be quite performant. If you don't > care about that, here's a flexible alternative using eval: > > user> (defmacro methodfn [name] >`

Re: apply-ing Java methods

2010-03-09 Thread Michael Gardner
On Mar 8, 2010, at 1:06 PM, Nurullah Akkaya wrote: > Using this, > > http://paste.lisp.org/display/67182 > > would allow you to do, > > (let [config {:str "fred" :beg 2 :end 3}] > (apply (jfn 'substring) (map config [:str :beg :end]))) That's quite nice. Thanks! -- You received this message

Re: apply-ing Java methods

2010-03-08 Thread Michał Marczyk
On 8 March 2010 17:37, Michael Gardner wrote: > Thanks for the tip. After some experimentation: > > (apply (memfn connect a b c d) store (map config [:host :port :user > :password])) Oh right, you wanted more arguments. So I should have suggested #(.connect %1 %2 %3 %4). > but why does memfn re

Re: apply-ing Java methods

2010-03-08 Thread Michael Gardner
On Mar 8, 2010, at 9:16 AM, Adrian Cuthbertson wrote: > Maybe just; > (let [{:keys host port user password} config] > (.connect store host port user password)) Having to repeat the variable names rather defeats the purpose, since this version is longer than the original and still feels redunda

Re: apply-ing Java methods

2010-03-08 Thread Michael Gardner
On Mar 8, 2010, at 6:50 AM, Volkan YAZICI wrote: > See memfn in Clojure API docs. Thanks for the tip. After some experimentation: (apply (memfn connect a b c d) store (map config [:host :port :user :password])) but why does memfn require these "dummy" arguments? -- You received this message b

Re: apply-ing Java methods

2010-03-08 Thread Michał Marczyk
I find #(.connect %) to be the most pleasing form. Sincerely, Michał -- 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

Re: apply-ing Java methods

2010-03-08 Thread Nurullah Akkaya
On Mon, Mar 8, 2010 at 9:47 AM, Michael Gardner wrote: > Given a Java instance 'store' with a .connect method that takes a host, port, > user and password, and given a hash-map 'config' with corresponding keyword > values, I wanted to do something like: > > (apply .connect store (map config [:ho

Re: apply-ing Java methods

2010-03-08 Thread Adrian Cuthbertson
There's a fundamental law of nature that says; if you don't try it at the repl before posting, you WILL get it wrong :-). On Mon, Mar 8, 2010 at 5:19 PM, Meikel Brandmeyer wrote: > >> (let [{:keys host port user password} config] >>    (.connect store host port user password)) > > module missing

Re: apply-ing Java methods

2010-03-08 Thread Meikel Brandmeyer
> (let [{:keys host port user password} config] >    (.connect store host port user password)) module missing [] around the keys. ;) And of course this does not work for non-constant keylists. However I think in the majority of cases the list should be constant. -- You received this message be

Re: apply-ing Java methods

2010-03-08 Thread Adrian Cuthbertson
Maybe just; (let [{:keys host port user password} config] (.connect store host port user password)) On Mon, Mar 8, 2010 at 9:47 AM, Michael Gardner wrote: > Given a Java instance 'store' with a .connect method that takes a host, port, > user and password, and given a hash-map 'config' with co

Re: apply-ing Java methods

2010-03-08 Thread Volkan YAZICI
See memfn in Clojure API docs. -- 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

apply-ing Java methods

2010-03-08 Thread Michael Gardner
Given a Java instance 'store' with a .connect method that takes a host, port, user and password, and given a hash-map 'config' with corresponding keyword values, I wanted to do something like: (apply .connect store (map config [:host :port :user :password])) rather than: (.connect store (:host