family(
  person( tom, fox, date( 7, may, 1960), works( bbc, 15200)),
  person( ann, fox, date( 9, may, 1961), unemployed),
  [ person( pat, fox, date( 5, may, 1983), unemployed),
    person( jim, fox, data( 5, may, 1983), unemployed) ] ).
family(
  person( marco, valtorta, date( 7, may, 1956), works( usc, 51000)),
  person( laura, valtorta, date( 12, january, 1958), works( self, 39000)),
  [ person( clara, valtorta, date( 10, september, 1984), unemployed),
    person( dante, valtorta, date( 7, april, 1995), unemployed) ] ).

husband( X) :- family( X, _, _).
wife( X) :- family( _, X, _).
child( X) :- family( _, _, Children), member( X, Children).
exists( Person) :- husband( Person); wife( Person); child( Person).
dateofbirth( person( _, _, Date, _), Date).
salary( person( _, _, _, works( _, S)), S).
salary( person( _, _, _, unemployed), 0).

/* total( List_of_people, Sum_of_their_salaries) */
total( [], 0).
total( [ Person | List], Sum) :-
  salary( Person, S),
  total( List, Rest),
  Sum is S + Rest.

/* Note for example on p.92: length/2 is built-in in SWI Prolog */
