[   ^ to index...   |   <-- previous   ]

A short quiz

1. Imagine there exists a hierarchy of classes implementing "WeakBoolean", which has three truth values: true, false, and maybe. Draw this class heirarchy, and show the method ifTrue:ifFalse:ifMaybe: for each node in the hierarchy, by analogy to the regular Boolean type.

 
 

2. Implement the equivalent of the Smalltalk ifTrue:ifFalse: message as an ML function. What is the type of this function? Why is this function more restrictive than the Smalltalk version?

 
 

3. Consider the following definition of a binary tree node:

    Object subclass: #TreeNode
        instanceVariables: 'value left right'
        classVariables: ''
        poolDictionaries: ''
        classCategory: 'Testing'

    value
        ^ value
    value: aValue
        value := aValue
    "etc., assume accessors/mutators are defined for left & right"

Define the method infixMap: over treeNodes, which takes a closure and applies it, in left to right order, to every node in the tree. The return value should be a tree containing the results. (Do you recall from lecture yesterday what such a function is conventionally called in Smalltalk?)

 
 

4. Consider the TreeNode subclass, SortedAssocTreeNode, where every node also has a key field, and we have defined a insert:withKey: method to insert the key/value pair in sorted left-to-right order. Give the class definition, then define the method lookup: which looks up the value matching a given key aKey. Try to make the code as immune as possible to changes in the implementation of TreeNode.

 
 
 
 
 
 
 
 
 

Keunwoo Lee
Last modified: Thu May 17 00:36:27 PDT 2001