/* Test of setof_okeefe_v3 in Picat v3. This is a test of bag_of/3, set_of/3, and findall/3 defined in setof_okeefe_v3.pi (a port of O'Keefe's setof.pl). This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import setof_okeefe_v3. main => go. go ?=> Tests = [ findall_test1, findall_test2, bagof_test1a, bagof_test1b, bagof_test2a, bagof_test2b, bagof_test3a, bagof_test3b, bagof_test4, bagof_test5, bagof_test6, bagof_test7, bagof_test8, setof_test1, setof_test2, setof_test3, setof_test4, setof_test5, setof_test6, setof_test7 ], foreach(Test in Tests) println(Test), call(Test), nl end, nl. go => true. findall_test1 ?=> findall([X,Y],$p(X,Y),L), println(l=L), nl. findall_test1 => true. findall_test2 ?=> findall([X,Y],$(p(X,Y),p2(X)),L), println(l=L), nl. findall_test2 => true. bagof_test1a ?=> bag_of([X,Y],$p(X,Y),L), println(l=L), fail, nl. bagof_test1a => true. bagof_test1b ?=> bag_of([X,Y],$(p(X,Y),p2(X)),L), println(l=L), fail, nl. bagof_test1b => true. bagof_test2a ?=> bag_of(X,$p(X,Y),L), println([y=Y,l=L]), fail, nl. bagof_test2a => true. bagof_test2b ?=> bag_of(X,$(p(X,Y),p2(X)),L), println([y=Y,l=L]), fail, nl. bagof_test2b => true. bagof_test3a ?=> bag_of(Y,$p(X,Y),L), println([x=X,l=L]), fail, nl. bagof_test3a => true. bagof_test3b ?=> bag_of(Y,$(p(X,Y),p2(X)),L), println([x=X,L]), fail, nl. bagof_test3b => true. bagof_test4 ?=> bag_of([X,Y],$p(X,Y),L), println(l=L), fail, nl. bagof_test4 => true. bagof_test5 ?=> bag_of([Y,X],$p(X,Y),L), println(l=L), fail, nl. bagof_test5 => true. bagof_test6 ?=> bag_of(Person, $likes(Person, pizza), L), println(l=L), fail, nl. bagof_test6 => true. bagof_test7 ?=> bag_of(Person, $likes(Person, What), L), println([what=What,l=L]), fail, nl. bagof_test7 => true. bagof_test8 ?=> bag_of(What, $likes(Person, What), L), println([person=Person,l=L]), fail, nl. bagof_test8 => true. setof_test1 ?=> set_of([X,Y],$p(X,Y),L), println(l=L), fail, nl. setof_test1 => true. setof_test2 ?=> set_of(X,$p(X,Y),L), println([y=Y,l=L]), fail, nl. setof_test2 => true. setof_test3 ?=> set_of(Y,$p(X,Y),L), println([x=X,l=L]), fail, nl. setof_test3 => true. setof_test4 ?=> set_of([Y,X],$p(X,Y),L), println(l=L), fail, nl. setof_test4 => true. setof_test5 ?=> set_of(Person, $likes(Person, pizza), L), println(l=L), fail, nl. setof_test5 => true. setof_test6 ?=> set_of(What, $likes(Person, What), L), println([person=Person,l=L]), fail, nl. setof_test6 => true. setof_test7 ?=> set_of(Person, $likes(Person, What), L), println([what=What,l=L]), fail, nl. setof_test7 => true. % Just a simple test p(7,a). p(7,x). p(2,y). p(1,p). p(1,p). p(4,a). p2(N) :- N > 2. % From https://www.cse.unsw.edu.au/~billw/dictionaries/prolog/bagof.html % ?- bagof(Person, likes(Person, pizza), Bag). % Person = _G180 % Bag = [mary, marco, marco] likes(mary, pizza). likes(marco, pizza). likes(adam,pancakes). likes(eve,pancakes). likes(eve,apples). likes(Human, pizza) :- italian(Human). italian(marco).