author | Claus Gittinger <cg@exept.de> |
Mon, 19 Jun 2017 16:54:35 +0200 | |
changeset 4418 | 05f82ac9d198 |
parent 4400 | 23f57acf91ff |
child 4429 | 7d3e464fb430 |
permissions | -rw-r--r-- |
2337
755696d72648
comment/format in: #asSoundexCode
Claus Gittinger <cg@exept.de>
parents:
2303
diff
changeset
|
1 |
"{ Package: 'stx:libbasic2' }"! |
1668 | 2 |
|
4381 | 3 |
!ArithmeticValue methodsFor:'converting'! |
4 |
||
5 |
asQDouble |
|
6 |
"return a QDouble with same value" |
|
7 |
||
8 |
^ self asFloat asQDouble |
|
9 |
||
10 |
" |
|
11 |
123 asQDouble |
|
12 |
" |
|
13 |
||
14 |
"Created: / 13-06-2017 / 16:48:24 / cg" |
|
15 |
! ! |
|
16 |
||
4379
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
17 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
18 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
19 |
differenceFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
20 |
"aQDouble does not know how to subtract the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
21 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
22 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
23 |
^ aQDouble retry:#- coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
24 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
25 |
"Created: / 13-06-2017 / 08:55:38 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
26 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
27 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
28 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
29 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
30 |
equalFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
31 |
"aQDouble does not know how to compare to the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
32 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
33 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
34 |
^ aQDouble retry:#= coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
35 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
36 |
"Created: / 13-06-2017 / 08:55:30 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
37 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
38 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
39 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
40 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
41 |
lessFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
42 |
"aQDouble does not know how to compare to the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
43 |
Return true if aQDouble < self. |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
44 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
45 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
46 |
^ aQDouble retry:#< coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
47 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
48 |
"Created: / 13-06-2017 / 08:55:20 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
49 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
50 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
51 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
52 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
53 |
productFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
54 |
"aQDouble does not know how to multiply the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
55 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
56 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
57 |
^ aQDouble retry:#* coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
58 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
59 |
"Created: / 13-06-2017 / 08:55:07 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
60 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
61 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
62 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
63 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
64 |
quotientFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
65 |
"aQDouble does not know how to divide by the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
66 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
67 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
68 |
^ aQDouble retry:#/ coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
69 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
70 |
"Created: / 13-06-2017 / 08:54:55 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
71 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
72 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
73 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
74 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
75 |
remainderFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
76 |
"aQDouble does not know how to compute the remainder with the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
77 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
78 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
79 |
^ aQDouble retry:#rem: coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
80 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
81 |
"Created: / 13-06-2017 / 08:54:47 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
82 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
83 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
84 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
85 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
86 |
sumFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
87 |
"aQDouble does not know how to add the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
88 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
89 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
90 |
^ aQDouble retry:#+ coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
91 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
92 |
"Created: / 13-06-2017 / 08:54:27 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
93 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
94 |
|
2288 | 95 |
!CharacterArray methodsFor:'matching - phonetic'! |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
96 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
97 |
asKoelnerPhoneticCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
98 |
"return a koelner phonetic code. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
99 |
The koelnerPhonetic code is for the german language what the soundex code is for english; |
2303 | 100 |
it returns simular strings for similar sounding words. |
101 |
There are some differences to soundex, though: |
|
102 |
its length is not limited to 4, but depends on the length of the original string; |
|
103 |
it does not start with the first character of the input. |
|
2288 | 104 |
|
105 |
Caveat: this phonetic code is especially suited for german words. |
|
2303 | 106 |
Please have a look at the other phonetic comparison operators found |
107 |
in PhoneticStringUtilities." |
|
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
108 |
|
2303 | 109 |
^ PhoneticStringUtilities koelnerPhoneticCodeOf:self |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
110 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
111 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
112 |
#( |
3715 | 113 |
'Müller' |
2303 | 114 |
'Miller' |
115 |
'Mueller' |
|
3715 | 116 |
'Mühler' |
117 |
'Mühlherr' |
|
118 |
'Mülherr' |
|
2303 | 119 |
'Myler' |
120 |
'Millar' |
|
121 |
'Myller' |
|
3715 | 122 |
'Müllar' |
123 |
'Müler' |
|
2303 | 124 |
'Muehler' |
3715 | 125 |
'Mülller' |
126 |
'Müllerr' |
|
2303 | 127 |
'Muehlherr' |
128 |
'Muellar' |
|
129 |
'Mueler' |
|
3715 | 130 |
'Mülleer' |
2303 | 131 |
'Mueller' |
3715 | 132 |
'Nüller' |
2303 | 133 |
'Nyller' |
134 |
'Niler' |
|
135 |
'Czerny' |
|
136 |
'Tscherny' |
|
137 |
'Czernie' |
|
138 |
'Tschernie' |
|
139 |
'Schernie' |
|
140 |
'Scherny' |
|
141 |
'Scherno' |
|
142 |
'Czerne' |
|
143 |
'Zerny' |
|
144 |
'Tzernie' |
|
145 |
'Breschnew' |
|
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
146 |
) do:[:w | |
2303 | 147 |
Transcript show:w; show:'->'; showCR:(w asKoelnerPhoneticCode) |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
148 |
]. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
149 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
150 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
151 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
152 |
'Breschnew' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
153 |
'Breschnew' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
154 |
'Breschneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
155 |
'Braeschneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
156 |
'Braessneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
157 |
'Pressneff' asKoelnerPhoneticCode -> '17863' |
3715 | 158 |
'Presznäph' asKoelnerPhoneticCode -> '17863' |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
159 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
160 |
! ! |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
161 |
|
2288 | 162 |
!CharacterArray methodsFor:'matching - phonetic'! |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
163 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
164 |
asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
165 |
"return a soundex phonetic code or nil. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
166 |
Soundex returns similar codes for similar sounding words, making it a useful |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
167 |
tool when searching for words where the correct spelling is unknown. |
4190 | 168 |
(read Knuth or search the web if you don't know what a soundex code is). |
2288 | 169 |
|
2337
755696d72648
comment/format in: #asSoundexCode
Claus Gittinger <cg@exept.de>
parents:
2303
diff
changeset
|
170 |
Caveat: 'similar sounding words' means: 'similar sounding in ENGLISH' |
4190 | 171 |
Please have a look at the other phonetic comparison operators found |
172 |
in PhoneticStringUtilities." |
|
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
173 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
174 |
^ PhoneticStringUtilities soundexCodeOf:self |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
175 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
176 |
" |
2303 | 177 |
'claus' asSoundexCode |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
178 |
'clause' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
179 |
'close' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
180 |
'smalltalk' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
181 |
'smaltalk' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
182 |
'smaltak' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
183 |
'smaltok' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
184 |
'smoltok' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
185 |
'aa' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
186 |
'by' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
187 |
'bab' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
188 |
'bob' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
189 |
'bop' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
190 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
191 |
! ! |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
192 |
|
2241 | 193 |
!CharacterArray methodsFor:'printing & storing'! |
194 |
||
2303 | 195 |
printf:args |
196 |
"Format and print the receiver with <args> formatted in C style, |
|
2295 | 197 |
as specified in the Unix C-language manual page for printf(3). |
3114 | 198 |
Return the resulting string (i.e actually, this is more like an sprintf). |
2241 | 199 |
|
200 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 201 |
|
2241 | 202 |
|aStream| |
203 |
||
3538 | 204 |
aStream := CharacterWriteStream on:(self species uninitializedNew:self size). |
2260 | 205 |
self printf:args on:aStream. |
2241 | 206 |
^ aStream contents |
207 |
||
208 |
" |
|
3796 | 209 |
('%05x %d %f %o' printf:{ 123. 234*5. 1.234. 8r377 } ) |
2303 | 210 |
Transcript showCR:('%05x %d %f %o' printf:{ 123. 234*5. 1.234. 8r377 } ) |
2256 | 211 |
" |
212 |
||
213 |
" |
|
2241 | 214 |
Transcript showCR: 'Some examples:'!! |
215 |
||
216 |
Transcript show:'''%#x %#X %03o%*.*s'' printf: #(16rABCD 16rEF 5 9 5 ''ghijklmn'') = .'. |
|
2303 | 217 |
Transcript show: ('%#x %#X %03o%*.*s' printf: #(16rABCD 16rEF 5 9 5 'ghijklmn')). |
2241 | 218 |
Transcript showCR: '.' |
219 |
||
220 |
Transcript show: '''%- 10.4s%.2e'' printf: (Array with: ''abcdefghijkl'' with: Float pi) = .'. |
|
2303 | 221 |
Transcript show: ('%- 10.4s%.2e' printf: (Array with: 'abcdefghijkl' with: Float pi)). |
2241 | 222 |
Transcript showCR: '.' |
223 |
||
224 |
Transcript show: '''%8.3f'' printf: (Array with: 200 sqrt negated) = .'. |
|
225 |
Transcript show: ('%8.3f' printf: (Array with: 200 sqrt negated)). |
|
226 |
Transcript showCR: '.' |
|
227 |
||
228 |
Transcript show: '''%c'' printf: #(16r41) = .'. |
|
229 |
Transcript show: ('%c' printf: #(16r41)). |
|
230 |
Transcript showCR: '.' |
|
231 |
||
232 |
Transcript show: '''%f%2s%s%s%s'' sscanf: ''237.0 this is a test'' = '. |
|
233 |
Transcript showCR: ('%f%2s%s%s%s' sscanf: '237.0 this is a test') printString. |
|
234 |
||
235 |
Transcript show: '''%d%f%s'' sscanf: ''25 54.32e-01 monday'' = '. |
|
236 |
Transcript showCR: ('%d%f%s' sscanf: '25 54.32e-01 monday') printString. |
|
237 |
||
238 |
Transcript show: '''%f%*f %8[A-F0-9]%c%d 0x%x%f'' sscanf: ''12.45 1048.73 AE40Z527 0x75BCD15 34'' = '. |
|
239 |
Transcript showCR: ('%f%*f %8[A-F0-9]%c%d 0x%x%f' sscanf: '12.45 1048.73 AE40Z527 0x75BCD15 34') printString. |
|
240 |
" |
|
241 |
! ! |
|
242 |
||
243 |
!CharacterArray methodsFor:'printing & storing'! |
|
244 |
||
2260 | 245 |
printf:args on:outStream |
246 |
"Format and print the receiver on <outStream> with <args> |
|
247 |
formatted in C style, as specified in the Unix C-language manual page for printf(3). |
|
248 |
||
249 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 250 |
|
4418 | 251 |
PrintfScanf printf:self on:outStream arguments: args |
252 |
||
253 |
" |
|
254 |
'%e' printf:{ 1234.567 ] on:Transcript |
|
255 |
||
256 |
'%10s%3d\n' printf:{ 'hello' . 12 } on:Transcript |
|
257 |
'%10s%3d\n' printf:{ '1234567890' . 12 } on:Transcript |
|
2260 | 258 |
|
4418 | 259 |
like C's printf, a longer datum may be formatted wider than the formatspec says: |
260 |
||
261 |
'%10s%3d\n' printf:{ '12345678901234' . 12 } on:Transcript |
|
262 |
||
263 |
'%10s%3d\n' printf:{ 'hello' . 12 } on:Transcript |
|
264 |
'%10s%03d\n' printf:{ 'hello' . 12 } on:Transcript |
|
265 |
" |
|
266 |
||
267 |
"Modified (comment): / 19-06-2017 / 15:51:57 / cg" |
|
2260 | 268 |
! ! |
269 |
||
270 |
!CharacterArray methodsFor:'printing & storing'! |
|
271 |
||
2303 | 272 |
printfWith:arg1 |
2295 | 273 |
"Format and print the receiver with <arg1> formatted in C style, |
274 |
as specified in the Unix C-language manual page for printf(3). |
|
3114 | 275 |
Return the resulting string (i.e actually, this is more like an sprintf)." |
2303 | 276 |
|
2256 | 277 |
^ self printf:(Array with:arg1) |
278 |
||
279 |
" |
|
3796 | 280 |
('%05x' printfWith:123) |
2303 | 281 |
Transcript showCR:('%05x' printfWith:123) |
2256 | 282 |
" |
283 |
! ! |
|
284 |
||
285 |
!CharacterArray methodsFor:'printing & storing'! |
|
286 |
||
2303 | 287 |
printfWith:arg1 with:arg2 |
288 |
"Format and print the receiver with <argI> formatted in C style, |
|
2295 | 289 |
as specified in the Unix C-language manual page for printf(3). |
3114 | 290 |
Return the resulting string (i.e actually, this is more like an sprintf)." |
2303 | 291 |
|
2256 | 292 |
^ self printf:(Array with:arg1 with:arg2) |
293 |
||
294 |
" |
|
2303 | 295 |
Transcript showCR:('%d %05x' printfWith:123 with:234) |
2256 | 296 |
" |
297 |
! ! |
|
298 |
||
299 |
!CharacterArray methodsFor:'printing & storing'! |
|
300 |
||
301 |
printfWith:arg1 with:arg2 with:arg3 |
|
2303 | 302 |
"Format and print the receiver with <argI> formatted in C style, |
2295 | 303 |
as specified in the Unix C-language manual page for printf(3). |
3114 | 304 |
Return the resulting string (i.e actually, this is more like an sprintf)." |
2303 | 305 |
|
2256 | 306 |
^ self printf:(Array with:arg1 with:arg2 with:arg3) |
307 |
||
308 |
" |
|
2303 | 309 |
Transcript showCR:('%d %05x %08o' printfWith:123 with:234 with:345) |
2256 | 310 |
" |
311 |
! ! |
|
312 |
||
313 |
!CharacterArray methodsFor:'printing & storing'! |
|
314 |
||
315 |
printfWith:arg1 with:arg2 with:arg3 with:arg4 |
|
2303 | 316 |
"Format and print the receiver with <argI> formatted in C style, |
2295 | 317 |
as specified in the Unix C-language manual page for printf(3). |
3114 | 318 |
Return the resulting string (i.e actually, this is more like an sprintf)." |
2303 | 319 |
|
2256 | 320 |
^ self printf:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
321 |
||
322 |
" |
|
2303 | 323 |
Transcript showCR:('%d %05x %08o %b' printfWith:123 with:234 with:345 with:123) |
2256 | 324 |
" |
325 |
! ! |
|
326 |
||
327 |
!CharacterArray methodsFor:'printing & storing'! |
|
328 |
||
2241 | 329 |
printf_formatArgCount |
330 |
"Return the number of arguments required/produced if the receiver is interpreted |
|
331 |
as a printf/scanf format control string. |
|
332 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 333 |
|
4418 | 334 |
^ PrintfScanf formatArgCountFor:self. |
2241 | 335 |
|
4418 | 336 |
"Modified: / 19-06-2017 / 16:54:10 / cg" |
2241 | 337 |
! ! |
338 |
||
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
339 |
!CharacterArray methodsFor:'private'! |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
340 |
|
4418 | 341 |
printf_printArgFrom:formatStream to:outStream withData:argStream |
342 |
<resource: #obsolete> |
|
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
343 |
"Interpret the required number of arguments from <argStream> |
4418 | 344 |
according to the formatting information in <formatStream>. |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
345 |
Place the interpretation on <outStream>. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
346 |
The interpretation is C printf(3) style, as |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
347 |
specified in the Unix C-language manual page for printf(3). |
4418 | 348 |
<formatStream> is assumed to be positioned just past |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
349 |
$%, and a complete control string is assumed available. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
350 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
351 |
Return when the conversion control string is consumed. |
4418 | 352 |
Leave <formatStream> pointing past the last character in the conversion control string. |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
353 |
|
4418 | 354 |
This code assumes that <formatStream> is formatted according to |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
355 |
specification, and error checking is minimal. Unexpected |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
356 |
results will be obtained by illegal control strings, or when |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
357 |
argument types do not match conversion codes, but it probably |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
358 |
won't dump core, like C does in such cases!! |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
359 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
360 |
For copyright information, see goodies/String-printf_scanf.chg" |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
361 |
|
4418 | 362 |
PrintfScanf printArgFrom:formatStream to:outStream arguments:argStream |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
363 |
|
4418 | 364 |
"Modified: / 19-06-2017 / 15:44:28 / cg" |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
365 |
! ! |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
366 |
|
2241 | 367 |
!CharacterArray methodsFor:'printing & storing'! |
368 |
||
2260 | 369 |
printf_printOn:outStream withData:args |
370 |
<resource: #obsolete> |
|
2303 | 371 |
|
2241 | 372 |
"Format and print the receiver on <outStream> with <args> |
373 |
formatted in C style, as specified in the Unix C-language manual page for printf(3). |
|
374 |
||
375 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
376 |
||
2260 | 377 |
self obsoleteMethodWarning:'use printf:on:'. |
378 |
self printf:args on:outStream |
|
2241 | 379 |
! ! |
380 |
||
381 |
!CharacterArray methodsFor:'converting'! |
|
382 |
||
2303 | 383 |
scanf:dataStream |
2241 | 384 |
"Return a Collection of objects found in the Character Stream |
2303 | 385 |
<dataStream> as interpreted according to the receiver. |
2241 | 386 |
The receiver is assumed to be a conversion control string as |
387 |
specified in the Unix C-language manual page for scanf(3). |
|
388 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 389 |
|
2241 | 390 |
|results format char| |
391 |
||
392 |
results := OrderedCollection new. |
|
393 |
format := ReadStream on:self. |
|
394 |
[ format atEnd ] whileFalse:[ |
|
2303 | 395 |
char := format next. |
396 |
(char == Character space or:[ char == Character tab ]) ifTrue:[ |
|
397 |
dataStream skipSeparators. |
|
398 |
format skipSeparators |
|
399 |
]. |
|
400 |
char == $% ifTrue:[ |
|
401 |
self |
|
402 |
scanf_scanArgFrom:dataStream |
|
403 |
to:results |
|
404 |
format:format |
|
405 |
] ifFalse:[ |
|
406 |
dataStream peekFor:char |
|
407 |
] |
|
2241 | 408 |
]. |
409 |
^ results |
|
410 |
||
411 |
" |
|
2303 | 412 |
'%d %x' scanf:(ReadStream on:'1234 ff00') |
2241 | 413 |
" |
414 |
! ! |
|
415 |
||
416 |
!CharacterArray methodsFor:'private'! |
|
417 |
||
2303 | 418 |
scanf_scanArgFrom:dataStream to:collection format:format |
4418 | 419 |
<resource: #obsolete> |
2241 | 420 |
"Add to <collection> an object who's representation is found |
421 |
in <dataStream> interpreted according to the conversion |
|
2303 | 422 |
control string in the Stream <format>. |
423 |
<format> is assumed to be positioned just past a $%, and a complete control |
|
2241 | 424 |
string is assumed available. |
425 |
||
426 |
Return when the conversion control string is consumed. Leave |
|
427 |
<format> pointing past the last character in the conversion |
|
428 |
control string, leave <dataStream> pointing past any width |
|
429 |
specified in <format>, or at the first character that doesn't |
|
430 |
make sense for the <format>. |
|
431 |
||
432 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 433 |
|
2241 | 434 |
|final width char pos data scanset exclusive return last| |
435 |
||
2303 | 436 |
final := [:retval | |
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
437 |
collection add:retval. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
438 |
data == dataStream ifFalse:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
439 |
dataStream position:dataStream position + data position |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
440 |
]. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
441 |
^ self |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
442 |
]. |
2241 | 443 |
width := 0. |
444 |
char := format peek. |
|
445 |
char == $% ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
446 |
^ dataStream peekFor:char |
2241 | 447 |
]. |
448 |
char == $* ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
449 |
format next. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
450 |
char := format peek. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
451 |
final := [:retval | |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
452 |
data == dataStream ifFalse:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
453 |
dataStream position:dataStream position + data position |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
454 |
]. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
455 |
^ self |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
456 |
] |
2241 | 457 |
]. |
458 |
char isDigit ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
459 |
width := Integer readFrom:format. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
460 |
char := format peek |
2241 | 461 |
]. |
462 |
('slhduoxfeg' includes:char) ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
463 |
dataStream skipSeparators |
2241 | 464 |
]. |
465 |
width = 0 ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
466 |
data := dataStream |
2241 | 467 |
] ifFalse:[ |
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
468 |
pos := dataStream position. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
469 |
data := ReadStream on:(dataStream next:width). |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
470 |
dataStream position:pos |
2241 | 471 |
]. |
472 |
char == $s ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
473 |
final value:(data upToSeparator) |
2241 | 474 |
]. |
475 |
char == $c ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
476 |
width = 0 ifTrue:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
477 |
final value:(String with:data next) |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
478 |
] ifFalse:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
479 |
final value:data contents |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
480 |
] |
2241 | 481 |
]. |
482 |
char == $[ "What a mess!!" ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
483 |
return := WriteStream on:(String new:8). |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
484 |
scanset := IdentitySet new. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
485 |
format next. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
486 |
width = 0 ifTrue:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
487 |
width := SmallInteger maxVal |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
488 |
]. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
489 |
exclusive := format peekFor:$^. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
490 |
[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
491 |
last := char. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
492 |
char := format next. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
493 |
char == $] |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
494 |
] whileFalse:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
495 |
char == $- ifFalse:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
496 |
scanset add:char |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
497 |
] ifTrue:[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
498 |
last to:format next do:[:c | |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
499 |
scanset add:c |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
500 |
] |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
501 |
] |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
502 |
]. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
503 |
[ |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
504 |
data atEnd not and:[ (scanset includes:data peek) xor:exclusive ] |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
505 |
] whileTrue:[ return nextPut:data next ]. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
506 |
final value:return contents |
2241 | 507 |
]. |
508 |
('lh' includes:char) ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
509 |
format next. |
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
510 |
char := format peek |
2241 | 511 |
]. |
512 |
('DUdu' includes:char) ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
513 |
final value:(Integer readFrom:data) |
2241 | 514 |
]. |
515 |
('FEGfeg' includes:char) ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
516 |
final value:(Float readFrom:data) |
2241 | 517 |
]. |
2256 | 518 |
('b' includes:char) ifTrue:[ |
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
519 |
final value:(Integer readFrom:data radix:2) |
2256 | 520 |
]. |
2241 | 521 |
('Oo' includes:char) ifTrue:[ |
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
522 |
final value:(Integer readFrom:data radix:8) |
2241 | 523 |
]. |
524 |
('Xx' includes:char) ifTrue:[ |
|
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
525 |
final value:(Integer readFrom:data radix:16) |
2241 | 526 |
] |
2256 | 527 |
|
528 |
" |
|
2303 | 529 |
'%d %x' sscanf:'1234 ff00' |
530 |
'%d %x %b' sscanf:'1234 ff00 1001' |
|
2256 | 531 |
" |
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
532 |
|
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
533 |
"Modified: / 29-11-2011 / 11:55:39 / cg" |
2241 | 534 |
! ! |
535 |
||
536 |
!CharacterArray methodsFor:'converting'! |
|
537 |
||
2303 | 538 |
sscanf:string |
2241 | 539 |
"Return a Collection of objects found in <string> as |
2303 | 540 |
interpreted according to the receiver. |
2241 | 541 |
The receiver is assumed to be a conversion control string as |
542 |
specified in the Unix C-language manual page for scanf(3). |
|
543 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 544 |
|
2241 | 545 |
^ self scanf:(ReadStream on:string) |
546 |
||
547 |
" |
|
2303 | 548 |
'%d %x' sscanf:'1234 ff00' |
549 |
'%d %x %b' sscanf:'1234 ff00 1001' |
|
2241 | 550 |
" |
551 |
! ! |
|
552 |
||
4365
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
553 |
!Collection methodsFor:'converting'! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
554 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
555 |
asHalfFloatArray |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
556 |
"return a new HalfFloatArray with the collection's elements |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
557 |
(which must convert to 16bit half-floats)." |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
558 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
559 |
^ self asArrayOfType:HalfFloatArray |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
560 |
! ! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
561 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
562 |
!Collection methodsFor:'converting'! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
563 |
|
4400 | 564 |
asIdentitySkipList |
565 |
"Answer a IdentitySkipList whose elements are the elements of the |
|
566 |
receiver. The sort order is the default less than or equal." |
|
567 |
||
568 |
^ self as: IdentitySkipList |
|
569 |
! ! |
|
570 |
||
571 |
!Collection methodsFor:'converting'! |
|
572 |
||
4365
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
573 |
asList |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
574 |
"return a new List with the receiver collection's elements" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
575 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
576 |
^ self addAllTo:(List new:self size) |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
577 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
578 |
"Created: 14.2.1997 / 16:25:23 / cg" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
579 |
! ! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
580 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
581 |
!Collection methodsFor:'converting'! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
582 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
583 |
asRunArray |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
584 |
"return a new RunArray with the collection's elements" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
585 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
586 |
^ RunArray from:self. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
587 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
588 |
"/ |runs lastElement occurrences| |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
589 |
"/ |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
590 |
"/ runs := RunArray new. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
591 |
"/ occurrences := 0. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
592 |
"/ self do:[:each | |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
593 |
"/ each == lastElement ifTrue:[ |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
594 |
"/ occurrences := occurrences + 1 |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
595 |
"/ ] ifFalse:[ |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
596 |
"/ runs add:lastElement withOccurrences:occurrences. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
597 |
"/ occurrences := 1. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
598 |
"/ lastElement := each |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
599 |
"/ ]. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
600 |
"/ ]. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
601 |
"/ occurrences ~~ 0 ifTrue:[ |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
602 |
"/ runs add:lastElement withOccurrences:occurrences |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
603 |
"/ ]. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
604 |
"/ ^ runs |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
605 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
606 |
" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
607 |
#(1 2 3 3 3 4 4 4 4 5 6 7) asRunArray |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
608 |
" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
609 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
610 |
"Modified: / 7.4.1998 / 09:50:54 / cg" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
611 |
! ! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
612 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
613 |
!Collection methodsFor:'converting'! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
614 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
615 |
asSharedCollection |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
616 |
"return a shared collection on the receiver. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
617 |
This implements synchronized (i.e. mutually excluded) access to me. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
618 |
Use this for safe access when multiple processes access me concurrently. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
619 |
Notice that this is a general (possibly suboptimal) mechanism, which should |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
620 |
work with all collections. Look for specialized collections (SharedQueue), which are |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
621 |
tuned for this kind of operation." |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
622 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
623 |
^ SharedCollection for:self. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
624 |
! ! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
625 |
|
4400 | 626 |
!Collection methodsFor:'converting'! |
627 |
||
628 |
asSkipList |
|
629 |
"Answer a SkipList whose elements are the elements of the |
|
630 |
receiver. The sort order is the default less than or equal." |
|
631 |
||
632 |
^ self as: SkipList |
|
633 |
! ! |
|
634 |
||
635 |
!Collection methodsFor:'converting'! |
|
636 |
||
637 |
asSkipList: aSortBlock |
|
638 |
"Answer a SkipList whose elements are the elements of the |
|
639 |
receiver. The sort order is defined by the argument, aSortBlock." |
|
640 |
||
641 |
| skipList | |
|
642 |
skipList := SkipList new: self size sortBlock: aSortBlock. |
|
643 |
skipList addAll: self. |
|
644 |
^ skipList |
|
645 |
||
646 |
"Modified (comment): / 18-06-2017 / 22:40:10 / cg" |
|
647 |
! ! |
|
648 |
||
2237 | 649 |
!Float methodsFor:'private'! |
650 |
||
2303 | 651 |
absDecimalPrintOn:aStream digits:digits |
2237 | 652 |
"Place a string representation of the receiver's abs value |
653 |
on <aStream> using <digits> significant digits, using decimal notation. |
|
654 |
This is a helper for printf." |
|
655 |
||
656 |
|exp x fuzz i| |
|
657 |
||
658 |
"x is myself normalized to (1.0, 10.0), exp is my exponent" |
|
2303 | 659 |
exp := self abs < 1.0 |
4418 | 660 |
ifTrue:[ (10.0 / self abs) log10 floor negated ] |
661 |
ifFalse:[ self abs log10 floor ]. |
|
2237 | 662 |
x := self abs / (10.0 raisedTo:exp). |
663 |
fuzz := 10.0 raisedTo:1 - digits. |
|
664 |
"round the last digit to be printed" |
|
665 |
x := 0.5 * fuzz + x. |
|
666 |
x >= 10.0 "check if rounding has unnormalized x" ifTrue:[ |
|
4418 | 667 |
x := x / 10.0. |
668 |
exp := exp + 1 |
|
2237 | 669 |
]. |
670 |
exp < 0 ifTrue:[ |
|
4418 | 671 |
1 to:1 - exp do:[:j | |
672 |
aStream nextPut:('0.000000000000' at:j) |
|
673 |
] |
|
2237 | 674 |
]. |
675 |
[ x >= fuzz ] "use fuzz to track significance" whileTrue:[ |
|
4418 | 676 |
i := x truncated. |
677 |
aStream nextPut:(48 + i) asCharacter. |
|
678 |
x := (x - i) * 10.0. |
|
679 |
fuzz := fuzz * 10.0. |
|
680 |
exp := exp - 1. |
|
681 |
exp = -1 ifTrue:[ |
|
682 |
aStream nextPut:$. |
|
683 |
] |
|
2237 | 684 |
]. |
685 |
[ exp >= -1 ] whileTrue:[ |
|
4418 | 686 |
aStream nextPut:$0. |
687 |
exp := exp - 1. |
|
688 |
exp = -1 ifTrue:[ |
|
689 |
aStream nextPut:$. |
|
690 |
] |
|
2237 | 691 |
] |
4418 | 692 |
|
693 |
"Modified: / 19-06-2017 / 14:53:47 / cg" |
|
2237 | 694 |
! ! |
695 |
||
696 |
!Float methodsFor:'private'! |
|
697 |
||
2303 | 698 |
absPrintOn:aStream digits:digits |
699 |
"Place a string representation of the receiver's abs value on <aStream> using |
|
2237 | 700 |
<digits> significant digits. |
701 |
This is a helper for printf." |
|
2303 | 702 |
|
4418 | 703 |
PrintfScanf absPrintFloat:self on:aStream digits:digits |
704 |
||
705 |
"Modified: / 19-06-2017 / 15:04:24 / cg" |
|
2237 | 706 |
! ! |
707 |
||
708 |
!Float methodsFor:'private'! |
|
709 |
||
2303 | 710 |
absScientificPrintOn:aStream digits:digits |
2237 | 711 |
"Place a string representation of the receiver's abs value on <aStream> using <digits> significant |
712 |
digits, using scientific notation. |
|
713 |
This is a helper for printf." |
|
2303 | 714 |
|
4418 | 715 |
PrintfScanf absScientificPrintFloat:self on:aStream digits:digits. |
2237 | 716 |
|
4418 | 717 |
"Modified: / 19-06-2017 / 14:59:56 / cg" |
2237 | 718 |
! ! |
719 |
||
4381 | 720 |
!Float methodsFor:'coercing & converting'! |
721 |
||
722 |
asQDouble |
|
723 |
"return a QDouble with my value" |
|
724 |
||
725 |
^ QDouble fromFloat:self |
|
726 |
||
727 |
" |
|
728 |
1.0 asQDouble |
|
729 |
" |
|
730 |
||
731 |
"Created: / 13-06-2017 / 16:48:57 / cg" |
|
732 |
! ! |
|
733 |
||
4383 | 734 |
!Integer methodsFor:'coercing & converting'! |
735 |
||
736 |
asQDouble |
|
737 |
"return a QDouble with same value as myself." |
|
738 |
||
739 |
^ QDouble fromInteger:self |
|
740 |
||
741 |
" |
|
742 |
1234567890 asQDouble |
|
743 |
1234567890 asQDouble asInteger |
|
744 |
12345678901234567890 asQDouble |
|
745 |
12345678901234567890 asQDouble asInteger |
|
746 |
" |
|
747 |
||
748 |
"Created: / 12-06-2017 / 18:41:07 / cg" |
|
749 |
"Modified (comment): / 12-06-2017 / 20:55:24 / cg" |
|
750 |
! ! |
|
751 |
||
1759 | 752 |
!Object methodsFor:'dependents-interests'! |
753 |
||
754 |
addInterest:anInterest |
|
755 |
"install an interest forwarder. |
|
756 |
Here, we use the nonWeakDependencies." |
|
757 |
||
758 |
self addNonWeakDependent:anInterest |
|
759 |
||
760 |
"Created: 14.10.1996 / 22:27:34 / stefan" |
|
761 |
! ! |
|
762 |
||
3896 | 763 |
!Object methodsFor:'converting'! |
764 |
||
765 |
asDoubleLink |
|
766 |
"return a valueDoubleLink for the receiver. |
|
767 |
Used to make sure the receiver can be added to a double linked list" |
|
768 |
||
769 |
^ ValueDoubleLink value:self |
|
770 |
! ! |
|
771 |
||
1759 | 772 |
!Object methodsFor:'dependents-interests'! |
773 |
||
774 |
expressInterestIn:aspect for:anObject sendBack:aSelector |
|
775 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
776 |
changes aspect." |
|
777 |
||
778 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
779 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
780 |
||
2303 | 781 |
self addInterest:(InterestConverter |
782 |
destination:anObject |
|
783 |
selector:aSelector |
|
784 |
aspect:aspect) |
|
1759 | 785 |
|
786 |
" |
|
787 |
|p b| |
|
788 |
||
789 |
b := [Transcript showCR:' -> the point changed']. |
|
790 |
||
791 |
p := Point new. |
|
792 |
Transcript showCR:'interest in #foo:'. |
|
793 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
794 |
p x:1. |
|
795 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
796 |
p changed:#bar. |
|
797 |
Transcript cr. |
|
798 |
||
799 |
Delay waitForSeconds:1. |
|
800 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
801 |
p changed:#foo. |
|
802 |
Transcript cr. |
|
803 |
||
804 |
Delay waitForSeconds:1. |
|
805 |
Transcript showCR:'no more interest in #foo:'. |
|
806 |
p retractInterestIn:#foo for:b. |
|
807 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
808 |
p changed:#foo. |
|
809 |
Transcript cr. |
|
810 |
||
811 |
Delay waitForSeconds:1. |
|
812 |
Transcript showCR:'interest in #bar now:'. |
|
813 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
814 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
815 |
p changed:#foo. |
|
816 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
817 |
p changed:#bar. |
|
818 |
Transcript cr. |
|
819 |
||
820 |
Delay waitForSeconds:1. |
|
821 |
Transcript showCR:'interest in #foo now:'. |
|
822 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
823 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
824 |
p changed:#foo. |
|
825 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
826 |
p changed:#bar. |
|
827 |
Transcript cr. |
|
828 |
||
829 |
Delay waitForSeconds:1. |
|
830 |
Transcript showCR:'no more interests:'. |
|
831 |
p retractInterestsFor:b. |
|
832 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
833 |
p changed:#foo. |
|
834 |
Transcript showCR:'now changing #bar... (expect no notification)'. |
|
835 |
p changed:#bar. |
|
836 |
Transcript cr. |
|
837 |
||
838 |
p release. |
|
839 |
" |
|
1668 | 840 |
|
1759 | 841 |
"Created: 19.4.1996 / 10:26:22 / cg" |
842 |
"Modified: 19.4.1996 / 12:34:08 / cg" |
|
843 |
"Modified: 14.10.1996 / 22:28:20 / stefan" |
|
844 |
! ! |
|
845 |
||
846 |
!Object methodsFor:'dependents-interests'! |
|
847 |
||
848 |
interests |
|
849 |
"return a Collection of interests - empty if there is none. |
|
850 |
Here, we use the nonWeakDependents for interests." |
|
851 |
||
852 |
^ self nonWeakDependents |
|
853 |
||
854 |
"Created: / 14.10.1996 / 22:20:51 / stefan" |
|
855 |
"Modified: / 30.1.1998 / 14:07:35 / cg" |
|
856 |
! ! |
|
857 |
||
858 |
!Object methodsFor:'dependents-interests'! |
|
859 |
||
860 |
interestsFor:someOne |
|
861 |
"return a collection of interests of someOne - empty if there is none." |
|
862 |
||
863 |
|coll deps| |
|
864 |
||
865 |
deps := self interests. |
|
866 |
deps size == 0 ifTrue:[^ #()]. |
|
867 |
||
868 |
coll := IdentitySet new. |
|
869 |
||
870 |
deps do:[:dep | |
|
2303 | 871 |
(dep isInterestConverter) ifTrue:[ |
872 |
dep destination == someOne ifTrue:[ |
|
873 |
coll add:dep. |
|
874 |
] |
|
875 |
] |
|
1759 | 876 |
]. |
877 |
^ coll |
|
878 |
||
879 |
"Created: / 30.1.1998 / 14:02:26 / cg" |
|
880 |
"Modified: / 30.1.1998 / 14:08:24 / cg" |
|
881 |
! ! |
|
1668 | 882 |
|
1759 | 883 |
!Object methodsFor:'dependents-interests'! |
884 |
||
885 |
onChangeEvaluate:aBlock |
|
886 |
"arrange for aBlock to be evaluated whenever the receiver changes." |
|
887 |
||
2149
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
888 |
|na selector| |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
889 |
|
3559
fa3443d808a1
Changed Object>>#onChangeEvaluate: (send #argumentCount instead of #numArgs)
Stefan Vogel <sv@exept.de>
parents:
3538
diff
changeset
|
890 |
na := aBlock argumentCount. |
2149
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
891 |
na == 0 ifTrue:[ |
3559
fa3443d808a1
Changed Object>>#onChangeEvaluate: (send #argumentCount instead of #numArgs)
Stefan Vogel <sv@exept.de>
parents:
3538
diff
changeset
|
892 |
selector := #value |
2149
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
893 |
] ifFalse:[ |
3559
fa3443d808a1
Changed Object>>#onChangeEvaluate: (send #argumentCount instead of #numArgs)
Stefan Vogel <sv@exept.de>
parents:
3538
diff
changeset
|
894 |
selector := #( #'value:' #'value:value:' #'value:value:value:') at:na |
2149
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
895 |
]. |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
896 |
^ self onChangeSend:selector to:aBlock |
1759 | 897 |
|
898 |
" |
|
899 |
|p b| |
|
900 |
||
901 |
b := [Transcript showCR:' -> the point changed']. |
|
902 |
||
903 |
p := Point new. |
|
904 |
Transcript showCR:'interest in #foo:'. |
|
905 |
p onChangeEvaluate:b. |
|
906 |
p x:1. |
|
907 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
908 |
p changed:#bar. |
|
909 |
||
910 |
p retractInterests. |
|
911 |
p changed:#bar. |
|
912 |
" |
|
913 |
! ! |
|
914 |
||
915 |
!Object methodsFor:'dependents-interests'! |
|
916 |
||
917 |
onChangeSend:aSelector to:anObject |
|
918 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
4030 | 919 |
changes. |
920 |
Use retractInterestsFor: in case you are no longer interested" |
|
1759 | 921 |
|
922 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
923 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
924 |
||
925 |
((self interests ? #()) |
|
4030 | 926 |
contains:[:anInterest | |
927 |
(anInterest isInterestConverter) |
|
928 |
and:[ anInterest destination == anObject |
|
929 |
and:[ anInterest selector == aSelector]] |
|
930 |
]) |
|
931 |
ifTrue:[^ self]. |
|
1759 | 932 |
|
2303 | 933 |
self addInterest:(InterestConverter |
4030 | 934 |
destination:anObject |
935 |
selector:aSelector) |
|
1668 | 936 |
|
937 |
" |
|
1759 | 938 |
|p b| |
939 |
||
940 |
b := [Transcript showCR:'the point changed']. |
|
941 |
||
942 |
p := Point new. |
|
943 |
p onChangeSend:#value to:b. |
|
944 |
p x:1. |
|
945 |
Transcript showCR:'now changing'. |
|
946 |
p changed. |
|
947 |
Transcript cr. |
|
948 |
||
949 |
Delay waitForSeconds:1. |
|
950 |
Transcript showCR:'now changing'. |
|
951 |
p changed. |
|
952 |
Transcript cr. |
|
953 |
||
954 |
Delay waitForSeconds:1. |
|
955 |
Transcript showCR:'no more interest'. |
|
956 |
p retractInterestsFor:b. |
|
957 |
Transcript showCR:'now changing again'. |
|
958 |
p changed. |
|
959 |
Transcript cr. |
|
960 |
||
961 |
Delay waitForSeconds:1. |
|
962 |
Transcript showCR:'interest again'. |
|
963 |
p onChangeSend:#value to:b. |
|
964 |
Transcript showCR:'now changing again'. |
|
965 |
p changed. |
|
966 |
Transcript cr. |
|
967 |
" |
|
968 |
||
969 |
"Created: 19.4.1996 / 10:26:38 / cg" |
|
970 |
"Modified: 19.4.1996 / 12:34:26 / cg" |
|
971 |
"Modified: 14.10.1996 / 22:28:27 / stefan" |
|
972 |
! ! |
|
973 |
||
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
974 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
975 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
976 |
removeActionsForEvent:eventSymbol |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
977 |
"remove ST/V-style event triggers." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
978 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
979 |
self retractInterestsIn:eventSymbol |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
980 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
981 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
982 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
983 |
|
2903 | 984 |
removeActionsWithReceiver:aReceiver |
985 |
"remove ST/V-style event triggers." |
|
986 |
||
987 |
self retractInterestsFor:aReceiver |
|
988 |
! ! |
|
989 |
||
990 |
!Object methodsFor:'dependents-st/v event simulation'! |
|
991 |
||
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
992 |
removeAllActionsWithReceiver:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
993 |
"remove ST/V-style event triggers." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
994 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
995 |
self retractInterestsFor:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
996 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
997 |
|
1759 | 998 |
!Object methodsFor:'dependents-interests'! |
999 |
||
1000 |
removeInterest:anInterest |
|
1001 |
"remove an interest forwarder. |
|
1002 |
Here, we use the nonWeakDependencies." |
|
1003 |
||
1004 |
self removeNonWeakDependent:anInterest |
|
1005 |
||
1006 |
"Created: 14.10.1996 / 22:21:59 / stefan" |
|
1007 |
! ! |
|
1008 |
||
1009 |
!Object methodsFor:'dependents-interests'! |
|
1010 |
||
1011 |
retractInterestIn:aspect for:someOne |
|
1012 |
"remove the interest of someOne in the receiver changing aspect |
|
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1013 |
(as installed with #expressInterestIn:for:sendBack:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1014 |
Answer the retracted interests." |
1759 | 1015 |
|
1016 |
"/ for now, remove the interestConverter. |
|
1017 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1018 |
||
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1019 |
^ self retractInterestsForWhich:[:i | |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1020 |
(i aspect == aspect) and:[i destination == someOne] |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1021 |
] |
1759 | 1022 |
|
1668 | 1023 |
" |
1759 | 1024 |
|p b| |
1025 |
||
1026 |
b := [Transcript showCR:'the point changed']. |
|
1027 |
||
1028 |
p := Point new. |
|
1029 |
Transcript showCR:'interest in #foo'. |
|
1030 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
1031 |
p x:1. |
|
1032 |
Transcript showCR:'now changing #bar'. |
|
1033 |
p changed:#bar. |
|
1034 |
Transcript cr. |
|
1035 |
||
1036 |
Delay waitForSeconds:1. |
|
1037 |
Transcript showCR:'now changing #foo'. |
|
1038 |
p changed:#foo. |
|
1039 |
Transcript cr. |
|
1040 |
||
1041 |
Delay waitForSeconds:1. |
|
1042 |
Transcript showCR:'no more interest in #foo'. |
|
1043 |
p retractInterestIn:#foo for:b. |
|
1044 |
Transcript showCR:'now changing #foo'. |
|
1045 |
p changed:#foo. |
|
1046 |
Transcript cr. |
|
1047 |
||
1048 |
Delay waitForSeconds:1. |
|
1049 |
Transcript showCR:'interest in #bar now'. |
|
1050 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
1051 |
Transcript showCR:'now changing #foo'. |
|
1052 |
p changed:#foo. |
|
1053 |
Transcript showCR:'now changing #bar'. |
|
1054 |
p changed:#bar. |
|
1055 |
Transcript cr. |
|
1056 |
||
1057 |
Delay waitForSeconds:1. |
|
1058 |
Transcript showCR:'interest in #foo now'. |
|
1059 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
1060 |
Transcript showCR:'now changing #foo'. |
|
1061 |
p changed:#foo. |
|
1062 |
Transcript showCR:'now changing #bar'. |
|
1063 |
p changed:#bar. |
|
1064 |
Transcript cr. |
|
1065 |
||
1066 |
Delay waitForSeconds:1. |
|
1067 |
Transcript showCR:'no more interests'. |
|
1068 |
p retractInterestsFor:b. |
|
1069 |
Transcript showCR:'now changing #foo'. |
|
1070 |
p changed:#foo. |
|
1071 |
Transcript showCR:'now changing #bar'. |
|
1072 |
p changed:#bar. |
|
1073 |
Transcript cr. |
|
1074 |
" |
|
1075 |
||
1076 |
"Created: / 19.4.1996 / 10:27:11 / cg" |
|
1077 |
"Modified: / 14.10.1996 / 22:21:19 / stefan" |
|
1078 |
"Modified: / 30.1.1998 / 14:05:34 / cg" |
|
1079 |
! ! |
|
1080 |
||
1081 |
!Object methodsFor:'dependents-interests'! |
|
1082 |
||
1083 |
retractInterests |
|
1084 |
"remove all interests in the receiver changing aspect |
|
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1085 |
(as installed with #expressInterestIn:for:sendBack:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1086 |
Answer the retraced interests." |
1759 | 1087 |
|
1088 |
"/ for now, remove the interestConverter. |
|
1089 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1090 |
||
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1091 |
^ self retractInterestsForWhich:[:i | true ] |
1759 | 1092 |
! ! |
1093 |
||
1094 |
!Object methodsFor:'dependents-interests'! |
|
1095 |
||
1096 |
retractInterestsFor:someOne |
|
2303 | 1097 |
"remove the interest of someOne in the receiver |
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1098 |
(as installed with #onChangeSend:to:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1099 |
Answer the retracted interests." |
1759 | 1100 |
|
1101 |
"/ for now, remove the interestConverter. |
|
1102 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1103 |
||
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1104 |
^ self retractInterestsForWhich:[:i | i destination == someOne ] |
1759 | 1105 |
|
1106 |
" |
|
1107 |
|p b| |
|
1108 |
||
1109 |
b := [Transcript showCR:'the point changed']. |
|
1110 |
||
1111 |
p := Point new. |
|
1112 |
p onChangeSend:#value to:b. |
|
1113 |
p x:1. |
|
1114 |
Transcript showCR:'now changing'. |
|
1115 |
p changed. |
|
1116 |
Transcript cr. |
|
1117 |
||
1118 |
Delay waitForSeconds:1. |
|
1119 |
Transcript showCR:'now changing'. |
|
1120 |
p changed. |
|
1121 |
Transcript cr. |
|
1122 |
||
1123 |
Delay waitForSeconds:1. |
|
1124 |
Transcript showCR:'no more interest'. |
|
1125 |
p retractInterestsFor:b. |
|
1126 |
Transcript showCR:'now changing again'. |
|
1127 |
p changed. |
|
1128 |
Transcript cr. |
|
1129 |
||
1130 |
Delay waitForSeconds:1. |
|
1131 |
Transcript showCR:'interest again'. |
|
1132 |
p onChangeSend:#value to:b. |
|
1133 |
Transcript showCR:'now changing again'. |
|
1134 |
p changed. |
|
1135 |
Transcript cr. |
|
1136 |
" |
|
1137 |
||
1138 |
"Created: / 19.4.1996 / 10:23:46 / cg" |
|
1139 |
"Modified: / 14.10.1996 / 22:21:25 / stefan" |
|
1140 |
"Modified: / 30.1.1998 / 14:04:52 / cg" |
|
1141 |
! ! |
|
1142 |
||
1143 |
!Object methodsFor:'dependents-interests'! |
|
1144 |
||
1145 |
retractInterestsForWhich:aBlock |
|
1146 |
"remove all interests in the receiver changing aspect |
|
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1147 |
(as installed with #expressInterestIn:for:sendBack:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1148 |
Answer the retracted interests." |
1759 | 1149 |
|
1150 |
"/ for now, remove the interestConverter. |
|
1151 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1152 |
||
1153 |
|deps coll| |
|
1154 |
||
1155 |
deps := self interests. |
|
1156 |
deps size ~~ 0 ifTrue:[ |
|
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1157 |
"/ cannot removeDependent within the loop - the interests collection rehashes |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1158 |
coll := IdentitySet new. |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1159 |
deps do:[:dep | |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1160 |
dep isInterestConverter ifTrue:[ |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1161 |
(aBlock value:dep) ifTrue:[coll add:dep]. |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1162 |
] |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1163 |
]. |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1164 |
coll do:[:dep | |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1165 |
self removeInterest:dep. |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1166 |
]. |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1167 |
^ coll. |
1759 | 1168 |
]. |
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1169 |
^ #() |
1759 | 1170 |
! ! |
1171 |
||
1172 |
!Object methodsFor:'dependents-interests'! |
|
1173 |
||
1174 |
retractInterestsIn:aspect |
|
1175 |
"remove all interests in the receiver changing aspect |
|
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1176 |
(as installed with #expressInterestIn:for:sendBack:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1177 |
Answer the retracted interests." |
1759 | 1178 |
|
1179 |
"/ for now, remove the interestConverter. |
|
1180 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1181 |
||
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1182 |
^ self retractInterestsForWhich:[:i | i aspect == aspect ] |
1668 | 1183 |
! ! |
1184 |
||
2901 | 1185 |
!Object methodsFor:'Compatibility-Dolphin'! |
1186 |
||
1187 |
trigger:anAspect |
|
1188 |
self changed:anAspect |
|
1189 |
! ! |
|
1190 |
||
1191 |
!Object methodsFor:'Compatibility-Dolphin'! |
|
1192 |
||
1193 |
trigger:anAspect with:anArgument |
|
1194 |
self changed:anAspect with:anArgument |
|
1195 |
! ! |
|
1196 |
||
1197 |
!Object methodsFor:'dependents-st/v event simulation'! |
|
1198 |
||
1199 |
triggerEvent:aSymbol |
|
1200 |
self changed:aSymbol |
|
1201 |
! ! |
|
1202 |
||
1668 | 1203 |
!Object methodsFor:'dependents-st/v event simulation'! |
1204 |
||
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1205 |
triggerEvent:eventSymbol with:aParameter |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1206 |
"perform ST/V-style event triggering." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1207 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1208 |
self changed:eventSymbol with:(Array with:aParameter). |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1209 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1210 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1211 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1212 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1213 |
triggerEvent:eventSymbol withArguments:parameters |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1214 |
"perform ST/V-style event triggering." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1215 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1216 |
self changed:eventSymbol with:parameters. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1217 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1218 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1219 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1220 |
|
1668 | 1221 |
when:eventSymbol send:selector to:anObject |
1222 |
"install an ST/V-style interest forwarder. |
|
1223 |
Here, we use the nonWeakDependencies." |
|
1224 |
||
1225 |
self addInterest:(InterestConverterWithParameters |
|
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1226 |
destination:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1227 |
selector:selector |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1228 |
aspect:eventSymbol). |
1668 | 1229 |
|
1230 |
" |
|
1231 |
|p b| |
|
1232 |
||
1233 |
b := [Transcript showCR:'the point changed']. |
|
1234 |
||
1235 |
p := Point new. |
|
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1236 |
p when:#foo:bar: send:#value:value: to:[:a :b | Transcript show:'foo: '; show:a; show:' bar: '; showCR:b]. |
1668 | 1237 |
Transcript showCR:'now changing'. |
1238 |
p triggerEvent:#foo:bar: withArguments:#('fooArg' 'barArg'). |
|
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1239 |
p removeActionsForEvent:#foo:bar:. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1240 |
" |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1241 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1242 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1243 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1244 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1245 |
when:eventSymbol send:selector to:anObject with:aParameter |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1246 |
"install an ST/V-style interest forwarder. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1247 |
Here, we use the nonWeakDependencies." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1248 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1249 |
self addInterest:((InterestConverterWithParameters |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1250 |
destination:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1251 |
selector:selector |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1252 |
aspect:eventSymbol) |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1253 |
defaultParameters:(Array with:aParameter)). |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1254 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1255 |
" |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1256 |
|p b| |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1257 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1258 |
b := [Transcript showCR:'the point changed']. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1259 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1260 |
p := Point new. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1261 |
p |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1262 |
when:#foo: |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1263 |
send:#value: |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1264 |
to:[:a | Transcript show:'foo: '; showCR:a] |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1265 |
with:123. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1266 |
Transcript showCR:'now changing'. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1267 |
p triggerEvent:#foo:. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1268 |
p triggerEvent:#foo: with:987. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1269 |
p removeActionsForEvent:#foo:. |
1668 | 1270 |
" |
1271 |
! ! |
|
1272 |
||
2901 | 1273 |
!Object methodsFor:'Compatibility-Dolphin'! |
1274 |
||
1275 |
when:anAspect sendTo:anObject |
|
1276 |
self expressInterestIn:anAspect for:anObject sendBack:anAspect |
|
1277 |
! ! |
|
1278 |
||
2364 | 1279 |
!Stream methodsFor:'stacked computing streams'! |
1280 |
||
1281 |
collecting:aBlock |
|
1282 |
"return a stacked computing stream, which reads elements from the receiver, |
|
1283 |
applies aBlock to each read element, and provides the results as elements to its reader." |
|
1284 |
||
1285 |
^ CollectingReadStream on:self collecting:aBlock |
|
3094 | 1286 |
|
1287 |
" |
|
1288 |
|s s2| |
|
1289 |
||
1290 |
s := 'hello world' readStream. |
|
1291 |
s2 := s collecting:[:ch | ch asUppercase]. |
|
1292 |
s2 upToEnd. |
|
1293 |
" |
|
2364 | 1294 |
! ! |
1295 |
||
1296 |
!Stream methodsFor:'stacked computing streams'! |
|
1297 |
||
1298 |
selecting:aBlock |
|
1299 |
"return a stacked computing stream, which reads elements from the receiver, |
|
1300 |
but only provides elements for which aBlock returns true to its reader." |
|
1301 |
||
1302 |
^ SelectingReadStream on:self selecting:aBlock |
|
3094 | 1303 |
|
1304 |
" |
|
1305 |
|s s2| |
|
1306 |
||
1307 |
s := 'hello world' readStream. |
|
1308 |
s2 := s selecting:[:ch | ch isVowel]. |
|
1309 |
s2 upToEnd. |
|
1310 |
" |
|
2364 | 1311 |
! ! |
1312 |
||
2303 | 1313 |
!stx_libbasic2 class methodsFor:'documentation'! |
1314 |
||
1315 |
extensionsVersion_CVS |
|
3715 | 1316 |
^ '$Header$' |
3005 | 1317 |
! ! |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
1318 |