This preview shows pages 1–3. Sign up to view the full content.
How to Design Programs: An Introduction to Computing and Programming [Go to first, previous, next page; contents; index]Section 13Intermezzo 2: List Abbreviations[../icons/plt.gif]Intermediate Student Using consto create lists is cumbersome if a list contains many items. Fortunately, Scheme provides the listoperation, which consumes an arbitrary number of values and creates a list. Here is Scheme's extended syntax: <prm> = listThe extended collection of values is <val> = (list <val> ... <val>)A simpler way to understand listexpressions is to think of them as abbreviations. Specifically, every expression of the shape (list exp-1 ... exp-n)stands for a series of nconsexpressions: (cons exp-1 (cons ... (cons exp-n empty)))Recall that emptyis not an item of the list here, but the rest of the list. Here are three examples: (list 1 2)= (cons 1 (cons 2 empty)) (list 'Houston 'Dallas 'SanAntonio)= (cons 'Houston (cons 'Dallas (cons 'SanAntonio empty))) (list false true false false)= (cons false (cons true (cons false (cons false empty)))) (1 of 6) [2/5/2008 4:46:35 PM]
has intentionally blurred sections.
Sign up to view the full version.