[up] [next]

Smalltalk/X Cheat Sheet

A short, one page summary of what beginners need to know about syntax and st/x command line on one page.

Syntax

Comments

regular comment
" this is a comment "
EOL-Comment
"/ this is an End-of-Line comment
Token-Comment
">> END
a multiline token-comment up to
a line starting with 'END'
more commented stuff here
...
comment ends here
END

Constants

2r010101
8r0777
-6.9
-6e-10
Float pi
Float e
-6f-10
-6q-10
-6Q-10
(17/2)
Character space
Character nl
integers
12345
-12345
large integers
1234567890123456789012345...

(arbitrary size)
integers with radix
16rAFFE
16r-AFFE
floats
(IEEE double; roughly 17 decimals)
12.456
1.234e17
short floats
(IEEE single; roughly 8 decimals)
1.234f17
long floats
(IEEE quad; roughly 20 decimals)
1.234q17
high prec. floats; roughly 60 decimals
1.234Q17
fractions
(1/3)
characters
$a
strings
'hello'
arrays
#( el1 el2 ... elN )

(each element a literal constant)

byte arrays
#[ b1 b2 ... bN ]

(each byte-element an integer constant in 0..255)

special number arrays
#XX( v1 v2 ... vN )

(XX: one of
 'u8', 's8', 'u16', 's16', 'u32', 's32', 'u64', 's64', 'f32', 'f64'
 and each element being an integer or float constant)

Lambda Blocks (Closures)

without argument
[ expr1 . expr2 ... exprN ]

when evaluated, the value is the value
 from the last expression, exprN

one argument
[:arg |
expr1 . expr2 ... exprN
]
multiple arguments
[:a1 :a2 ... :aN |
expr1 . expr2 ... exprN
]

Expressions

whitespace between the colon and the argExpression is optional.

with binOP being any combination of special characters: * , + , - , % , & , / , \ , | , = , < , > , ? and ,

i.e. "foo ==> 123" is the binary message "==>"
sent to foo with 123 as argument)

and "foo ? 123" is the binary message "?"
sent to foo with 123 as argument)

unary expression (without argument)
receiver messageName

receiver is itself either a constant, a lambda-block, a unary expression or a parenthesized expression

keyword expression: (1 arg)
receiver messageNamePart:argExpression
keyword expression: (any number of args)
receiver
     messageNamePart1:argExpression1
     messageNamePart2:argExpression2
     ...
     messageNamePartN:argExpressionN
binary expression
receiver binOP arg
parentheses for grouping
( any expression )
assignment
variable := expression

Remaining Syntax

local variables (in block or method)
| var1 var2 ... varN |

variable declarations must be at the beginning (before any expression).

separating multiple expressions (sequence)
expr1 . expr2 . ... exprN

expressions (statements) are separated by fullstop (period) characters.
The last expression may or may not be followed by a fullstop (if there is one, this is treated like a followup empty statement)

return from method
^ expression

returns from the enclosing method (also if inside a block-closure)

Wellknown Messages

conditional execution
boolExpr1 ifTrue:[ ... ] ifFalse:[ ... ]

variations without true-part, without false part and with the order reversed are available.

while loop
[ boolExpr1 ] whileTrue:[ ... ]

notice the receiver being a block.
A whileFalse variant is also available.

for loop
start to:stop do:[:iterVar | ... ]

evaluates the lambda for each value in start..stop.

enumerating collections
collection do:[:elementVar | ... ]

evaluates the lambda for each element in the collection.

evaluating a lambda block
without arguments:

with arguments:

aBlock value

aBlock value:expr1 ... value:exprN

the number of arguments must match the number expected by the lambda (although varArg lambdas are also available)

return from method
^ expression

returns from the enclosing method (also if inside a block-closure)

Wellknown Globals

Logging and Messaging
Transcript - console window

Stdout - standard output

Stderr - standard error

Stdin - standard input

Logger - redefinable logger (defaults to standard error)

Most Wellknown Classes

Collections
Array             (fixed size array)


OrderedCollection (variable size)

List

SortedCollection


Set               (unordered)

Bag


Dictionary        (mapped collections)

BinaryTree

AVLTree


SharedQueue       (shared, synchronized)
Process Handling
Process           (lightweight thread)


OSProcess         (heavyweight OS process)


Semaphore         (synchronization)

RecursionLock

Monitor

BoltLock

Delay
Files & Streams
Filename          (file naming, directory access, mime type)


Stream            (basic stream framework)

ReadStream

WriteStream

EncodedStream


ExternalStream    (OS streams)

FileStream

Socket

EncodedStream
Low Level Access
OperatingSystem   (OS API calls)


Smalltalk         (startup, shutdown and globals)



ObjectMemory      (VM access)

Comand Line

-I ignore snapshot image
--repl start an interactive read-eval-print-loop
--print expr eval expr, print its value then exit
--eval expr eval expr (without printing) then exit
--execute filename execute the script in fileName then exit
--loadPackage package-ID preload a compiled smalltalk class library (package)
--help show all other command line options


Copyright © 2017 Claus Gittinger Development & Consulting

<cg@exept.de>

Doc $Revision: 1.3 $ $Date: 2017/08/30 19:47:17 $