A function can have multiple signatures if the signatures differ in arity. You can use that to supply default values.
(defn string->integer
([s] (string->integer s 10))
([s base] (Integer/parseInt s base)))
Note that assuming false
and nil
are both considered non-values, (if (nil? base) 10 base)
could be shortened to (if base base 10)
, or further to (or base 10)
.
Brian Carper
2010-07-08 22:10:18