This is working well. It is pretty complex to do something that is suppose to be simple. I am not yet able to understand this code. I find Clojure hard to learn.
Thank you Keith. Le mercredi 20 mai 2015 21:36:02 UTC-4, Keith Irwin a écrit : > > What about eval? > > user => (eval `(. ~(resolve (symbol "String")) ~(symbol "format") "%s" > (to-array ["adasd"]))) > “adasd" > > I have a function form: > > (defn static-invoke > [c meth & args] > (eval `(. ~(resolve (symbol c)) ~(symbol meth) ~@args))) > > Which works for some things: > > user => (static-invoke “System” “currentTimeMillis”) > 1432171781154 > > But the String thing was problematic: > > user => (static-invoke "String" "format" "a %s” (quote (to-array ["foo”]))) > “a foo” > > (This gave a weird error until I quoted the to-array form.) > > Still not helpful? > > > On May 20, 2015, at 6:09 PM, Ambrose Bonnaire-Sergeant < > abonnair...@gmail.com <javascript:>> wrote: > > Macros won't work because they are expanded at compile-time. We want to > choose the method at runtime. > > Thanks, > Ambrose > > On Thu, May 21, 2015 at 9:02 AM, Keith Irwin <ke...@zentrope.com > <javascript:>> wrote: > >> Not sure if this helps, but: >> >> user => (eval (symbol "Math" "PI”)) >> 3.141592653589793 >> >> user => (eval `(. ~(resolve (symbol "String")) ~(symbol "format") "%s" >> (to-array ["adasd"]))) >> “adasd" >> >> Maybe a macro of some sort? >> >> (defmacro invoke-static >> [c meth & args] >> `(. ~(resolve (symbol c)) ~(symbol meth) ~@args)) >> >> user => (invoke-static "java.lang.String" "format" "the %s" (to-array >> ["foo"])) >> “the foo" >> >> user=> (invoke-static "System" "currentTimeMillis") >> 1432170076378 >> >> That kind of thing? >> >> On May 20, 2015, at 4:54 PM, Pierre Thibault <pierre.t...@gmail.com >> <javascript:>> wrote: >> >> I gave it a try: >> >> (.. (class String) (getMethod "format" (into-array Class [String >> (Class/forName "[Ljava.lang.Object;")]))) >> >> But I am unable to get the method. I gave up. >> >> Le mercredi 20 mai 2015 19:12:05 UTC-4, Pierre Thibault a écrit : >>> >>> Hi Laurens, >>> >>> My example was not very good. Here another one: >>> >>> (.format (first '(String)) "%s" "foo") >>> >>> Imagine String is obtained dynamically. I guess then I have to use Java >>> reflection to do a dynamic invocation. I guess I am confused because >>> classes in Java are not objects. >>> >>> Le mercredi 20 mai 2015 18:40:13 UTC-4, Laurens Van Houtven a écrit : >>>> >>>> Hi Pierre, >>>> >>>> On May 20, 2015, at 3:38 PM, Pierre Thibault <pierre.t...@gmail.com> >>>> wrote: >>>> >>>> I can do Math/PI put how can I access PI if Math is in a expression >>>> like '(Math) for example? >>>> >>>> >>>> Can you provide a more specific example? Math/PI is always Math/PI, it >>>> doesn’t change if you put it in a nested form/expression. >>>> >>>> hth >>>> lvh >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Clojure" group. >>>> To post to this group, send email to clo...@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+u...@googlegroups.com >>>> For more options, visit this group at >>>> http://groups.google.com/group/clojure?hl=en >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "Clojure" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to clojure+u...@googlegroups.com. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>>> >>>> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com >> <javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> >> >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com >> <javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clo...@googlegroups.com <javascript:> > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+u...@googlegroups.com <javascript:> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+u...@googlegroups.com <javascript:>. > For more options, visit https://groups.google.com/d/optout. > > > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.