While playing with Clojure, I noticed that ('+ 2 2) did not give an error, as I expected - it returns 2. I spent several minutes playing around:
(def f (cast clojure.lang.IFn 'a-symbol))
(f 5) ;; => nil
(f 5 5) ;; => 5
(f 5 5 5) ;; ArityException Wrong number of args (3) passed to: Symbol
(f "hey") ;; => nil
(f "foo" "bar") ;; => "bar"
(f "foo" "bar" "baz") ;; => ArityException Wrong number of args (3) passed to: Symbol
As far as I can tell, the characters are passed to some function called Symbol, which takes two arguments and returns the second. I assume this has something to do with implementing a character class?
source
share