Logic Programming
06-25433
Autumn 2012

 

 

 

Lecture 7: Processing lists in Prolog

This lecture begins by revisiting the example of iteration expressed as recursion. Lists are introduced as a versatile data structure then the essentials of list processing in Prolog are demonstrated.

This lecture will:

  • explain why lists offer versatility;
  • describe the syntax of lists in Prolog;
  • show how Prolog unifies lists;
  • introduce three common patterns of termination in list processing:
    • when a certain number of list elements have been scanned;
    • when the end of a list is reached (ald so all elements scanned);
    • when a given element is found.
How to prepare

  Revise you knowledge of basic list processing either by: or
Video

  Recording of the lecture (Vimeo)

Slides

  If you really want the slides from the lecture ... but don't forget printing the slides is not the same as understanding them.

Summary

  Summary and programs with commentary from the lecture

Programs from the lecture

 
Example 1 - for_loop Example 2 - length of a list Example 3 - classifying elements of a list
Example 4 - membership of a list Example 5 - finding the nth member  

Individual study suggestions and further reading

 

Topics on lists to be studied include:

List processing is covered in:

Assessed work associated with this lecture

  Tutorial sheet 3

Tutorial sheet 4