lambdaisland

plexus 2020-12-09T06:24:04.045700Z

Streaming in a few moments: https://youtu.be/YHkYp0378Uo

plexus 2020-12-09T07:18:03.045900Z

Recording: https://youtu.be/7gp4MZdCDQc

๐Ÿ‘ 1
pez 2020-12-09T11:30:29.047900Z

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

2020-12-09T11:33:52.048500Z

because Integer/parseInt compiler converts to static field accessor

2020-12-09T11:34:18.049100Z

and there is no such field in Integer class

pez 2020-12-09T12:30:32.050700Z

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

2020-12-09T12:35:03.052400Z

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

pez 2020-12-09T14:25:18.055Z

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.

pez 2020-12-09T14:31:39.056300Z

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

borkdude 2020-12-09T14:31:55.056700Z

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

pez 2020-12-09T14:32:59.057600Z

Yes, that is what I do. (The latter one) ๐Ÿ˜ƒ . Iโ€™m just trying to understand why I have to.

borkdude 2020-12-09T14:34:02.058800Z

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

2020-12-09T14:34:25.059400Z

https://clojure.org/reference/java_interop#_alternative_macro_syntax also in guide there is a note about using memfn Note it almost always preferable to do this directly now, with syntax like:

๐Ÿ’ฏ 1
pez 2020-12-09T14:34:39.059900Z

Thanks for memfn !

borkdude 2020-12-09T14:35:10.060100Z

yeah, consider it dead

pez 2020-12-09T14:36:10.060600Z

Just when I got to know of it it died.

borkdude 2020-12-09T14:37:13.060900Z

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

๐Ÿ˜† 1
pez 2020-12-09T14:39:01.061700Z

You should write a We didnโ€™t start the fire with Clojure context. ๐Ÿ˜‚

oxalorg (Mitesh) 2020-12-09T14:41:46.063100Z

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

๐Ÿ‘ 1
plexus 2020-12-09T14:42:17.063900Z

> (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.

plexus 2020-12-09T14:43:41.065200Z

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

๐Ÿ’ฏ 3
โค๏ธ 1