![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
The language that GNU Smalltalk accepts is basically the same that other Smalltalk
environment accept and the same syntax used in the Blue Book, also
known as Smalltalk-80: The Language and Its Implementation.
The return operator, which is represented in the Blue Book as an
up-arrow, is mapped to the ASCII caret symbol ^
; the assignment
operator (left-arrow) is usually represented as :=
(6).
Actually, the grammar of GNU Smalltalk is slightly different from the grammar of other Smalltalk environments in order to simplify interaction with the system in a command-line environment as well as in full-screen editors.
Statements are executed one by one; multiple statements are separated by a period. At end-of-line, if a valid statement is complete, a period is implicit. For example,
8r300. 16rFFFF |
300
and hex FFFF
,
each followed by a newline.
Multiple statements share the same local variables, which are automatically
declared. To delete the local variables, terminate a statement with
!
rather than .
or newline. Here,
a := 42 a! a |
a
s are printed as 42
, but the third one
is uninitialized and thus printed as nil
.
In order to evaluate multiple statements in a single block, wrap them into an eval block as follows:
Eval [ a := 42. a printString ] |
'42'
).
ObjectMemory quit |
GNU Smalltalk provides three extensions to the language that make it simpler to write complete programs in an editor. However, it is also compatible with the file out syntax as shown in the Green Book (also known as Smalltalk-80: Bits of History, Words of Advice by Glenn Krasner).
A new class is created using this syntax:
superclass-name subclass: new-class-name [ | instance variables | pragmas message-pattern-1 [ statements ] message-pattern-2 [ statements ] ... class-variable-1 := expression. class-variable-2 := expression. ... ] |
In short:
<comment: 'Class comment'> <category: 'Examples-Intriguing'> <import: SystemExceptions> <shape: #pointer> |
A similar syntax is used to define new methods in an existing class.
class-expression extend [ ... ] |
The class-expression is an expression that evaluates to a class
object, which is typically just the name of a class, although it can be
the name of a class followed by the word class
, which causes the
method definitions that follow to apply to the named class itself,
rather than to its instances.
Number extend [ radiusToArea [ ^self squared * Float pi ] radiusToCircumference [ ^self * 2 * Float pi ] ] |
A complete treatment of the Smalltalk syntax and of the class library can be found in the included tutorial and class reference (see section `Class Reference' in the GNU Smalltalk Library Reference).
More information on the implementation of the language can be found in the Blue Book; the relevant parts are available, scanned, at http://stephane.ducasse.free.fr/FreeBooks/BlueBook/Bluebook.pdf.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |