From 818eeb6c573b28497283df2008f27d12b0809f9c Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Fri, 15 Feb 2019 20:44:31 -0700 Subject: [PATCH] correct attribute_goals/2 bug, add freeze/2, update README --- src/prolog/lib/freeze.pl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/prolog/lib/freeze.pl diff --git a/src/prolog/lib/freeze.pl b/src/prolog/lib/freeze.pl new file mode 100644 index 00000000..ab95dbf3 --- /dev/null +++ b/src/prolog/lib/freeze.pl @@ -0,0 +1,33 @@ +:- module(freeze, [freeze/2]). + +:- use_module(library(atts)). + +:- attribute frozen/1. + +verify_attributes(Var, Other, Goals) :- + get_atts(Var, frozen(Fa)), !, % are we involved? + ( var(Other) -> % must be attributed then + ( get_atts(Other, frozen(Fb)) % has a pending goal? + -> put_atts(Other, -frozen(Fb)), + put_atts(Other, frozen((Fb,Fa))) % rescue conjunction + ; put_atts(Other, frozen(Fa)) % rescue the pending goal + ), + Goals = [] + ; Goals = [Fa] + ). +verify_attributes(_, _, []). + +freeze(X, Goal) :- + put_atts(Fresh, frozen(Goal)), + Fresh = X. + +gather_freeze_goals(Attrs, _) :- + var(Attrs), !. +gather_freeze_goals([frozen(X) | Attrs], [frozen(X) | Goals]) :- + gather_freeze_goals(Attrs, Goals). +gather_freeze_goals([_ | Attrs], Goals) :- + gather_freeze_goals(Attrs, Goals). + +attribute_goals(X, Goals) :- + '$get_attr_list'(X, Attrs), + gather_freeze_goals(Attrs, Goals). -- 2.54.0