2. Announcements
PS1 is due Monday (electronic submission and
paper submission): don’t wait to get started!
Quiz 1 is Wednesday (in class)
Chapters 1-4 of Course Book
Chapters 1-3 of The Information
Classes 1-5 (including questions from class
notes)
I haven’t forgotten about answering your questions from PS0.
I will post my answers by tomorrow.
3. Recap: Assigning Meanings
Program ::= ε | ProgramElement Program
ProgramElement ::= Expression | Definition
Definition ::= (define Name Expression)
Expression ::= PrimitiveExpression | NameExpression
| ApplicationExpression | ProcedureExpression | IfExpression
PrimitiveExpression ::= Number | true | false| PrimitiveProcedure
NameExpression ::= Name
ApplicationExpression ::= (Expression MoreExpressions)
MoreExpressions ::= ε | Expression MoreExpressions
ProcedureExpression ::= (lambda (Parameters) Expression)
Parameters ::= ε | Name Parameters
IfExpression ::= (if ExpressionPred ExpressionConsequent ExpressionAlt)
This grammar generates (nearly) all surface forms in the Scheme.
language. If we have a meaning rule for each grammar rule, we can
determine the meaning of every Scheme program.
3
4. Evaluation Rules: Last Class
PrimitiveExpression ::= Number | true | false| PrimitiveProcedure
Rule 1: If the expression is a primitive, it evaluates to its pre-
defined value.
NameExpression ::= Name
Rule 2: A name evaluates to the value associated with that name.
ApplicationExpression ::= (Expression MoreExpressions)
MoreExpressions ::= ε | Expression MoreExpressions
Rule 3: To evaluate an application expression:
a) Evaluate all the subexpressions (in any order)
b) Apply the value of the first subexpression to the values of all the other
subexpressions.
4
5. Last class: Rules for Application
1. Primitives. If the procedure to apply is a
primitive procedure, just do it.
2. Constructed Procedures. If the procedure is
a constructed procedure, evaluate the body
of the procedure with each parameter name
bound to the corresponding input
expression value.
This only makes sense if we know what a constructed procedure is!
5
7. Constructing Procedures
lambda means “make a procedure”
Expression ::= ProcedureExpression
ProcedureExpression ::=
(lambda (Parameters) Expression)
Parameters ::= ε
Parameters ::= Name Parameters
7
8. Evaluation Rule 4: Lambda
A lambda expression evaluates to a
procedure that takes the given
parameters and has the expression as
its body.
ProcedureExpression ::= (lambda (Parameters) Expression)
Parameters ::= ε | Name Parameters
8
10. Applying Compound Procedures
Rule 3: To evaluate an application expression:
((lambda () (a) Evaluate all the subexpressions (in any
order)
true) (b) Apply the value of the first subexpression
to the values of all the other subexpressions.
1120)
Apply Rule for constructed procedures:
Evaluate the body of the procedure with each
parameter name bound to the corresponding
input expression value.
Evaluation Rule 4. A lambda expression
evaluates to a procedure that takes the given
parameters and has the expression as its body.
11. Applying Compound Procedures
Rule 3: To evaluate an application expression:
((lambda (x) (a) Evaluate all the subexpressions (in any
order)
(+ x 1000)) (b) Apply the value of the first subexpression
to the values of all the other subexpressions.
120)
Apply Rule for constructed procedures:
Evaluate the body of the procedure with each
parameter name bound to the corresponding
input expression value.
Evaluation Rule 4. A lambda expression
evaluates to a procedure that takes the given
parameters and has the expression as its body.
12. Applying Compound Procedures
Rule 3: To evaluate an application expression:
((lambda (x) (a) Evaluate all the subexpressions (in any
order)
(+ x 1000)) (b) Apply the value of the first subexpression
to the values of all the other subexpressions.
x)
Apply Rule for constructed procedures:
Evaluate the body of the procedure with each
parameter name bound to the corresponding
input expression value.
Evaluation Rule 4. A lambda expression
evaluates to a procedure that takes the given
parameters and has the expression as its body.
13. Applying Compound Procedures
Rule 3: To evaluate an application expression:
((lambda (a) (a) Evaluate all the subexpressions (in any
order)
(lambda (b) (b) Apply the value of the first subexpression
to the values of all the other subexpressions.
(+ a b)))
Apply Rule for constructed procedures:
5) Evaluate the body of the procedure with each
parameter name bound to the corresponding
input expression value.
Evaluation Rule 4. A lambda expression
evaluates to a procedure that takes the given
parameters and has the expression as its body.
14. Applying Compound Procedures
Rule 3: To evaluate an application expression:
(((lambda (a) (a) Evaluate all the subexpressions (in any
order)
(lambda (b) (b) Apply the value of the first subexpression
to the values of all the other subexpressions.
(+ a b)))
Apply Rule for constructed procedures:
5) Evaluate the body of the procedure with each
parameter name bound to the corresponding
6) input expression value.
Evaluation Rule 4. A lambda expression
evaluates to a procedure that takes the given
parameters and has the expression as its body.
15. Do we have everything we
need to describe all
computations?
16. Language Elements
Question from Class 2:
When learning a foreign language, which
elements are hardest to learn?
Primitives
Means of Combination
Means of Abstraction
16
17. Primitives: lots of them, and hard to learn real meaning (but its
just memorization)
Means of Combination
Complex, but, all natural languages have similar ones [Chomsky]
Sentence ::= Subject Object Verb (45%)
Sentence ::= Subject Verb Object (42%) Welsh: “Lladdodd y ddraig y dyn.”
Sentence ::= Verb Subject Object (9%)
Sentence ::= Object Subject Verb (<1%)
Scheme:
Means of Abstraction: few of these, but tricky to learn
differences across languages
Tok Pisin (Papua New Guinea): mi (I), mitupela (he/she and I), mitripela
(both of them and I), mipela (all of them and I), yumitupela (you and
I), yumitripela (both of you and I), yumipela (all of you and I)
Scheme:
17