Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

In cljs:

ClojureScript 1.10.238
app:cljs.user=> (defn f [a] a) (f)
#'cljs.user/f
----  Compiler Warning on   <cljs form>   line:1  column:2  ----

  Wrong number of args (0) passed to cljs.user/f

  1  (f)
     ^--- 

----  Compiler Warning  ----
nil
app:cljs.user=> (defn f [a] a) (apply f [])
#'cljs.user/f
nil

In clj:

> (defn f [a] a) (f)
#'redacted.ns/f
Execution error (ArityException) at redacted.ns/eval28662 (form-init217321140160545149.clj:2261).
Wrong number of args (0) passed to: redacted.ns/f
> (defn f [a] a) (apply f [])
#'redacted.ns/f
Execution error (ArityException) at redacted.ns/eval28665 (form-init217321140160545149.clj:2265).
Wrong number of args (0) passed to: redacted.ns/f

In cljs, apply silently returns nil, while in clj, an ArityException is thrown.

1 Answer

+1 vote
by

This is a host environment difference. JS functions never throw when called with too few or too many arguments. CLJS does not try to change this.

by
In direct function calls, cljs can warn you about that. But you can turn off the warning and the code still compiles
But indirect calls, like apply, or even map, the compiler can't infer it.
by
That's a good addition, thanks.
...