defer expand
: expand-quasiquote ;
-: expand-definition ;
-: expand-assignment ;
: expand-define-macro ;
: expand-if ;
: expand-lambda ;
-: expand-begin ;
: expand-application ;
: expand-macro ( exp -- result )
R> drop ['] expand goto-deferred
;
+: expand-definition ( exp -- result )
+ define-symbol 2swap
+
+ 2dup definition-var
+ 2swap definition-val expand
+ nil ( define var val' nil )
+
+ cons cons cons ;
+
+: expand-assignment ( exp -- result )
+ set!-symbol 2swap
+
+ 2dup assignment-var
+ 2swap assignment-val expand
+ nil ( define var val' nil )
+
+ cons cons cons ;
+
+: expand-sequence ( exp -- res )
+ nil? if exit then
+
+ 2dup car expand
+ 2swap cdr recurse
+
+ cons ;
+
+: expand-begin ( exp -- res )
+ begin-symbol 2swap
+ begin-actions expand-sequence
+
+ cons ;
+
+: expand-lambda ( exp -- res )
+ lambda-symbol 2swap
+ 2dup lambda-parameters
+ 2swap lambda-body expand-sequence
+
+ cons cons ;
+
:noname ( exp -- result )
expand-macro
+ quote? if exit then
+
quasiquote? if expand-quasiquote exit then
definition? if expand-definition exit then