next up previous
Next: Equating Lists Up: No Title Previous: A program ... FINALLY!!

Compound Terms and Structures



An example, a menu :

lunch( Soft_drink, Main_meal, Donut, Beverage)

eg : lunch( diet_coke, pizza, donut, coffee)

donut(jam_donut, ring_donut, choc_donut, caramel_donut, custard_donut)

With lunch now becoming a mouthful :

lunch( Soft_drink, Main_meal,
donut(jam_donut, ring_donut, choc_donut, caramel_donut, custard_donut),
Beverage).

etc ...

As structures get more complex, it is usually better to start representing them as Trees, so that the relationships between sub-structures become more clear.

More Lists

A non-empty list consists of a HEAD and a TAIL.

The FIRST ELEMENT is said to be the HEAD of the list and the rest constitutes the TAIL.

We can make this explicit, by using the \| notation, for instance :

[1,2,3] = [1 | [2,3]]


["One", "Two", "Three"]		"One" 	["Two","Three"]


[145]				145	[]


[]				undefined undefined


[[1,2],[3,4,5],[]]		[1,2]	[[3,4,5],[]]


[a]				a	[]

List is a very important and useful data structure within Prolog, and extensively used.



Omer F Rana
Mon Feb 3 13:14:13 GMT 1997