 DEFER: lisp-macro?
 DEFER: lisp-var?
 DEFER: define-lisp-macro
-    
+
 ! Functions to convert s-exps to quotations
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 : convert-body ( cons -- quot )
     [ ] [ convert-form compose ] foldl ; inline
-    
-: convert-cond ( cons -- quot )  
+
+: convert-cond ( cons -- quot )
     cdr [ 2car [ convert-form ] bi@ 2array ]
     { } lmap-as '[ , cond ] ;
-    
+
 : convert-general-form ( cons -- quot )
     uncons [ convert-body ] [ convert-form ] bi* '[ , @ funcall ] ;
 
-! words for convert-lambda  
-<PRIVATE  
-: localize-body ( assoc body -- assoc newbody )  
+! words for convert-lambda
+<PRIVATE
+: localize-body ( assoc body -- assoc newbody )
     {
       { [ dup list? ] [ [ lisp-symbol? ] pick '[ [ name>> , at ] [ ] bi or ] traverse ] }
       { [ dup lisp-symbol? ] [ name>> over at ] }

      { [ dup lisp-symbol? ] [ '[ , lookup-var ] ] }
     [ 1quotation ]
    } cond ;
    
: lisp-string>factor ( str -- quot )
    lisp-expr compile-form ;
    
: lisp-eval ( str -- * )    
  lisp-string>factor call ;
    
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

SYMBOL: lisp-env
SYMBOL: macro-env
    
ERROR: no-such-var variable-name ;
M: no-such-var summary drop "No such variable" ;


: localize-lambda ( body vars -- newvars newbody )
    make-locals dup push-locals swap
    [ swap localize-body convert-form swap pop-locals ] dip swap ;

: split-lambda ( cons -- body-cons vars-seq )
    cdr uncons [ car ] [ [ name>> ] lmap>array ] bi* ; inline

: rest-lambda ( body vars -- quot )
    "&rest" swap [ index ] [ remove ] 2bi
    swapd localize-lambda <lambda> lambda-rewrite call
    '[ , cut '[ @ , seq>list ] call , call ] ;

: normal-lambda ( body vars -- quot )
    localize-lambda <lambda> lambda-rewrite [ compose call ] compose 1quotation ;
PRIVATE>

: convert-lambda ( cons -- quot )
    split-lambda "&rest" over member? [ rest-lambda ] [ normal-lambda ] if ;

: convert-quoted ( cons -- quot )
    cadr 1quotation ;

: convert-defmacro ( cons -- quot )
    cdr [ car ] keep [ convert-lambda ] [ car name>> ] bi define-lisp-macro 1quotation ;

: macro-expand ( cons -- quot )
    uncons [ list>seq >quotation ] [ lookup-macro ] bi* call convert-form ;

: form-dispatch ( cons lisp-symbol -- quot )
    name>>
    { { "lambda" [ convert-lambda ] }
