shithub: martian9

Download patch

ref: 2b66d7d69e8f6da6f2f211c7fd3636b586588053
parent: e26bf9e3ac9cd57902b158feaef9234e2901ce9c
author: McKay Marston <mckay.marston@greymanlabs.com>
date: Wed Sep 30 20:08:04 EDT 2020

macros suck

--- a/eval.ml
+++ b/eval.ml
@@ -28,9 +28,13 @@
                                           | _ -> T.Nil
                                         with
                                         | T.Macro { T.value = sym; meta } -> 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);
-                                                                             eval foo env
+                                                                             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 *)
                                                                              (* raise (Reader.Syntax_error ("EVAL_AST MACRO: ast: " ^ Printer.print ast true)) *)
                                         | _ -> T.List { T.value = List.map (fun x -> eval x env) xs; T.meta })
   (* | T.List { T.value = xs; T.meta } -> T.List { T.value = List.map (fun x -> eval x env) xs; T.meta } *)
@@ -113,7 +117,8 @@
   | T.List { T.value = [ T.Symbol { T.value = "quasiquote" }; ast ] } -> eval (quasiquote ast) env
   | T.List _ ->
     (match eval_ast ast env with
-    | T.List { T.value = T.Proc { T.value = f } :: args } -> f args
+     | 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 = 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 true ^ "))" in
+    let expr = "'(lambda (" ^ Printer.stringify pt false ^ ") " ^ Printer.print template false ^ ")" in
     print_endline ("  lambdaize empty list: " ^ expr);
     Reader.read expr
   | _ ->
--- a/printer.ml
+++ b/printer.ml
@@ -32,7 +32,7 @@
     if r
     then
       "\""
-      ^ Reader.gsub
+      ^ Utils.gsub
           (Str.regexp "\\([\"\\\n]\\)")
           (function
             | "\n" -> "\\n"
--- a/reader.ml
+++ b/reader.ml
@@ -2,7 +2,7 @@
 
 exception Syntax_error of string
 
-let token_re = Str.regexp "~@\\|[][{}()'`~^@]\\|\"\\(\\\\.\\|[^\"]\\)*\"?\\|;.*\\|[^][  \n{}('\"`,;)]*"
+let token_re = Str.regexp "~@\\|[][{}()'`~^@]\\|\"\\(\\\\.\\|[^\"]\\)*\"?\\|;.*\\$\\|[^][  \n{}('\"`,;)]*"
 let string_re = Str.regexp "\"\\(\\\\.\\|[^\\\\\"]\\)*\""
 
 type reader =
@@ -27,22 +27,11 @@
        (Str.full_split token_re str))
 ;;
 
-(* copied verbatim - must needs grok *)
-let gsub re f str =
-  String.concat
-    ""
-    (List.map
-       (function
-         | Str.Delim x -> f x
-         | Str.Text x -> x)
-       (Str.full_split re str))
-;;
-
 let unescape_string token =
   if Str.string_match string_re token 0
   then (
     let without_quotes = String.sub token 1 (String.length token - 2) in
-    gsub
+    Utils.gsub
       (Str.regexp "\\\\.")
       (function
         | "\\n" -> "\n"
@@ -112,7 +101,7 @@
     | "#" -> read_vector tokens
     | "#|" ->
        let list_reader = read_list "|#" { list_form = []; tokens } in
-       print_endline ("block comment: " ^ (String.concat " " list_reader.tokens));
+       print_endline ("block comment: " ^ Printer.dump list_reader.list_form);
       { form = T.Unspecified; tokens = list_reader.tokens }
     | "(" ->
       let list_reader = read_list ")" { list_form = []; tokens } in
@@ -119,7 +108,7 @@
       { form = Types.list list_reader.list_form; tokens = list_reader.tokens }
     | "" | "\t" | "\n" -> read_form tokens
     | _ -> if token.[0] = ';' then
-             let list_reader = read_list "\n" { list_form = []; tokens } in
+             let list_reader = read_list "\\n" { list_form = []; tokens } in
              print_endline ("line comment: " ^ (String.concat " " list_reader.tokens));
              { form = T.Unspecified; tokens = list_reader.tokens }
            else { form = read_atom token; tokens })