How to create a list from facts in Prolog?

前端 未结 2 833
自闭症患者
自闭症患者 2021-01-18 11:59

There are these facts:

man(john).
man(carl).
woman(mary).
woman(rose).

I need to create the predicate people(List), which returns a list wi

2条回答
  •  情深已故
    2021-01-18 12:31

    Using findall/3:

    people(L) :- findall(X, (man(X) ; woman(X)), L).
    
    ?- people(X).
    X = [john, carl, mary, rose].
    

提交回复
热议问题