The Smalltalk

Programming basics

Basic elements of Smalltalk built-in class hierarchy

Every Smalltalk implementation usually comes with some built-in classes, which allow you to perform basic programming tasks, including basic data types and structures, control structures, I/O operations etc.
In Smalltalk almost everything, you work with, is either a class or an instance of some class. Even so called primitive types (integer, char, string, array...) are objects here. That's why learnig Smalltalk usually means learning features of particular classes rather than learning syntax.

| using literals   | using constructor   |
|                  |                     |
| |a|              | |a|                 |
|                  |                     |
| a := 3.          | a := Integer new: 3.|
|                  |                     | 
Constructors will be discused later in chapter "Extending the class hierarchy"

Control Structures

Control structures in Smalltalk are implemented using messages and blocks. Block is a sequence of Smalltalk expressions separated by dot, which is closed into square brackets. Blocks are ordinary objects, so it's possible to work with them same way as with any other object.

|a i|
i := 1.
a := [:x|i := i+x].  ":x declares x as a block argument (local variable)"
a value: 10.         "x=10 and evaluate the referenced block"
^ i.                 "return: 11"
This is of course only very short "intro" to using Smalltalk . The best way how to learn more is either to look to the "Blue book" or to use System browser in Smalltalk/X (or similar tool in other implementations) and look through the class hierarchy, where it's possible to find all classes and their methods, usually with short descriptions of what they are and what they do.