-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuiltins.pl
56 lines (45 loc) · 1.54 KB
/
builtins.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Auxiliary Prolog programs for the book %
% SIMPLY LOGICAL: Intelligent reasoning by example %
% (c) Peter A. Flach/John Wiley & Sons, 1994. %
% %
% Predicates: not/1 %
% '\='/2 %
% forall/2 %
% varsin/2 %
% %
% These predicates are available in some Prologs, %
% but not in others (eg., in Quintus Prolog they %
% are not built-in, but available in libraries). %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:-op(700,xfx,'\=').
:-op(900,fy,not).
not(X):-X,!,fail.
not(X).
X \= Y :- not X=Y.
forall(Goal,Condition):-
bagof0(Condition,Goal,List),
forall1(List).
forall1([]).
forall1([H|T]):-
call(H),
forall1(T).
bagof0(X,G,L):-
bagof(X,G,L),!.
bagof0(X,G,[]).
varsin(Term,Vars):-
varsin(Term,[],V),
sort(V,Vars).
varsin(V,Vars,[V|Vars]):-
var(V).
varsin(Term,V0,V):-
functor(Term,F,N),
varsin_args(N,Term,V0,V).
varsin_args(0,Term,Vars,Vars).
varsin_args(N,Term,V0,V):-
N>0, N1 is N-1,
arg(N,Term,ArgN),
varsin(ArgN,V0,V1),
varsin_args(N1,Term,V1,V).