Prolog/Primi passi: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Filnik (discussione | contributi)
m typo
Riga 275:
 
== Esempi ==
?-madre(Mother,Child)
partner(john, gloria).
partner(david, britney).
partner(gino, topino).
partner(john, karen).
sex(john, man). % maschietti
sex(david, man).
sex(gino, man).
sex(bobbysolo, man).
 
sex(karen, woman). % femminucce
sex(sasha, woman).
sex(gloria, woman).
 
havechild(john, sasha). % genitori
havechild(john, david).
havechild(karen, sasha).
havechild(gloria, david).
 
isfather(A, B) :- sex( A, man), havechild( A, B).
ismother(A, B) :- sex( A, woman), havechild(A,B).
parents(A, F, M) :- isfather(F, A), sex(F, man), ismother(M,A), sex(M,woman).
 
===Interrogazioni :===
?- consult('prolog1.pl'). % carico il programma
% prolog1.pl compiled 0.00 sec, 288 bytes
true.
 
?- human( Person ).
Person = john ;
Person = david ;
Person = gino ;
Person = bobbysolo ;
Person = karen ;
Person = gloria.
 
?- partner( john, Who ).
Who = gloria ;
Who = karen.
 
?- sex(karen, woman).
true.
 
?- havechild(john, Child).
Child = sasha ;
Child = david.
 
?- isfather( john, sasha).
true .
 
?- parents( david, Father, Mother).
Father = john,
Mother = gloria .
 
?- parents( sasha, Father, Mother).
Father = john,
Mother = karen .
 
== Esercizi ==