0
votes

is there a way I can query a SWI Prolog database to check if it doesn't contain an element?

I have tried using "not" but doesn't seem to work with this version of Prolog.

1
If you have defined something like st(1). and when you execute your program you type a query st(45). you would get false as an answer. That would mean that the database you've created doesn't contain that element. Is that what you want?Shevliaskovic
Perhaps you can be explicit about what you've tried and in what way it "doesn't seem to work"?hardmath
SWI-Prolog's 7.1.0 documentation urges developers to use "\+" rather than "not" for new code. See bottom of page here. However "not" should still be available for backward compatibility.hardmath

1 Answers

2
votes

maybe you're looking for clause/2. A dummy session sample

1 ?- [user].
|: a(1).
|: a(2).
|: a(X) :- b(X).
|: b(3).
|: b(4).
% user://1 compiled 0.03 sec, 6 clauses
true.

2 ?- clause(a(X),Body).
X = 1,
Body = true ;
X = 2,
Body = true ;
Body = b(X).

3 ?- clause(b(X),Body).
X = 3,
Body = true ;
X = 4,
Body = true.

4 ?- clause(c(X),Body).
false.

you can see that c/1 is not defined...

Anyway, SWi-Prolog database is a complex beast, and it offers much more control about its contents.