On Thu, Jun 25, 2009 at 2:20 AM, Timothy Pratley<timothyprat...@gmail.com> wrote: > > Here are some of my common mistakes: > > user=> (def data (ref {})) > #'user/data > user=> (dosync alter data assoc :a "a") > "a" > user=> (dosync (alter data assoc :a "a")) > {:a "a"} > ;; leaving out the parenthesis on a dosync can be silent and fatal, > like a ninja
Interesting. Can there ever be a purpose in having something other than a list before the tail position of a 'do'? Hm, I suppose you could make calls that have side-effects within a map or vector literal, although that would be weird since the map or vector itself would be thrown away: (do [(println "why??")] 5) So even if the compiler ought to let that pass, is there ever a purpose in having a bare symbol before the tail position of a 'do'? (do samurai 10) It might be nice to get a "useless bare symbol" warning in cases like this. I'd be happy to try to write a patch for this if one is welcome. > (if-let [a 1] > (println a) > a > (inc c)) > java.lang.IllegalArgumentException: if-let requires a vector for its > binding (NO_SOURCE_FILE:0) > ;; rather cryptic errors from if-let when not quite right, like an > illusionist using misdirection to awe the audience This message is the result of an earlier attempt at specific and helpful error messages. It is based on the assumption that you're trying to use an old form of if-let: (if-let [a b] my-pair a (inc c)) java.lang.IllegalArgumentException: if-let requires a vector for its binding (NO_SOURCE_FILE:0) Would you recommend a more general and therefore more accurate message? Something like "your if-let syntax is incorrect"? > (javax.swing.UIManager/setLookAndFeel > javax.swing.UIManager/getSystemLookAndFeelClassName) > java.lang.Exception: Unable to find static field: > getSystemLookAndFeelClassName in class javax.swing.UIManager > (NO_SOURCE_FILE:7) > ;; this one drives me nuts, I forget to call the method > ;; if you don't read carefully it looks like maybe I just typoed the > long method name so I spend about 10minutes checking javadocs, cutting > and pasting, importing etc > ;; The error while correct seems a bit odd seeing Class/method looks a > method (though I understand why it isn't). So in this case the message is accurate but too general? These must be hard to get right! I suppose the compiler could look for a no-arg method by that name and suggest that specific cause in the message. > (java.lang.Math/abs 2/3) > java.lang.IllegalArgumentException: No matching method found: abs > (NO_SOURCE_FILE:0) > ;; abs wont work on ratios, but the error message doesn't give the > signature being sought. > ;; abs for java numbers exists, abs for ratios doesn't. > ;; It is not always obvious that 2/3 is a ratio if it is a passed in > variable. I agree that it'd be helpful to list the arg types passed in: "No 'abs' method found for [clojure.lang.Ratio]" I wouldn't expect this to be too hard to patch either. --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---