Variables, Assignment & Pseudo-Variables
Six reserved identifiers you cannot assign to:
8.1 Temporary variables and assignment
Variable names start with a letter; by convention lowerCamelCase for temporaries and instance variables, UpperCamelCase for globals, class variables, and classes.
Uninitialized variables hold nil.
Old code (and Squeak's display option) may show _ or ← for assignment — modern code uses :=.
| x y greeting | "declare temporaries between vertical bars"
x := 3. "assignment with :="
y := x * 2.
greeting := 'Hi'.
x := y := 0. "assignments are expressions: chained assignment"8.2 Kinds of variables
Method or block | a b | at the start in the selector / [:x |...] — read only Instance variable (slot) in the class definition Class variable (shared variable)
Class, subclasses, both sides, all instances Class-side instance variable Each class object separately class-side slots: Smalltalk globals at: #Foo put:... Classes that import the pool used without declaration
8.3 Pseudo-variables
Six reserved identifiers you cannot assign to:
The receiver of the current method The receiver, but method lookup starts in the superclass of the class defining the method
The unique instance of UndefinedObject — "no value" The unique instance of True The unique instance of False
The current execution frame (a Context object) — reflection on the stack
nil isNil. "→ true"
thisContext. "→ the Playground's DoIt context"
thisContext sender. "→ who called us"8.4 Globals
Globals live in Smalltalk globals (Smalltalk globals at: #Counter put: 0, removeKey:, includesKey:). Important globals: Smalltalk (the system dictionary/image), Transcript, Processor (the process scheduler), World (Morphic world), and every class.