[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]
Back to Continuations, Continued. On to Introduction to Formal Semantics.
Held Monday, February 15
Summary
Contents
Notes
There are a number of issues that we need to discuss pertaining to assignment 2.
It's fine if you copy code from elsewhere, provided you
Many of you copied code from Mr. Walker and Mr. Stone. While their code did not have comments, it was typically preceded by a few pages of narrative comments. I don't want the narrative comments, I want in-code comments.
ifI saw things like the following in too many assignments.
(if (test) #t #f) (if (test) #f #t)
(test)
(not (test))
On a similar note, what is the point of things like the following?
(+ x 0) (* x 1)
Most of your sorts? predicates were awful. First of all,
many of you assumed that a method sorts a particular list correctly
if it returns a sorted list. Under that criterion, the following
method sorts correctly.
(define (sort l) '(1 2 3))
How should you have tested your sorting methods? The earlier parts of part A (as well as the introduction) should have given you a clue. Start with a few sorted lists. Generate permutations of those sorted lists. Try sorting those permutations. If each sorted permutation is the same as the original list, then it seems that the sorting mechanism works.
(call-with-current-continuation cpsfun)
call/cc.
This discussion is based on some notes by folks at Oberlin and Essentials of Programming Languages by Friedman, Wand, and Haynes.
call/cc
it replaces the current continuation.
call/cc provide a useful framework for
creating an interesting break/resume structure.
set! is a side-effecting
assignment operator.
(call/cc (lambda (y) (set! top y)))
break function that grabs the current
context (the context in which break was called), stores that context
as a method, resume, prints a message, and then uses
the top-level context to stop execution.
(define break
(lambda (x)
(call/cc (lambda (k) ; What will be done with x?
(begin
(set! resume k) ; Remember what to do
(display "Break! Use (resume val) to continue. ");
(display "Last value was: ");
(top x) ; Exit!
) ; begin
) ; lambda(k)
) ; call/cc
) ; lambda (x)
) ; define break
> (+ (* (break 1) 2) (- 17 (break 3))))
Break! Use (resume val) to continue. Last value was: 3
> (resume 3)
Break! Use (resume val) to continue. Last value was: 1
> (resume 1)
16
> (+ (break (* (break 2) (break 3)))
(break (- (break 4) (break 5))))
Break! Use (resume val) to continue. Last value was: 5
> (resume 5)
Break! Use (resume val) to continue. Last value was: 4
> (resume 4)
Break! Use (resume val) to continue. Last value was: -1
> (resume -1)
Break! Use (resume val) to continue. Last value was: 3
> (resume 3)
Break! Use (resume val) to continue. Last value was: 2
> (resume 2)
Break! Use (resume val) to continue. Last value was: 6
> (resume 6)
5
> (+ (break (* (break 2) (break 3)))
(break (- (break 4) (break 5))))
Break! Use (resume val) to continue. Last value was: 5
> (resume 10) ; Look, we're substituting a different value.
Break! Use (resume val) to continue. Last value was: 4
> (resume 4)
Break! Use (resume val) to continue. Last value was: -6
break?
History
Back to Continuations, Continued. On to Introduction to Formal Semantics.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]
Disclaimer Often, these pages were created ``on the fly'' with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS302/99S/Outlines/outline.10.html
Source text last modified Wed Feb 17 10:08:57 1999.
This page generated on Wed May 12 15:12:20 1999 by SiteWeaver. Validate this page's HTML.
Contact our webmaster at rebelsky@math.grin.edu