Constructing Java Interop calls

2009-10-28 Thread Tiago Antão
Hi, Sorry for the newbie question, but I am trying to understand how to construct and call java dynamically from clojure. As an example, imagine that there is a bean property called "Bla" and one wants to set Bla to 1 on object x, which has that property. So, the objective would be to construct,

Re: Constructing Java Interop calls

2009-10-28 Thread Wilson MacGyver
Is there a reason you don't want to use doto? http://clojure.org/java_interop#toc15 ie (doto Bla (.setProperty "x" 1)) 2009/10/28 Tiago Antão : > > Hi, > > Sorry for the newbie question, but I am trying to understand how to > construct and call java dynamically from clojure. > As an example, im

Re: Constructing Java Interop calls

2009-10-28 Thread John Harrop
2009/10/28 Tiago Antão > > Hi, > > Sorry for the newbie question, but I am trying to understand how to > construct and call java dynamically from clojure. > As an example, imagine that there is a bean property called "Bla" and > one wants to set Bla to 1 on object x, which has that property. > So

Re: Constructing Java Interop calls

2009-10-28 Thread Tiago Antão
On Wed, Oct 28, 2009 at 7:34 PM, Wilson MacGyver wrote: > > Is there a reason you don't want to use doto? > > http://clojure.org/java_interop#toc15 > > ie (doto Bla (.setProperty "x" 1)) I really want to do something different: (def x (new StringBuffer "")) (doto x (.setLength 2)) But my p

Re: Constructing Java Interop calls

2009-10-28 Thread Michael Wood
2009/10/28 Tiago Antão : [...] > Again, the point here is to be able to construct method names (full > call signatures, really) on runtime. > > I am lost. As in newbie clueless :( I suspect you want reflection, but I don't know off hand how to do it. -- Michael Wood --~--~-~--~~--

Re: Constructing Java Interop calls

2009-10-28 Thread Meikel Brandmeyer
Hi, Am 28.10.2009 um 20:46 schrieb Tiago Antão: > But my point is to be able to construct the method name in runtime. You'll need reflection for that. AFAIU method calls are wired in the bytecode and hence the method name must be known at compile time. Sincerely Meikel smime.p7s Descriptio

Re: Constructing Java Interop calls

2009-10-28 Thread Kevin Downey
you can always just construct the call as a string or as a datastructure and pass it through read/eval On Wed, Oct 28, 2009 at 2:04 PM, Meikel Brandmeyer wrote: > Hi, > > Am 28.10.2009 um 20:46 schrieb Tiago Antão: > >> But my point is to be able to construct the method name in runtime. > > You'

Re: Constructing Java Interop calls

2009-10-28 Thread Alex Osborne
Tiago Antão wrote: > Again, the point here is to be able to construct method names (full > call signatures, really) on runtime. > > I am lost. As in newbie clueless :( As others have suggested you need to use either Java's reflection or Clojure's eval. Here's some examples: Using reflection:

Re: Constructing Java Interop calls

2009-10-28 Thread John Harrop
On Wed, Oct 28, 2009 at 10:15 PM, Alex Osborne wrote: > > Tiago Antão wrote: > > Again, the point here is to be able to construct method names (full > > call signatures, really) on runtime. > > > > I am lost. As in newbie clueless :( > > As others have suggested you need to use either Java's refl

Re: Constructing Java Interop calls

2009-10-29 Thread Tiago Antão
On Thu, Oct 29, 2009 at 2:15 AM, Alex Osborne wrote: > > Using eval (which will also work for dynamically calling Clojure functions): > >   (let [obj "some string" >         fname ".substring"] >     (eval (list (symbol fname) obj 2))) Thanks a lot. I was trying to avoid reflection (ie, looking

Re: Constructing Java Interop calls

2009-10-29 Thread Meikel Brandmeyer
Hi, On Oct 29, 2:07 pm, Tiago Antão wrote: > The eval form still shows some problems, if I do this preparation: > > (import javax.swing.JFileChooser) > (def jfc (new JFileChooser)) > > And then do: > > user=> (.setFileSelectionMode jfc 1) > nil > > All good here, but, if I do the eval variation

Re: Constructing Java Interop calls

2009-10-29 Thread Kevin Downey
user=> ((eval `(fn [x#] (~(symbol ".setFileSelectionMode") x# 1))) jfc) nil user=> On Thu, Oct 29, 2009 at 6:38 AM, Meikel Brandmeyer wrote: > > Hi, > > On Oct 29, 2:07 pm, Tiago Antão wrote: > >> The eval form still shows some problems, if I do this preparation: >> >> (import javax.swing.JFil

Re: Constructing Java Interop calls

2009-10-30 Thread Tiago Antão
On Thu, Oct 29, 2009 at 1:38 PM, Meikel Brandmeyer wrote: >> All good here, but, if I do the eval variation, >> user=> (eval (list (symbol ".setFileSelectionMode") jfc 1)) > > Another example which shows that eval is not worth the trouble. It is > better to use reflection. You cannot embed the JF

Re: Constructing Java Interop calls

2009-10-30 Thread Kevin Downey
eval calls read for somethings. 2009/10/30 Tiago Antão : > > On Thu, Oct 29, 2009 at 1:38 PM, Meikel Brandmeyer wrote: >>> All good here, but, if I do the eval variation, >>> user=> (eval (list (symbol ".setFileSelectionMode") jfc 1)) >> >> Another example which shows that eval is not worth the