Elijah.Lnd
Elijah.Lnd

Reputation: 46

How to read a list inside a fact?

I have this piece of code person/3 ( name , date of birth , work ) , in which the first two persons are the parents and the last two are the children.

person(name(nicko,grossenbacher),date(7,may,1969),works(spc,15200)).
person(name(maria,grossenbacher),date(9,may,1969),works(unemployed,0)).
person(name(pat,grossenbacher),date(5,may,1999),works(unemployed,0)).
person(name(jim,grossenbacher),date(5,may,1999),works(unemployed,0)).

I have defined a family/3 in which the first place is taken by the father, second by the mother and the third is a list which is taken by the two children.

family(
   name(nicko,grossenbacher),
   name(maria,grossenbacher),
   [(name(pat,grossenbacher),name(jim,grossenbacher))]).

This is a rule I created in which I defined that in a family the parent will be in either the first or the second place of family/3

parent(name(X,Y)):-family(name(X,Y),_,_);family(_,name(X,Y),_).

What I am trying to do is, firstly, I am defining a rule that the child is located in the third place of family/3 with the following rule

child(X):- family(_,_,Children), member(X,Children).

Which, when I invoke it, it comes as false.

Secondly, what I wanted to do is, using the other rule date of birth/2 to return the persons name and date of birth for everyone born in the same year however it doesn’t seem to do that.

dateofbirth(name(X,Y),L)):-person(name(X,Y),date(_,_,L),_).

Upvotes: 1

Views: 57

Answers (1)

Deffa
Deffa

Reputation: 184

You've got actually two syntax errors:

  1. [(name(pat,grossenbacher),name(jim,grossenbacher))] should be [name(pat,grossenbacher),name(jim,grossenbacher)]
  2. dateofbirth(name(X,Y),L)):-person(name(X,Y),date(_,_,L),_). should be dateofbirth(name(X,Y),L):-person(name(X,Y),date(_,_,L),_).

Upvotes: 1

Related Questions