#### Assignments Due

• Wednesday, 2 September (beginning of class): Problem Set 1
• Friday, 4 September: Read through the end of Chapter 4
• Monday, 7 September: read through the end of Section 5.4

### Backus-Naur Form Scheme Grammar with Rules of Evaluation

Expression ::= PrimitiveExpression
PrimitiveExpression ::= Number | true | false | Primitive Procedure

Evaluation Rule 1: Primitives. A primitive, evaluates to __________________________________________.

Expression ::= NameExpression
NameExpression ::= Name

Evaluation Rule 2: Names. A name expression evaluates to __________________________________________.

Expression ::= ApplicationExpression
ApplicationExpression ::= (Expression MoreExpressions)
MoreExpressions ::=
MoreExpressions ::= Expression MoreExpressions

Evaluation Rule 3: Application. To evaluate an application:
(a) Evaluate all the subexpressions (in any order)
(b) Apply the value of the first subexpression to the values of all the other subexpressions.

Application Rule 1: Primitives. If the procedure to apply is a primitive, __________________.

Application Rule 2: Constructed Procedures. If the procedure is a constructed procedure, ___________________ the body of the procedure with each formal parameter replaced by the corresponding actual argument expression value.

Expression ::= ProcedureExpression
ProcedureExpression ::= (lambda (Parameters) Expression)
Parameters ::=
Parameters ::= Name Parameters
Evaluation Rule 4: Lambda. A lambda expression evaluates to a procedure that takes the given parameters and has the expression as its body. (Do not do anything until it is applied.)

Expression ::= IfExpression
IfExpression ::= (if ExpressionPredicate ExpressionConsequent ExpressionAlternate)

Evaluation Rule 5: If. To evaluate an if expression, (a) evaluate the ___________________; then, (b) if the value of the predicate expression is ___________ then the value of the if expression is the value of the alternate expression; otherwise, the value of the if expression is the value of the _____________________________________.

### Questions

Show how the Rules of Evaluation would evaluate (square 4) where square is defined by:
(define square (lambda (x) (* x x)))
You will need more space for this, but its worth doing. Of course, you know the final value, but the important thing is to understand how following the Scheme evaluation rules steps will produce that value. You should be confident that you can determine the value of any Scheme expression just by following the evaluation rules systematically.

Evaluation Rule 3a does not say in what order the subexpressions should be evaluated in. For example, we could evaluate them left to right, or right to left, or in any other order. Does it ever matter in which order the subexpressions of an application are evaluated? (Tough question, but try to think of a Scheme expression where it would make a difference.)