There is a large variety of literal constants (including numbers, characters, strings, symbols, byte arrays and literal arrays), as depicted in slide sm-expr-1.
A special kind of expression is the block expression that consists of a program fragment, possibly parametrized with an argument. Block expressions are used to define control structures employing message expressions. Block expressions correspond to function literals (lambda-expressions) in languages such as Lisp and Smalltalk.
Message expressions may be characterized as either unary, binary or keyword messages. See slide sm-expr-3.
As binary method expressions, we have the familiar arithmetic and comparison
expressions as well as the less
familiar combination expression
(used for graphics coordinates)
and association expression
(used to define associative maps).
All binary (infix) message selectors have the
same precedence and bind to the left.
Despite their common appearance,
these are all true message expressions
(which may lead to surprises, for example
in the case of a non-commutative definition
of the arithmetic operations).
Examples of keyword message selectors are given
in slide sm-control.
Control
For self-reference the special expression self may be used. To invoke methods from the parent class the expression super may be used.
An example of an object class description is given in slide sm-objects-2. The class Ctr is defined as a subclass of the class behavior. It supports an initialization protocol (containing the method initialize), a protocol for modification (containing the method add), and an inspection protocol (containing the method value).
In addition, we need a class description defining the object functionality of Ctr, which consists of an {\em instance creation} protocol defining the class method new. See slide sm-objects-3. This class description is (implicitly) an instance of a meta class generated by the Smalltalk system. See section meta.
...
initialize
value := 0.
TV open: self.
...
add: anInt
value := value + anInt.
self changed: #value.
instanceVariableNames: ''
TV methodsFor: 'updating'
update: aValue
Transcript show: 'ok'; cr .
TV class
instanceVariableNames: ''
TV class methodsFor: 'instance creation'
open: aCtr
self new model: aCtr
The view class TV defines a class method open to create a new view object for an instance of the Ctr class. It must further define a method update (that will automatically be invoked when the Ctr instance signals a change) to display some message, for example the value of the Ctr object monitored.
The programming environment
forms an integral part of the Smalltalk
system.
The code depicted above
(which clearly reflects the object nature of classes)
is usually not the result of text editing,
but is generated by the system.
The Smalltalk programming system,
in particular the standard library,
however,
will take some time to get familiar with.
Summary
draft version 0.1 (15/7/2001)