How to Design Programs: An Introduction to Programming and Computing

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
How to Design Programs: An Introduction to Computing and Programming [Go to first , previous , next page; contents ; index ] Section 13 Intermezzo 2: List Abbreviations [../icons/plt.gif] Intermediate Student Using cons to create lists is cumbersome if a list contains many items. Fortunately, Scheme provides the list operation, which consumes an arbitrary number of values and creates a list. Here is Scheme's extended syntax: <prm> = list The extended collection of values is <val> = (list <val> ... <val>) A simpler way to understand list expressions is to think of them as abbreviations. Specifically, every expression of the shape (list exp-1 ... exp-n) stands for a series of n cons expressions: (cons exp-1 (cons ... (cons exp-n empty))) Recall that empty is 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]
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon