The Grinnell Scheme Web: The cddddr
procedure

What kind of a structure can the cddddr procedure be applied to? What must its operand look like?

The operand must be a pair (pr1) in which the second component is also a pair (pr2); moreover, the second component of pr2 must also be a pair (pr3), and the second component of pr3 must also be a pair (pr4).

Which of the elements of such a structure does cddddr return?

It returns the second component of pr4.

> (define example-1 (cons #f (cons #f (cons #f (cons #f #t)))))
> (cddddr example-1)
#t
> (define example-2 (cons (cons (cons (cons 1 2) (cons 3 4))
                                (cons (cons 5 6) (cons 7 8)))
                          (cons (cons (cons 9 10) (cons 11 12))
                                (cons (cons 13 14) (cons 15 16)))))
> (cddddr example-2)
16
What happens if the structure has the wrong shape?

It is an error, so under most implementations the program crashes:

> (cddddr (cons (cons (cons 1 2) (cons 3 4))
                (cons (cons 5 6) (cons 7 8))))

ERROR: cddddr: Wrong type in arg1 8


Next topic
Previous topic
Table of contents


This document is available on the World Wide Web as

http://www.math.grin.edu/~stone/scheme-web/cddddr.html


created August 5, 1995
last revised December 26, 1995

Copyright 1995 by John David Stone (stone@math.grin.edu)