Numbers
3
30.45
-3
0.005
-14.0
13772
8r377
8r153
8r34.1
8r-37
16r106
16rFF
16rAC.DC
16r-1.C
1.586e5
1.586e-3
8r3e2
2r11e6
Strings and characters
$a
$M
$-
$$
$1
'hi'
'food'
'the Smalltalk-80 system'
'can''t'
Symbols
#bill
#M63
#+
#*
Arrays
#(1 2 3)
#('food' 'utilities' 'rent' 'household' 'transportation' 'taxes' 'recreation')
#(('one' 1) ('not' 'negative') 0 -1)
#(9 'nine' $9 (0 'zero' $0 ( ) 'e' $f 'g' $h 'i'))
Blocks
sum := 0.
#(2 3 5 7 11) do: [ :primel | sum := sum + (prime * prime)]
sizeAdder := [ :array | total := total + array size].
[ :x :y | (x * x) + (y * y)]
[ :frame :clippingBox | frame intersect: clippingBox]
Full example
Object>>method: num
"comment 123"
| var1 var2 |
(1 to: num) do: [:i | |var| ^i].
Klass with: var1.
Klass new.
arr := #('123' 123.345 #hello Transcript var $@).
arr := #().
var2 = arr at: 3.
^ self abc
heapExample
"HeapTest new heapExample"
"Multiline
decription"
| n rnd array time sorted |
n := 5000.
"# of elements to sort"
rnd := Random new.
array := (1 to: n)
collect: [:i | rnd next].
"First, the heap version"
time := Time
millisecondsToRun: [sorted := Heap withAll: array.
1
to: n
do: [:i |
sorted removeFirst.
sorted add: rnd next]].
Transcript cr; show: 'Time for Heap: ' , time printString , ' msecs'.
"The quicksort version"
time := Time
millisecondsToRun: [sorted := SortedCollection withAll: array.
1
to: n
do: [:i |
sorted removeFirst.
sorted add: rnd next]].
Transcript cr; show: 'Time for SortedCollection: ' , time printString , ' msecs'