Section 38

How to Design Programs: An Introduction to Programming and Computing

Info iconThis 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 38 Intermezzo 7: The Final Syntax and Semantics With the introduction of set! -expressions and begin -expressions we have covered most of Scheme's kernel language. In DrScheme, this portion is called Advanced Student Scheme. Considering the complexity of set! , this is a good place to summarize our programming language in the spirit of intermezzo 1. Following the organization of that intermezzo, we discuss the vocabulary, the grammar, and the meaning of Advanced Student Scheme. The last subsection explains what kind of errors we may encounter in Advanced Student Scheme. 38.1 The Vocabulary of Advanced Scheme The foundation of any language is its vocabulary. In Beginning Student Scheme, we distinguish four categories of words: variables, constants, primitive functions, and keywords. The classification ignores parentheses but we know that every compound phrase is surrounded by a pair of parentheses, and that every atomic phrase stands on its own. Advanced Student Scheme respects this basic classification, though it contains four important new keywords: local , lambda , set! , and begin . The first two are important for organizing and abstracting programs; the last two are important for the computation of effects. Still, keywords per se have no meaning. They are road signs that tell us what is ahead so that we can orient ourselves. It is the grammar and the meaning of a language that explains the role of the keywords. 38.2 The Grammar of Advanced Scheme Even though Scheme is a full-fledged language with as much power as any other programming language, its designers have kept its grammar simple. The grammar of Advanced Student Scheme, which is most of Scheme, is only a few lines longer than that of Beginning Student Scheme. file:///C|/Documents%20and%20Settings/Linda%20Graue. ..How%20to%20Design%20Programs/curriculum-Z-H-47.html (1 of 22) [2/5/2008 4:58:03 PM]
Background image of page 1

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

View Full Document Right Arrow Icon
How to Design Programs: An Introduction to Computing and Programming <def> = ( define ( <var> <var> ...<var> ) <exp> ) | ( define <var> <exp> ) | ( define-struct <var0> ( <var-1> ... <var-n> )) <exp> = <var> | <con> | <prm> | ( <exp> <exp> ...<exp> ) | ( cond ( <exp> <exp> ) ... ( <exp> <exp> )) | ( cond ( <exp> <exp> ) ... ( else <exp> )) | ( local ( <def> ...<def> ) <exp> ) | ( lambda ( <var> ...<var> ) <exp> ) | ( set! <var> <exp> ) | ( begin <exp> ...<exp> ) Figure 111: Advanced Student Scheme: The core grammar Figure 111 contains the essential grammar of the Advanced Student Scheme language. 71 It extends Intermediate Student Scheme with three new forms of expressions: lambda -expressions, set! - expressions, and begin -expressions. The specification of local -expressions refers to the category of definitions, which refers back to the category of expressions. A lambda -expression consists of a sequence of variables, enclosed in parentheses, and an expression. Similarly, a
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 22

Section 38 - How to Design Programs An Introduction to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online