Marci-man
Marci-man

Reputation: 2233

Prolog: Stating more facts in less statements

I have a problem in Prolog and I really really need help with it.

There are people (male and female) and they have propterties:

I need state these facts about a person, but I am not supposed to state more than 3 facts! could someone help me?

Upvotes: 0

Views: 93

Answers (1)

Daniel Lyons
Daniel Lyons

Reputation: 22803

Here's an easy way:

person(PersonName, Gender, Age, Weight, HairColor).
favorite(PersonName, Song, Sport, Book).

There's no reason you have to limit yourself to arity-1 or -2 facts. You can design your Prolog fact database the same way you would design a relational database. Prolog will index the first term of the fact automatically anyway, so make that a candidate key and observe as your program performs well despite the apparent searching. :)

Edit: To illustrate a few queries:

person(maria, female, 28, 61, blond).

Is there a person named Maria?

?- person(maria, _, _, _, _).
yes.

What is Maria's favorite sport?

?- favorite(maria, _, Sport, _).
Sport = tennis ;
no.

etc. For more details, see @mbratch's comment below.

Upvotes: 3

Related Questions