Skip to content

Instantly share code, notes, and snippets.

@bnyeggen
Created February 2, 2013 21:13
Show Gist options
  • Save bnyeggen/4699262 to your computer and use it in GitHub Desktop.
Save bnyeggen/4699262 to your computer and use it in GitHub Desktop.
Macro-generated deftype with type-hinted fields.
(defmacro hinttype
[type-name & hint-symbols]
`(deftype ~type-name
[~@(for [s hint-symbols]
(with-meta (gensym "a")
{:tag (case s
:int 'int
:long 'long
:float 'float
:double 'double
:char 'char
:short 'short
:boolean 'boolean
:byte 'byte
'Object)}))]))
(hinttype alpha :int :long :double)
(alpha. 1 2 3) ;success
(alpha. "hi" 2 3) ;failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment