diff --git a/ast.ml b/ast.ml index 8db8724..4b49ed0 100644 --- a/ast.ml +++ b/ast.ml @@ -61,6 +61,10 @@ let print ast = | Nexternal e -> pr "(extern %s)" e | Var v -> pr "%s" v + | Let (v, Nfunction (args, e)) -> + pr "(define (%s" v; + List.iter (pr " %s") args; + pr ") "; aux e; pr ")" | Let (v, e) -> pr "(define %s " v; aux e; pr ")" | Letin (v, e, f) -> diff --git a/eval.ml b/eval.ml index 4e9c8d6..0a5e022 100644 --- a/eval.ml +++ b/eval.ml @@ -329,6 +329,7 @@ and apply global env expr args = begin match args with | [] -> f | args -> + (* bind arguments to variables *) let rec aux e = function | [], [] -> [], [], e | vars, [] -> vars, [], e diff --git a/parser.ml b/parser.ml index 5a7be02..c420626 100644 --- a/parser.ml +++ b/parser.ml @@ -177,9 +177,13 @@ and nothing seq = and let_global seq = let _, seq = ident "let" seq in let id, seq = any_ident seq in + let args, seq = more any_ident seq in let _, seq = token Token.Equal seq in let e, seq = expr min_int seq in - Let (id, e), seq + (if args = [] + then Let (id, e) + else Let (id, Nfunction (args, e))), + seq (* expr := level * | let_value diff --git a/todo.md b/todo.md new file mode 100644 index 0000000..85ba1bf --- /dev/null +++ b/todo.md @@ -0,0 +1,5 @@ +# Todo + +- macro +- implementing custom operator +- abstract stack machine & compiler