compiler option | since v0.0-1424 | Edit |
Controls how multi-arity function calls are generated. A "static" call
means the dispatch to the appropriate arity is handled at compile time (better
performance), whereas a "dynamic" call means the dispatch is handled at run time
(allows safer redefinition in REPL). Static is enabled by default in advanced
:optimizations
.
:static-fns true
See Static-Free ClojureScript REPL for details.
With the following multi-arity function foo
:
(defn foo
([] "zero")
([x] "one")
([x & y] "multi"))
When static is disabled,:
;; compiles to...
(foo) ;; foo.call(null)
(foo 1) ;; foo.call(null,(1))
(foo 1 2) ;; foo.call(null,(1),(2))
When static is enabled:
;; compiles to...
(foo) ;; foo..._arity$0()
(foo 1) ;; foo..._arity$1((1))
(foo 1 2) ;; foo..._arity$variadic((1),cljs.core.array_seq([(2)], 0))
If foo
was redefined to have an arity removed, any previous static calls to
the removed arity would be broken, whereas previous dynamic calls would
remain working as expected.