ref: bfe18062adfcad6af73f1b5ab204763df12649a6
parent: 2b66d7d69e8f6da6f2f211c7fd3636b586588053
author: smazga <[email protected]>
date: Sat Oct 10 16:11:22 EDT 2020
macro
--- a/eval.ml
+++ b/eval.ml
@@ -27,11 +27,12 @@
try Env.get env (List.hd xs) with
| _ -> T.Nil
with
- | T.Macro { T.value = sym; meta } -> print_endline (" EVAL_AST: the rest: " ^ Printer.dump (List.tl xs));
+ | T.Macro { T.value = sym; meta } as om -> print_endline (" EVAL_AST: the rest: " ^ Printer.dump (List.tl xs));
print_endline (" EVAL_AST: AST: " ^ Printer.print ast true);
let foo = Macro.expand ast env (List.tl xs) sym meta in
print_endline (" expanded: " ^ Printer.print foo true);
- T.List { T.value = [foo]; T.meta }
+ T.List { T.value = [ om; foo ]; T.meta }
+ (* T.List { T.value = [foo]; T.meta } *)
(* T.List { T.value = [ Types.symbol (Printer.print sym true); foo; T.List { T.value = (List.tl xs); T.meta } ]; T.meta } *)
(* T.List { T.value = [eval foo env]; T.meta } *)
(* eval foo env *)
@@ -57,6 +58,7 @@
* | _ -> ast *)
and eval ast env =
+ print_endline ("AST: " ^ Printer.print ast true);
match ast with
| T.List { T.value = [] } -> ast
(* Can this be replaced with a define-syntax thing? *)
@@ -118,7 +120,7 @@
| T.List _ ->
(match eval_ast ast env with
| T.List { T.value = T.Proc { T.value = f } :: args } -> f args
- | T.List { T.value = macro } -> List.map (fun x -> eval x env) macro
+ | T.List { T.value = T.Macro { T.value = _ } :: macro :: _ } -> print_endline "MACRO EVALUATION"; eval macro env
(* | T.List { T.value = T.Macro { T.value = sym; meta } :: args } ->
* (\* eval (Macro.expand ast env args sym meta) env *\)
* let foo = Macro.expand ast env args sym meta in
--- a/macro.ml
+++ b/macro.ml
@@ -102,7 +102,7 @@
print_endline (" lambdaize short list: " ^ expr);
Reader.read expr
| ph :: pt, [] ->
- let expr = "'(lambda (" ^ Printer.stringify pt false ^ ") " ^ Printer.print template false ^ ")" in
+ let expr = "((lambda (" ^ Printer.stringify pt false ^ ") " ^ Printer.print template false ^ "))" in
print_endline (" lambdaize empty list: " ^ expr);
Reader.read expr
| _ ->
--- a/notes.org
+++ b/notes.org
@@ -39,6 +39,7 @@
Eval seems too late to handle it, so maybe try to do expansion at read?
So, at read, do an expansion and store the macro variants with unique names
+Then, when the original macro is called again, match the pattern and sub-in the appropriate variant.
* Macros
** and
(define-syntax and (syntax-rules ()