Advanced Methods in Programming Languages (201-2-4411-01)
HW Assignment 4 - Spring 2001 - Michael Elhadad

Continuations, Coroutines, Multithreading

Problems for 17 June 2001

Coroutines in Scheme

Implement the makecoroutine procedure studied in class in Scheme. Use makecoroutine to implement the same-leaves? predicate over two trees. The function you must write will be called:
(same-leaves? t1 t2)
The trees are defined according to the following BNF:
<tree>  ::= ()
            | (<root> <left-tree> <right-tree>)
<root>  ::= <symbol>            
The function must return true if the two trees have the same fringe (ordered list of leaves left-to-right) and false otherwise. The function must return immediately as the first mismatch is found between two leaves.

Write another version of the same function using streams. You must write a stream-generator function that takes a tree as input and returns the stream of its leaves.

(same-leaves-with-streams? t1 t2)
(leaves-generator tree)

Coroutines in Java

Write a class Coroutine in Java.

The coroutine constructor must receive as a parameter an instance of a class implementing the Runnable interface (similarly to the Thread class).

Coroutines interact using the resume method.

Use this class to implement a solution to the same-leaves problem in Java.

CSP in Java

For this exercise, you can use either CTJ or JCSP. The following provides documentation for the 2 packages:
Implement a solution similar to the coroutines same-leaves problem using the CSP formalism.