resin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/README.markdown +52 -0
  2. data/amber/css/amber.css +519 -0
  3. data/amber/css/documentation.css +84 -0
  4. data/amber/css/profstef.css +75 -0
  5. data/amber/css/style.css +313 -0
  6. data/amber/images/amber.png +0 -0
  7. data/amber/images/amber_small.png +0 -0
  8. data/amber/images/off.png +0 -0
  9. data/amber/images/offHover.png +0 -0
  10. data/amber/images/presentation.png +0 -0
  11. data/amber/images/profstef.png +0 -0
  12. data/amber/images/sprite.png +0 -0
  13. data/amber/images/tinylogo.png +0 -0
  14. data/amber/images/twitterwall.png +0 -0
  15. data/amber/js/Additional-Examples.deploy.js +15 -0
  16. data/amber/js/Additional-Examples.js +21 -0
  17. data/amber/js/Benchfib.deploy.js +132 -0
  18. data/amber/js/Benchfib.js +167 -0
  19. data/amber/js/Canvas.deploy.js +1304 -0
  20. data/amber/js/Canvas.js +1885 -0
  21. data/amber/js/Compiler.deploy.js +1871 -0
  22. data/amber/js/Compiler.js +2616 -0
  23. data/amber/js/Documentation.deploy.js +961 -0
  24. data/amber/js/Documentation.js +1376 -0
  25. data/amber/js/Examples.deploy.js +53 -0
  26. data/amber/js/Examples.js +73 -0
  27. data/amber/js/IDE.deploy.js +3468 -0
  28. data/amber/js/IDE.js +4883 -0
  29. data/amber/js/Kernel-Announcements.deploy.js +107 -0
  30. data/amber/js/Kernel-Announcements.js +152 -0
  31. data/amber/js/Kernel-Classes.deploy.js +675 -0
  32. data/amber/js/Kernel-Classes.js +956 -0
  33. data/amber/js/Kernel-Collections.deploy.js +3273 -0
  34. data/amber/js/Kernel-Collections.js +4644 -0
  35. data/amber/js/Kernel-Exceptions.deploy.js +244 -0
  36. data/amber/js/Kernel-Exceptions.js +349 -0
  37. data/amber/js/Kernel-Methods.deploy.js +510 -0
  38. data/amber/js/Kernel-Methods.js +739 -0
  39. data/amber/js/Kernel-Objects.deploy.js +2698 -0
  40. data/amber/js/Kernel-Objects.js +3858 -0
  41. data/amber/js/Kernel-Tests.deploy.js +1419 -0
  42. data/amber/js/Kernel-Tests.js +1929 -0
  43. data/amber/js/Kernel-Transcript.deploy.js +142 -0
  44. data/amber/js/Kernel-Transcript.js +202 -0
  45. data/amber/js/SUnit.deploy.js +351 -0
  46. data/amber/js/SUnit.js +501 -0
  47. data/amber/js/amber.js +250 -0
  48. data/amber/js/boot.js +587 -0
  49. data/amber/js/compat.js +22 -0
  50. data/amber/js/init.js +8 -0
  51. data/amber/js/lib/CodeMirror/LICENSE +19 -0
  52. data/amber/js/lib/CodeMirror/amber.css +21 -0
  53. data/amber/js/lib/CodeMirror/codemirror.css +67 -0
  54. data/amber/js/lib/CodeMirror/codemirror.js +2144 -0
  55. data/amber/js/lib/CodeMirror/smalltalk.js +134 -0
  56. data/amber/js/lib/jQuery/jquery-1.4.4.min.js +167 -0
  57. data/amber/js/lib/jQuery/jquery-1.6.4.min.js +4 -0
  58. data/amber/js/lib/jQuery/jquery-ui-1.8.16.custom.min.js +791 -0
  59. data/amber/js/lib/jQuery/jquery.textarea.js +267 -0
  60. data/amber/js/lib/peg-0.6.2.min.js +2 -0
  61. data/amber/js/lib/showdown.js +419 -0
  62. data/amber/js/parser.js +4005 -0
  63. data/amber/js/parser.pegjs +220 -0
  64. data/amber/st/Benchfib.st +124 -0
  65. data/amber/st/Canvas.st +556 -0
  66. data/amber/st/Compiler.st +1425 -0
  67. data/amber/st/Documentation.st +758 -0
  68. data/amber/st/Examples.st +38 -0
  69. data/amber/st/IDE.st +2336 -0
  70. data/amber/st/Kernel-Announcements.st +61 -0
  71. data/amber/st/Kernel-Classes.st +403 -0
  72. data/amber/st/Kernel-Collections.st +1673 -0
  73. data/amber/st/Kernel-Exceptions.st +124 -0
  74. data/amber/st/Kernel-Methods.st +287 -0
  75. data/amber/st/Kernel-Objects.st +1489 -0
  76. data/amber/st/Kernel-Tests.st +892 -0
  77. data/amber/st/Kernel-Transcript.st +70 -0
  78. data/amber/st/SUnit.st +172 -0
  79. data/bin/runresin +12 -0
  80. data/lib/resin.rb +0 -0
  81. data/lib/resin/app/app.rb +121 -0
  82. data/lib/resin/app/views/index.haml +10 -0
  83. metadata +216 -0
