Removing 'begin' as a macro, doing it as a special form
parent
3ae000d5ab
commit
9d61d71e61
|
@ -67,14 +67,6 @@ IN: lisp.test
|
||||||
"(list 1 2 (list 3 (list 4) 5))" lisp-eval cons>seq
|
"(list 1 2 (list 3 (list 4) 5))" lisp-eval cons>seq
|
||||||
] unit-test
|
] 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 } [
|
{ 5 } [
|
||||||
"(begin (+ 1 4))" lisp-eval
|
"(begin (+ 1 4))" lisp-eval
|
||||||
] unit-test
|
] unit-test
|
||||||
|
@ -84,7 +76,7 @@ IN: lisp.test
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
{ T{ lisp-symbol f "if" } } [
|
{ 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
|
] unit-test
|
||||||
|
|
||||||
{ t } [
|
{ t } [
|
||||||
|
|
|
@ -64,12 +64,17 @@ PRIVATE>
|
||||||
: macro-expand ( cons -- quot )
|
: macro-expand ( cons -- quot )
|
||||||
uncons [ list>seq >quotation ] [ lookup-macro ] bi* call convert-form ;
|
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 )
|
: form-dispatch ( cons lisp-symbol -- quot )
|
||||||
name>>
|
name>>
|
||||||
{ { "lambda" [ convert-lambda ] }
|
{ { "lambda" [ convert-lambda ] }
|
||||||
{ "defmacro" [ convert-defmacro ] }
|
{ "defmacro" [ convert-defmacro ] }
|
||||||
{ "quote" [ convert-quoted ] }
|
{ "quote" [ convert-quoted ] }
|
||||||
{ "cond" [ convert-cond ] }
|
{ "cond" [ convert-cond ] }
|
||||||
|
{ "begin" [ convert-begin ] }
|
||||||
[ drop convert-general-form ]
|
[ drop convert-general-form ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue