[Previous] [Up]
Go backward to Prolog Samples
Go up to Difference Lists and Definite Clause Grammars

Exercises

  1. When you use the difference list format, it is important to be careful with the choice of variable names. What would happen if you made the following query?
    | ?- List = [a,b,c|X], X = [d,e,f|X].
    
  2. We do not strictly use the difference list format to concatenate lists, but rather to identify parts of lists. You could use it to concatenate lists however. Here is a single fact which encodes difference list concatenation:
    dl_conc(S0-S1,S1-S2,S0-S2).
    
    (I have used A-B instead of A,B to make it easier to see which lists belong together.) Call it with a few different lists so that you understand how it works.
  3. To think about: Why is an explicit call to dl_conc not needed in the Prolog procedure?

<a.von.klopp@bangor.ac.uk>

[Previous] [Up]