shithub: martian9

Download patch

ref: 1554de912987175430a808ad1d949f0567ca44bd
parent: dffe9bae1142fff062f6dc1a0867d8a9247f5bcf
author: McKay Marston <mckay.marston@greymanlabs.com>
date: Fri Aug 28 17:41:17 EDT 2020

working macro??

--- a/eval.ml
+++ b/eval.ml
@@ -130,10 +130,10 @@
     (match eval_ast ast env with
     | T.List { T.value = T.Proc { T.value = f } :: args } -> f args
     | 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
-      print_endline (":::: " ^ Printer.print foo true);
-      eval foo env
+      eval (Macro.expand ast env args sym meta) env
+      (* let foo = Macro.expand ast env args sym meta in
+       * print_endline (":::: " ^ Printer.print foo true);
+       * eval foo env *)
     | _ as x ->
       raise (Reader.Syntax_error ("'" ^ Printer.print x true ^ "' not a function")))
   | _ -> eval_ast ast env
--- a/macro.ml
+++ b/macro.ml
@@ -15,34 +15,34 @@
   match pattern, args with
   (* literals and ellipses not handled, yet *)
   | ph :: pt, ah :: at ->
-    print_endline "    LIST <-> LIST";
+    (* print_endline "    LIST <-> LIST"; *)
     if ph = "_" || (ph = Printer.print sym true && sym = ah)
     then is_matching_pattern sym pt at matched && true
     else (
-      print_endline (" ------> " ^ ph ^ " vs " ^ Printer.print ah true);
+      (* print_endline (" ------> " ^ ph ^ " vs " ^ Printer.print ah true); *)
       is_matching_pattern sym pt at matched)
   | ph :: pt, [] ->
-    print_endline "    LIST <-> []";
+    (* print_endline "    LIST <-> []"; *)
     if ph = "_" || ph = Printer.print sym true
     then is_matching_pattern sym pt [] matched && true
     else ph = "..."
   | [], ah :: at ->
-    print_endline "    [] <-> LIST";
+    (* print_endline "    [] <-> LIST"; *)
     false
   | _, _ -> matched
 ;;
 
 let rec ellipsis pattern template args =
-    print_endline
-    ("pattern length: "
-    ^ string_of_int (List.length pattern)
-    ^ "  arg length: "
-    ^ string_of_int (List.length args));
+    (* print_endline
+     * ("pattern length: "
+     * ^ string_of_int (List.length pattern)
+     * ^ "  arg length: "
+     * ^ string_of_int (List.length args)); *)
     let has_ellipsis = (try ignore (Str.search_forward (Str.regexp "...") (Printer.stringify pattern true) 0); true
                         with Not_found -> false) in
   let ellipsis_substitutions = ref [] in
   let missing = List.length args - List.length pattern + (if has_ellipsis then 1 else 0) in
