December 22, 2024
Textual Representation of Message Answers
When you send an object a message in Smalltalk there is
always a message answer and that answer is itself an object. However sometimes
it helps to read a piece of text telling you what that message answer
is. A textual representation of an object is just a very brief description
of the object. It is not the object itself. In LearningWorks the M206
course team has set things up to show a variety of textual representations.
Consequently with Frog instances you get something like:
An instance of class Frog (position 1, colour Green)
Things could have been set up differently to accept the default which
would have been
a Frog
LearningWorks will identify the name of the class that the object is an instance of and check the first letter. For example, consider an object named arnold, an instance of the class Duck, which receives the following message:
arnold fly
Assume that this will return, or answer with, the receiver; that
is the object receiving the fly message.
Unless the programmer of the Duck class has
written some special code, LWs will display a textual representation of
the object arnold as
a Duck
Correct grammar! It won't display
an Duck
However if arnold was an instance of the class
Albatross, evaluating
arnold fly
and again assuming that this answers the receiver, then LWs will display
a textual representation of the object arnold as
an Albatross
and not
a Albatross
Consequently the system can spot the difference between a vowel and a consonant.
An Albatross object could have been programmed to
describe an instance of the class as:
An instance of class Albatross (habitat 'Oceanic')
But the really important thing to realise, and it's something that students
get wrong every year, is that the message answer is arnold
and not the textual representation. The former is an
object and the latter is just a piece of descriptive text.
⇑ Up to top of page