shithub: martian9

Download patch

ref: 10a9adc7d9a6caa80c7bce6fb6df64ddd79bf8dc
parent: 98dd156dfa4ec242fa2ffd07d288805f468d5f28
author: smazga <smazga@greymanlabs.com>
date: Mon Aug 10 17:22:15 EDT 2020

still working on (let)

--- a/m9.ml
+++ b/m9.ml
@@ -54,15 +54,47 @@
       { T.value = [ T.Symbol { T.value = "let" }; T.List { T.value = bindings }; body ] }
     ->
     let sub_env = Env.make (Some env) in
-    let rec bind_pairs = function
-      | sym :: expr :: more ->
-         (print_endline (Printer.print sym true));
-        Env.set sub_env sym (eval expr sub_env);
-        bind_pairs more
-      | x::[] -> raise (Reader.Syntax_error ("missing 'let' bindings (" ^ (Printer.print x true) ^ ")"))
+    (* let rec bind_pairs pairs =
+     *   match pairs with
+     *   | T.List { T.value = pair } :: more ->
+     *      (function
+     *       | sym :: expr -> print_endline
+     *                          ("sym: " ^ String.concat " " (List.map (fun xs -> Printer.print xs true) sym));
+     *                        Env.set sub_env sym (eval expr sub_env);
+     *                        bind_pairs 
+     *                        (\* print_endline
+     *                         *   ("expr: " ^ String.concat " " (List.map (fun xs -> Printer.print xs true) expr)) *\)
+     *       | [] -> ())
+     *      (\*   print_endline
+     *       *   ("pair: " ^ String.concat " " (List.map (fun xs -> Printer.print xs true) pair));
+     *       * print_endline
+     *       *   ("more: " ^ String.concat " " (List.map (fun xs -> Printer.print xs true) more)); *\)
+     *     (\* Env.set sub_env sym (eval expr sub_env); *\)
+     *      (\* bind_pairs more *\)
+     *        (\* | _ -> () *\)
+     *   | _ -> pairs *)
+    (* | [] -> () *)
+
+
+    
+      (* let rec bind_pairs = function
+       *   | sym :: expr :: more ->
+       *      (print_endline (Printer.print sym true));
+       *     Env.set sub_env sym (eval expr sub_env);
+       *     print_endline "foo";
+       *     bind_pairs more;
+       *   | x::[] -> raise (Reader.Syntax_error ("missing 'let' bindings '" ^ (Printer.print x true) ^ "'"))
+       *   | [] -> () *)
+    let rec bind_pairs pairs =
+      match pairs with
+      | sym :: expr ->
+         print_endline ("sym: " ^ sym ^ "  expr: " ^ (String.concat " " expr)); (* (List.map (fun xs -> Printer.print xs true) expr))); *)
+         Env.set sub_env (Types.symbol sym) (eval expr sub_env)
       | [] -> ()
     in
-    print_endline ("bind_pairs:body: " ^ (Printer.print body true));
+    print_endline ("bind_pairs:body: " ^ Printer.print body true);
+    print_endline ("bind_pairs: bindings: " ^ String.concat "*" (List.map (fun xs -> Printer.print xs true) bindings));
+    print_endline ("bind_pairs:ast: " ^ Printer.print ast true);
     bind_pairs bindings;
     eval body sub_env
   | T.List