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,
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
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
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
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
--~--~-~--~~--
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
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'
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:
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
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
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
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
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
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
14 matches
Mail list logo