3.2: Pseudo-Variables
- Page ID
- 36343
In Smalltalk, there are 6 reserved keywords, or pseudo-variables: nil
, true
, false
, self
, super
, and thisContext
. They are called pseudo-variables because they are predefined and cannot be assigned to. true
, false
, and nil
are constants while the values of self
, super
, and thisContext
vary dynamically as code is executed.
true
and false
are the unique instances of the Boolean
classes True
and False
. See Chapter 8 for more details.
self
always refers to the receiver of the currently executing method.
super
also refers to the receiver of the current method, but when you send a message to super
, the method-lookup changes so that it starts from the superclass of the class containing the method that uses super
. For further details see Chapter 5.
nil
is the undefined object. It is the unique instance of the class UndefinedObject
. Instance variables, class variables and local variables are initialized to nil
.
thisContext
is a pseudo-variable that represents the top frame of the run-time stack. In other words, it represents the currently executing MethodContext
or BlockContext
. thisContext
is normally not of interest to most programmers, but it is essential for implementing development tools like the debugger and it is also used to implement exception handling and continuations.