@@ -0,0 +1,1673 @@
1
+ Smalltalk current createPackage: 'Kernel-Collections' properties: #{}!
2
+ Object subclass: #Collection
3
+ instanceVariableNames: ''
4
+ category: 'Kernel-Collections'!
5
+
6
+ !Collection methodsFor: 'accessing'!
7
+
8
+ size
9
+ self subclassResponsibility
10
+ !
11
+
12
+ readStream
13
+ ^self stream
14
+ !
15
+
16
+ writeStream
17
+ ^self stream
18
+ !
19
+
20
+ stream
21
+ ^self streamClass on: self
22
+ !
23
+
24
+ streamClass
25
+ ^self class streamClass
26
+ ! !
27
+
28
+ !Collection methodsFor: 'adding/removing'!
29
+
30
+ add: anObject
31
+ self subclassResponsibility
32
+ !
33
+
34
+ addAll: aCollection
35
+ aCollection do: [:each |
36
+ self add: each].
37
+ ^aCollection
38
+ !
39
+
40
+ remove: anObject
41
+ ^self remove: anObject ifAbsent: [self errorNotFound]
42
+ !
43
+
44
+ remove: anObject ifAbsent: aBlock
45
+ self subclassResponsibility
46
+ ! !
47
+
48
+ !Collection methodsFor: 'converting'!
49
+
50
+ asArray
51
+ ^Array withAll: self
52
+ !
53
+
54
+ asSet
55
+ ^Set withAll: self
56
+ !
57
+
58
+ asJSONString
59
+ ^JSON stringify: (self collect: [:each | each asJSONString])
60
+ !
61
+
62
+ asOrderedCollection
63
+ ^OrderedCollection withAll: self
64
+ ! !
65
+
66
+ !Collection methodsFor: 'copying'!
67
+
68
+ , aCollection
69
+ ^self copy
70
+ addAll: aCollection;
71
+ yourself
72
+ !
73
+
74
+ copyWith: anObject
75
+ ^self copy add: anObject; yourself
76
+ !
77
+
78
+ copyWithAll: aCollection
79
+ ^self copy addAll: aCollection; yourself
80
+ !
81
+
82
+ copyWithoutAll: aCollection
83
+ "Answer a copy of the receiver that does not contain any elements
84
+ equal to those in aCollection."
85
+
86
+ ^ self reject: [:each | aCollection includes: each]
87
+ ! !
88
+
89
+ !Collection methodsFor: 'enumerating'!
90
+
91
+ do: aBlock
92
+ <for(var i=0;i<self.length;i++){aBlock(self[i]);}>
93
+ !
94
+
95
+ collect: aBlock
96
+ | newCollection |
97
+ newCollection := self class new.
98
+ self do: [:each |
99
+ newCollection add: (aBlock value: each)].
100
+ ^newCollection
101
+ !
102
+
103
+ detect: aBlock
104
+ ^self detect: aBlock ifNone: [self errorNotFound]
105
+ !
106
+
107
+ detect: aBlock ifNone: anotherBlock
108
+ <
109
+ for(var i = 0; i < self.length; i++)
110
+ if(aBlock(self[i]))
111
+ return self[i];
112
+ return anotherBlock();
113
+ >
114
+ !
115
+
116
+ do: aBlock separatedBy: anotherBlock
117
+ | first |
118
+ first := true.
119
+ self do: [:each |
120
+ first
121
+ ifTrue: [first := false]
122
+ ifFalse: [anotherBlock value].
123
+ aBlock value: each]
124
+ !
125
+
126
+ inject: anObject into: aBlock
127
+ | result |
128
+ result := anObject.
129
+ self do: [:each |
130
+ result := aBlock value: result value: each].
131
+ ^result
132
+ !
133
+
134
+ reject: aBlock
135
+ ^self select: [:each | (aBlock value: each) = false]
136
+ !
137
+
138
+ select: aBlock
139
+ | stream |
140
+ stream := self class new writeStream.
141
+ self do: [:each |
142
+ (aBlock value: each) ifTrue: [
143
+ stream nextPut: each]].
144
+ ^stream contents
145
+ ! !
146
+
147
+ !Collection methodsFor: 'error handling'!
148
+
149
+ errorNotFound
150
+ self error: 'Object is not in the collection'
151
+ ! !
152
+
153
+ !Collection methodsFor: 'testing'!
154
+
155
+ includes: anObject
156
+ <
157
+ var i = self.length;
158
+ while (i--) {
159
+ if (smalltalk.send(self[i], "__eq", [anObject])) {return true;}
160
+ }
161
+ return false
162
+ >
163
+ !
164
+
165
+ notEmpty
166
+ ^self isEmpty not
167
+ !
168
+
169
+ isEmpty
170
+ ^self size = 0
171
+ !
172
+
173
+ ifNotEmpty: aBlock
174
+ self notEmpty ifTrue: aBlock.
175
+ !
176
+
177
+ ifEmpty: aBlock
178
+ self isEmpty ifTrue: aBlock.
179
+ ! !
180
+
181
+ !Collection class methodsFor: 'accessing'!
182
+
183
+ streamClass
184
+ ^Stream
185
+ ! !
186
+
187
+ !Collection class methodsFor: 'instance creation'!
188
+
189
+ with: anObject
190
+ ^self new
191
+ add: anObject;
192
+ yourself
193
+ !
194
+
195
+ with: anObject with: anotherObject
196
+ ^self new
197
+ add: anObject;
198
+ add: anotherObject;
199
+ yourself
200
+ !
201
+
202
+ with: firstObject with: secondObject with: thirdObject
203
+ ^self new
204
+ add: firstObject;
205
+ add: secondObject;
206
+ add: thirdObject;
207
+ yourself
208
+ !
209
+
210
+ withAll: aCollection
211
+ ^self new
212
+ addAll: aCollection;
213
+ yourself
214
+ !
215
+
216
+ new: anInteger
217
+ ^self new
218
+ ! !
219
+
220
+ Collection subclass: #SequenceableCollection
221
+ instanceVariableNames: ''
222
+ category: 'Kernel-Collections'!
223
+
224
+ !SequenceableCollection methodsFor: 'accessing'!
225
+
226
+ at: anIndex
227
+ ^self at: anIndex ifAbsent: [
228
+ self errorNotFound]
229
+ !
230
+
231
+ at: anIndex ifAbsent: aBlock
232
+ self subclassResponsibility
233
+ !
234
+
235
+ at: anIndex put: anObject
236
+ self subclassResponsibility
237
+ !
238
+
239
+ first
240
+ ^self at: 1
241
+ !
242
+
243
+ fourth
244
+ ^self at: 4
245
+ !
246
+
247
+ last
248
+ ^self at: self size
249
+ !
250
+
251
+ second
252
+ ^self at: 2
253
+ !
254
+
255
+ third
256
+ ^self at: 3
257
+ !
258
+
259
+ allButFirst
260
+ ^self copyFrom: 2 to: self size
261
+ !
262
+
263
+ allButLast
264
+ ^self copyFrom: 1 to: self size - 1
265
+ !
266
+
267
+ indexOf: anObject
268
+ ^self indexOf: anObject ifAbsent: [self errorNotFound]
269
+ !
270
+
271
+ indexOf: anObject ifAbsent: aBlock
272
+ <
273
+ for(var i=0;i<self.length;i++){
274
+ if(self[i].__eq(anObject)) {return i+1}
275
+ }
276
+ return aBlock();
277
+ >
278
+ !
279
+
280
+ indexOf: anObject startingAt: start ifAbsent: aBlock
281
+ <
282
+ for(var i=start-1;i<self.length;i++){
283
+ if(self[i].__eq(anObject)) {return i+1}
284
+ }
285
+ return aBlock();
286
+ >
287
+ !
288
+
289
+ indexOf: anObject startingAt: start
290
+ "Answer the index of the first occurence of anElement after start
291
+ within the receiver. If the receiver does not contain anElement,
292
+ answer 0."
293
+ ^self indexOf: anObject startingAt: start ifAbsent: [0]
294
+ !
295
+
296
+ atRandom
297
+ ^ self at: self size atRandom
298
+ ! !
299
+
300
+ !SequenceableCollection methodsFor: 'adding'!
301
+
302
+ removeLast
303
+ self remove: self last
304
+ !
305
+
306
+ addLast: anObject
307
+ self add: anObject
308
+ ! !
309
+
310
+ !SequenceableCollection methodsFor: 'comparing'!
311
+
312
+ = aCollection
313
+ (self class = aCollection class and: [
314
+ self size = aCollection size]) ifFalse: [^false].
315
+ self withIndexDo: [:each :i |
316
+ (aCollection at: i) = each ifFalse: [^false]].
317
+ ^true
318
+ ! !
319
+
320
+ !SequenceableCollection methodsFor: 'converting'!
321
+
322
+ reversed
323
+ self subclassResponsibility
324
+ ! !
325
+
326
+ !SequenceableCollection methodsFor: 'copying'!
327
+
328
+ copyFrom: anIndex to: anotherIndex
329
+ | range newCollection |
330
+ range := anIndex to: anotherIndex.
331
+ newCollection := self class new: range size.
332
+ range do: [:each |
333
+ newCollection at: each put: (self at: each)].
334
+ ^newCollection
335
+ !
336
+
337
+ shallowCopy
338
+ | newCollection |
339
+ newCollection := self class new: self size.
340
+ self withIndexDo: [ :each :index |
341
+ newCollection at: index put: each].
342
+ ^newCollection
343
+ !
344
+
345
+ deepCopy
346
+ | newCollection |
347
+ newCollection := self class new: self size.
348
+ self withIndexDo: [:each :index |
349
+ newCollection at: index put: each deepCopy].
350
+ ^newCollection
351
+ ! !
352
+
353
+ !SequenceableCollection methodsFor: 'enumerating'!
354
+
355
+ withIndexDo: aBlock
356
+ <for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
357
+ ! !
358
+
359
+ !SequenceableCollection methodsFor: 'printing'!
360
+
361
+ printString
362
+ | str |
363
+ str := '' writeStream.
364
+ str nextPutAll: super printString, ' ('.
365
+ self
366
+ do: [:each | str nextPutAll: each printString]
367
+ separatedBy: [str nextPutAll: ' '].
368
+ str nextPutAll: ')'.
369
+ ^str contents
370
+ ! !
371
+
372
+ SequenceableCollection subclass: #CharacterArray
373
+ instanceVariableNames: ''
374
+ category: 'Kernel-Collections'!
375
+
376
+ !CharacterArray methodsFor: 'accessing'!
377
+
378
+ at: anIndex put: anObject
379
+ self errorReadOnly
380
+ ! !
381
+
382
+ !CharacterArray methodsFor: 'adding'!
383
+
384
+ add: anObject
385
+ self errorReadOnly
386
+ !
387
+
388
+ remove: anObject
389
+ self errorReadOnly
390
+ ! !
391
+
392
+ !CharacterArray methodsFor: 'converting'!
393
+
394
+ asString
395
+ ^self subclassResponsibility
396
+ !
397
+
398
+ asNumber
399
+ ^self asString asNumber
400
+ !
401
+
402
+ asUppercase
403
+ ^self class fromString: self asString asUppercase
404
+ !
405
+
406
+ asSymbol
407
+ ^self subclassResponsibility
408
+ !
409
+
410
+ asLowercase
411
+ ^self class fromString: self asString asLowercase
412
+ ! !
413
+
414
+ !CharacterArray methodsFor: 'copying'!
415
+
416
+ , aString
417
+ ^self asString, aString asString
418
+ ! !
419
+
420
+ !CharacterArray methodsFor: 'error handling'!
421
+
422
+ errorReadOnly
423
+ self error: 'Object is read-only'
424
+ ! !
425
+
426
+ !CharacterArray methodsFor: 'printing'!
427
+
428
+ printString
429
+ ^self asString printString
430
+ ! !
431
+
432
+ !CharacterArray class methodsFor: 'instance creation'!
433
+
434
+ fromString: aString
435
+ self subclassResponsibility
436
+ ! !
437
+
438
+ CharacterArray subclass: #String
439
+ instanceVariableNames: ''
440
+ category: 'Kernel-Collections'!
441
+
442
+ !String methodsFor: 'accessing'!
443
+
444
+ size
445
+ <return self.length>
446
+ !
447
+
448
+ at: anIndex ifAbsent: aBlock
449
+ <return self[anIndex - 1] || aBlock()>
450
+ !
451
+
452
+ escaped
453
+ <return escape(self)>
454
+ !
455
+
456
+ unescaped
457
+ <return unescape(self)>
458
+ !
459
+
460
+ asciiValue
461
+ <return self.charCodeAt(0);>
462
+ ! !
463
+
464
+ !String methodsFor: 'comparing'!
465
+
466
+ = aString
467
+ aString class = self class ifFalse: [^false].
468
+ <return String(self) === String(aString)>
469
+ !
470
+
471
+ > aString
472
+ <return String(self) >> aString._asString()>
473
+ !
474
+
475
+ < aString
476
+ <return String(self) < aString._asString()>
477
+ !
478
+
479
+ >= aString
480
+ <return String(self) >>= aString._asString()>
481
+ !
482
+
483
+ <= aString
484
+ <return String(self) <= aString._asString()>
485
+ ! !
486
+
487
+ !String methodsFor: 'converting'!
488
+
489
+ asSelector
490
+ "If you change this method, change smalltalk.convertSelector too (see js/boot.js file)"
491
+
492
+ | selector |
493
+ selector := '_', self.
494
+ selector := selector replace: ':' with: '_'.
495
+ selector := selector replace: '[+]' with: '_plus'.
496
+ selector := selector replace: '-' with: '_minus'.
497
+ selector := selector replace: '[*]' with: '_star'.
498
+ selector := selector replace: '[/]' with: '_slash'.
499
+ selector := selector replace: '>' with: '_gt'.
500
+ selector := selector replace: '<' with: '_lt'.
501
+ selector := selector replace: '=' with: '_eq'.
502
+ selector := selector replace: ',' with: '_comma'.
503
+ selector := selector replace: '[@]' with: '_at'.
504
+ ^selector
505
+ !
506
+
507
+ asJavascript
508
+ <
509
+ if(self.search(/^[a-zA-Z0-9_:.$ ]*$/) == -1)
510
+ return "unescape(\"" + escape(self) + "\")";
511
+ else
512
+ return "\"" + self + "\"";
513
+ >
514
+ !
515
+
516
+ tokenize: aString
517
+ <return self.split(aString)>
518
+ !
519
+
520
+ asString
521
+ ^self
522
+ !
523
+
524
+ asNumber
525
+ <return Number(self)>
526
+ !
527
+
528
+ asLowercase
529
+ <return self.toLowerCase()>
530
+ !
531
+
532
+ asUppercase
533
+ <return self.toUpperCase()>
534
+ !
535
+
536
+ reversed
537
+ <return self.split("").reverse().join("")>
538
+ !
539
+
540
+ asJavaScriptSelector
541
+ ^(self asSelector replace: '^_' with: '') replace: '_.*' with: ''.
542
+ !
543
+
544
+ asJSONString
545
+ ^self
546
+ !
547
+
548
+ asSymbol
549
+ ^Symbol lookup: self
550
+ ! !
551
+
552
+ !String methodsFor: 'copying'!
553
+
554
+ , aString
555
+ <return self + aString>
556
+ !
557
+
558
+ copyFrom: anIndex to: anotherIndex
559
+ <return self.substring(anIndex - 1, anotherIndex)>
560
+ !
561
+
562
+ shallowCopy
563
+ ^self class fromString: self
564
+ !
565
+
566
+ deepCopy
567
+ ^self shallowCopy
568
+ ! !
569
+
570
+ !String methodsFor: 'printing'!
571
+
572
+ printString
573
+ ^'''', self, ''''
574
+ !
575
+
576
+ printNl
577
+ <console.log(self)>
578
+ ! !
579
+
580
+ !String methodsFor: 'regular expressions'!
581
+
582
+ replace: aString with: anotherString
583
+ ^self replaceRegexp: (RegularExpression fromString: aString flag: 'g') with: anotherString
584
+ !
585
+
586
+ replaceRegexp: aRegexp with: aString
587
+ <return self.replace(aRegexp, aString)>
588
+ !
589
+
590
+ match: aRegexp
591
+ <return self.search(aRegexp) !!= -1>
592
+ !
593
+
594
+ trimLeft: separators
595
+
596
+ ^self replaceRegexp: (RegularExpression fromString: '^[', separators, ']+' flag: 'g') with: ''
597
+ !
598
+
599
+ trimRight: separators
600
+
601
+ ^self replaceRegexp: (RegularExpression fromString: '[', separators, ']+$' flag: 'g') with: ''
602
+ !
603
+
604
+ trimLeft
605
+ ^self trimLeft: '\s'
606
+ !
607
+
608
+ trimRight
609
+ ^self trimRight: '\s'
610
+ !
611
+
612
+ trimBoth
613
+ ^self trimBoth: '\s'
614
+ !
615
+
616
+ trimBoth: separators
617
+
618
+ ^(self trimLeft: separators) trimRight: separators
619
+ ! !
620
+
621
+ !String methodsFor: 'split join'!
622
+
623
+ join: aCollection
624
+ ^ String
625
+ streamContents: [:stream | aCollection
626
+ do: [:each | stream nextPutAll: each asString]
627
+ separatedBy: [stream nextPutAll: self]]
628
+ !
629
+
630
+ lineIndicesDo: aBlock
631
+ "execute aBlock with 3 arguments for each line:
632
+ - start index of line
633
+ - end index of line without line delimiter
634
+ - end index of line including line delimiter(s) CR, LF or CRLF"
635
+
636
+ | cr lf start sz nextLF nextCR |
637
+ start := 1.
638
+ sz := self size.
639
+ cr := String cr.
640
+ nextCR := self indexOf: cr startingAt: 1.
641
+ lf := String lf.
642
+ nextLF := self indexOf: lf startingAt: 1.
643
+ [ start <= sz ] whileTrue: [
644
+ (nextLF = 0 and: [ nextCR = 0 ])
645
+ ifTrue: [ "No more CR, nor LF, the string is over"
646
+ aBlock value: start value: sz value: sz.
647
+ ^self ].
648
+ (nextCR = 0 or: [ 0 < nextLF and: [ nextLF < nextCR ] ])
649
+ ifTrue: [ "Found a LF"
650
+ aBlock value: start value: nextLF - 1 value: nextLF.
651
+ start := 1 + nextLF.
652
+ nextLF := self indexOf: lf startingAt: start ]
653
+ ifFalse: [ 1 + nextCR = nextLF
654
+ ifTrue: [ "Found a CR-LF pair"
655
+ aBlock value: start value: nextCR - 1 value: nextLF.
656
+ start := 1 + nextLF.
657
+ nextCR := self indexOf: cr startingAt: start.
658
+ nextLF := self indexOf: lf startingAt: start ]
659
+ ifFalse: [ "Found a CR"
660
+ aBlock value: start value: nextCR - 1 value: nextCR.
661
+ start := 1 + nextCR.
662
+ nextCR := self indexOf: cr startingAt: start ]]]
663
+ !
664
+
665
+ linesDo: aBlock
666
+ "Execute aBlock with each line in this string. The terminating line
667
+ delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock"
668
+
669
+ self lineIndicesDo: [:start :endWithoutDelimiters :end |
670
+ aBlock value: (self copyFrom: start to: endWithoutDelimiters)]
671
+ !
672
+
673
+ lines
674
+ "Answer an array of lines composing this receiver without the line ending delimiters."
675
+
676
+ | lines |
677
+ lines := Array new.
678
+ self linesDo: [:aLine | lines add: aLine].
679
+ ^lines
680
+ !
681
+
682
+ lineNumber: anIndex
683
+ "Answer a string containing the characters in the given line number."
684
+
685
+ | lineCount |
686
+ lineCount := 0.
687
+ self lineIndicesDo: [:start :endWithoutDelimiters :end |
688
+ (lineCount := lineCount + 1) = anIndex ifTrue: [^self copyFrom: start to: endWithoutDelimiters]].
689
+ ^nil
690
+ ! !
691
+
692
+ !String methodsFor: 'testing'!
693
+
694
+ isString
695
+ ^true
696
+ !
697
+
698
+ includesSubString: subString
699
+ < return self.indexOf(subString) !!= -1 >
700
+ ! !
701
+
702
+ !String class methodsFor: 'accessing'!
703
+
704
+ streamClass
705
+ ^StringStream
706
+ !
707
+
708
+ cr
709
+ <return '\r'>
710
+ !
711
+
712
+ lf
713
+ <return '\n'>
714
+ !
715
+
716
+ space
717
+ <return ' '>
718
+ !
719
+
720
+ tab
721
+ <return '\t'>
722
+ !
723
+
724
+ crlf
725
+ <return '\r\n'>
726
+ ! !
727
+
728
+ !String class methodsFor: 'instance creation'!
729
+
730
+ fromString: aString
731
+ <return new self.fn(aString)>
732
+ !
733
+
734
+ streamContents: blockWithArg
735
+ |stream|
736
+ stream := (self streamClass on: String new).
737
+ blockWithArg value: stream.
738
+ ^ stream contents
739
+ !
740
+
741
+ value: aUTFCharCode
742
+
743
+ <return String.fromCharCode(aUTFCharCode);>
744
+ ! !
745
+
746
+ CharacterArray subclass: #Symbol
747
+ instanceVariableNames: ''
748
+ category: 'Kernel-Collections'!
749
+
750
+ !Symbol methodsFor: 'accessing'!
751
+
752
+ at: anIndex ifAbsent: aBlock
753
+ ^self asString at: anIndex ifAbsent: aBlock
754
+ !
755
+
756
+ size
757
+ ^self asString size
758
+ ! !
759
+
760
+ !Symbol methodsFor: 'comparing'!
761
+
762
+ < aSymbol
763
+ ^self asString < aSymbol asString
764
+ !
765
+
766
+ <= aSymbol
767
+ ^self asString <= aSymbol asString
768
+ !
769
+
770
+ >= aSymbol
771
+ ^self asString >= aSymbol asString
772
+ !
773
+
774
+ = aSymbol
775
+ aSymbol class = self class ifFalse: [^false].
776
+ ^self asString = aSymbol asString
777
+ !
778
+
779
+ > aSymbol
780
+ ^self asString > aSymbol asString
781
+ ! !
782
+
783
+ !Symbol methodsFor: 'converting'!
784
+
785
+ asString
786
+ <return self.value>
787
+ !
788
+
789
+ asSymbol
790
+ ^self
791
+ !
792
+
793
+ asJavascript
794
+ ^'smalltalk.symbolFor("', self asString, '")'
795
+ !
796
+
797
+ asSelector
798
+ ^self asString asSelector
799
+ ! !
800
+
801
+ !Symbol methodsFor: 'copying'!
802
+
803
+ copyFrom: anIndex to: anotherIndex
804
+ ^self class fromString: (self asString copyFrom: anIndex to: anotherIndex)
805
+ !
806
+
807
+ deepCopy
808
+ ^self
809
+ !
810
+
811
+ shallowCopy
812
+ ^self
813
+ ! !
814
+
815
+ !Symbol methodsFor: 'printing'!
816
+
817
+ printString
818
+ ^'#', self asString
819
+ !
820
+
821
+ isSymbol
822
+ ^true
823
+ ! !
824
+
825
+ !Symbol class methodsFor: 'instance creation'!
826
+
827
+ lookup: aString
828
+ <return smalltalk.symbolFor(aString);>
829
+ !
830
+
831
+ basicNew
832
+ self shouldNotImplement
833
+ !
834
+
835
+ fromString: aString
836
+ ^self lookup: aString
837
+ ! !
838
+
839
+ SequenceableCollection subclass: #Array
840
+ instanceVariableNames: ''
841
+ category: 'Kernel-Collections'!
842
+
843
+ !Array methodsFor: 'accessing'!
844
+
845
+ size
846
+ <return self.length>
847
+ !
848
+
849
+ at: anIndex put: anObject
850
+ <return self[anIndex - 1] = anObject>
851
+ !
852
+
853
+ at: anIndex ifAbsent: aBlock
854
+ <
855
+ var value = self[anIndex - 1];
856
+ if(value === undefined) {
857
+ return aBlock();
858
+ } else {
859
+ return value;
860
+ }
861
+ >
862
+ ! !
863
+
864
+ !Array methodsFor: 'adding/removing'!
865
+
866
+ add: anObject
867
+ <self.push(anObject); return anObject;>
868
+ !
869
+
870
+ remove: anObject
871
+ <
872
+ for(var i=0;i<self.length;i++) {
873
+ if(self[i] == anObject) {
874
+ self.splice(i,1);
875
+ break;
876
+ }
877
+ }
878
+ >
879
+ !
880
+
881
+ removeFrom: aNumber to: anotherNumber
882
+ <self.splice(aNumber - 1,anotherNumber - 1)>
883
+ ! !
884
+
885
+ !Array methodsFor: 'converting'!
886
+
887
+ asJavascript
888
+ ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
889
+ !
890
+
891
+ reversed
892
+ <return self._copy().reverse()>
893
+ ! !
894
+
895
+ !Array methodsFor: 'enumerating'!
896
+
897
+ join: aString
898
+ <return self.join(aString)>
899
+ !
900
+
901
+ sort
902
+ ^self basicPerform: 'sort'
903
+ !
904
+
905
+ sort: aBlock
906
+ <
907
+ return self.sort(function(a, b) {
908
+ if(aBlock(a,b)) {return -1} else {return 1}
909
+ })
910
+ >
911
+ !
912
+
913
+ sorted
914
+ ^self copy sort
915
+ !
916
+
917
+ sorted: aBlock
918
+ ^self copy sort: aBlock
919
+ ! !
920
+
921
+ !Array class methodsFor: 'instance creation'!
922
+
923
+ new: anInteger
924
+ <return new Array(anInteger)>
925
+ !
926
+
927
+ with: anObject
928
+ ^(self new: 1)
929
+ at: 1 put: anObject;
930
+ yourself
931
+ !
932
+
933
+ with: anObject with: anObject2
934
+ ^(self new: 2)
935
+ at: 1 put: anObject;
936
+ at: 2 put: anObject2;
937
+ yourself
938
+ !
939
+
940
+ with: anObject with: anObject2 with: anObject3
941
+ ^(self new: 3)
942
+ at: 1 put: anObject;
943
+ at: 2 put: anObject2;
944
+ at: 3 put: anObject3;
945
+ yourself
946
+ !
947
+
948
+ withAll: aCollection
949
+ | instance |
950
+ instance := self new: aCollection size.
951
+ aCollection withIndexDo: [:index :each |
952
+ instance at: index put: each].
953
+ ^instance
954
+ ! !
955
+
956
+ Object subclass: #RegularExpression
957
+ instanceVariableNames: ''
958
+ category: 'Kernel-Collections'!
959
+
960
+ !RegularExpression methodsFor: 'evaluating'!
961
+
962
+ compile: aString
963
+ <return self.compile(aString)>
964
+ !
965
+
966
+ exec: aString
967
+ <return self.exec(aString) || nil>
968
+ !
969
+
970
+ test: aString
971
+ <return self.test(aString)>
972
+ ! !
973
+
974
+ !RegularExpression class methodsFor: 'instance creation'!
975
+
976
+ fromString: aString flag: anotherString
977
+ <return new RegExp(aString, anotherString)>
978
+ !
979
+
980
+ fromString: aString
981
+ ^self fromString: aString flag: ''
982
+ ! !
983
+
984
+ Object subclass: #Association
985
+ instanceVariableNames: 'key value'
986
+ category: 'Kernel-Collections'!
987
+
988
+ !Association methodsFor: 'accessing'!
989
+
990
+ key: aKey
991
+ key := aKey
992
+ !
993
+
994
+ key
995
+ ^key
996
+ !
997
+
998
+ value: aValue
999
+ value := aValue
1000
+ !
1001
+
1002
+ value
1003
+ ^value
1004
+ ! !
1005
+
1006
+ !Association methodsFor: 'comparing'!
1007
+
1008
+ = anAssociation
1009
+ ^self class = anAssociation class and: [
1010
+ self key = anAssociation key and: [
1011
+ self value = anAssociation value]]
1012
+ !
1013
+
1014
+ storeOn: aStream
1015
+ "Store in the format (key->value)"
1016
+
1017
+ "aStream nextPutAll: '('."
1018
+ key storeOn: aStream.
1019
+ aStream nextPutAll: '->'.
1020
+ value storeOn: aStream.
1021
+ "aStream nextPutAll: ')'"
1022
+ ! !
1023
+
1024
+ !Association class methodsFor: 'instance creation'!
1025
+
1026
+ key: aKey value: aValue
1027
+ ^self new
1028
+ key: aKey;
1029
+ value: aValue;
1030
+ yourself
1031
+ ! !
1032
+
1033
+ Object subclass: #Stream
1034
+ instanceVariableNames: 'collection position streamSize'
1035
+ category: 'Kernel-Collections'!
1036
+
1037
+ !Stream methodsFor: 'accessing'!
1038
+
1039
+ collection
1040
+ ^collection
1041
+ !
1042
+
1043
+ setCollection: aCollection
1044
+ collection := aCollection
1045
+ !
1046
+
1047
+ position
1048
+ ^position ifNil: [position := 0]
1049
+ !
1050
+
1051
+ position: anInteger
1052
+ position := anInteger
1053
+ !
1054
+
1055
+ streamSize
1056
+ ^streamSize
1057
+ !
1058
+
1059
+ setStreamSize: anInteger
1060
+ streamSize := anInteger
1061
+ !
1062
+
1063
+ contents
1064
+ ^self collection
1065
+ copyFrom: 1
1066
+ to: self streamSize
1067
+ !
1068
+
1069
+ size
1070
+ ^self streamSize
1071
+ ! !
1072
+
1073
+ !Stream methodsFor: 'actions'!
1074
+
1075
+ reset
1076
+ self position: 0
1077
+ !
1078
+
1079
+ close
1080
+ !
1081
+
1082
+ flush
1083
+ !
1084
+
1085
+ resetContents
1086
+ self reset.
1087
+ self setStreamSize: 0
1088
+ ! !
1089
+
1090
+ !Stream methodsFor: 'enumerating'!
1091
+
1092
+ do: aBlock
1093
+ [self atEnd] whileFalse: [aBlock value: self next]
1094
+ ! !
1095
+
1096
+ !Stream methodsFor: 'positioning'!
1097
+
1098
+ setToEnd
1099
+ self position: self size
1100
+ !
1101
+
1102
+ skip: anInteger
1103
+ self position: ((self position + anInteger) min: self size max: 0)
1104
+ ! !
1105
+
1106
+ !Stream methodsFor: 'reading'!
1107
+
1108
+ next
1109
+ ^self atEnd
1110
+ ifTrue: [nil]
1111
+ ifFalse: [
1112
+ self position: self position + 1.
1113
+ collection at: self position]
1114
+ !
1115
+
1116
+ next: anInteger
1117
+ | tempCollection |
1118
+ tempCollection := self collection class new.
1119
+ anInteger timesRepeat: [
1120
+ self atEnd ifFalse: [
1121
+ tempCollection add: self next]].
1122
+ ^tempCollection
1123
+ !
1124
+
1125
+ peek
1126
+ ^self atEnd ifFalse: [
1127
+ self collection at: self position + 1]
1128
+ ! !
1129
+
1130
+ !Stream methodsFor: 'testing'!
1131
+
1132
+ atEnd
1133
+ ^self position = self size
1134
+ !
1135
+
1136
+ atStart
1137
+ ^self position = 0
1138
+ !
1139
+
1140
+ isEmpty
1141
+ ^self size = 0
1142
+ ! !
1143
+
1144
+ !Stream methodsFor: 'writing'!
1145
+
1146
+ nextPut: anObject
1147
+ self position: self position + 1.
1148
+ self collection at: self position put: anObject.
1149
+ self setStreamSize: (self streamSize max: self position)
1150
+ !
1151
+
1152
+ nextPutAll: aCollection
1153
+ aCollection do: [:each |
1154
+ self nextPut: each]
1155
+ ! !
1156
+
1157
+ !Stream class methodsFor: 'instance creation'!
1158
+
1159
+ on: aCollection
1160
+ ^self new
1161
+ setCollection: aCollection;
1162
+ setStreamSize: aCollection size;
1163
+ yourself
1164
+ ! !
1165
+
1166
+ Stream subclass: #StringStream
1167
+ instanceVariableNames: ''
1168
+ category: 'Kernel-Collections'!
1169
+
1170
+ !StringStream methodsFor: 'reading'!
1171
+
1172
+ next: anInteger
1173
+ | tempCollection |
1174
+ tempCollection := self collection class new.
1175
+ anInteger timesRepeat: [
1176
+ self atEnd ifFalse: [
1177
+ tempCollection := tempCollection, self next]].
1178
+ ^tempCollection
1179
+ ! !
1180
+
1181
+ !StringStream methodsFor: 'writing'!
1182
+
1183
+ nextPut: aString
1184
+ self nextPutAll: aString
1185
+ !
1186
+
1187
+ nextPutAll: aString
1188
+ self setCollection:
1189
+ (self collection copyFrom: 1 to: self position),
1190
+ aString,
1191
+ (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
1192
+ self position: self position + aString size.
1193
+ self setStreamSize: (self streamSize max: self position)
1194
+ !
1195
+
1196
+ cr
1197
+ ^self nextPutAll: String cr
1198
+ !
1199
+
1200
+ crlf
1201
+ ^self nextPutAll: String crlf
1202
+ !
1203
+
1204
+ lf
1205
+ ^self nextPutAll: String lf
1206
+ !
1207
+
1208
+ space
1209
+ self nextPut: ' '
1210
+ ! !
1211
+
1212
+ Collection subclass: #Set
1213
+ instanceVariableNames: 'elements'
1214
+ category: 'Kernel-Collections'!
1215
+
1216
+ !Set methodsFor: 'accessing'!
1217
+
1218
+ size
1219
+ ^elements size
1220
+ ! !
1221
+
1222
+ !Set methodsFor: 'adding/removing'!
1223
+
1224
+ add: anObject
1225
+ <
1226
+ var found;
1227
+ for(var i in self['@elements']) {
1228
+ if(anObject == self['@elements'][i]) {
1229
+ found = true;
1230
+ break;
1231
+ }
1232
+ }
1233
+ if(!!found) {self['@elements'].push(anObject)}
1234
+ >
1235
+ !
1236
+
1237
+ remove: anObject
1238
+ elements remove: anObject
1239
+ ! !
1240
+
1241
+ !Set methodsFor: 'comparing'!
1242
+
1243
+ = aCollection
1244
+ ^self class = aCollection class and: [
1245
+ elements = aCollection asArray]
1246
+ ! !
1247
+
1248
+ !Set methodsFor: 'converting'!
1249
+
1250
+ asArray
1251
+ ^elements copy
1252
+ ! !
1253
+
1254
+ !Set methodsFor: 'enumerating'!
1255
+
1256
+ detect: aBlock ifNone: anotherBlock
1257
+ ^elements detect: aBlock ifNone: anotherBlock
1258
+ !
1259
+
1260
+ do: aBlock
1261
+ elements do: aBlock
1262
+ !
1263
+
1264
+ select: aBlock
1265
+ | collection |
1266
+ collection := self class new.
1267
+ self do: [:each |
1268
+ (aBlock value: each) ifTrue: [
1269
+ collection add: each]].
1270
+ ^collection
1271
+ ! !
1272
+
1273
+ !Set methodsFor: 'initialization'!
1274
+
1275
+ initialize
1276
+ super initialize.
1277
+ elements := #()
1278
+ ! !
1279
+
1280
+ !Set methodsFor: 'testing'!
1281
+
1282
+ includes: anObject
1283
+ ^elements includes: anObject
1284
+ ! !
1285
+
1286
+ Collection subclass: #HashedCollection
1287
+ instanceVariableNames: ''
1288
+ category: 'Kernel-Collections'!
1289
+ !HashedCollection commentStamp!
1290
+ A HashedCollection is a traditional JavaScript object, or a Smalltalk Dictionary.
1291
+
1292
+ Unlike a Dictionary, it can only have strings as keys.!
1293
+
1294
+ !HashedCollection methodsFor: 'accessing'!
1295
+
1296
+ size
1297
+ ^self keys size
1298
+ !
1299
+
1300
+ associations
1301
+ | associations |
1302
+ associations := #().
1303
+ self keys do: [:each |
1304
+ associations add: (Association key: each value: (self at: each))].
1305
+ ^associations
1306
+ !
1307
+
1308
+ keys
1309
+ <
1310
+ var keys = [];
1311
+ for(var i in self) {
1312
+ if(self.hasOwnProperty(i)) {
1313
+ keys.push(i);
1314
+ }
1315
+ };
1316
+ return keys;
1317
+ >
1318
+ !
1319
+
1320
+ values
1321
+ ^self keys collect: [:each | self at: each]
1322
+ !
1323
+
1324
+ at: aKey put: aValue
1325
+ ^self basicAt: aKey put: aValue
1326
+ !
1327
+
1328
+ at: aKey ifAbsent: aBlock
1329
+ ^(self includesKey: aKey)
1330
+ ifTrue: [self basicAt: aKey]
1331
+ ifFalse: aBlock
1332
+ !
1333
+
1334
+ at: aKey ifAbsentPut: aBlock
1335
+ ^self at: aKey ifAbsent: [
1336
+ self at: aKey put: aBlock value]
1337
+ !
1338
+
1339
+ at: aKey ifPresent: aBlock
1340
+ ^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
1341
+ !
1342
+
1343
+ at: aKey ifPresent: aBlock ifAbsent: anotherBlock
1344
+ ^(self basicAt: aKey)
1345
+ ifNil: anotherBlock
1346
+ ifNotNil: [aBlock value: (self at: aKey)]
1347
+ !
1348
+
1349
+ at: aKey
1350
+ ^self at: aKey ifAbsent: [self errorNotFound]
1351
+ ! !
1352
+
1353
+ !HashedCollection methodsFor: 'adding/removing'!
1354
+
1355
+ add: anAssociation
1356
+ self at: anAssociation key put: anAssociation value
1357
+ !
1358
+
1359
+ addAll: aHashedCollection
1360
+ super addAll: aHashedCollection associations.
1361
+ ^aHashedCollection
1362
+ !
1363
+
1364
+ removeKey: aKey
1365
+ self remove: aKey
1366
+ !
1367
+
1368
+ remove: aKey ifAbsent: aBlock
1369
+ ^self removeKey: aKey ifAbsent: aBlock
1370
+ !
1371
+
1372
+ removeKey: aKey ifAbsent: aBlock
1373
+ ^(self includesKey: aKey)
1374
+ ifFalse: [aBlock value]
1375
+ ifTrue: [self basicDelete: aKey]
1376
+ ! !
1377
+
1378
+ !HashedCollection methodsFor: 'comparing'!
1379
+
1380
+ = aHashedCollection
1381
+ self class = aHashedCollection class ifFalse: [^false].
1382
+ self size = aHashedCollection size ifFalse: [^false].
1383
+ ^self associations = aHashedCollection associations
1384
+ ! !
1385
+
1386
+ !HashedCollection methodsFor: 'converting'!
1387
+
1388
+ asDictionary
1389
+ ^Dictionary fromPairs: self associations
1390
+ ! !
1391
+
1392
+ !HashedCollection methodsFor: 'copying'!
1393
+
1394
+ shallowCopy
1395
+ | copy |
1396
+ copy := self class new.
1397
+ self associationsDo: [:each |
1398
+ copy at: each key put: each value].
1399
+ ^copy
1400
+ !
1401
+
1402
+ , aCollection
1403
+ self shouldNotImplement
1404
+ !
1405
+
1406
+ copyFrom: anIndex to: anotherIndex
1407
+ self shouldNotImplement
1408
+ !
1409
+
1410
+ deepCopy
1411
+ | copy |
1412
+ copy := self class new.
1413
+ self associationsDo: [:each |
1414
+ copy at: each key put: each value deepCopy].
1415
+ ^copy
1416
+ ! !
1417
+
1418
+ !HashedCollection methodsFor: 'enumerating'!
1419
+
1420
+ associationsDo: aBlock
1421
+ self associations do: aBlock
1422
+ !
1423
+
1424
+ keysAndValuesDo: aBlock
1425
+ self associationsDo: [:each |
1426
+ aBlock value: each key value: each value]
1427
+ !
1428
+
1429
+ do: aBlock
1430
+ self values do: aBlock
1431
+ !
1432
+
1433
+ select: aBlock
1434
+ | newDict |
1435
+ newDict := self class new.
1436
+ self keysAndValuesDo: [:key :value |
1437
+ (aBlock value: value) ifTrue: [newDict at: key put: value]].
1438
+ ^newDict
1439
+ !
1440
+
1441
+ collect: aBlock
1442
+ | newDict |
1443
+ newDict := self class new.
1444
+ self keysAndValuesDo: [:key :value |
1445
+ newDict at: key put: (aBlock value: value)].
1446
+ ^newDict
1447
+ !
1448
+
1449
+ detect: aBlock ifNone: anotherBlock
1450
+ ^self values detect: aBlock ifNone: anotherBlock
1451
+ !
1452
+
1453
+ includes: anObject
1454
+ ^self values includes: anObject
1455
+ ! !
1456
+
1457
+ !HashedCollection methodsFor: 'printing'!
1458
+
1459
+ printString
1460
+ ^String streamContents: [:aStream|
1461
+ aStream
1462
+ nextPutAll: super printString;
1463
+ nextPutAll: '('.
1464
+ self associations
1465
+ do: [:anAssociation|
1466
+ aStream
1467
+ nextPutAll: anAssociation key printString;
1468
+ nextPutAll: ' -> ';
1469
+ nextPutAll: anAssociation value printString]
1470
+ separatedBy: [aStream nextPutAll: ' , '].
1471
+ aStream nextPutAll: ')']
1472
+ !
1473
+
1474
+ storeOn: aStream
1475
+ aStream nextPutAll: '#{'.
1476
+ self associations
1477
+ do: [:each | each storeOn: aStream]
1478
+ separatedBy: [ aStream nextPutAll: '. '].
1479
+ aStream nextPutAll: '}'
1480
+ ! !
1481
+
1482
+ !HashedCollection methodsFor: 'testing'!
1483
+
1484
+ includesKey: aKey
1485
+ <return self.hasOwnProperty(aKey)>
1486
+ ! !
1487
+
1488
+ !HashedCollection class methodsFor: 'instance creation'!
1489
+
1490
+ fromPairs: aCollection
1491
+ | dict |
1492
+ dict := self new.
1493
+ aCollection do: [:each | dict add: each].
1494
+ ^dict
1495
+ ! !
1496
+
1497
+ HashedCollection subclass: #Dictionary
1498
+ instanceVariableNames: 'keys values'
1499
+ category: 'Kernel-Collections'!
1500
+
1501
+ !Dictionary methodsFor: 'accessing'!
1502
+
1503
+ at: aKey ifAbsent: aBlock
1504
+ <
1505
+ var index;
1506
+ for(var i=0;i<self['@keys'].length;i++){
1507
+ if(self['@keys'][i].__eq(aKey)) {index = i;}
1508
+ };
1509
+ if(typeof index === 'undefined') {
1510
+ return aBlock();
1511
+ } else {
1512
+ return self['@values'][index];
1513
+ }
1514
+ >
1515
+ !
1516
+
1517
+ keys
1518
+ ^keys copy
1519
+ !
1520
+
1521
+ values
1522
+ ^values copy
1523
+ !
1524
+
1525
+ at: aKey put: aValue
1526
+ <
1527
+ var index = self['@keys'].indexOf(aKey);
1528
+ if(index === -1) {
1529
+ self['@values'].push(aValue);
1530
+ self['@keys'].push(aKey);
1531
+ } else {
1532
+ self['@values'][index] = aValue;
1533
+ };
1534
+
1535
+ return aValue;
1536
+ >
1537
+ ! !
1538
+
1539
+ !Dictionary methodsFor: 'adding/removing'!
1540
+
1541
+ removeKey: aKey ifAbsent: aBlock
1542
+ <
1543
+ var index = self['@keys'].indexOf(aKey);
1544
+ if(index === -1) {
1545
+ return aBlock()
1546
+ } else {
1547
+ self['@keys'].splice(i, 1);
1548
+ self['@values'].splice(i, 1);
1549
+ return aKey
1550
+ };
1551
+ >
1552
+ ! !
1553
+
1554
+ !Dictionary methodsFor: 'converting'!
1555
+
1556
+ asHashedCollection
1557
+ ^HashedCollection fromPairs: self associations
1558
+ !
1559
+
1560
+ asJSONString
1561
+ ^self asHashedCollection asJSONString
1562
+ ! !
1563
+
1564
+ !Dictionary methodsFor: 'initialization'!
1565
+
1566
+ initialize
1567
+ super initialize.
1568
+ keys := #().
1569
+ values := #()
1570
+ ! !
1571
+
1572
+ !Dictionary methodsFor: 'testing'!
1573
+
1574
+ includesKey: aKey
1575
+ ^keys includes: aKey
1576
+ ! !
1577
+
1578
+ SequenceableCollection subclass: #OrderedCollection
1579
+ instanceVariableNames: 'elements'
1580
+ category: 'Kernel-Collections'!
1581
+
1582
+ !OrderedCollection methodsFor: 'accessing'!
1583
+
1584
+ size
1585
+ ^elements size
1586
+ !
1587
+
1588
+ at: anIndex put: anObject
1589
+ <return self['@elements'][anIndex - 1] = anObject>
1590
+ !
1591
+
1592
+ at: anIndex ifAbsent: aBlock
1593
+ ^elements at: anIndex ifAbsent: aBlock
1594
+ ! !
1595
+
1596
+ !OrderedCollection methodsFor: 'adding/removing'!
1597
+
1598
+ add: anObject
1599
+ <self['@elements'].push(anObject); return anObject;>
1600
+ !
1601
+
1602
+ remove: anObject
1603
+ <
1604
+ for(var i=0;i<self['@elements'].length;i++) {
1605
+ if(self['@elements'][i] == anObject) {
1606
+ self['@elements'].splice(i,1);
1607
+ break;
1608
+ }
1609
+ }
1610
+ >
1611
+ !
1612
+
1613
+ removeFrom: aNumber to: anotherNumber
1614
+ <self['@elements'].splice(aNumber - 1,anotherNumber - 1)>
1615
+ ! !
1616
+
1617
+ !OrderedCollection methodsFor: 'converting'!
1618
+
1619
+ reversed
1620
+ ^self asArray reversed asOrderedCollection
1621
+ !
1622
+
1623
+ asOrderedCollection
1624
+ ^self
1625
+ !
1626
+
1627
+ asArray
1628
+ ^elements copy
1629
+ ! !
1630
+
1631
+ !OrderedCollection methodsFor: 'enumerating'!
1632
+
1633
+ join: aString
1634
+ ^elements join: aString
1635
+ !
1636
+
1637
+ sort
1638
+ elements sort.
1639
+ ^self
1640
+ !
1641
+
1642
+ sort: aBlock
1643
+ elements sort: aBlock.
1644
+ ^self
1645
+ !
1646
+
1647
+ sorted
1648
+ ^self copy sort
1649
+ !
1650
+
1651
+ sorted: aBlock
1652
+ ^self copy sort: aBlock
1653
+ !
1654
+
1655
+ withIndexDo: aBlock
1656
+ elements withIndexDo: aBlock
1657
+ !
1658
+
1659
+ detect: aBlock ifNone: anotherBlock
1660
+ ^elements detect: aBlock ifNone: anotherBlock
1661
+ !
1662
+
1663
+ do: aBlock
1664
+ elements do: aBlock
1665
+ ! !
1666
+
1667
+ !OrderedCollection methodsFor: 'initialization'!
1668
+
1669
+ initialize
1670
+ super initialize.
1671
+ elements := #()
1672
+ ! !
1673
+