The goal of this question is to extend the Eventlang interpreter to add expressions for unregistering an

Question:

The goal of this question is to extend the Eventlang interpreter to add expressions for unregistering an observer expression. So far, we have only discussed registering an observer expression using the when expression, but once registered, the observer expression cannot be removed. Some programming languages also provide facilities for unregistering an observer expression.

Modify the semantics of the Eventlang language to provide facilities to unregister an observer expression. You can support this new expression by making two extensions. First, extend the semantics of the when expression to return a unique identifier that can be used to identify a registered observer expression. Then, implement the new unregister expression as given in this problem.

Some examples illustrating the new semantics of when expression appear here. A when expression returns a numeric value (an identifier) that can be used to unregister the observer expression:$ (define ev (event (a b))) $(when ev do (+ a b)) 5.001 ev do (* a b)) $(when 5.002

Notice that the encoding for the identifier is not important, so long as it can uniquely identify the observer expression to be unregistered.
The new expression unregister takes two parameters, an event and the unique identifier corresponding to the observer expression to be unregistered, and removes that observer expression so that when that event is announced, the unregistered observer expression is no longer evaluated.

The syntax for this new expression appears here:unregisterexp: '(' unregister exp exp ')';

In the syntax of the unregister expression, the first expression evaluates to an EventVal and the second expression evaluates to the unique identifier representing the observer expression. This expression unregisters the observer corresponding to the unique identifier:$ (unregister #t ev 5.002) ev 5.001) $ (unregister ev 5.002) #f $ (announce ev (6 7)) $ (unregister #t

The value produced by an unregister expression is true if unregistration was successful, and false otherwise.
Notice that in the current design of the unregister expression, it is possible to fool the interpreter by guessing the identifier of the registered observer expression. A more secure design is possible, but that task is outside the scope of this problem. Readers are encouraged to consider such designs on their own.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: