Lecture overview -- Keyboard shortcut: 'u'  Previous page: Simulating Coroutines in Scheme -- Keyboard shortcut: 'p'  Next page: Simultaneous traversal of two binary trees (1) -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 3 - Page 38 : 43
Programming Paradigms
Simulation of other Paradigms and Continuations
A simpel producer and consumer

We show two different variants of a simple producer consumer pattern

c:/Users/Kurt/Teaching-material/Pp-Scheme-17/notes/includes/producer-consumer-fp.scmProducer Consumer - pure functional programming in Scheme. This program is explained


  • Essential steps:

    • Start the producer

    • The producer prepares the first iteration, and returns its first continuation via exit

    • The consumer starts - it receives the first producer continuation

    • Now the resume-resume interaction takes place

    • At the end the producer sends a stop value to the consumer

    • In the consumer, the stop value ends consumation

c:/Users/Kurt/Teaching-material/Pp-Scheme-17/notes/includes/producer-consumer-non-fp.scmAlternative Producer Consumer - the other coroutine is maintained in mutable state. This program is explained


It is tricky to start up the two continuations

Explicit passing of continuations between the coroutines is clumsy - Keeping the continuation 'of the other part' in mutable state is an alternative