Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created July 19, 2011 15:22
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 jcromartie/f2e6713ba14261115dde to your computer and use it in GitHub Desktop.
Save jcromartie/f2e6713ba14261115dde to your computer and use it in GitHub Desktop.
Crude type checking?
(defn
^{:types [Integer Integer Integer]}
add
[x y]
(+ x y))
(defn
^{:types [Integer Integer Integer]}
mult
[x y]
(* x y))
(defn typecheck*
[code]
(let [types (-> code first meta :types)
f-type (first types)
expected-arg-types (rest types)
actual-arg-types (map type (rest code))]
(when (some false? (map #(isa? %1 %2) actual-arg-types expected-arg-types))
(throw (Exception. "Type error")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment