On Fri, Jun 17, 2011 at 2:59 AM, de1976 <davidescobar1...@gmail.com> wrote: > Hi everyone. Ran into an interesting case here when trying stuff out > in the REPL. > > user=> (Math/sqrt 4) > 2.0 > > user=> (map #(Math/sqrt %) (range 1 10)) > (1.0 1.4142135623730951 ......) > > user=> (map Math/sqrt (range 1 10)) > java.lang.Exception: Unable to find static field: sqrt in class > java.lang.Math (NO_SOURCE_FILE: 2) > > Shouldn't it be possible to apply Math/sqrt directly? If I use a > function from the clojure.core, I can do it: > user=> (map str (range 1 10)) > ("1" "2" "3" "4" "5" "6" "7" "8" "9")
Java methods aren't first-class functions, so they can't be mapped, or used directly in filter or partition-by or similarly. But as you've found you can wrap one in a closure to use it. -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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