From 98a046500f487fb9a1acc35df012f11ee364f1fa Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sat, 20 Jan 2024 10:24:57 +0100 Subject: [PATCH 1/5] MODIFIED: (->)/2 in DCGs is now only supported in the context of if-then-else. That is, ( If -> Then ; Else ) is still supported, but ( If -> Then ) not. --- src/lib/dcgs.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/dcgs.pl b/src/lib/dcgs.pl index 9f7dfacf..0876bd5a 100644 --- a/src/lib/dcgs.pl +++ b/src/lib/dcgs.pl @@ -177,7 +177,7 @@ dcg_constr(phrase(_,_)). % extension of 7.14.9 dcg_constr(phrase(_,_,_)). % extension of 7.14.9 dcg_constr(!). % 7.14.10 %% dcg_constr(\+ _). % 7.14.11 - not (existence implementation dep.) -dcg_constr((_->_)). % 7.14.12 - if-then (existence implementation dep.) +%% dcg_constr((_->_)). % 7.14.12 - if-then (existence implementation dep.) % The principal functor of the first argument indicates % the construct to be expanded. From 0559ddca2a28969de19faac9d427b0fef6888057 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sat, 20 Jan 2024 10:33:24 +0100 Subject: [PATCH 2/5] ENHANCED: Throw representation errors for DCG bodies that use unsupported constructs. This addresses #2285. --- src/lib/dcgs.pl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/dcgs.pl b/src/lib/dcgs.pl index 0876bd5a..40f44a59 100644 --- a/src/lib/dcgs.pl +++ b/src/lib/dcgs.pl @@ -176,8 +176,10 @@ dcg_constr(phrase(_)). % 7.14.9 dcg_constr(phrase(_,_)). % extension of 7.14.9 dcg_constr(phrase(_,_,_)). % extension of 7.14.9 dcg_constr(!). % 7.14.10 -%% dcg_constr(\+ _). % 7.14.11 - not (existence implementation dep.) -%% dcg_constr((_->_)). % 7.14.12 - if-then (existence implementation dep.) +dcg_constr(\+ _) :- % 7.14.11 - not (existence implementation dep.) + throw(error(representation_error(dcg_body), phrase/3)). +dcg_constr((_->_)) :- % 7.14.12 - if-then (existence implementation dep.) + throw(error(representation_error(dcg_body), phrase/3)). % The principal functor of the first argument indicates % the construct to be expanded. @@ -244,6 +246,8 @@ seqq([Es|Ess]) --> seq(Es), seqq(Ess). error_goal(error(E, must_be/2), error(E, must_be/2)). error_goal(error(E, (=..)/2), error(E, (=..)/2)). +error_goal(error(representation_error(dcg_body), Context), + error(representation_error(dcg_body), Context)). error_goal(E, _) :- throw(E). user:goal_expansion(phrase(GRBody, S, S0), GRBody2) :- From fe3241c07ca78bdce3dea06caa73c4bba9eebda6 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sat, 20 Jan 2024 11:02:54 +0100 Subject: [PATCH 3/5] remove checks that are now no longer needed due to representation errors --- src/lib/dcgs.pl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/dcgs.pl b/src/lib/dcgs.pl index 40f44a59..0fa9109c 100644 --- a/src/lib/dcgs.pl +++ b/src/lib/dcgs.pl @@ -154,8 +154,6 @@ dcg_body(GRBody, S0, S, Body) :- dcg_body(NonTerminal, S0, S, Goal1) :- nonvar(NonTerminal), \+ dcg_constr(NonTerminal), - NonTerminal \= ( _ -> _ ), - NonTerminal \= ( \+ _ ), loader:strip_module(NonTerminal, M, NonTerminal0), dcg_non_terminal(NonTerminal0, S0, S, Goal0), ( functor(NonTerminal, (:), 2) -> From 388fa5baa91683af68f1d4201e819d29bfce4965 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sun, 21 Jan 2024 22:50:36 +0100 Subject: [PATCH 4/5] no longer use (->)//2, since it is implementation dependent --- src/lib/clpz.pl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/clpz.pl b/src/lib/clpz.pl index 57309470..631399de 100644 --- a/src/lib/clpz.pl +++ b/src/lib/clpz.pl @@ -4171,6 +4171,7 @@ var(V) --> { var(V) }. ground(T) --> { ground(T) }. true --> []. +false --> { false }. X >= Y --> { X >= Y }. X =< Y --> { X =< Y }. @@ -4665,7 +4666,7 @@ run_propagator(x_eq_abs_plus_v(X,V), MState) --> ( nonvar(V) -> ( V =:= 0 -> kill(MState), { X in 0..sup } ; V < 0 -> kill(MState), { X #= V / 2 } - ; V > 0 -> { false } + ; false % V > 0 ) ; nonvar(X) -> kill(MState), @@ -5062,7 +5063,7 @@ run_propagator(pmod(X,Y,Z), MState) --> Z is X mod Y ; nonvar(Y), nonvar(Z) -> ( Y > 0 -> Z >= 0, Z < Y - ; Y < 0 -> Z =< 0, Z > Y + ; Z =< 0, Z > Y % Y < 0 ), ( { fd_get(X, _, n(XL), _, _) } -> ( (XL - Z) mod Y =\= 0 -> @@ -5131,7 +5132,7 @@ run_propagator(pmodz(X,Y,Z), MState) --> fd_put(Z, ZD2, ZPs) % queue_goal(Z #=< X) ) - ; X < 0 -> + ; X < 0, ( { fd_get(Y, _, _, n(YU), _), YU < X } -> kill(MState), queue_goal(Z = X) @@ -5171,7 +5172,7 @@ run_propagator(pmodz(X,Y,Z), MState) --> fd_put(Z, ZD5, ZPs) % queue_goal(Z in ZMin..0) ) - ; Y > 0 -> + ; Y > 0, ( { fd_get(X, _, n(XL), n(XU), _), XL >= 0, Y > XU } -> kill(MState), queue_goal(Z = X) From 81dba11ab1c99fee3c6d586e1fbc18077f3bc7f3 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sun, 21 Jan 2024 22:53:22 +0100 Subject: [PATCH 5/5] use newly available false//0 --- src/lib/clpz.pl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/lib/clpz.pl b/src/lib/clpz.pl index 631399de..07768da5 100644 --- a/src/lib/clpz.pl +++ b/src/lib/clpz.pl @@ -4229,7 +4229,7 @@ activate_propagator(propagator(P,State)) --> ) ). -%do_queue --> print_queue, { false }. +%do_queue --> print_queue, false. do_queue --> ( queue_enabled -> ( queue_get_goal(Goal) -> { call(Goal) }, do_queue @@ -4593,7 +4593,7 @@ run_propagator(pserialized(S_I, D_I, S_J, D_J, _), MState) --> kill(MState), ( S_I + D_I =< S_J -> [] ; S_J + D_J =< S_I -> [] - ; { false } + ; false ) ; serialize_lower_upper(S_I, D_I, S_J, D_J, MState), serialize_lower_upper(S_J, D_J, S_I, D_I, MState) @@ -5053,8 +5053,8 @@ run_propagator(ptzdiv(X,Y,Z,Morph), MState) --> %% % Z = X mod Y run_propagator(pmod(X,Y,Z), MState) --> - ( Y == 0 -> { false } - ; Y == Z -> { false } + ( Y == 0 -> false + ; Y == Z -> false ; X == Y -> kill(MState), queue_goal(Z = 0) ; true ), @@ -5383,7 +5383,7 @@ run_propagator(pmax(X,Y,Z), MState) --> ; nonvar(Z) -> ( Z =:= X -> kill(MState), queue_goal(X #>= Y) ; Z > X -> queue_goal(Z = Y) - ; { false } % Z < X + ; false % Z < X ) ; Y == Z -> kill(MState), queue_goal(Y #>= X) ; { fd_get(Y, _, YInf, YSup, _) }, @@ -5419,7 +5419,7 @@ run_propagator(pmin(X,Y,Z), MState) --> ; nonvar(Z) -> ( Z =:= X -> kill(MState), { X #=< Y } ; Z < X -> Z = Y - ; { false } % Z > X + ; false % Z > X ) ; Y == Z -> kill(MState), queue_goal(Y #=< X) ; { fd_get(Y, _, YInf, YSup, _) }, @@ -5734,8 +5734,7 @@ run_propagator(reified_fd(V,B), MState) --> B = 1 ; { B == 0 } -> ( { fd_inf(V, inf) } -> [] - ; { fd_sup(V, sup) } -> [] - ; { false } + ; { fd_sup(V, sup) } ) ; [] ).