How to Design Programs: An Introduction to Computing and Programming [Go to first, previous, next page; contents; index]Section 18Intermezzo 3: Local Definitions and Lexical Scope[../icons/plt.gif]Intermediate Student Programs do not just consist of single definitions. In many cases, a program requires the definition of auxiliary functions or of functions with mutual references. Indeed, as we become more experienced, we write programs that consist of numerous auxiliary functions. If we are not careful, these large collections of functions overwhelm us. As the size of our functions grows, we need to organize them so that we (and other readers) can quickly identify the relationships between parts.This section introduces local, a simple construct for organizing collections of functions. With local, a programmer can group function definitions that belong together so that readers immediately recognize the connection between the functions. Finally, the introduction of localalso forces us to discuss the concept of variable binding. While the variable and function definitions of Beginning StudentScheme already introduce bindings into a program, a good understanding of localdefinitions is possible only with a thorough familiarity of this concept.18.1 Organizing Programs with localA local-expression groups together an arbitrarily long sequence of definitions similar to those found in the Definitionswindow. Following our established rules, we first introduce the syntax and then the semantics and pragmatics of local-expressions.Syntax of localA local-expression is just another kind of expression: <exp>= (local(<def-1>...<def-n>) <exp>) As usual, <def-1>...<def-n>is an arbitrarily long sequence of definitions (see figure 51) and <exp>is an arbitrary expression. In other words, a local-expression consists of the keyword local, followed by a sequence of definitions grouped with (and ), followed by an expression. file:///C|/Documents%20and%20Settings/Linda%20Graue...How%20to%20Design%20Programs/curriculum-Z-H-23.html (1 of 19) [2/5/2008 4:48:59 PM]
has intentionally blurred sections.
Sign up to view the full version.