next up previous contents index
Next: Selector `car' Up: Basic abstractions for pairs Previous: Basic abstractions for pairs   Contents   Index

Constructor `cons'

The constructor consists of a synthesis of a head-item and a tail-item.
(define cons (lambda (hd tl)
(lambda (sel)
(sel hd tl))))
The abstraction `cons' takes two arguments, the head and the tail of the pair to be built and returns a function taking one argument which represents the new list.

To be precise we should have said the new `pair'. But because a pair has a tail pointing normally to another pair, we effectively have a new list as well. This is true however only if the convention is followed that the last pair in the list has a tail-value of `nil'.

`nil' is a special abstraction required at the end of a list to be able to determine the length of the list which depends on being able to recognize its end. The abstraction `nil', also called the `empty list', is defined as follows:
(define nil (lambda (f)

Georg P. Loczewski 2004-03-05

Impressum und Datenschutz