There's also this, I suppose:
(defn accepts-arity? [n f]
(try
(apply f (repeat n nil))
true
(catch IllegalArgumentException e
(not (.startsWith (.getMessage e) "Wrong number of args")))
(catch Throwable _
true)))
This directly tests for the exception that's generated if the arity is
wrong. Caveats:
1. It's somewhat evil; in particular it throws away all exceptions
generated and relies on the exact wording of the throw-arity
exception message text which is meant for humans and so probably
isn't considered part of the api per se. In particular it might
change, and this function might even stop working if you take it
outside of EN_us.
2. It calls the function, so that better not have side effects or take
forever to run (at least when called with nil arguments).
3. If the function, called with a valid arglist, can generate an IAE
that starts with "Wrong number of args" it could produce a false
negative. The likeliest source of these would be functions that
contain bugs of the form of having a nested function call with a
bad arity.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en