Re: generated class with overloaded methods
Laurent PETIT a écrit : 2009/2/13 Christophe Grand christo...@cgrand.net mailto:christo...@cgrand.net Laurent PETIT a écrit : Hello, Thanks for having shared that, Do you know if there's a way to overload methods with the same arity, then ? I'm thinking about .read(char ) .read(byte ) .read(String ) .read(Integer ) ... for example, ? Create functions named -read-char -read-byte -read-String -read-Integer. Is it documented ? I can't find a reference to it. The documentation says: At runtime, a call to some method foo of the generated class will find the current value of the var implementing.namespace/prefixfoo and call it. The truth is that a call to some method foo will first try to find the current value of the var implementing.namespace/prefixfoo-arg1SimpleTypeName-arg2SimpleTypeName-... (or implementing.namespace/prefixfoo-void if no args) and if this current value is null, it will fallback to implementing.namespace/prefixfoo. Christophe --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Re: generated class with overloaded methods
??? 2009/2/13 Craig McDaniel craig...@gmail.com I just tried it out to be sure. Overloaded methods with the same arity work as expected. Clojure picks the right method to call via reflection. package expmeth; public class ClassA { public void hello() { System.err.println(hello from Java!); } public void hello(int x) { System.err.println(hello from Java. int: + x); } public void hello(String x) { System.err.println(hello from Java. string: + x); } } (ns expmeth.TestMe (:gen-class :extends expmeth.ClassA :exposes-methods {hello helloSuper})) (defn -hello ([this] (.helloSuper this) (println hello from clojure!)) ([this x] (.helloSuper this x) (println hello from clojure... x))) --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Re: generated class with overloaded methods
Christophe, you're right. I tried it and that method also works. I didn't know about that secret feature. (ns expmeth.TestMe (:gen-class :extends expmeth.ClassA :exposes-methods {hello helloSuper})) (defn -hello [this] (.helloSuper this) (println hello from clojure!)) (defn -hello-String [this x] (.helloSuper this x) (println hello-String from clojure x)) (defn -hello-int [this x] (.helloSuper this x) (println hello-int from clojure... x)) --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Re: generated class with overloaded methods
Thanks Christophe, that's the answer I was hoping to get, If I was twenty years younger, I would just say Clojure roxxXXooRR :-) (well, I think this is supposed to say that clojure is really cool, hope I didn't misunderstood the rooxxXXooRR thing :-) -- Laurent 2009/2/13 Christophe Grand christo...@cgrand.net Laurent PETIT a écrit : 2009/2/13 Christophe Grand christo...@cgrand.net mailto:christo...@cgrand.net Laurent PETIT a écrit : Hello, Thanks for having shared that, Do you know if there's a way to overload methods with the same arity, then ? I'm thinking about .read(char ) .read(byte ) .read(String ) .read(Integer ) ... for example, ? Create functions named -read-char -read-byte -read-String -read-Integer. Is it documented ? I can't find a reference to it. The documentation says: At runtime, a call to some method foo of the generated class will find the current value of the var implementing.namespace/prefixfoo and call it. The truth is that a call to some method foo will first try to find the current value of the var implementing.namespace/prefixfoo-arg1SimpleTypeName-arg2SimpleTypeName-... (or implementing.namespace/prefixfoo-void if no args) and if this current value is null, it will fallback to implementing.namespace/prefixfoo. Christophe --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Re: generated class with overloaded methods
Hello , Your example code below is not complete (where's helloSuper definition ?), but I think it does not answer my specific question ? Anyway, it seems that Christophe found the answer. But I don't know if we should use this knowledge, since it is not exposed as an API ? -- Laurent 2009/2/13 Craig McDaniel craig...@gmail.com I just tried it out to be sure. Overloaded methods with the same arity work as expected. Clojure picks the right method to call via reflection. package expmeth; public class ClassA { public void hello() { System.err.println(hello from Java!); } public void hello(int x) { System.err.println(hello from Java. int: + x); } public void hello(String x) { System.err.println(hello from Java. string: + x); } } (ns expmeth.TestMe (:gen-class :extends expmeth.ClassA :exposes-methods {hello helloSuper})) (defn -hello ([this] (.helloSuper this) (println hello from clojure!)) ([this x] (.helloSuper this x) (println hello from clojure... x))) --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Re: generated class with overloaded methods
On Feb 13, 9:59 am, Laurent PETIT laurent.pe...@gmail.com wrote: Your example code below is not complete (where's helloSuper definition ?), Yes, it is complete. See :exposes-methods under (doc gen-class). helloSuper is the exposed name for the hello method in the superclass. Clojure creates that method for you. -Craig --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Re: generated class with overloaded methods
Didn't know, thank you again for this knowledge, -- laurent 2009/2/13 Craig McDaniel craig...@gmail.com On Feb 13, 9:59 am, Laurent PETIT laurent.pe...@gmail.com wrote: Your example code below is not complete (where's helloSuper definition ?), Yes, it is complete. See :exposes-methods under (doc gen-class). helloSuper is the exposed name for the hello method in the superclass. Clojure creates that method for you. -Craig --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Re: generated class with overloaded methods
Yes, but please note that Christophe's method also solves the problem of defining overloaded methods with different java signatures, but still same name and same arity. I still can't see how your proposed method solves this particular problem ? Regards, -- Laurent 2009/2/13 Craig McDaniel craig...@gmail.com Both my method (multi-arity) and Christophe's method (overridden method names contain arguments) do work. I tested them both with the code posted. -Craig --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Re: generated class with overloaded methods
On Feb 12, 6:12 pm, Laurent PETIT laurent.pe...@gmail.com wrote: Do you know if there's a way to overload methods with the same arity, then ? I'm thinking about .read(char ) .read(byte ) .read(String ) .read(Integer ) ... for example, ? I think they're all the same method, from the Clojure point of view. If you want different behavior, you have to check the type in your function or use a multimethod. -Stuart Sierra --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---