Added a (when) macro

This commit is contained in:
Justin Ethier 2015-06-29 17:59:14 -04:00
parent 63669620de
commit d4c27b9c63
3 changed files with 12 additions and 1 deletions

3
TODO
View file

@ -12,8 +12,9 @@ Working TODO list:
- Constructs require for self-hosting
- named let
- when
- eval
there is no concept of macro expansion, probably other deficiencies as well
- vectors
- make-vector should have an optional 'fill' arg in compiled code

View file

@ -6,3 +6,7 @@
(if (zero? i)
(write 'done)
(loop (- i 1))))
(write (when (lambda () #t) 'true))
(write (when (lambda () #f) 'false))

View file

@ -74,6 +74,12 @@
(error "bad let* syntax")))))
(cons 'begin (lambda (exp rename compare) (begin=>let exp)))
(cons 'letrec (lambda (exp rename compare) (letrec=>lets+sets exp)))
(cons 'when (lambda (exp rename compare)
(if (null? (cdr exp)) (error "empty when" exp))
(if (null? (cddr exp)) (error "no when body" exp))
`(if ,(cadr exp)
((lambda () ,(caddr exp)))
#f)))
(cons 'cond
(lambda (expr rename compare)
(if (null? (cdr expr))