Skip to content

Instantly share code, notes, and snippets.

@maxov maxov/cond.lisp
Created May 16, 2015

Embed
What would you like to do?
; 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
You can’t perform that action at this time.