The coroutines code, with notes

How to Design Programs: An Introduction to Programming and Computing

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
;; The first three lines of this file were inserted by DrScheme. ;; They record information about the language level. #reader(lib "plai-pretty-big-reader.ss" "plai")((modname coroutines) (read- case-sensitive #t) (teachpacks ())) ;; cs536: programming with continuations ;; The final coroutine code from class ;; Kathi Fisler, Oct 19, 2007 (define (make-coroutine from-proc) (let ([hold false]) (lambda () (if hold (hold 'dummy) (from-proc (lambda (resume-other) (let/cc k (set! hold k) (resume-other)))))))) (define corouteA (make-coroutine (lambda (switch) (begin (printf "a1~n") (switch corouteB) (printf "a2~n") (switch corouteB))))) (define corouteB (make-coroutine (lambda (switch) (begin (printf "b1~n") (switch corouteA) (printf "b2~n"))))) #| NOTES The key to "getting" this code is to actually work out the values of k (ie, the hold values). Do this very mechanically, following the rules of substitution. For example: (corouteA) = [by subst value of corouteA within parens] ((make-coroutine
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

The coroutines code, with notes - ; The first three lines...

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

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