shithub: martian9

Download patch

ref: a3f06577db37f23d89755dd66e1e6f6b803037d2
parent: 7bcded464070dc7573edcdaa2c6f451d3f20b78d
author: smazga <[email protected]>
date: Fri Sep 18 07:48:07 EDT 2020

time to reevaluate macros

--- a/eval.ml
+++ b/eval.ml
@@ -51,7 +51,7 @@
     value
   | T.List { T.value = [ T.Symbol { T.value = "define-syntax" }; keyword; T.List { T.value = macro } ] } ->
     (match macro with
-     | _ :: literals :: groups ->
+    | _ :: literals :: groups ->
       let macro_entry = Types.macro (Printer.print keyword true) literals (Types.list groups) in
       Env.set env keyword macro_entry;
       macro_entry
--- a/macro.ml
+++ b/macro.ml
@@ -86,26 +86,24 @@
 let lambdaize pattern template args =
   match pattern, args with
   | ph :: pt, ah :: at :: rest ->
-     let expr = "((lambda " ^ ellipsis pt template args ^ Printer.stringify args false ^ ")" in
-     print_endline ("  lambdaize list list: " ^ expr);
-     Reader.read expr
+    let expr = "((lambda " ^ ellipsis pt template args ^ Printer.stringify args false ^ ")" in
+    print_endline ("  lambdaize list list: " ^ expr);
+    Reader.read expr
   | ph :: pt, ah :: at ->
-     let expr = "((lambda ("
+    let expr =
+      "((lambda ("
       ^ Printer.stringify pt true
       ^ ")"
       ^ Printer.print template true
       ^ ")"
       ^ Printer.stringify args true
-      ^ ")" in
-     print_endline ("  lambdaize short list: " ^ expr);
+      ^ ")"
+    in
+    print_endline ("  lambdaize short list: " ^ expr);
     Reader.read expr
   | ph :: pt, [] ->
-     let expr = "((lambda ("
-      ^ Printer.stringify pt false
-      ^ ") "
-      ^ Printer.print template true
-      ^ "))" in
-     print_endline ("  lambdaize empty list: " ^ expr);
+    let expr = "((lambda (" ^ Printer.stringify pt false ^ ") " ^ Printer.print template true ^ "))" in
+    print_endline ("  lambdaize empty list: " ^ expr);
     Reader.read expr
   | _ ->
     print_endline "lambdaize: empty";
--- a/notes.org
+++ b/notes.org
@@ -37,6 +37,8 @@
 ...but what about ellipsis??
 ** Thoughts
 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
 * Macros
 ** and
 (define-syntax and (syntax-rules ()
--- a/reader.ml
+++ b/reader.ml
@@ -113,6 +113,9 @@
     | "#|" ->
       let list_reader = read_list "|#" { list_form = []; tokens } in
       { form = T.Unspecified; tokens = list_reader.tokens }
+    (* | "define-syntax" ->
+     *   print_endline "MACRO";
+     *   read_macro tokens *)
     | "(" ->
       let list_reader = read_list ")" { list_form = []; tokens } in
       { form = Types.list list_reader.list_form; tokens = list_reader.tokens }