Hello, yes, you are right, for the change to be correct, instance? should not return false, but nil if it is not an instance. (nil is a logical false too).
But maybe, as was suggested by others, just having a variant of cast returning nil instead of throwing an exception (or making returning nil the new behavior of cast) could serve the purpose as well, and maybe even better. 2009/3/10 Tassilo Horn <tass...@member.fsf.org> > > Laurent PETIT <laurent.pe...@gmail.com> writes: > > Hi Laurent, > > > For this to work, instance? would have to return logical true instead > > of real true. > > I'm new to clojure, so please forgive any stupid questions. But you > mean that (instance? java.lang.Integer 17) should return 17 instead of > true, right? Seems plausible, but there's this corner case: > > (instance? java.lang.Boolean false) > > If it returned false, then instance? would be broken. So I guess the > current behavior is correct. Maybe this can act as a workaround: > > --8<---------------cut here---------------start------------->8--- > user> (defn maybe-print-int [n] > (when-let [i (and (instance? java.lang.Integer n) n)] > (println "Foo" i))) > #'user/maybe-print-int > user> (maybe-print-int 17) > Foo 17 > nil > user> (maybe-print-int "A String") > nil > --8<---------------cut here---------------end--------------->8--- > > Bye, > Tassilo > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---