forked from gracelang/minigrace
-
Notifications
You must be signed in to change notification settings - Fork 3
/
standardBundle.grace
110 lines (89 loc) · 3.27 KB
/
standardBundle.grace
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
dialect "none"
import "intrinsic" as intrinsic
import "basicTypesBundle" as basicTypesBundle
import "collections" as collections
import "pattern+typeBundle" as patternAndTypeBundle
import "pointBundle" as pointBundle
trait open {
use basicTypesBundle.open
use patternAndTypeBundle.open
use intrinsic.controlStructures
use intrinsic.constants
use intrinsic.annotations
use pointBundle.open
method do(action)while(condition) {
self.while {
action.apply
condition.apply
} do { }
}
method repeat(n)times(action) {
if (n.isInteger.not) then {
self.ProgrammingError.raise "you can't repeat {n} times, because {n} is not an integer"
}
var ix := n
self.while {ix > 0} do {
ix := ix - 1
action.apply
}
}
method for (collection) do (block) {
collection.do(block)
}
method for (cs) and (ds) do (action) {
def dIter = ds.iterator
cs.do { c ->
if (dIter.hasNext) then {
action.apply(c, dIter.next)
} else {
return
}
}
}
method min(a, b) {
if (a < b) then { a } else { b }
}
method max(a, b) {
if (a > b) then { a } else { b }
}
method valueOf (nullaryBlock) {
nullaryBlock.apply
}
trait singleton {
use BasePattern
use identityEquality
method matches(other) { self.isMe(other) }
}
trait singleton (nameString) {
use singleton
method asString { nameString }
}
type Collection⟦T⟧ = collections.Collection⟦T⟧
// type Sequence⟦T⟧ is defined in basicTypeBundle
type List⟦T⟧ = collections.List⟦T⟧
type Set⟦T⟧ = collections.Set⟦T⟧
type Dictionary⟦K,T⟧ = collections.Dictionary⟦K,T⟧
once method BoundsError { collections.BoundsError }
once method IteratorExhausted { collections.IteratorExhausted }
once method NoSuchObject { collections.NoSuchObject }
once method RequestError { collections.RequestError }
once method SubobjectResponsibility { collections.SubobjectResponsibility }
once method ConcurrentModification { collections.ConcurrentModification }
once method UninitializedVariable { self.ProgrammingError.refine "UninitializedVariable" }
once method π { 3.141592653589793 }
once method pi { π }
method collection⟦T⟧ { collections.collection⟦T⟧ }
method enumerable⟦T⟧ { collections.enumerable⟦T⟧ }
method indexable⟦T⟧ { collections.indexable⟦T⟧ }
method sequence⟦T⟧ { collections.sequence⟦T⟧ }
method sequence⟦T⟧(arg) { collections.sequence⟦T⟧.withAll(arg) }
method list⟦T⟧ { collections.list⟦T⟧ }
method list⟦T⟧(arg) { collections.list⟦T⟧.withAll(arg) }
method set⟦T⟧ { collections.set⟦T⟧ }
method set⟦T⟧(arg) { collections.set⟦T⟧.withAll(arg) }
method dictionary⟦K, T⟧ { collections.dictionary⟦K, T⟧ }
method dictionary⟦K, T⟧(arg) { collections.dictionary⟦K, T⟧.withAll(arg) }
once method binding { collections.binding }
once method range { collections.range }
method hashCombine(h1, h2) { intrinsic.hashCombine(h1, h2) }
}