This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-14
Channels
- # admin-announcements (5)
- # aws (3)
- # beginners (35)
- # boot (96)
- # cider (1)
- # clara (6)
- # cljs-dev (12)
- # cljsrn (34)
- # clojure (151)
- # clojure-boston (3)
- # clojure-brasil (4)
- # clojure-canada (1)
- # clojure-czech (8)
- # clojure-dusseldorf (11)
- # clojure-japan (5)
- # clojure-russia (120)
- # clojure-taiwan (1)
- # clojure-uk (3)
- # clojurescript (7)
- # component (27)
- # cursive (13)
- # data-science (45)
- # datomic (1)
- # devcards (5)
- # emacs (3)
- # funcool (65)
- # hoplon (103)
- # instaparse (3)
- # jobs (14)
- # jobs-discuss (1)
- # juxt (2)
- # lein-figwheel (2)
- # off-topic (16)
- # om (20)
- # onyx (49)
- # parinfer (17)
- # perun (1)
- # planck (5)
- # proton (4)
- # re-frame (14)
- # ring-swagger (4)
- # spacemacs (4)
- # untangled (110)
- # yada (14)
Something weird happens with static-fns true
In some cases, we end up using call
Look I discovered something weird with static-fns true Look here http://app.klipse.tech/?cljs_in=(defn%20foo%20%5B%5D%20%3Afoo)%0A%0A(defn%20bar%0A%20%20(%5B%5D%20%3Abar)%0A%20%20(%5Bx%5D%20x))%0A%0A%0A(foo)%0A(bar)%0A(bar%20%3Amy-bar)%0A%0A(def%20f%20foo)%0A(def%20g%20bar)%0A(f)%0A(g)%0A%0A&static-fns=true
is transpiled to
(f)` becomes (cljs.user.f.cljs$core$IFn$_invoke$arity$0 ? cljs.user.f.cljs$core$IFn$_invoke$arity$0() : cljs.user.f.call(null));
At run time, it will be cljs.user.f.call(null))
Because cljs.user.f.cljs$core$IFn$_invoke$arity$0
is undefined
while (g)
will be cljs.user.g.cljs$core$IFn$_invoke$arity$0()
It’s related to this part of the compiler code https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/compiler.cljc#L1008-L1013
it’s an optimization for higher order function calls where it’s not possible to know the arity statically
FWIW, I revised the else branch to look like f "(" (comma-sep args) "))”
and it works in this particular case and for the compiler unit tests (in other words, it blindly makes a static call if the desired arity is not found). Perhaps the assumption that it is a non-multi-arity function misses corner cases though, and even though :static-fns true
is enabled, it is safer to dynamically dispatch.