Questions
10.1. Freezing by proxying. In the Chaining and Fluent Interfacessection of Chapter 8, Connecting Functions - Pipelining and Composition, we used a proxy for getting operations in order to provide for automatic chaining. By using a proxy for setting and deleting operations, you may do your own freezing (if, instead of setting an object's property, you'd rather throw an exception). Implement a freezeByProxy(obj)
function that will apply this idea to forbid all kinds of updates (adding, modifying, or deleting properties) for an object. Remember to work recursively, in case an object has other objects as properties!
10.2. Inserting into a list, persistently. In the Working with lists section, we described how an algorithm could add a new node to a list, but in a persistent way, by creating a new list as we earlier described. Implement an insertAfter(list, newKey, oldKey)
function that will create a new list, but adding a new node with key newKey
just after the node with key oldKey
...