<< >> Up Title Contents

2.1.2. Exercises:

1. Define a predicate fifth/2 that, given a list as first argument, returns the fifth element of the list as its second argument. E.g.

| ?- fifth([1,2,3,4,5,6,7], X).

X = 5

yes

2. Recall that every list (the empty list) has both a head and a tail. Use this fact, and the head|tail notation to define a predicate is_list/1 that returns true if its argument is a list (including the empty list) and false otherwise.

3. Define a predicate cons/3, which takes a list as its second argument, anything as its first argument and returns as its third argument a new list in with the first argument as head and the second argument as tail.


<< >> Up Title Contents