File: prism-smalltalk.html

package info (click to toggle)
node-prismjs 1.30.0%2Bdfsg%2B~1.26.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,220 kB
  • sloc: javascript: 27,628; makefile: 9; sh: 7; awk: 4
file content (92 lines) | stat: -rw-r--r-- 1,930 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<h2>Numbers</h2>
<pre><code>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</code></pre>

<h2>Strings and characters</h2>
<pre><code>$a
$M
$-
$$
$1
'hi'
'food'
'the Smalltalk-80 system'
'can''t'</code></pre>

<h2>Symbols</h2>
<pre><code>#bill
#M63
#+
#*</code></pre>

<h2>Arrays</h2>
<pre><code>#(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'))</code></pre>

<h2>Blocks</h2>
<pre><code>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]</code></pre>

<h2>Full example</h2>
<pre><code>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'</code></pre>