205x Filetype PDF File size 0.15 MB Source: www.inf.ed.ac.uk
N I V E R
U S
H E I T
Y
T
O F H
E G
D U R
I N B
Logic Programming:
Recursion, lists, data structures
Alan Smaill
Sep 28 2015
Alan Smaill Logic Programming: Recursion, lists, data structures Sep 28 2015 1/28
N I V E R
U S
Today H E I T
Y
T
O F H
E G
D U R
I N B
Recursion
proof search
practical concerns
List processing
Programming with terms as data structures.
Alan Smaill Logic Programming: Recursion, lists, data structures Sep 28 2015 2/28
N I V E R
U S
Recursion H E I T
Y
T
O F H
E G
D U R
I N B
So far the rules we have seen have been (mostly) non-recursive.
This is a limit on what can be expressed.
Without recursion, we cannot define transitive closure
eg define ancestor/2 in terms of parent/2.
Alan Smaill Logic Programming: Recursion, lists, data structures Sep 28 2015 3/28
This is a fine declarative description of what it is to be an ancestor.
But watch out for the traps!!!
N I V E R
U S
Recursion ctd H E I T
Y
T
O F H
E G
D U R
I N B
In recursive use, the same predicate is used in the head (lhs) of the
rule as in the body (rhs)
(in the second clause below):
ancestor(X,Y) :- parent(X,Y).
ancestor(X,Y) :- parent(X,Z),
ancestor(Z,Y).
Alan Smaill Logic Programming: Recursion, lists, data structures Sep 28 2015 4/28
no reviews yet
Please Login to review.