next up previous contents
Next: Building Structure in Up: Reconstructing Lists Previous: Reconstructing Lists

Building Structure in the Clause Head

This is the same as the previous return a result ---having processed all elements. The following version of predicate triple/2 is described as building structure in the clause head:

 
triple([],[]).

triple([H1T1],[H2T2]):-

H2 is 3*H1,

triple(T1,T2).

We can see this if we think of the output argument as a structure which is to be constructed out of two parts: a bit we can calculate easily ( H2) and another bit which requires a recursive call to determine its structure ( T2). The term [H2T2] just shows how the result is constructed out of these bits.



Paul Brna
Mon May 24 20:14:48 BST 1999