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

0 votes
in ClojureScript by

For defns with a variadic arity: if invoked with a missing fixed arity, they use the variadic method instead of erroring; if invoked with a fixed arity that is the max fixed arity, variadic mathod instead of fixed form is invoked.

(defn f-hole
([a] 1)
([a b c d & args] "4 or more"))

(f-hole 1 2) ; =>"4 or more", should be error

(defn f-overlap-mfa
([a b] 2)
([a b & c] "2+"))

(f-overlap-mfa 1) ;=> "2+", should be error
(f-overlap-mfa 1 2) ;=> "2+", should be 2
(f-overlap-mfa 1 2 3) ;=> "2+", correct

A way to fix the f-hole bug is to emit a "case X:" into the switch statement for all X with no signature or less than max-fixed-arity.

The f-overlap-mfa I'm not sure why is happening and didn't investigate deeply.

3 Answers

0 votes

Comment made by: favila

Sorry, filed against CLJ instead of CLJS!

0 votes

Comment made by: rohitaggarwal

The behaviour I am seeing for {{f-overlap-mfa}} is:

(f-overlap-mfa 1) ;=> "2+" (f-overlap-mfa 1 2) ;=> 2 (f-overlap-mfa 1 2 3) ;=> "2+"

So the two argument result is different for me than you, (link: ~favila).

The call with just one argument does give a warning though:

{{WARNING: Wrong number of args (1) passed to cljs.user/f-overlap-mfa}}

0 votes
Reference: https://clojure.atlassian.net/browse/CLJS-1678 (reported by favila)