Skip to content

Instantly share code, notes, and snippets.

@bkyrlach
Created July 14, 2012 13:55
Show Gist options
  • Select an option

  • Save bkyrlach/3111475 to your computer and use it in GitHub Desktop.

Select an option

Save bkyrlach/3111475 to your computer and use it in GitHub Desktop.
Understanding Clojure functions...
(defn foo
([a b] (println "bar"))
([a b c] (println "foobar")))
;#'user/foo
(foo 1 2)
;bar
;nil
(foo 1 2 3)
;foobar
;nil
(foo 1)
;ArityException Wrong number of args (1) passed to: core$foo clojure.lang.AFn.throwArity (AFn.java:437)
(foo 1 2 3 4)
;ArityException Wrong number of args (4) passed to: core$foo clojure.lang.AFn.throwArity (AFn.java:437)
(if false (foo 1 2) (foo 1))
;ArityException Wrong number of args (1) passed to: core$foo clojure.lang.AFn.throwArity (AFn.java:437)
(defn bar [runme] (if runme (foo 1 2) (foo 1)))
;#'user/bar
(bar true)
;bar
;nil
(bar false)
;ArityException Wrong number of args (1) passed to: core$foo clojure.lang.AFn.throwArity (AFn.java:437)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment