CMSC 15100 — Lecture 11

Lists

It turns out that what we have just described are actually lists. Lists happen to be a fundamental structure in programming, functional programming, and in Racket. In fact, Lisp, the family of languages to which Racket belongs, is named so for List Processor.

Racket has built-in facilities for working with lists. This means we will need to translate the bespoke UnaryTree concepts that we've played with into their actual Racket built-in counterparts.

A list is either

The fact that lists are really made of pairs is intriguing, but when you really sit down and think about it, our UnaryTree structure Cons is really a pair, since it contains exactly two fields: root and sub. So we could hypothetically envision it as a (Pairof A (UnaryTree A)).

Lists have type (Listof A), where A is a type variable as in our previous definitions. So just as we had (Tree Integer) for a binary tree of Integers, we would have (Listof Integer) for a list of Integers.

Our structure, Cons is meant to emulate the built-in function cons, which is short for construct. We can use this to draw analogies to the built-in functions for working with lists.