CS 350 Homework 3

1 Instructions

  • This is a homework to be done individually.

2 Questions

  1. Write a lazy Oz function for the Hamming problem. The function should generate the infinite list in a lazy manner. [10 points]
  2. Implement the procedure {Wait X} which waits until X is bound, and when X gets bound, completes execution. Your code should be in the deterministic concurrent model, so you may not use WaitTwo and IsDet. [10 points]
  3. The function {IsDet X} returns true when X is determined, and false otherwise, without suspending. Show that adding IsDet 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]

  4. A programmer can create a trigger in an eager language, if instead of a value V, at any stage of a computation, if we return fun {$} 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]

  5. Write a function {WaitBoth X1 X2} which waits until both X1 and X2 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 procedures P1 and P2 in separate threads. The main thread then waits for the two child threads to terminate, and only then it itself terminates.

  6. [Server] Using port objects, create a port which takes a message-processing procedure P as an argument (See NewPort2 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, using P.
  7. [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.

Author: Satyadev Nandakumar

Created: 2018-10-22 Mon 11:14

Validate