On 30 Sep 2010, at 11.36 am, K. wrote: > Can somebody explains me why the instance? function accepts one > argument whereas the documentation states "Usage: (instance? c x)"
What an interesting question. If you try and emulate the behaviour yourself by creating a separate fn with a different name, it works as you might expect: (def ^{:arglists '([^Class c x]) :doc "Evaluates x and tests if it is an instance of the class c. Returns true or false" :added "1.0"} eggs? (fn eggs? [^Class c x] (. c (isInstance x)))) #'user/eggs? user=> (eggs?) IllegalArgumentException Wrong number of args (0) passed to: user$eggs-QMARK- clojure.lang.AFn.throwArity (AFn.java:439) user=> (eggs? Integer) IllegalArgumentException Wrong number of args (1) passed to: user$eggs-QMARK- clojure.lang.AFn.throwArity (AFn.java:439) user=> (eggs? java.lang.Long 1) true This fn must be created deep down in the guts of the Clojure implementation where things are murky and magical... I assume that x defaults to nil in the case where the number of args passed to instance? is less than the required arity (2). However, that's just a guess... Can anyone shed some more light? Sam --- http://sam.aaron.name -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en