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).
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).
?- male(P),P\=ahmed.
– CapelliCdif(P, ahmed), male(P)
– false