In clojure,
(assoc {})
throws an arity exception, but
(dissoc {})
does not. Why? I would have expected either both of them to throw an exception, or both to make no changes when no keys or values are provided.
EDIT: I see a rationale for allowing these forms; it means we can apply assoc or dissoc to a possibly empty list of arguments. I just don't see why one would be allowed and the other not, and I'm curious as to whether there's a good reason for this that I'm missing.
I personally think the lack of 1-arity assoc is an oversight: whenever a trailing list of parameters is expected (& stuff
), the function should normally be capable of working with zero parameters in order to make it possible to apply
it to an empty list.
Clojure has plenty of other functions that work correctly with zero arguments, e.g. +
and merge
.
On the other hand, Clojure has other functions that don't accept zero trailing parameters, e.g. conj
.
So the Clojure API is a bit inconsistent in this regard.....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With