Skip to content

Commit

Permalink
Add useful exprs/1/2 interface functions
Browse files Browse the repository at this point in the history
These 2 expand macros while evaluating the expressions.
  • Loading branch information
rvirding committed Apr 23, 2024
1 parent 9df7134 commit 6a34f5b
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/lfe_eval.erl
Expand Up @@ -24,9 +24,9 @@

-module(lfe_eval).

-export([expr/1,expr/2,literal/1,literal/2,body/1,body/2,
gexpr/1,gexpr/2,guard/1,guard/2,match/3,match_when/4,
apply/2,apply/3,
-export([expr/1,expr/2,exprs/1,exprs/2,
literal/1,literal/2,body/1,body/2,gexpr/1,gexpr/2,guard/1,guard/2,
match/3,match_when/4,apply/2,apply/3,
make_letrec_env/2,add_lexical_func/4,add_dynamic_func/4,
format_error/1]).

Expand Down Expand Up @@ -121,9 +121,22 @@ expr(E) -> expr(E, lfe_env:new()).

expr(E, Env) ->
Exp = lfe_macro:expand_expr_all(E, Env),
%% lfe_io:fwrite("e: ~p\n", [{E,Exp,Env}]),
eval_expr(Exp, Env).

%% exprs([Sexpr]) -> Value.
%% exprs([Sexpr], Env) -> Value.
%% Evaluate the sexprs in order, first expanding all macros.

exprs(Es) ->
exprs(Es, lfe_env:new()).

exprs([E | Es], Env) ->
Exp = lfe_macro:expand_expr_all(E, Env),
Value = eval_expr(Exp, Env),
[Value | exprs(Es, Env)];
exprs([], _Env) ->
[].

%% literal(Literal) -> Value.
%% literal(Literal, Env) -> Value.
%% body(Body) -> Value.
Expand All @@ -132,6 +145,8 @@ expr(E, Env) ->
%% gexpr(GuardTest, Env) -> Value.
%% guard(Guard) -> true | false.
%% guard(Guard, Env) -> true | false.
%% These do NOT expand macros. Note that match and match_when in the
%% same way but have suitable names.

literal(L) -> literal(L, lfe_env:new()).

Expand Down

0 comments on commit 6a34f5b

Please sign in to comment.