have a server that like does stuff now

This commit is contained in:
2025-10-11 02:07:20 -06:00
parent fa16da8178
commit 6c45f30919
8 changed files with 107 additions and 24 deletions
+21 -1
View File
@@ -21,7 +21,9 @@
%-type sexp() :: {sexp, [expr()]}.
%-type expr() :: sexp() | ltr() | op() | snowflake() | pattern() | val().
-spec eval(expr()) -> {ok, eval_result(), context()} | {error, string()}.
-spec eval(expr()) -> Result
when Result :: {ok, eval_result(), NewContext :: context()}
| {error, string()}.
eval(Expr) ->
eval(Expr, wfc_eval_context:default()).
@@ -57,6 +59,24 @@ eval_sexp(Args = [{snowflake, <<"define">>}, {pattern, Pat}, Expr], Ctx0) ->
Error ->
Error
end;
eval_sexp([{snowflake, SF} | Args], Ctx0) ->
% first evaluate the arguments individually
case eval_sexp_args(Args, Ctx0, []) of
% assuming they each evaluate to sentences and some new context
{ok, Sentences, Ctx1} ->
% look up the snowflake in the context
case wfc_eval_context:resolve_snowflake(SF, Ctx1) of
{ok, SnowflakeFun} ->
case SnowflakeFun(Sentences) of
{ok, Sentence} -> {ok, Sentence, Ctx1};
Error -> Error
end;
Error ->
Error
end;
Error ->
Error
end;
eval_sexp([{op, '+'} | Exprs], Ctx) ->
case eval_sexp_args(Exprs, Ctx, []) of
{ok, Sentences, NewCtx} -> {ok, wfc_sentence:add(Sentences), NewCtx};