Fork me on GitHub

Streaming in a few moments:


If you have time for a newb question in some of your AoC live broadcasts: Why can’t I (map Integer/parseInt coll)? The error message confuses me too:

CompilerException java.lang.RuntimeException: Unable to find static field: parseInt in class java.lang.Integer


because Integer/parseInt compiler converts to static field accessor


and there is no such field in Integer class


Thanks. So the compiler does something else with (Integer/parseInt coll), then, right?


right, first of all compiler will try to identify symbol Integer/parseInt in some context. In case of (Integer/parseInt x) it will be recognized as method call


Are there some “native” Clojure objects with similar treatment? I’ve been working in cljc land mostly, and then mostly on the cljs side of things, so not all that much Java interop. Part of what AoC does for me is to get some more of the JVM experience.


(So, for instance, in cljs (map js/String.fromCharCode [65 66 67]) is perfectly fine. Or (map js/parseInt ["1" "-1"]), for that matter.)


@pez clojure has a macro called memfn but hardly anyone I know uses it. So you just gotta do (map #(Integer/parseInt %) ...)


Yes, that is what I do. (The latter one) 😃 . I’m just trying to understand why I have to.


memfn also is only for instances, not static calls, but anyway, it's not used much

delaguardo14:12:25 also in guide there is a note about using memfn Note it almost always preferable to do this directly now, with syntax like:

💯 3

Thanks for memfn !


yeah, consider it dead


Just when I got to know of it it died.


We're just guiding you through the history of Clojure real quick

😆 3

You should write a We didn’t start the fire with Clojure context. 😂

oxalorg (Mitesh)14:12:46

Something interesting I tried on the repl:

user=> (macroexpand-all '(map Integer/parseInt ["1" "2"]))
(map Integer/parseInt ["1" "2"])
user=> (macroexpand-all '(map #(Integer/parseInt %) ["1" "2"]))
(map (fn* [p1__149#] (. Integer parseInt p1__149#)) ["1" "2"])
user=> (macroexpand-all '(Integer/parseInt "2"))
(. Integer parseInt "2")
The first call didn't expand into anything, whereas the last call did. So in the first one clojure expects it to be a static field which it is not

👍 3

> (map js/String.fromCharCode [65 66 67]) In JS that makes sense because all functions are firstclass, in Java Integer/parseInt doesn't mean anything, you can't just get a function handle/lambda like that. You could get a method object through reflection but it's not trivial.


or to put it differently, if you write Integer/parseInt in Java without an argument list, then that implies that you are looking for a static variable, not for a method. Clojure continues that distinction, Foo/bar vs (Foo/bar ...) hence the error Unable to find static field

💯 9
❤️ 3