Re: Something missing from the clojure compiler's java annotation support for gen-class and defrecord? Am I driving while bouncing off the guard rails?
I'm not sure deftype handles annotations on *parameters* of constructors. I'd be pleasantly surprised to be shown it does though. I think Stuart's workaround should work, though I think I might have to make my Java adaptor extend my Clojure gen-class rather than the other way around. On Sep 23, 3:42 pm, Tarantoga d.bushe...@gmail.com wrote: Deftype handles annotations and all the other features of java classes. Have a look here for an example:http://translate.google.com/translate?sl=autotl=enjs=nprev=_thl=e... On Sep 23, 10:11 pm, Warren Wood warrenthomasw...@yahoo.com wrote: Excellent, thanks! And thanks for sharing the taxi from Strange Loop to STL tuesday night! :) On Sep 23, 2:07 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: Hi Warren, Clojure doesn't try to be support every possible feature of Java when generating Java classes, it just provides enough for interop purposes. Annotations have always been a weak area. I don't know if annotations on constructor arguments in `gen-class` are supported, but my suspicion is they are not. A patch would be possible - the `gen-class` code is written mostly in Clojure. But the easier solution for now would be to write a small class in Java and `:extend` it in your gen-class. -Stuart Sierra clojure.com -- 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
Something missing from the clojure compiler's java annotation support for gen-class and defrecord? Am I driving while bouncing off the guard rails?
Ideally when generating a java class from Clojure for interop purposes, we should be able to generate any annotations that the equivalent java code could generate. Thus if a java class can annotate a constructor parameter, then gen-class and defrecord should be able to do that too. (I'm trying to interoperate with some Spring Framework stuff that expects to inject stuff into my class via an annotated constructor parameter. I'm trying to gradually introduce clojure code into the project starting with this one class that has that requirement. Maybe that's not a good idea to begin with, but I always find it very tempting. It's probably a case of driving while bouncing off the guard rails. :)) Did I put my constructor annotation in the wrong place in my example below? I also tried putting directly on the parameter of the -init function. If this is truly missing functionality, I may try to level up enough to patch the clojure compiler, send in a CA, submit a pull request... But I think I have a ways to go to level up my clojure to that level. Many thanks in advance for any insights/feedback from the wonderful clojure community. (ns com.warrenthomaswood.MyGenClass (:gen-class :methods [[foo [^{Deprecated true} String] void]] :init init :constructors {[^{Deprecated true} String] []})) (defn -init [word] (println word)) (defn -foo [this word] (println word)) ;;; given the above clojure-generated class MyGenClass, and a plain java class MyClass with a ;;; constructor parameter annotation as follows: package com.warrenthomaswood; public class MyClass { public MyClass(@Deprecated String s) { } } ;;; when I try to retrieve the annotations in a JUnit test, I can retrieve the method parameter ;;; annotation from the clojure generated class using MyGenClass.class.getMethods() and then calling ;;; getAnnotations() on the method. ;;; I can retrieve the constructor parameter annotation from the java generated class using ;;; MyClass.class.getConstructors() and then calling getAnnotations on the constructor ;;; but the clojure compiler does not seem to have a way of getting the constructor parameter ;;; annotation into the byte code. I can get annotations on the whole constructor I think, but ;;; not on the individual parameters of the construct. -- 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
Re: Something missing from the clojure compiler's java annotation support for gen-class and defrecord? Am I driving while bouncing off the guard rails?
Excellent, thanks! And thanks for sharing the taxi from Strange Loop to STL tuesday night! :) On Sep 23, 2:07 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: Hi Warren, Clojure doesn't try to be support every possible feature of Java when generating Java classes, it just provides enough for interop purposes. Annotations have always been a weak area. I don't know if annotations on constructor arguments in `gen-class` are supported, but my suspicion is they are not. A patch would be possible - the `gen-class` code is written mostly in Clojure. But the easier solution for now would be to write a small class in Java and `:extend` it in your gen-class. -Stuart Sierra clojure.com -- 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
Re: Clojure 1.2 Release
Can we get a status update on that :) ? On Aug 19, 3:22 pm, Mark Derricutt m...@talios.com wrote: I think I can do that - or at least push that along. Will check into it when I get to the office in about 30 minutes. PS: Direct sync to central is easy via oss.sonatype.org repositories. -- Pull me down under... On Fri, Aug 20, 2010 at 6:42 AM, Stuart Sierra the.stuart.sie...@gmail.comwrote: We don't have a direct sync to Maven central. They don't seem to be giving those out anymore. So someone with the authority will have to upload it manually. :( -- 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
ClassCastException from RT.java in Day Communique
The cast in the following method from RT.java throws a ClassCastException when trying to compile Clojure within the Day Communique 4.2.1 content management system. Any suggestions? thanks, Warren static public long lastModified(URL url, String libfile) throws Exception{ if(url.getProtocol().equals(jar)) { return ((JarURLConnection) url.openConnection()).getJarFile().getEntry (libfile).getTime(); } else { return url.openConnection().getLastModified(); } } -- 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
Re: ClassCastException from RT.java in Day Communique
Here is what the exception says : Caused by: java.lang.RuntimeException: java.lang.ClassCastException: com.day.cq.net.jar.ContentBusJarURLConnection cannot be cast to java.net.JarURLConnection at clojure.lang.RT.clinit(RT.java:291) On Jan 6, 3:11 pm, Warren Wood warrenthomasw...@yahoo.com wrote: The cast in the following method from RT.java throws a ClassCastException when trying to compile Clojure within the Day Communique 4.2.1 content management system. Any suggestions? thanks, Warren static public long lastModified(URL url, String libfile) throws Exception{ if(url.getProtocol().equals(jar)) { return ((JarURLConnection) url.openConnection()).getJarFile().getEntry (libfile).getTime();} else { return url.openConnection().getLastModified(); } } -- 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
Re: newbie question
On Nov 6, 12:10 pm, John Harrop jharrop...@gmail.com wrote: On Fri, Nov 6, 2009 at 1:07 PM, John Harrop jharrop...@gmail.com wrote: On Fri, Nov 6, 2009 at 1:01 PM, Warren Wood warrenthomasw...@yahoo.comwrote: In the meantime, I came up with the following, which seems to work. I'm sure it can be improved. (defn NOT [pred] (fn [x] (not (pred x ... Which leads me to another question, are there standard functions sitting around somewhere already to do boolean combinations of predicates (conjoin, disjoin, negate perhaps?)? Like my NOT above. How about complement? user= (def x (complement even?)) #'user/x user= (x 4) false user= (x 3) true And WHAT the devil is with complement's messy implementation? (defn complement [f] (comp not f)) seems much cleaner. :) Ok, I'm embarrassed that I didn't find complement. I know I had known about it at one time. I think I had been wondering about versions of union and intersection that would apply to predicates as well as sets, since mathematically a predicate can be deemed as defining the set of all things for which it is true. I was thinking of a procedure like AND (again probably not a great name... maybe conjunction would be better). I don't think anything like comp can be used in this case since and is a macro. (defn AND [f g] (fn [x] (and (f x) (g x Is there any standard function like THAT? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: newbie question
Thanks, that was indeed helpful! On Nov 6, 6:47 pm, Alex Osborne a...@meshy.org wrote: Alex Osborne wrote: Like Mark's but using split-with instead of split-at: (defn partition-when [pred coll] (lazy-seq (when-let [[x xs] (seq coll)] (let [[xs ys] (split-with (complement pred) xs)] (cons (cons x xs) (partition-when pred ys)) Just realised this is almost the same as Warren's -- I had missed reading Warren's before posting. Thought it might be helpful if I explain the differences: * lazy-seq on the outside of the conditional. This means the seq is fully lazy, so if you never call first/next on it, nothing is ever run. * As suggested by others complement instead of NOT. * (when (seq coll) ...) instead of (if (empty? coll) () ...). We can simplify things like this as (lazy-seq nil) = () and (seq ()) = nil. * Using destructuring instead of (first coll) (next coll). Makes it a bit shorter and is quite useful if you're going to use the result of (first coll) or (next coll) multiple times, but in this case it doesn't really matter. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: newbie question
Thought of this, which I like better. Again, I'm surprised if conjunction is not already a standard function, but I can't find it. I'm still a bit tempted to call it AND for readabilty of code. (I spent some time studying combinatory logic back in the day. (I even had a Curry Fellowship at Penn State where Haskell Curry used to work.) Can't remember what combinator letter my dual function is.) (defn dual [x] (fn [f] (f x))) (defn conjunction [ preds] (fn [x] (every? (dual x) preds))) (filter (conjunction even? (partial = 16) (partial = 9)) (range 1 20)) evaluates to (10 12 14 16) On Nov 7, 9:39 pm, Warren Wood warrenthomasw...@yahoo.com wrote: On Nov 6, 12:10 pm, John Harrop jharrop...@gmail.com wrote: On Fri, Nov 6, 2009 at 1:07 PM, John Harrop jharrop...@gmail.com wrote: On Fri, Nov 6, 2009 at 1:01 PM, Warren Wood warrenthomasw...@yahoo.comwrote: In the meantime, I came up with the following, which seems to work. I'm sure it can be improved. (defn NOT [pred] (fn [x] (not (pred x ... Which leads me to another question, are there standard functions sitting around somewhere already to do boolean combinations of predicates (conjoin, disjoin, negate perhaps?)? Like my NOT above. How about complement? user= (def x (complement even?)) #'user/x user= (x 4) false user= (x 3) true And WHAT the devil is with complement's messy implementation? (defn complement [f] (comp not f)) seems much cleaner. :) Ok, I'm embarrassed that I didn't find complement. I know I had known about it at one time. I think I had been wondering about versions of union and intersection that would apply to predicates as well as sets, since mathematically a predicate can be deemed as defining the set of all things for which it is true. I was thinking of a procedure like AND (again probably not a great name... maybe conjunction would be better). I don't think anything like comp can be used in this case since and is a macro. (defn AND [f g] (fn [x] (and (f x) (g x Is there any standard function like THAT? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---