Jonathan Graveline pushed to branch graveline at Stefan / Typer
Commits: 66f64c95 by Jonathan Graveline at 2018-05-30T20:27:21Z action now use block - - - - -
1 changed file:
- samples/do.typer
Changes:
===================================== samples/do.typer ===================================== --- a/samples/do.typer +++ b/samples/do.typer @@ -5,10 +5,10 @@ %% %% Here's an example : %% -%% fun = action ( -%% str <- return "\n\tHello world\n\n"; -%% print str; -%% ); +%% fun = action { +%% str <- return "\n\tHello world!\n\n"; +%% print str; +%% }; %% %% str is bind by macro, %% @@ -57,24 +57,22 @@ get-decl : List Sexp -> List Sexp; get-decl args = let
err = lambda _ -> cons Sexp_error nil; - -in Sexp_dispatch (List_nth 0 args Sexp_error) - - (lambda s ss -> if_then_else_ - (Sexp_eq (Sexp_symbol "_;_") s) - - (ss) % return declarations + + % Expecting a Block of command separated by ";" + + node = Sexp_dispatch (List_nth 0 args Sexp_error) + + (lambda _ _ -> cons Sexp_error nil) err err err err
- (cons (Sexp_node s ss) nil) % assuming there's only one declaration - ) - (lambda s -> cons (Sexp_symbol s) nil) - err err err err; + (lambda l -> l); + +in node;
%% %% The idea of the macro is : %% -%% IO_bind a-op (lambda a-sym -> [next command or return a-sym]) -%% IO_bind a-op (lambda a-sym -> (IO_bind b-op (lambda b-sym -> [next command or return a-sym]))) +%% IO_bind a-op (lambda a-sym -> [next command or return a-sym]) +%% IO_bind a-op (lambda a-sym -> (IO_bind b-op (lambda b-sym -> [next command or return b-sym]))) %% %% this way a-sym is defined within b-op and so on %% a-sym is now just `a` and not `IO a` @@ -91,16 +89,13 @@ set-fun args = let
op = get-op s;
- in (case ss - | cons _ _ => Sexp_node (Sexp_symbol "IO_bind") (cons (op) + in Sexp_node (Sexp_symbol "IO_bind") (cons (op) (cons (Sexp_node (Sexp_symbol "lambda_->_") (cons sym (cons (helper sym ss) nil))) nil)) - | nil => Sexp_node (Sexp_symbol "IO_return") (cons lsym nil) - ) )
- | nil => Sexp_error; + | nil => Sexp_node (Sexp_symbol "IO_return") (cons lsym nil);
-in helper (Sexp_symbol "()") args; +in helper (Sexp_symbol "") args; % return Unit if no command given
%% Serie of command
@@ -121,13 +116,13 @@ tab = print "\t"; float2string v = IO_return (Float->String v);
%% -%% example0 = action ( +%% example0 = action { %% str <- return "\n\tHello world!"; %% print str; %% return 0.0; -%% ); +%% }; %% -%% example1 = action ( +%% example1 = action { %% flt <- example0; %% str <- float2string flt; %% newline; @@ -135,5 +130,5 @@ float2string v = IO_return (Float->String v); %% print str; %% newline; %% newline; -%% ); +%% }; %%
View it on GitLab: https://gitlab.com/monnier/typer/commit/66f64c9567ae50cd45fdae5e2a7b789a4773...