20-CS-4003-001 Organization of Programming Languages Fall 2018
Lab Assignment 7

Lambda calculus, Type theory, Formal semantics, Program analysis


Due: 22 October, 2018 (submit instructions: here)

    Exercise your understanding of call-with-current-continuation
Lab Problem (two parts):
1. Consider the following code:
   (define escape
      (lambda ()
         (set! halt (call/cc (lambda (k) k)))

   (define multiply
      (lambda (l)
         (if (null? l)
             (if (zero? (car l))
                 (halt halt)
                 (* (car l) (multiply (cdr l)))))))
Consider two objections to this code: first, it uses the unnatural (halt halt) and second, it must escape out of multiply to another procedure called escape.

Redesign multiply so that halt returns the value of the answer and you do not have to invoke a procedure like escape in order to grab a continuation.

2. The following procedure displays the tokens of a given list L:

   (define pl
      (lambda (l)
         (if (null? l)
             (begin (display (car l)) (pl (cdr l))))))
Modify pl (call/cc to be used somewhere) and add any other needed procedures, including a new one called main, so that you can do the following:
   prompt> (main '(3 4 5) '(w e ty) '(hello there now))
which will return the tokens interleaved as (in this case)
   3 w hello 4 e there 5 ty now
Remember, only one coded copy of pl is allowed (of course, you will find the tricks needed to make copies of that one pl). There should be three procedures running at the same time and they should be co-routining. Allow for the possibility of any size lists. When a list runs out of tokens its process disappears from the "round robin".