liveBook · Manning

List

As explained in How Computers Make Books

A list is an ordered collection of elements that can be empty or decomposed into a first element and a remaining sublist.

A list is an ordered collection of values, written with square brackets and commas. Order matters: [1, 5, 4] differs from [5, 4, 1], while [] represents a list with no elements. section 7.6

A list can be understood through its first element and everything that follows:

Working through a list

List functions can handle the empty list first, then reduce a nonempty list to its head and tail. Length is 0 for []; otherwise it is 1 plus the length of the tail. The same pattern calculates a sum. Reversing [1, 3, 5, 7] produces [7, 5, 3, 1], even though the end cannot be accessed directly. section 7.6

Sorting by insertion

Sorting [53, 9, 2, 6, 19] into [2, 6, 9, 19, 53] becomes manageable when the tail is sorted first. Insert the head into that sorted tail: place it at the front when it is small enough, or continue searching through the tail. section 7.7

How How Computers Make Books covers it

How deep it goes
Defines heads, tails, emptiness, concatenation, and recursive list algorithms, without detailing underlying storage.
Examples
Uses empty lists, ordered number lists, length, sum, reversal, and insertion sorting as worked examples.
What it assumes
Assumes familiarity with simple numbers, truth values, arithmetic, and functions while introducing structured data.
What you can do after
Build it from scratch by defining list length, sum, reversal, insertion, and sorting functions.
How it connects
Connects lists with functions, arithmetic, structured data, recursion, and sorting.

Also explained in

Compare how 21 books explain list →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of How Computers Make Books. The section links point to the parts of the book it draws on.