Compound Data, Part 2: Lists

#drnsecrecordslists#9135> external ~<#62009#>Programming is only necessary if we wish to process large amounts of data. To do so, we must develop data definitions that include data objects of all kinds of sizes. The key is that we don't know how large the data item is. We could refer to it as a ``data item of unknown size,'' but we prefer to use the mathematical term ``arbitrarily large.'' For motivation, have students play with the protect-the-wall game. Use the teachpack <#9137#>protect-play.ss<#9137#>. Discuss how the game needs functions that manages a collection of balls: one function removes those balls that are no longer in the playing field, another one moves the remaining balls, etc. Each of these functions consumes a data item that describes an unknown number of balls. In conventional languages, our first encounter with arbitrarily large data is about files. We read items from a file until no more items are left. This kind of function, however, involves io, which is what we don't want. Lists will play an analogous role in our world, but they are different, and because they are different, they generalize to other forms of data.<#62009#> Structures are one way to represent compound information, and lists are another. Forming lists is something that all of us do. Before we go grocery shopping, we often write down a list of items that we want to purchase. When we plan out a day in the morning, we write down a list of things to do. During December, many children prepare Christmas wish lists. To plan a party, we enumerate the people we want to invite. In short, arranging information in the form of lists is a ubiquitous part of our life, and we should learn to represents lists as Scheme data. In this section, we first learn to create lists and then move on to developing functions that consume lists.