0
votes

For the following SWI-Prolog program, I want to create a predicate that returns all values except a single one.
For example, return all males except ahmed.
How can I do that?

male(ahmed).
male(mohamed).
male(ali).
male(samir).
male(khalid).
1
?- male(P),P\=ahmed.CapelliC
@CapelliC, oh please: dif(P, ahmed), male(P)false

1 Answers

2
votes

Not sure to understand.

Do you want a predicate that return one single name of a (no Ahmed) male and, recalling it, via backtraching, another name, and another one... ?

I suppose that you can simply write

noAhmed(M) :-
  male(M),
  M \= ahmed.

Or do you want a predicate that return a list with all the (no Ahmed) male names?

In this case, you can write

noAhmedList(L) :-
  findall(M, (male(M), M \= ahmed), L).