0
votes

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

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

  • Name
  • Gender
  • Age
  • Weight
  • Hair color
    and
  • favourite song
  • favourite sport
  • favourite book

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

1

1 Answers

3
votes

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.