eyeprolog 1.3.96 → 1.3.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/freeze.pl +14 -4
- package/test/run-regression.mjs +32 -0
- package/the-art-of-eyeprolog.md +5 -2
package/package.json
CHANGED
package/src/lib/freeze.pl
CHANGED
|
@@ -10,19 +10,29 @@ verify_attributes(Var, Other, Goals) :-
|
|
|
10
10
|
get_atts(Var, frozen(FrozenA)), !,
|
|
11
11
|
( var(Other) ->
|
|
12
12
|
( get_atts(Other, frozen(FrozenB)) ->
|
|
13
|
-
|
|
13
|
+
append_frozen(FrozenB, FrozenA, Frozen),
|
|
14
|
+
put_atts(Other, frozen(Frozen))
|
|
14
15
|
; put_atts(Other, frozen(FrozenA))
|
|
15
16
|
),
|
|
16
17
|
Goals = []
|
|
17
|
-
; Goals =
|
|
18
|
+
; Goals = FrozenA
|
|
18
19
|
).
|
|
19
20
|
verify_attributes(_, _, []).
|
|
20
21
|
|
|
21
22
|
freeze(X, Goal) :-
|
|
22
|
-
put_atts(Fresh, frozen(Goal)),
|
|
23
|
+
put_atts(Fresh, frozen([Goal])),
|
|
23
24
|
Fresh = X.
|
|
24
25
|
|
|
25
26
|
attribute_goals(Var) -->
|
|
26
27
|
{ get_atts(Var, frozen(Goals)),
|
|
27
28
|
put_atts(Var, -frozen(_)) },
|
|
28
|
-
|
|
29
|
+
frozen_attribute_goals(Goals, Var).
|
|
30
|
+
|
|
31
|
+
frozen_attribute_goals([], _) --> [].
|
|
32
|
+
frozen_attribute_goals([Goal|Goals], Var) -->
|
|
33
|
+
[freeze:freeze(Var, Goal)],
|
|
34
|
+
frozen_attribute_goals(Goals, Var).
|
|
35
|
+
|
|
36
|
+
append_frozen([], Tail, Tail).
|
|
37
|
+
append_frozen([Goal|Goals], Tail, [Goal|Merged]) :-
|
|
38
|
+
append_frozen(Goals, Tail, Merged).
|
package/test/run-regression.mjs
CHANGED
|
@@ -2078,6 +2078,38 @@ c4 ?- call((!;1)).
|
|
|
2078
2078
|
assertEqual(result.stdout, 'quads: 1 run, 1 passed, 0 failed.\n', 'quad report');
|
|
2079
2079
|
},
|
|
2080
2080
|
},
|
|
2081
|
+
{
|
|
2082
|
+
name: 'Prologue freeze keeps multiple delayed goals in separate cut scopes (issue #84)',
|
|
2083
|
+
run: () => {
|
|
2084
|
+
const result = publicApi.runQuads(`:- use_module(library(prologue)).
|
|
2085
|
+
39
|
|
2086
|
+
?- freeze(X,(Y=1;Y=2)), freeze(X,!), X = c ; X=end.
|
|
2087
|
+
X = c, Y = 1
|
|
2088
|
+
; X = end, unexpected.
|
|
2089
|
+
X = c, Y = 1
|
|
2090
|
+
; X = c, Y = 2
|
|
2091
|
+
; X = end.
|
|
2092
|
+
`);
|
|
2093
|
+
assertEqual(result.total, 2, 'quad total');
|
|
2094
|
+
assertEqual(result.passed, 2, 'quad passed');
|
|
2095
|
+
assertEqual(result.failed, 0, 'quad failed');
|
|
2096
|
+
assertEqual(result.stdout, 'quads: 2 run, 2 passed, 0 failed.\n', 'quad report');
|
|
2097
|
+
|
|
2098
|
+
const residuals = runCli([], {
|
|
2099
|
+
input:
|
|
2100
|
+
'use_module(library(freeze)).\n' +
|
|
2101
|
+
'freeze(X,(Y=1;Y=2)), freeze(X,!).\n' +
|
|
2102
|
+
'halt.\n',
|
|
2103
|
+
});
|
|
2104
|
+
assertEqual(residuals.status, 0, 'freeze residual display status');
|
|
2105
|
+
assertEqual(residuals.stdout,
|
|
2106
|
+
'?- true.\n' +
|
|
2107
|
+
'?- freeze:freeze(X, (Y=1;Y=2)), freeze:freeze(X, !).\n' +
|
|
2108
|
+
'?- ',
|
|
2109
|
+
'multiple freeze/2 residuals stay separate');
|
|
2110
|
+
assertEqual(residuals.stderr, '', 'freeze residual display stderr');
|
|
2111
|
+
},
|
|
2112
|
+
},
|
|
2081
2113
|
{
|
|
2082
2114
|
name: 'runQuads covers the remaining finite Prologue examples and arities',
|
|
2083
2115
|
run: () => {
|
package/the-art-of-eyeprolog.md
CHANGED
|
@@ -6286,8 +6286,11 @@ kept in the logical environment, so bindings and backtracking remain isolated
|
|
|
6286
6286
|
between solution branches. When a suspension wakes, its goal is meta-invoked
|
|
6287
6287
|
with its own cut scope: a `!` inside the delayed goal may commit choices made by
|
|
6288
6288
|
that invocation, but it cannot prune alternatives that were created before the
|
|
6289
|
-
`freeze/2` call.
|
|
6290
|
-
|
|
6289
|
+
`freeze/2` call. Multiple suspensions on the same variable also remain distinct
|
|
6290
|
+
meta-invocations rather than being collapsed into one conjunction, so a cut in
|
|
6291
|
+
one frozen goal cannot prune alternatives produced by another frozen goal. Thus
|
|
6292
|
+
`call(((Y=1;Y=2),freeze(X,!),X=c));Y=3` retains the three answers `Y=1`, `Y=2`,
|
|
6293
|
+
and `Y=3`.
|
|
6291
6294
|
|
|
6292
6295
|
`dif(?Left,?Right)` posts a delayed finite-tree disequality when its arguments
|
|
6293
6296
|
can still unify. Its residual store is normalized by logical implication:
|