-  print_endline (" NEED TO ADD " ^ string_of_int missing ^ " PLACEHOLDERS");
+  (* print_endline (" NEED TO ADD " ^ string_of_int missing ^ " PLACEHOLDERS"); *)
   if missing > 0
   then (
     for i = 1 to missing do
@@ -60,8 +60,8 @@
       (String.concat " " !ellipsis_substitutions)
       (Printer.print template true)
   in
-  let args_str = Printer.stringify args true in
-  print_endline ("ellipsis: template: " ^ template_str ^ "  args: " ^ args_str);
+  (* let args_str = Printer.stringify args true in *)
+  (* print_endline ("ellipsis: template: " ^ template_str ^ "  args: " ^ args_str); *)
   "(" ^ pattern_str ^ ") " ^ template_str ^ ")"
 ;;
 
@@ -68,11 +68,11 @@
 let lambdaize pattern template args =
   match pattern, args with
   | ph :: pt, ah :: at :: rest ->
-    print_endline "lambdaize: list list";
+    (* print_endline "lambdaize: list list"; *)
     Reader.read
       ("((lambda " ^ ellipsis pt template args ^ Printer.stringify args false ^ ")")
   | ph :: pt, ah :: at ->
-    print_endline "lambdaize: list short";
+    (* print_endline "lambdaize: list short"; *)
     Reader.read
       ("((lambda ("
       ^ Printer.stringify pt true
@@ -82,7 +82,7 @@
       ^ Printer.stringify args true
       ^ ")")
   | ph :: pt, [] ->
-    print_endline "lambdaize: list empty";
+    (* print_endline "lambdaize: list empty"; *)
     Reader.read
       ("((lambda ("
       ^ Printer.stringify pt false
@@ -90,47 +90,47 @@
       ^ Printer.print template true
       ^ "))")
   | _ ->
-    print_endline "lambdaize: empty";
+    (* print_endline "lambdaize: empty"; *)
     Reader.read ("((lambda () " ^ Printer.print template true ^ "))")
 ;;
 
 let rec expand ast env args sym meta =
-  print_endline ("\n\nTHIS IS A MACRO: " ^ Printer.print sym true);
-  print_endline ("   META: " ^ Printer.print meta true);
-  print_endline ("   ARGS: " ^ Printer.dump args);
-  print_endline ("  AST:   " ^ Printer.print ast true);
+  (* print_endline ("\n\nTHIS IS A MACRO: " ^ Printer.print sym true);
+   * print_endline ("   META: " ^ Printer.print meta true);
+   * print_endline ("   ARGS: " ^ Printer.dump args);
+   * print_endline ("  AST:   " ^ Printer.print ast true); *)
   match meta with
   | T.Map { T.value = m } ->
     (try
-       let literals = Types.M9map.find Types.macro_literals m in
+       (* let literals = Types.M9map.find Types.macro_literals m in *)
        let transformers = Types.M9map.find Types.macro_transformers m in
-       print_endline
-         ("  -- EVAL_MACRO: literals: "
-         ^ Printer.print literals true
-         ^ "     transformers: "
-         ^ Printer.print transformers true);
-       print_endline ("    args: " ^ Printer.dump args);
+       (* print_endline
+        *   ("  -- EVAL_MACRO: literals: "
+        *   ^ Printer.print literals true
+        *   ^ "     transformers: "
+        *   ^ Printer.print transformers true); *)
+       (* print_endline ("    args: " ^ Printer.dump args); *)
        let rec match_transform transforms =
          match transforms with
          | hd :: tl ->
-           print_endline ("      transform: " ^ Printer.print hd true);
+           (* print_endline ("      transform: " ^ Printer.print hd true); *)
            (match hd with
            | T.List
                { T.value = [ T.List { T.value = pattern }; T.List { T.value = template } ]
                } ->
-             print_endline "   MULTI";
-             print_endline ("     - template: " ^ Printer.dump template);
-             print_endline
-               ("      matched?: "
-               ^ (if is_matching_pattern
-                       sym
-                       (List.map (fun x -> Printer.print x true) pattern)
-                       (Core.seq ast)
-                       true
-                 then "yes"
-                 else "no")
-               ^ " ::> "
-               ^ Printer.dump pattern);
+             (* print_endline "   MULTI";
+              * print_endline ("     - template: " ^ Printer.dump template);
+              * print_endline
+              *   ("      matched?: "
+              *   ^ (if is_matching_pattern
+              *           sym
+              *           (List.map (fun x -> Printer.print x true) pattern)
+              *           (Core.seq ast)
+              *           true
+              *     then "yes"
+              *     else "no")
+              *   ^ " ::> "
+              *   ^ Printer.dump pattern); *)
              if is_matching_pattern
                   sym
                   (List.map (fun x -> Printer.print x true) pattern)
@@ -139,18 +139,18 @@
              then lambdaize pattern (Types.list template) args
              else match_transform tl
            | T.List { T.value = [ T.List { T.value = pattern }; atom ] } ->
-             print_endline "   SINGLE";
-             print_endline
-               ("      matched?: "
-               ^ (if is_matching_pattern
-                       sym
-                       (List.map (fun x -> Printer.print x true) pattern)
-                       (Core.seq ast)
-                       true
-                 then "yes"
-                 else "no")
-               ^ " ::> "
-               ^ Printer.dump pattern);
+             (* print_endline "   SINGLE";
+              * print_endline
+              *   ("      matched?: "
+              *   ^ (if is_matching_pattern
+              *           sym
+              *           (List.map (fun x -> Printer.print x true) pattern)
+              *           (Core.seq ast)
+              *           true
+              *     then "yes"
+              *     else "no")
+              *   ^ " ::> "
+              *   ^ Printer.dump pattern); *)
              if is_matching_pattern
                   sym
                   (List.map (fun x -> Printer.print x true) pattern)