]> gitweb.factorcode.org Git - factor.git/commitdiff
Removing 'begin' as a macro, doing it as a special form
authorJames Cash <james.nvc@gmail.com>
Thu, 14 Aug 2008 04:42:19 +0000 (00:42 -0400)
committerJames Cash <james.nvc@gmail.com>
Sun, 24 Aug 2008 03:13:33 +0000 (23:13 -0400)
extra/lisp/lisp-tests.factor
extra/lisp/lisp.factor

index cf9811e4a50eaf8b1ef5e13302260cb2495aab28..e539221eaf9c74ab51d4ce82f589b9151370f249 100644 (file)
@@ -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 } [
index e6e3a7b13bbb65f31ad73cebc424d8bb3e25dab8..967c52a1177a5f1b08a6b2f98425bfb8d14d912d 100644 (file)
@@ -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 ;