• Home
  • Textbooks
  • A little Smalltalk
  • Basic Classes

A little Smalltalk

Timothy Budd

Chapter 3

Basic Classes - all with Video Answers

Educators


Chapter Questions

Problem 1

Suppose you created a new instance of the class UndefinedObject, as follows:
$\leftarrow$ UndefinedObject new
How does i respond to print? To isNil or notNil? To the object comparison message $==$ with nil ? Is $i$ nil? List facts to support your answer.

Check back soon!
00:41

Problem 2

Note that the messages $\operatorname{arcSin}$ and $\operatorname{arcCos}$ produce an object of type Radian and not of type Float. Furthermore, only objects of type Radian respond to $\sin$ and $\cos$. An alternative would have been to eliminate the class Radian and to permit all objects of class Float to respond to the messages $\sin$ and $\cos$. Discuss the advantages and disadvantages of these two different arrangements.

Linh Vu
Linh Vu
Numerade Educator

Problem 3

Suppose you have a Bag containing numbers. How would you go about producing an instance of the class List containing the numbers listed in sorted order?

Check back soon!

Problem 4

What is the class of Class? what is the superclass of Class?

Check back soon!

Problem 5

Many times, two or more different sequences of messages to collections will have the same effect. In each of the following, describe a sequence of messages that will have the same effect as the indicated message.
a) implement reject: in terms of select:
b) implement size in terms of inject:into:
c) implement includes: in terms of inject:into:.

Check back soon!