CS 350 Homework 3
1 Instructions
- This is a homework to be done individually.
2 Questions
- Write a lazy Oz function for the Hamming problem. The function should generate the infinite list in a lazy manner. [10 points]
- Implement the procedure
{Wait X}
which waits untilX
is bound, and whenX
gets bound, completes execution. Your code should be in the deterministic concurrent model, so you may not useWaitTwo
andIsDet
. [10 points] The function
{IsDet X}
returns true whenX
is determined, and false otherwise, without suspending. Show that addingIsDet
will cause the model to be non-declarative.(Hint: Construct a threaded program using
IsDet
where different interleavings succeed with logical inequivalent stores. Why does this suffice to show that the model is not declarative?) [10 points]A programmer can create a trigger in an eager language, if instead of a value
V
, at any stage of a computation, if we returnfun {$} V end
.The caller now should evaluate the function when the value is really required. This technique is called thunking.
Using this idea, write an eager Oz function to return the merged sorted list of two given sorted lists of numbers. [15 points]
Write a function
{WaitBoth X1 X2}
which waits until bothX1
andX2
are determined.Using the above function, write a function
{Thread P1 P2}
which simulates threading with a parent-children relationship: the main thread of the function runs the proceduresP1
andP2
in separate threads. The main thread then waits for the two child threads to terminate, and only then it itself terminates.- [Server] Using port objects, create a port which takes a
message-processing procedure
P
as an argument (SeeNewPort2
in the course notes, and adapt the code.) Ensure that the port object creates a non-terminating thread to process the individual messages it later receives, usingP
. [Client] Create a client which creates a client port, which upon receving any message, displays it in the Browser.
It should also create a server port as per the above question. The message-processing procedure should be a function which takes a string, and does the following.
- It reverses the string
- It sends the reversed string to the client port.