From d90cf6384c38fc992163573d86616a6759e71e9f Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Sat, 8 Jan 2022 00:04:04 -0700 Subject: [PATCH] complete handling of control operators in interpreted (,)/2 (#1172) --- src/lib/builtins.pl | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/lib/builtins.pl b/src/lib/builtins.pl index 32527df9..4619bfad 100644 --- a/src/lib/builtins.pl +++ b/src/lib/builtins.pl @@ -225,6 +225,11 @@ comma_dispatch(G1, G2, B) :- comma_dispatch_prep((G1, G2), B, Conts), comma_dispatch_call_list(Conts). +:- non_counted_backtracking cont_list_to_goal/2. + +cont_list_goal([Cont], Cont) :- !. +cont_list_goal(Conts, builtins:comma_dispatch_call_list(Conts)). + :- non_counted_backtracking comma_dispatch_prep/3. comma_dispatch_prep(Gs, B, [Cont|Conts]) :- @@ -232,14 +237,30 @@ comma_dispatch_prep(Gs, B, [Cont|Conts]) :- ( functor(Gs, ',', 2) -> arg(1, Gs, G1), arg(2, Gs, G2), - ( nonvar(G1), ( G1 = ! ; G1 = _:! ) -> - Cont = builtins:set_cp(B) - ; Cont = G1 - ), + comma_dispatch_prep(G1, B, IConts1), + cont_list_goal(IConts1, Cont), comma_dispatch_prep(G2, B, Conts) ; ( Gs = ! ; Gs = _:! ) -> Cont = builtins:set_cp(B), Conts = [] + ; functor(Gs, ';', 2) -> + arg(1, Gs, G1), + arg(2, Gs, G2), + comma_dispatch_prep(G1, B, IConts0), + comma_dispatch_prep(G2, B, IConts1), + cont_list_goal(IConts0, Cont0), + cont_list_goal(IConts1, Cont1), + Cont = ( Cont0 ; Cont1 ), + Conts = [] + ; functor(Gs, ->, 2) -> + arg(1, Gs, G1), + arg(2, Gs, G2), + comma_dispatch_prep(G1, B, IConts1), + comma_dispatch_prep(G2, B, IConts2), + cont_list_goal(IConts1, Cont1), + cont_list_goal(IConts2, Cont2), + Cont = (Cont1 -> Cont2), + Conts = [] ; Cont = Gs, Conts = [] ) @@ -247,7 +268,6 @@ comma_dispatch_prep(Gs, B, [Cont|Conts]) :- Conts = [] ). - :- non_counted_backtracking comma_dispatch_call_list/1. comma_dispatch_call_list([]). -- 2.54.0