Introduction
Allowable characters
a-z
, A-Z
, 0-9
, .+/\*~<>@%|&?
, blank
, tab
, cr
, ff
, lf
Variables
- Variables must be declared before use
- Shared vars (globals, pools, and class vars) must begin with uppercase
- Local vars must begin with lowercase
- Reserved names:
self
, super
, thisContext
, true
, false
, and nil
Variable scope
- Global: defined in current environment (that is usually
Smalltalk
) and accessible by all objects in system - Special (reserved):
self
, super
, thisContext
, true
, false
, and nil
- Method Temporary: local to a method
- Block Temporary: local to a block
- Pool: variables in a
Dictionary
object - Method Parameters: automatic local vars created as a result of message call with params
- Block Parameters: automatic local vars created as a result of value: message call
- Class: shared with all instances of one class & its subclasses
- Class Instance: unique to each instance of a class
- Instance Variables: unique to each instance
Syntax
- Comments are enclosed in quotes (
"
) - Period (
.
) is the statement separator
Transcript
Assignment
Constants
Booleans
Arithmetic expressions
Bitwise Manipulation
Conversion
Blocks
- Blocks are objects and may be assigned to a variable
- Value is last expression evaluated unless explicit return
- Blocks may be nested
- Specification
[ arguments | | localvars | expressions ]
- Up to 15 arguments are possible; for up to 5 arguments, there are
#value:
, #value:value:
, …; for more, use #valueWithArguments:
^
expression terminates block & method (exits all nested blocks) - Blocks intended for long-term storage must not contain
^
, as they can not return to the sender context - Use
#cull:
(and #cull:cull:
, …) or #valueWithEnoughArguments:
if you do not know the exact number of arguments - Blocks (along with polymorphism on booleans) are the basis of control structures; see Conditional Expressions below
Method calls
- Unary methods are messages with no arguments
- Binary methods
- Keyword methods are messages with selectors including colons
Standard categories/protocols
initialize-release
(methods called for new instance) accessing
(get/set methods) testing
(boolean tests - is) comparing
(boolean tests with parameter displaying
(gui related methods) printing
(methods for printing) updating
(receive notification of changes) private
(methods private to class) instance-creation
(class methods for creating instance)
Conditional Expressions
- Conditional expressions, or control structures in general, use blocks as deferred computations which can be evaluated selectively
Iteration statements
Character
Symbol
String
Array
Array
: Fixed length collection ByteArray
: Array limited to byte elements (0-255) WordArray
: Array limited to word elements (0-2^32)
OrderedCollection
Acts like an expandable array
SortedCollection
Like OrderedCollection except order of elements determined by sorting criteria
Bag
Like OrderedCollection except elements are in no particular order
Sets
Set
: like Bag
except duplicates not allowed IdentitySet
: uses identity test (==
rather than =
)
Interval
Associations
Dictionaries
Dictionary
IdentityDictionary
: uses identity test (==
rather than =
)
Internal Stream
FileStream
Date
Time
Point
Rectangle
Pen
Dynamic Message Calling/Compiling
Debugging
Misc