caching works correctly

This commit is contained in:
2025-10-11 17:24:11 -06:00
parent a942d79869
commit 673bc3ae52
5 changed files with 172 additions and 17 deletions
+12 -6
View File
@@ -9,6 +9,7 @@
default/0,
default_snowflakes/0,
define/3,
undefine/2,
resolve_pattern/2,
resolve_snowflake/2
]).
@@ -33,6 +34,7 @@ default() ->
default_snowflakes() ->
#{<<"and">> => fun wfc:mul/1,
<<"xor">> => fun wfc:add/1,
<<"implies">> => fun snf_implies/1,
<<"ior">> =>
fun IOR([S1 | Rest]) ->
case IOR(Rest) of
@@ -46,10 +48,6 @@ default_snowflakes() ->
fun ([S]) -> {ok, sf_not(S)};
(Bad) -> {error, wfc_utils:str("not/1: wrong number of arguments: ~p", [Bad])}
end,
<<"implies">> =>
fun ([A, B]) -> {ok, sf_implies(A, B)};
(Bad) -> {error, wfc_utils:str("implies/2: wrong number of arguments: ~p", [Bad])}
end,
<<"impliedby">> =>
fun ([A, B]) -> {ok, sf_impliedby(A, B)};
(Bad) -> {error, wfc_utils:str("impliedby/2: wrong number of arguments: ~p", [Bad])}
@@ -60,6 +58,10 @@ default_snowflakes() ->
end
}.
snf_implies([A, B]) -> {ok, sf_implies(A, B)};
snf_implies(Bad) -> {error, wfc_utils:str("implies/2: wrong number of arguments: ~p", [Bad])}.
sf_ior(A, B) ->
wfc_sftt:appl_ttf(fun ttf_ior/2, [A, B]).
@@ -93,14 +95,18 @@ define(Pat, Sentence, Ctx = #ctx{patterns = OldPatterns}) ->
NewPatterns = maps:put(Pat, Sentence, OldPatterns),
{ok, Ctx#ctx{patterns = NewPatterns}}.
undefine(Pat, Ctx = #ctx{patterns = OldPatterns}) ->
NewPatterns = maps:remove(Pat, OldPatterns),
{ok, Ctx#ctx{patterns = NewPatterns}}.
resolve_pattern(Pat, Ctx = #ctx{patterns = Patterns}) ->
case maps:find(Pat, Patterns) of
error -> {error, wfc_utils:str("wfc_eval_context:resolve_pattern: not found: ~w; context: ~w", [Pat, Ctx])};
error -> {error, wfc_utils:str("wfc_eval_context:resolve_pattern: not found: ~s; context: ~w", [Pat, Ctx])};
Result -> Result
end.
resolve_snowflake(SF, Ctx = #ctx{snowflakes = Snowflakes}) ->
case maps:find(SF, Snowflakes) of
error -> {error, wfc_utils:str("wfc_eval_context:resolve_snowflake: not found: ~w; context: ~w", [SF, Ctx])};
error -> {error, wfc_utils:str("wfc_eval_context:resolve_snowflake: not found: ~s; context: ~w", [SF, Ctx])};
Result -> Result
end.