Created
May 16, 2015 08:14
-
-
Save maxov/52a41db017254c356893 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
; the let macro | |
(set macros "let" (fn (tree) | |
(if (== (len tree) 0) | |
(err "let takes at least one arg") | |
(let | |
(expr (last tree)) | |
(body (map (init tree) (fn (tree) | |
(cons (quote "def") tree)))) | |
(form (push (cons (quote "do") body) expr)) | |
(compileExpr form body))))) | |
; the cond macro | |
(set macros "cond" (fn (tree) | |
; TODO when I get the >= operator in here, use that | |
; also mod | |
(if (== (len tree) 0) | |
(err "cond takes at least two args") | |
(let | |
(lt (last tree)) | |
(rest (slice tree 0 (- (len tree) 2))) | |
(grouped (group2 rest)) | |
(form (foldR grouped (fn (acc con) | |
(list (quote "if") (head con) (at con 1) acc)) lt)) | |
(compileExpr form))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment