Assignment 1 - Assignment 1 Due Date: January 31, 2012 For...

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

View Full Document Right Arrow Icon
Assignment 1 Due Date: January 31, 2012 For this assignment, you will examine how to use continuations to build co-routines. The assignment will use Racket and its programming environment Part I The traditional coroutining example is that of producers and consumers. The producer (or producers) and consumer (or consumers) share a common buffer. Producers add values to the buffer and consumers remove values from the buffer. In Racket (i.e., Scheme), we might model a buffer as an object. (define make-buffer (lambda (_capacity) (let ((contents (make-vector _capacity)) (front 0) (back 0) (capacity _capacity) (size 0)) (lambda (command . params) (cond ((eq? command ':empty?) (<= size 0)) ((eq? command ':full?) (>= size capacity)) ((eq? command ':get!) (let ((tmp (vector-ref contents front))) (set! front (modulo (+ front 1) capacity)) (set! size (- size 1)) tmp)) ((eq? command ':put!) (vector-set! contents back (car params)) (set! back (modulo (+ back 1) capacity)) (set! size (+ size 1))) ((eq? command ':dump) (display "capacity: ") (display capacity) (newline) (display "size: ") (display size) (newline) (display "front: ") (display front) (newline) (display "back: ") (display back) (newline) (display "contents: ") (display contents) (newline))
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.

This note was uploaded on 03/26/2012 for the course CS 390 taught by Professor Staff during the Spring '08 term at Purdue University-West Lafayette.

Page1 / 4

Assignment 1 - Assignment 1 Due Date: January 31, 2012 For...

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