Compound Data, Part 1: Structures

external ~<#3704#>Remind your students of ping-pong. To implement this kind of game, we need to compound data: position, velocity, balls. Otherwise we quickly lose track of what is what, especially if we were to use many balls. We will study a game with a large number of balls in a short while.<#3704#> The input of a function is seldom a single measurement (number), a single switch position (boolean), or a single name (symbol). Instead, it is almost always a piece of data that represents an object with many properties. Each property is a piece of information. For example, a function may consume a record about a CD; the relevant information might include the artist's name, the CD title, and the price. Similarly, if we are to model the movement of an object across a plane with a function, we must represent the position of the object in the plane, its speed in each direction, and possibly its color. In both cases, we refer to several pieces of information as if they were one: <#3705#>one<#3705#> record and <#3706#>one<#3706#> point. In short, we <#60943#><#3707#>COMPOUND<#3707#><#60943#> several pieces of data into a single piece of data. Scheme provides many different methods for compounding data. In this section, we deal with <#60944#><#3708#>STRUCTURES<#3708#><#60944#>. A structure combines a fixed number of values into a single piece of data. In section~#seclists#3709>, we will encounter a method for combining an arbitrarily large number of values into a single piece of data.