Bug in clojure.java.io
Hi, I noticed a bug in the clojure.java.io namespace at Line 57: URL (as-url [u] u) (as-file [u] (if (= file (.getProtocol u)) (as-file (.getPath u)) -- (throw (IllegalArgumentException. Not a file: u ++ (throw (IllegalArgumentException. (str Not a file: u) Right now it throws the error: Caused by: java.lang.ClassCastException: java.net.URL cannot be cast to java.lang.Throwable at clojure.java.io$fn__7354.invoke(io.clj:56) at clojure.java.io$fn__7328$G__7323__7333.invoke(io.clj:34) Should I report this bug on Asembla? Regards, Abhinav -- 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: Removed Clojure binaries from contrib 'complete' jar
I think what Stuart meant is that the class files compiled from the core clojure library will not be incide the clojure contrib uberjar. Only the class files compiled from the clojure contrib libs will be in there. On Wed, Aug 25, 2010 at 8:20 AM, ataggart alex.tagg...@gmail.com wrote: Pardon the silly question, but if it doesn't contain any AOT compiled .class files, then is it a de facto source jar? On Aug 24, 2:56 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: I've updated the clojure-contrib build to create the uberjar at modules/complete/target/complete-1.3.0-SNAPSHOT-bin.jar WITHOUT the Clojure .class build files included. This is a binary-only JAR right now. I will look into building a JAR that includes the clojure-contrib source files. -S -- 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.comclojure%2bunsubscr...@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 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
Wrong package name of record classes
Hi, I noticed that when I define a record (using defrecord) in a namespace having hyphen in its name (like abc.d-ef) and compile the clj file using AOT, a class file corresponding to the record defined is created in the package with the name same as the namespace it is defined in, with hyphen (in this case abc.d-ef) whereas everything else goes in the package with the name of the namespace with hyphens replaced by underscore (in this case abc.d_ef). This seems like a bug to me. Just wanted to confirm here before reporting. Cheers, Abhinav -- 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: Speeding up equals using the cached hash code?
If two objects are equal, they must have same hash code. But it does not imply the other way too. Two objects having the same hash code may be not equal (see, hash collision). So this approach may give false positives. - Abhinav On Thu, Aug 5, 2010 at 1:45 PM, Nicolas Oury nicolas.o...@gmail.com wrote: That's might be an interesting trade-of to try. It is really good when big data structures are nearly equal. The comparison is linear but the comparaison once you know the hash is O(1) with a high probability. It is bad on very different structure, if you force a hash. Ideally, the equals method could hash as it goes. When 2 structures are equal, their hashes would be known. If not, by comparing the numbero fo elments hashed to the count, the implementation could decide whether or not to continue hashing... On Wed, Aug 4, 2010 at 10:40 PM, sune.simonsen sune.simon...@gmail.com wrote: I was looking around the Clojure source code and noticed that the persistent immutable collections caches their hash codes. The java doc says the following about the equals method: (http:// download.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html) If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. So I was thinking, wouldn't it be possible to use the cached hash code to rule out cases of equals where equals returns false? public boolean equals(Object obj){ ... if (_hash != -1 hashCode() != obj.hashCode()) { return false; } ... } This might of cause result in an extra call to hashCode(), so I don't know if it is worth it. Maybe some internal functionality could be added, to ask the collections if their hash code has been cached. What are your thoughts? Kind regards Sune Simonsen -- 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.comclojure%2bunsubscr...@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 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.comclojure%2bunsubscr...@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 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: How to do multiple trys
Thanks to everyone for their suggestions. This is what I have used finally: (defn parse-date [date-str] (when-not (blank? date-str) (let [clean-date-str (trim date-str) parse-or-nil (fn [format] (try (.parse format clean-date-str) (catch java.text.ParseException e nil)))] (some parse-or-nil [full-date-format date-format-wo-tz short-date-format-wo-tz] Using some is better than using map because it will stop at the first successful parsing. Regards, Abhinav On Sat, Jul 31, 2010 at 3:05 AM, ataggart alex.tagg...@gmail.com wrote: Untested, but maybe this: (def- parse-date [date-str] (when-not (blank? date-str) (let [date-str (trim date-str)] (take 1 (filter identity (map #(try (.parse % date-str) (catch ParseException e nil)) [full-date-format date-format-wo-tz short-date-format-wo- tz])) WARNING: SimpleDateFormat is not thread-safe, so it's probably a bad idea to stick one in a shared context like def. On Jul 29, 10:35 pm, abhinav sarkar abhinav.sar...@gmail.com wrote: Hi, I am just starting to learn Clojure by writing a small library. I came across a situation in which I have to parse a String for getting a Date. Now the string can be in one of the three formats. So I wrote this functions to parse it: (def #^{:private true :tag SimpleDateFormat} full-date-format (doto (SimpleDateFormat. EEE, dd HH:mm:ss +) (.setTimeZone (TimeZone/getTimeZone GMT (def #^{:private true :tag SimpleDateFormat} date-format-wo-tz (doto (SimpleDateFormat. EEE, dd HH:mm:ss) (.setTimeZone (TimeZone/getTimeZone GMT (def #^{:private true :tag SimpleDateFormat} short-date-format-wo-tz (doto (SimpleDateFormat. dd MMM , HH:mm) (.setTimeZone (TimeZone/getTimeZone GMT (defn- parse-date [date-str] (if (some #(% date-str) [nil? blank?]) nil (let [clean-date-str (trim date-str)] (try (.parse full-date-format clean-date-str) (catch java.text.ParseException e (try (.parse date-format-wo-tz clean-date-str) (catch java.text.ParseException e (.parse short-date-format-wo-tz clean-date-str I can't help but think that there must be a better way to do the same without so many nested try catch blocks. If this were Java, I could have looped over all the date formats and used an explicit return in the try block and continue in catch block. I don't understand how to do explicit return in Clojure. Also as the number of formats grows, I'll have to add more nested try catch blocks. Please suggest a cleaner way to do this. Regards, Abhinav -- 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.comclojure%2bunsubscr...@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 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
How to do multiple trys
Hi, I am just starting to learn Clojure by writing a small library. I came across a situation in which I have to parse a String for getting a Date. Now the string can be in one of the three formats. So I wrote this functions to parse it: (def #^{:private true :tag SimpleDateFormat} full-date-format (doto (SimpleDateFormat. EEE, dd HH:mm:ss +) (.setTimeZone (TimeZone/getTimeZone GMT (def #^{:private true :tag SimpleDateFormat} date-format-wo-tz (doto (SimpleDateFormat. EEE, dd HH:mm:ss) (.setTimeZone (TimeZone/getTimeZone GMT (def #^{:private true :tag SimpleDateFormat} short-date-format-wo-tz (doto (SimpleDateFormat. dd MMM , HH:mm) (.setTimeZone (TimeZone/getTimeZone GMT (defn- parse-date [date-str] (if (some #(% date-str) [nil? blank?]) nil (let [clean-date-str (trim date-str)] (try (.parse full-date-format clean-date-str) (catch java.text.ParseException e (try (.parse date-format-wo-tz clean-date-str) (catch java.text.ParseException e (.parse short-date-format-wo-tz clean-date-str I can't help but think that there must be a better way to do the same without so many nested try catch blocks. If this were Java, I could have looped over all the date formats and used an explicit return in the try block and continue in catch block. I don't understand how to do explicit return in Clojure. Also as the number of formats grows, I'll have to add more nested try catch blocks. Please suggest a cleaner way to do this. Regards, Abhinav -- 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