Exercises in this lecture               Go to the notes, in which this exercise belongs -- Keyboard shortcut: 'u'   Alphabetic index   Course home      

Exercise 1.4
A Proper List Predicate *


The Scheme function (predicate) pair? tells if its parameter is a pair (constructed by cons). The function null? tells if its parameter is the empty list. The function list? tells if its parameter is a proper list. In this exercise, write your own version of list? Let us call our function proper-list?

Intuitively, a proper list is empty, or it is 'ended by' an empty list (by following the cdr chain).

You may want to read about pairs and lists in the Scheme Report.

Can you write your predicate without thinking (and programming) in terms of a while loop?

Can you write your predicate without using if or cond?

Is your function efficient? What is the time complexity?

Please - consider these questions carefully.


Solution