程序代写代做代考 interpreter Prelude:

Prelude:
Courtesy of Matt Ellis and Kyle Gossman
(define evil ; their name for it, not mine! ((lambda (lambda)
((lambda lambda) lambda))
((lambda ‘lambda ‘lambda)
it out.
Matt and Kyle are 2005 CS alumni whose legacy lives on.
(lambda (lambda)
Perhaps the use of trace- (lambda lambda))lambda will help you figure
(lambda (lambda)
lambda))))
evil is legal in Scheme! What does it do?
CSSE 304 Day 22
Answers to Student questions Continuations
CPS procedures
1

CONTINUATIONS AND CPS
Control flow in Scheme
• The two most basic things that affect flow of control in a program are:
• The ___c_o_n_t_in_u_a_t_io_n______ which tells what is to be done with that value.
expression
• The current ______________ to be evaluated.
2

Scheme Control Flow Details
• What is the current expression to be evaluated?
• Once that is done, what remains to be done with the value of the current expression?
• Consider the evaluation of (+ a 5) in the process of evaluating
(- 4 (* b (+ a 5))).
• What remains to be done with the value of (+ a 5) ?
• Can we express that as a procedure?
• We can call that procedure the continuation of the
(+ a 5) computation
• The process of Scheme evaluation can be expressed as
– Loop:
• Evaluate the current expression
• Apply the current continuation to the result
• In A18, you will rewrite your interpreter in this style, which is known as continuation-passing style (CPS).
More Examples
• What is the continuation of (< x 5) in (if(