A type hint makes no difference because the param "state" is treated as an Object instance. user=> (:x @*aa*) 3 user=> (.invoke :x @*aa*) ; [16] invoke : Object (Object) 3
Besides, I don't think it's a good idea trying to setup some sort of static type-checker and strongly-typed functions. You're bound to shoot yourself somewhere else. On Apr 21, 12:39 am, Albert Cardona <sapri...@gmail.com> wrote: > 2011/4/21 Tzach <tzach.livya...@gmail.com>: > > > > > > > I made a stupid mistake, and I want to share. This is not the actual code, I > > simplify it to demonstrate the point. > > > I use a atom to a global hash as follow: > > > (def *aa* (atom {:x 3 :y 4 :z 17})) > > > Somewhere on the code, I have a function which look at the state and do > > something: > > > (defn foo [state] > > > (when (:x state) print "yes")) > > > My mistake - call foo as: > > > (foo *aa*) > > > where I should have call it > > > (foo @*aa*) > > > Since (:x (atom *aa*)) is nil, print was not execute. > > > 4 long hours later, I got it, fix it, and added the appropriate > > precondition. > > > I understand there is no escape from my own silliness, but could I have > > avoided this mistake to begin with? > > > Any best practice I broke? > > The compiler could have pointed out the error if you had given a type > to the argument such as ^Map. > > (That is my main use for types: to prevent shooting myself on the foot > like you did.) > > Albert > > --http://albert.rierol.net- Hide quoted text - > > - Show quoted text - -- 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