Skip to content

Instantly share code, notes, and snippets.

@bnyeggen
Created February 2, 2013 21:13
Show Gist options
  • Select an option

  • Save bnyeggen/4699262 to your computer and use it in GitHub Desktop.

Select an option

Save bnyeggen/4699262 to your computer and use it in GitHub Desktop.

Revisions

  1. bnyeggen created this gist Feb 2, 2013.
    19 changes: 19 additions & 0 deletions hinttype.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    (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