Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Prolog
Topic & Structure of The Lesson
• Facts
• Rules
• Prolog
• Fact
• Rules
• Definition:
• The recursion in any language is a
function that can call itself until the goal
has been succeed.
• In Prolog:
• Recursion appears when a predicate
contain a goal that refers to itself.
• A program calls itself typically until some
final point is reached.
somerelationship(a,b,c,[1,2,3])
|?-addr(flat(4),street(‘Home
Str.’),postcode(eh8_9lw))
= addr(flat(Z),Yy,postcode(Xxx)).
Z = 4,
Yy = street(‘Home Str.’),
Xxx = eh8_9lw ?
yes
• To add item to a list, easiest way is to put item in front of the list.
• X is the new item Added to list L will be given by relation
[X | L] or add(X,L,[X|L] ) .
| ?- X = 1+2.
Operator ‘is’ is a built-in
X = 1+2
procedure.
yes
| ?- X is 1+2.
X=3
yes
length1( [ ], 0).
length1( [ _ | Tail], N) :- length1( Tail, N1),
N = 1 + N1.
length2( [ ], 0).
length2( [ _ | Tail], N) :- N = 1 + N1,
length2( Tail, N1).
length2( [ _ | Tail], 1 + N) :- length2( Tail, N).
| ?- length2([a,b,c],N), Length is N.
Length = 2
N = 1+(1+(1+0))
Q&A
• Rete Algorithm