Class 38: Student Presentation: Smalltalk
Back to Discussion of Exam 3.
On to Student Presentations II.
Held Wednesday, May 5
- General overview of Smalltalk with Scott
- Smalltalk Lab with Cathy and
- The annual Math/CS Spring picnic is ths Sunday (mother's day; don't
forget to call your mothers) at noon. There's a signup list.
- If you're on board, entry your number.
- If you're not on board, the department will cover your food.
- There's a cool statistics talk tomorrow at 4:30 in Science 2413:
Statistical Lessons from Basketball. Learn whether the ``hot
hand'' is myth or statistical reality.
- We are happy to have a visitor--Mr. Rebelksy here with us
today, feel free to ask him tough questions.
- Of all object oriented languages, Smalltalk is the most true to the
Object Oriented paradigm.
- Smalltalk uses a virtual image, which contains the compiled
code of all the classes and objects that are a part of the system.
- Smalltalk code is compiled into byte codes which are interpreted into
actions during runtime.
The Basic concepts of who Smalltalk works are based on the
interaction of five core concepts, some of which should be very familiar
to those of you who have used Objetc Oriented languages before:
- Objects - Everything is an object in Smalltalk.
- Classes - An object that defines properties for a specific type of
object. Classes are arranged in a hierarchy of inheritance.
- Instances - An instance is an object of a specific class, with
properties and actions defined by the class it derives from.
- Messages - A message is an identifier sent to an object that triggers
some sort of action in response.
- Methods - A method is an implimentation detail to the action
triggered by an object receiving a message.
How these concepts interact form the basis for how Smalltalk works
- An Object responds to a Message according to how the Methods of teh
Object's Class indicates
Everything in Smalltalk is an object. Everything. This includes:
- data structures
- external devices
- blocks of code
- messages from one object to another
What does this mean in terms of typing?
- We're not entirely sure. It's being argued as we speak
- Some say that Smalltalk is essentially typeless, given that the exact
nature of data depends on how it is defined in its class
- Some say that the only type is classes, given everything is an object
and therefore an instance of a class
Classes are grouped together into a hierarchy of objects with similar
- For instance, Numbers are a subclass of the Magnitude class, which
consists of objects that can be compared to one another and be ordered,
such as Time, Date, Number and Character
- All Magnitude Objects have a set of conditional methods used for
- In turn, Integers, Floats, Imaginary numbers and Complex numbers are
all children of the Number class.
Messages come in three flavors:
- Unary - Unary messages consist of a single identifier with no
5 factorial "Return factorial of 5"
theta sin "Return sin of theta"
'hello' outputToPrinter "Send 'hello' to the printer"
- Binary - Binary messages consist of an identifier with a object as a
a + b "Send + b to a, i.e. add b to a"
a < b "Send < b to a, i.e. return true if a is less than b"
a ~= b "Send ~= b to a, i.e. return true is a is not equal to b"
- Keyword - Keyword messages are a list of identifier/parameter pairs
send to an object
"Send day:dayInt to aDate (assigning dayInt to the day field of aDate)"
aInt between:min and:max
"Send between:min and and:max to aInt (returning true if aInt is between min and max)"
Since all methods return objects, messages can be nested and strung
- Messages are resolved left to right, with precidence given in order
of Unary messages, Binary messages, then Keyword messages.
- Thus, all unary messages are resolved, from left to right, then all
binmary messages, left to right then keyword messages, left to right.
- Note tha 'arithmetic operations' do not follow the usual order of
operations. Thus '1 + 10 / 10' is not 2 as one might expect, but 11/10 as
'1 + 10' is evaluated and returns 11 and then '11 / 10' is evaluated.
Reserved Words - Smalltalk has five reserved words, which are
pseudo-variables, meaning they can be referenced as variables, but can
not be assigned to:
- true - the constant for Boolean true
- false - the constant for Boolean false
- nil - a constant that represents an uninitialized object
- self - a constant in a method that refers to the object on which the
method is being invoked
- super - a constant in a method referring to the immediate parent of
the object on which the method is being invoked.
Block Context - a Block Context is an object that represents a block
of code surrounded by square brackets.
- Within a Block Context, temporary variables can be declared by
surrounding the variable name by veritcal bars.
- Such temporary variables are local and exist only in the scope of the
Assignment to a variable is done via the assignment mesaage ':='
Returning an object is done by placing a '^' before an object.
Conditionals - Conditionals are actually methods of the Boolean
Class. A conditional message (e.g. "3 < 4") resolves to either the object
true or the object false. if statements are Keyword messages
passed to the Boolean object.
Go to Smalltalk Lab
- Boolean ifTrue: BlockContext resolves the Block Context if the
Boolean object is true, that is the comparison message resolves to true.
ifFalse does a similar thing
- You can pass both ifTrue and ifFalse messages to the same boolean
object, having the same effect as an if-then-else.
- There is no if-then-elseif-then-else structure or case statement in
Smalltalk. This can be simulated by nesting more boolean objects in the
Block Context of the first.
Inc. The company that brings you VisualWorks -- free, non-commercial
versions available for downloading here. Interesting section, "Success
Stories", about big (and small) companies that actually use programs
written in Smalltalk.
created May 3, 1996
last revised May 5, 1999