This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-09
Channels
- # adventofcode (197)
- # announcements (25)
- # aws (1)
- # babashka (21)
- # beginners (138)
- # calva (21)
- # cider (5)
- # clara (1)
- # clj-kondo (35)
- # clojure (97)
- # clojure-australia (4)
- # clojure-dev (37)
- # clojure-europe (100)
- # clojure-nl (2)
- # clojure-spec (7)
- # clojure-uk (36)
- # clojurescript (11)
- # conjure (15)
- # cursive (20)
- # datomic (12)
- # emacs (10)
- # events (2)
- # fulcro (83)
- # graalvm (14)
- # jobs (1)
- # jobs-discuss (27)
- # kaocha (75)
- # lambdaisland (21)
- # off-topic (27)
- # pedestal (5)
- # reitit (2)
- # reveal (20)
- # rewrite-clj (24)
- # sql (9)
- # tools-deps (37)
- # xtdb (93)
Streaming in a few moments: https://youtu.be/YHkYp0378Uo
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
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.
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:
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