Removing 'begin' as a macro, doing it as a special form
parent
3ae000d5ab
commit
9d61d71e61
|
@ -66,14 +66,6 @@ IN: lisp.test
|
|||
{ { 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
|
||||
|
@ -84,7 +76,7 @@ IN: lisp.test
|
|||
] 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 } [
|
||||
|
|
|
@ -63,6 +63,10 @@ PRIVATE>
|
|||
|
||||
: 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>>
|
||||
|
@ -70,6 +74,7 @@ PRIVATE>
|
|||
{ "defmacro" [ convert-defmacro ] }
|
||||
{ "quote" [ convert-quoted ] }
|
||||
{ "cond" [ convert-cond ] }
|
||||
{ "begin" [ convert-begin ] }
|
||||
[ drop convert-general-form ]
|
||||
} case ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue