Created
November 22, 2014 21:08
-
-
Save frenchy64/c7e1a318c67baf7576c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns variant | |
(:require [clojure.core.typed :as t])) | |
(t/defalias V | |
(t/Rec [V] | |
(t/U '[':lambda t/Sym V] | |
'[':if V V V] | |
'[':val t/Any]))) | |
(t/ann command [V -> t/Str]) | |
(defmulti command first) | |
(defmethod command :lambda | |
[[_ s body]] | |
(command body)) | |
(defmethod command :val | |
[[_ val]] | |
(str val)) | |
(defmethod command :if | |
[[_ test then else]] | |
(str (map command [test then else]))) |
and if you like, it's small but not insignificant
(defmacro defmulti-variant [name & args]
`(defmulti ~name first ~@args))
Maybe it could use a better name though...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And for convenience,