{ { 1 2 { 3 { 4 } 5 } } } [
"(list 1 2 (list 3 (list 4) 5))" lisp-eval cons>seq
] unit-test
-
- { T{ lisp-symbol f "begin" } } [
- "(defmacro begin (&rest body) (list (cons (quote lambda) (cons (list) body))))" lisp-eval
- ] unit-test
-
- { t } [
- T{ lisp-symbol f "begin" } lisp-macro?
- ] unit-test
{ 5 } [
"(begin (+ 1 4))" lisp-eval
] unit-test
{ T{ lisp-symbol f "if" } } [
- "(defmacro if (pred tr fl) (list (list (quote cond) (list pred tr) (list (quote #t) fl))))" lisp-eval
+ "(defmacro if (pred tr fl) (list (quote cond) (list pred tr) (list (quote #t) fl)))" lisp-eval
] unit-test
{ t } [
: macro-expand ( cons -- quot )
uncons [ list>seq >quotation ] [ lookup-macro ] bi* call convert-form ;
+
+: convert-begin ( cons -- quot )
+ cdr [ convert-form ] [ ] lmap-as [ 1 tail* ] [ but-last ] bi
+ [ [ drop ] compose ] map prepend '[ , [ call ] each ] ;
: form-dispatch ( cons lisp-symbol -- quot )
name>>
{ "defmacro" [ convert-defmacro ] }
{ "quote" [ convert-quoted ] }
{ "cond" [ convert-cond ] }
+ { "begin" [ convert-begin ] }
[ drop convert-general-form ]
} case ;