Chapter 11: Logic Languages

Declarative languages go for logic

Declarative languages go for logic

flowery(X) <- rainy(x)

rainy(Portland)
------------
flowery(Portland)

Prolog

Prolog

Prolog

Prolog

Prolog

Prolog

Prolog

?- [user].
rainy(seattle).
|: rainy(rochester).
|: cold(rochester).
|: snowy(X) :- rainy(X), cold(X).
|: % user://1 compiled 0.01 sec, 5 clauses
true.

?- snowy(X).
X = rochester.

Prolog (previous example continued)

?- [user].
cold(seattle).
Warning: user://2:38:
     Redefined static procedure cold/1
     Previously defined at user://1:26
|: cold(rochester).
|: % user://2 compiled 0.00 sec, 2 clauses
true.

?- snowy(X).
X = seattle ;
X = rochester.

?- 

Imperative Prolog

statement :- condition, !, then.
statement :- else.

Imperative Prolog

?- [user].
natural(1).
|: natural(N) :- natural(M), N is M+1.
|: looping(N) :- natural(I), write(I), nl, I = N, !.
|: % user://3 compiled 0.01 sec, 4 clauses
true.

?- looping(5).
1
2
3
4
5
true.

?- 

Where logic languages are limited

The future?