General_9
General_9

Reputation: 2319

Prolog why does this query return this particular result and what is its effect

?- assert(p(a)),assert(p(b)),setof(X,p(X),R).
X = H142
R = [a, b] 
yes

Whats the effect of this query and why does it return this particular result?

Upvotes: 0

Views: 120

Answers (1)

mjv
mjv

Reputation: 75298

The reason for the yes result is that R, i.e. the set made of just a and b is effectively the set of all Xs that satisfy p(x) predicate.

If you were to add elements to R or to remove a or b from it, the result would be no.

p(a) and p(b) are true because the assert predicates added these clauses to the database.

Similarly, keeping R = [a, b] if you were to add another clause, with say assert(p(c)), the result would be no   (because R would be missing c to have all X which satisfy p(X)).

Upvotes: 2

Related Questions