some correction from most expensive text books.
?-consult(user).
doll(barbies).
doll(tubies).
play(farzanah,tubies).
like(farzanah,X) :- doll(X),play(farzanah,X).
like(suzi,Y) :- like(farzanah,Y).
tekan ctrl-z pastu tekan
yes
so then u will get errors on example for us to do practice.
its really hurts that u wasted your time for such simple errors.
How does Prolog find answers for:
- Suzi will like Y if farzanah likes Y.
- Farzanah will like Y if Y is a doll and farzanah plays with dolls.
- Barbies are dolls and farzanah plays with barbies.
From the situations above, we can say that suzi likes barbies because suzi likes what farzanah likes and it is also stated that farzanah likes barbies. Therefore, suzi likes barbies. How are such situations encoded in Prolog?
The statement ‘suzi will like Y if farzanah likes Y’ can be coded in a rule form since the statement shows conditional state.
like(suzi,Y) :- like(farzanah,Y).
The statement ‘farzanah will like Y if Y is a doll and farzanah plays with dolls’ can be encoded in Prolog as:
like(farzanah,Y) :- doll(Y),play(farzanah,Y).
The third statement ‘barbies are dolls’ and ‘farzanah plays with barbies’ can be written as facts in Prolog as:
doll(barbies).
play(farzanah,barbies).
play(farzanah,barbies).
?-consult(user).
doll(barbies).
doll(tubies).
play(farzanah,tubies).
doll(tubies).
play(farzanah,tubies).
play(farzanah,barbies). % pembetulan
like(farzanah,X) :- doll(X),play(farzanah,X).
like(suzi,Y) :- like(farzanah,Y).
tekan ctrl-z pastu tekan
like(farzanah,X) :- doll(X),play(farzanah,X).
like(suzi,Y) :- like(farzanah,Y).
tekan ctrl-z pastu tekan