Debian Codegraph @

examples/prism-smalltalk.html

raw symbols SCIP
1 <h2>Numbers</h2>
2 <pre><code>3
3 30.45
4 -3
5 0.005
6 -14.0
7 13772
8 8r377
9 8r153
10 8r34.1
11 8r-37
12 16r106
13 16rFF
14 16rAC.DC
15 16r-1.C
16 1.586e5
17 1.586e-3
18 8r3e2
19 2r11e6</code></pre>
20
21 <h2>Strings and characters</h2>
22 <pre><code>$a
23 $M
24 $-
25 $$
26 $1
27 'hi'
28 'food'
29 'the Smalltalk-80 system'
30 'can''t'</code></pre>
31
32 <h2>Symbols</h2>
33 <pre><code>#bill
34 #M63
35 #+
36 #*</code></pre>
37
38 <h2>Arrays</h2>
39 <pre><code>#(1 2 3)
40 #('food' 'utilities' 'rent' 'household' 'transportation' 'taxes' 'recreation')
41 #(('one' 1) ('not' 'negative') 0 -1)
42 #(9 'nine' $9 (0 'zero' $0 ( ) 'e' $f 'g' $h 'i'))</code></pre>
43
44 <h2>Blocks</h2>
45 <pre><code>sum := 0.
46 #(2 3 5 7 11) do: [ :primel | sum := sum + (prime * prime)]
47
48 sizeAdder := [ :array | total := total + array size].
49
50 [ :x :y | (x * x) + (y * y)]
51 [ :frame :clippingBox | frame intersect: clippingBox]</code></pre>
52
53 <h2>Full example</h2>
54 <pre><code>Object>>method: num
55 "comment 123"
56 | var1 var2 |
57 (1 to: num) do: [:i | |var| ^i].
58 Klass with: var1.
59 Klass new.
60 arr := #('123' 123.345 #hello Transcript var $@).
61 arr := #().
62 var2 = arr at: 3.
63 ^ self abc
64
65 heapExample
66 "HeapTest new heapExample"
67 "Multiline
68 decription"
69 | n rnd array time sorted |
70 n := 5000.
71 "# of elements to sort"
72 rnd := Random new.
73 array := (1 to: n)
74 collect: [:i | rnd next].
75 "First, the heap version"
76 time := Time
77 millisecondsToRun: [sorted := Heap withAll: array.
78 1
79 to: n
80 do: [:i |
81 sorted removeFirst.
82 sorted add: rnd next]].
83 Transcript cr; show: 'Time for Heap: ' , time printString , ' msecs'.
84 "The quicksort version"
85 time := Time
86 millisecondsToRun: [sorted := SortedCollection withAll: array.
87 1
88 to: n
89 do: [:i |
90 sorted removeFirst.
91 sorted add: rnd next]].
92 Transcript cr; show: 'Time for SortedCollection: ' , time printString , ' msecs'</code></pre>