Add syntax sugar let f args... = ...
This commit is contained in:
parent
74a4af9c33
commit
c2ee352f1c
4 changed files with 15 additions and 1 deletions
4
ast.ml
4
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) ->
|
||||
|
|
1
eval.ml
1
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
|
||||
|
|
|
@ -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
|
||||
|
|
5
todo.md
Normal file
5
todo.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Todo
|
||||
|
||||
- macro
|
||||
- implementing custom operator
|
||||
- abstract stack machine & compiler
|
Loading…
Add table
Reference in a new issue