user3264060
user3264060

Reputation: 9

Understanding how to use functors in Prolog

I have this database in Prolog. I'm trying to write a query that will return the names of all the people who own a honda.

I know how to do this with just car or truck with owns(X,car(honda,,)). , but I'm unsure how to return all the owners from car, truck and motorcycle at the same time.

Any help will be greatly appreciated I've been stuck on this problem for a while.

owns(bill, car(ford, mustang, 1964)).
owns(sue, car(pontiac, gto, 1967)).
owns(george, car(honda, civic, 2013)).
owns(betty, truck(ford, f150, 2013)).
owns(henry, motorcycle(honda, goldwing, 2010)).

Upvotes: 1

Views: 75

Answers (1)

CapelliC
CapelliC

Reputation: 60014

you could use univ/2

?- owns(Person, Owned), Owned =.. [_, honda|_].

or arg/3

?- owns(Person, Owned), arg(1, Owned, honda).

Upvotes: 2

Related Questions