Skip to content

Instantly share code, notes, and snippets.

@timmc
Last active December 16, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmc/5366403 to your computer and use it in GitHub Desktop.
Save timmc/5366403 to your computer and use it in GitHub Desktop.
(ns adhoc.core)
(defn arity
[n]
(let [args (repeatedly n gensym)]
`([~@args] (println "args" ~@args))))
;; Seriously though, don't do this.
(defn magic
#=(arity 1)
#=(arity 3)
#=(arity 5))
(comment
(magic :a :b :c)
; args :a :b :c
;= nil
(magic :a :b :c :d)
;! ArityException Wrong number of args (4) passed to: core$magic clojure.lang.AFn.throwArity (AFn.java:437)
(magic :a :b :c :d :e)
; args :a :b :c :d :e
;= nil
(source magic)
; (defn magic
; #=(arity 1)
; #=(arity 3)
; #=(arity 5))
;= nil
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment