ref: a818d0d894cbc356744023dc3d8093b124e80923
parent: 10a9adc7d9a6caa80c7bce6fb6df64ddd79bf8dc
author: smazga <[email protected]>
date: Tue Aug 11 11:45:38 EDT 2020
got let working
--- a/m9.ml
+++ b/m9.ml
@@ -54,47 +54,13 @@
{ 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 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)
- | [] -> ()
+ let rec bind_pairs = function
+ | T.List { T.value = [ T.Symbol { T.value = sym }; expr ] } :: more ->
+ let value = eval expr env in
+ Env.set env (Types.symbol sym) value;
+ bind_pairs more
+ | _ -> ()
in
- 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
--- a/notes.org
+++ b/notes.org
@@ -1,5 +1,7 @@
* First things:
-** (let) doesn't work at all
+** PROGRESSING (let) doesn't work at all
+** Should (let) include an implicit (begin)?
+s9fes seems to do it
** TODO need an "unspecified" type?
** TODO (display) should return unspecified
** TODO implement (pair)
--- a/reader.ml
+++ b/reader.ml
@@ -21,7 +21,7 @@
let tokenize str =
List.map
(function
- | Str.Delim x -> x
+ | Str.Delim x -> String.trim x (* move trim to regex for speed? *)
| Str.Text x -> "tokenize botch")
(List.filter
(function
@@ -82,9 +82,7 @@
let rec read_list eol list_reader =
match list_reader.tokens with
- | [] ->
- print_endline "unexpected EOF";
- raise End_of_file
+ | [] -> raise (Syntax_error ("unterminated '" ^ eol ^ "'"))
| token :: tokens ->
if Str.string_match (Str.regexp eol) token 0
then { list_form = list_reader.list_form; tokens }