There are these facts:
man(john).
man(carl).
woman(mary).
woman(rose).
I need to create the predicate people(List), which returns a list with the name of every man and woman based on the previous facts. This is what I need as output:
?- people(X).
X = [john, carl, mary, rose]
And here is the code I wrote, but it's not working:
people(X) :- man(X) ; woman(X).
people(X|Tail) :- (man(X) ; woman(X)) , people(Tail).
Could someone please help?
Using findall/3
:
people(L) :- findall(X, (man(X) ; woman(X)), L).
?- people(X).
X = [john, carl, mary, rose].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With