General
Material
Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 5

Matching tasks with lists

To get a feeling for how the different list representations work, ask some matching queries involving lists and try to understand why Prolog answers the way it does. For example,

  • .(a,.(b,.(c,.(d,[])))) = [a|[b|[c|[d|[]]]]].
  • .(a,.(b,.(c,.(d,[])))) = [a,b,c,d].
  • [a,b,c,d] = [a|[a,b,c]].
  • [a,b,c,d] = [Head|Tail].
  • [a,b,c,d] = [a|X].
  • [a,X] = [a|[a,b,c]].
  • [a,b,c,d] = [a,b|[c,d]].
  • [a,b,c,d] = [X,Y|_].
  • [] = [[]].
  • [X] = [[]].

Back to the practical session of day 3.