Skip to content

Commit 32d8991

Browse files
committed
Isolate cut in if_/3 subgoals
1 parent f2ccdbe commit 32d8991

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/lib/reif.pl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@
6666
\+ predicate_property(M:G_0, (meta_predicate _)),
6767
!,
6868
MGx_0 = M:G_0.
69-
goal_expanded(call(G_0), Gx_0) :-
69+
goal_expanded(call(if_(A,B,C)), if_(A,B,C)) :-
70+
acyclic_term(if_(A,B,C)),
71+
!.
72+
goal_expanded(call(M:G_0), M:G_0) :-
73+
acyclic_term(G_0),
74+
nonvar(G_0),
75+
atom(M),
76+
!.
77+
goal_expanded(call(G_0), call(Gx_0)) :-
7078
acyclic_term(G_0),
7179
nonvar(G_0),
7280
% more conditions

src/tests/reif.pl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
)).
2929

3030
test("doesnt modify free variables", (reif:goal_expanded(A,B), A == B, var(A))).
31-
test("expands call/1", reif:goal_expanded(call(a), a)).
31+
test("doesnt expand call/1", reif:goal_expanded(call(a), call(a))).
32+
test("expands call(if_/3)", reif:goal_expanded(call(if_(A,B,C)), if_(A,B,C))).
3233
test("expands call/1 for modules", reif:goal_expanded(call(a:b(1)), a:b(1))).
3334
test("expands call/2 for modules", reif:goal_expanded(call(a:b,c), a:b(c))).
3435
test("doesn't expand call/2", reif:goal_expanded(call(b,c), call(b,c))).
@@ -54,38 +55,38 @@
5455
*/
5556
test("goal_expansion (=)", (
5657
subsumes_full_expansion(if_(1=2,a,b), (
57-
1 \= 2 -> b
58-
; 1 == 2 -> a
59-
; 1 = 2, a
60-
; dif(1,2), b)))).
58+
1 \= 2 -> call(b)
59+
; 1 == 2 -> call(a)
60+
; 1 = 2, call(a)
61+
; dif(1,2), call(b))))).
6162

6263
test("goal_expansion (;)", (
6364
subsumes_full_expansion(if_((1=2;3=3),a,b), (
6465
1 \= 2 -> if_(3=3,a,b)
65-
; 1 == 2 -> a
66-
; 1 = 2, a
66+
; 1 == 2 -> call(a)
67+
; 1 = 2, call(a)
6768
; dif(1,2), if_(3=3,a,b))))).
6869

6970
test("goal_expansion (,)", (
7071
subsumes_full_expansion(if_((1=2,3=3),a,b), (
71-
1 \= 2 -> b
72+
1 \= 2 -> call(b)
7273
; 1 == 2 -> if_(3=3,a,b)
7374
; 1 = 2, if_(3=3,a,b)
74-
; dif(1,2), b)))).
75+
; dif(1,2), call(b))))).
7576

7677
test("goal_expansion memberd_t", (
7778
subsumes_full_expansion(if_(memberd_t(f,"abcdefgh"),t,f), (
7879
call(memberd_t(f,"abcdefgh"),A),
79-
( A == true -> t
80-
; A == false -> f
80+
( A == true -> call(t)
81+
; A == false -> call(f)
8182
; nonvar(A) -> throw(error(type_error(boolean,A),_))
8283
; throw(error(instantiation_error,_))))))).
8384

8485
test("goal_expansion cond_t", (
8586
subsumes_full_expansion(if_(cond_t(a,b),t,f), (
8687
call(cond_t(a,b),A),
87-
( A == true -> t
88-
; A == false -> f
88+
( A == true -> call(t)
89+
; A == false -> call(f)
8990
; nonvar(A) -> throw(error(type_error(boolean,A),_))
9091
; throw(error(instantiation_error,_))))))).
9192

0 commit comments

Comments
 (0)