Skip to content

Instantly share code, notes, and snippets.

@tomjack
Created September 4, 2010 18:19
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 tomjack/cf84a59543e31f42d2a2 to your computer and use it in GitHub Desktop.
Save tomjack/cf84a59543e31f42d2a2 to your computer and use it in GitHub Desktop.
user> (defmacro definttype [name n] `(defrecord ~name [~@(map (comp symbol str) (range n))]))
#'user/definttype
user> (macroexpand-1 '(definttype Foo 3))
(clojure.core/defrecord Foo [0 1 2])
user> (definttype Foo 3)
user.Foo
user> (Foo. :a :b :c)
#:user.Foo{:0 :a, :1 :b, :2 :c}
user> (:0 (Foo. :a :b :c))
:a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment