Ajay, > It tried the following in REPL and got no error. Personally, I feel that > I should get an error because calling square on strings is wrong in both > cases. > > Is there a way out of this in Clojure? > > |(defn square[n] (* n n)) > > (if (= 0 0) (println"hello") (map square["a" "b"])) >
What did you expect from Clojure? In the above form the `map` is a part of the else form and that's why it's not executed. If you don't know already, the syntax for `if` in Clojure is like this - (if expression (then form) (else form)) If you have multiple then or else forms, you can wrap them inside a `do` form like this - (if expression (do (then form) (more then form)) (else form)) > The following gives error (because it gets evaluated): > > |(defn square[n] (* n n)) > > (if (= 0 1) (println"hello") (map square["a" "b"])) In the above form, the map is a part of the else form and since 1 is not equal to 0, the `map` is executed. I hope your confusion is cleared. PS - If you are worried about "compile time type checking", I think it's prudent to mention now that Clojure is a dynamically typed programming language where types are checked at run-time and not compile time. Regards, BG -- Baishampayan Ghose <b.gh...@ocricket.com> oCricket.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