1
0

Kernel-Collections.st 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. Smalltalk current createPackage: 'Kernel-Collections' properties: #{}!
  2. Object subclass: #Association
  3. instanceVariableNames: 'key value'
  4. package: 'Kernel-Collections'!
  5. !Association methodsFor: 'accessing'!
  6. key
  7. ^key
  8. !
  9. key: aKey
  10. key := aKey
  11. !
  12. value
  13. ^value
  14. !
  15. value: aValue
  16. value := aValue
  17. ! !
  18. !Association methodsFor: 'comparing'!
  19. = anAssociation
  20. ^self class = anAssociation class and: [
  21. self key = anAssociation key and: [
  22. self value = anAssociation value]]
  23. ! !
  24. !Association methodsFor: 'printing'!
  25. printString
  26. "print the contents of the Association into a string and return the string"
  27. ^String streamContents: [:aStream |
  28. self storeOn: aStream]
  29. !
  30. storeOn: aStream
  31. "Store in the format: key->value"
  32. key storeOn: aStream.
  33. aStream nextPutAll: '->'.
  34. value storeOn: aStream.
  35. ! !
  36. !Association class methodsFor: 'instance creation'!
  37. key: aKey value: aValue
  38. ^self new
  39. key: aKey;
  40. value: aValue;
  41. yourself
  42. ! !
  43. Object subclass: #Collection
  44. instanceVariableNames: ''
  45. package: 'Kernel-Collections'!
  46. !Collection methodsFor: 'accessing'!
  47. occurrencesOf: anObject
  48. "Answer how many of the receiver's elements are equal to anObject."
  49. | tally |
  50. tally := 0.
  51. self do: [:each | anObject = each ifTrue: [tally := tally + 1]].
  52. ^tally
  53. !
  54. readStream
  55. ^self stream
  56. !
  57. size
  58. self subclassResponsibility
  59. !
  60. stream
  61. ^self streamClass on: self
  62. !
  63. streamClass
  64. ^self class streamClass
  65. !
  66. writeStream
  67. ^self stream
  68. ! !
  69. !Collection methodsFor: 'adding/removing'!
  70. add: anObject
  71. self subclassResponsibility
  72. !
  73. addAll: aCollection
  74. aCollection do: [:each |
  75. self add: each].
  76. ^aCollection
  77. !
  78. remove: anObject
  79. ^self remove: anObject ifAbsent: [self errorNotFound]
  80. !
  81. remove: anObject ifAbsent: aBlock
  82. self subclassResponsibility
  83. ! !
  84. !Collection methodsFor: 'converting'!
  85. asArray
  86. ^Array withAll: self
  87. !
  88. asJSON
  89. ^self asArray collect: [:each | each asJSON]
  90. !
  91. asOrderedCollection
  92. ^self asArray
  93. !
  94. asSet
  95. ^Set withAll: self
  96. ! !
  97. !Collection methodsFor: 'copying'!
  98. , aCollection
  99. ^self copy
  100. addAll: aCollection;
  101. yourself
  102. !
  103. copyWith: anObject
  104. ^self copy add: anObject; yourself
  105. !
  106. copyWithAll: aCollection
  107. ^self copy addAll: aCollection; yourself
  108. !
  109. copyWithoutAll: aCollection
  110. "Answer a copy of the receiver that does not contain any elements
  111. equal to those in aCollection."
  112. ^ self reject: [:each | aCollection includes: each]
  113. ! !
  114. !Collection methodsFor: 'enumerating'!
  115. collect: aBlock
  116. | stream |
  117. stream := self class new writeStream.
  118. self do: [ :each |
  119. stream nextPut: (aBlock value: each) ].
  120. ^stream contents
  121. !
  122. detect: aBlock
  123. ^self detect: aBlock ifNone: [self errorNotFound]
  124. !
  125. detect: aBlock ifNone: anotherBlock
  126. self subclassResponsibility
  127. !
  128. do: aBlock
  129. self subclassResponsibility
  130. !
  131. do: aBlock separatedBy: anotherBlock
  132. | actionBeforeElement |
  133. actionBeforeElement := [actionBeforeElement := anotherBlock].
  134. self do: [:each |
  135. actionBeforeElement value.
  136. aBlock value: each]
  137. !
  138. inject: anObject into: aBlock
  139. | result |
  140. result := anObject.
  141. self do: [:each |
  142. result := aBlock value: result value: each].
  143. ^result
  144. !
  145. intersection: aCollection
  146. "Answer the set theoretic intersection of two collections."
  147. | set outputSet |
  148. set := self asSet.
  149. outputSet := Set new.
  150. aCollection do: [ :each |
  151. ((set includes: each) and: [(outputSet includes: each) not])
  152. ifTrue: [
  153. outputSet add: each]].
  154. ^ self class withAll: outputSet asArray
  155. !
  156. reject: aBlock
  157. ^self select: [:each | (aBlock value: each) = false]
  158. !
  159. select: aBlock
  160. | stream |
  161. stream := self class new writeStream.
  162. self do: [:each |
  163. (aBlock value: each) ifTrue: [
  164. stream nextPut: each]].
  165. ^stream contents
  166. ! !
  167. !Collection methodsFor: 'error handling'!
  168. errorNotFound
  169. self error: 'Object is not in the collection'
  170. ! !
  171. !Collection methodsFor: 'printing'!
  172. printString
  173. "print the contents of the Collection into a string and return it"
  174. ^String streamContents: [:aStream |
  175. aStream
  176. nextPutAll: super printString, ' ('.
  177. self do: [:each | aStream nextPutAll: each printString]
  178. separatedBy: [aStream nextPutAll: ' '].
  179. aStream nextPutAll: ')']
  180. ! !
  181. !Collection methodsFor: 'testing'!
  182. ifEmpty: aBlock
  183. "Evaluate the given block with the receiver as argument, answering its value if the receiver is empty, otherwise answer the receiver. Note that the fact that this method returns its argument in case the receiver is not empty allows one to write expressions like the following ones: self classifyMethodAs:
  184. (myProtocol ifEmpty: ['As yet unclassified'])"
  185. ^ self isEmpty
  186. ifTrue: [ aBlock value ]
  187. ifFalse: [ self ]
  188. !
  189. ifNotEmpty: aBlock
  190. self notEmpty ifTrue: aBlock.
  191. !
  192. includes: anObject
  193. | sentinel |
  194. sentinel := Object new.
  195. ^(self detect: [ :each | each = anObject] ifNone: [ sentinel ]) ~= sentinel
  196. !
  197. isEmpty
  198. ^self size = 0
  199. !
  200. notEmpty
  201. ^self isEmpty not
  202. ! !
  203. !Collection class methodsFor: 'accessing'!
  204. streamClass
  205. ^Stream
  206. ! !
  207. !Collection class methodsFor: 'instance creation'!
  208. new: anInteger
  209. ^self new
  210. !
  211. with: anObject
  212. ^self new
  213. add: anObject;
  214. yourself
  215. !
  216. with: anObject with: anotherObject
  217. ^self new
  218. add: anObject;
  219. add: anotherObject;
  220. yourself
  221. !
  222. with: firstObject with: secondObject with: thirdObject
  223. ^self new
  224. add: firstObject;
  225. add: secondObject;
  226. add: thirdObject;
  227. yourself
  228. !
  229. withAll: aCollection
  230. ^self new
  231. addAll: aCollection;
  232. yourself
  233. ! !
  234. Collection subclass: #IndexableCollection
  235. instanceVariableNames: ''
  236. package: 'Kernel-Collections'!
  237. !IndexableCollection commentStamp!
  238. An IndexableCollection is a key-value store, that is,
  239. it stores values under indexes.
  240. As a rule of thumb, if a collection has at: and at:put:,
  241. it is an IndexableCollection.!
  242. IndexableCollection subclass: #HashedCollection
  243. instanceVariableNames: ''
  244. package: 'Kernel-Collections'!
  245. !HashedCollection commentStamp!
  246. A HashedCollection is a traditional JavaScript object, or a Smalltalk Dictionary.
  247. Unlike a Dictionary, it can only have strings as keys.!
  248. !HashedCollection methodsFor: 'accessing'!
  249. associations
  250. | associations |
  251. associations := #().
  252. self associationsDo: [:each | associations add: each].
  253. ^associations
  254. !
  255. at: aKey
  256. ^self at: aKey ifAbsent: [self errorNotFound]
  257. !
  258. at: aKey ifAbsent: aBlock
  259. ^(self includesKey: aKey)
  260. ifTrue: [self basicAt: aKey]
  261. ifFalse: aBlock
  262. !
  263. at: aKey ifAbsentPut: aBlock
  264. ^self at: aKey ifAbsent: [
  265. self at: aKey put: aBlock value]
  266. !
  267. at: aKey ifPresent: aBlock
  268. "Lookup the given key in the receiver.
  269. If it is present, answer the value of evaluating the given block with the value associated with the key.
  270. Otherwise, answer nil."
  271. ^(self includesKey: aKey)
  272. ifTrue: [ aBlock value: (self at: aKey) ]
  273. ifFalse: [ nil ]
  274. !
  275. at: aKey ifPresent: aBlock ifAbsent: anotherBlock
  276. "Lookup the given key in the receiver.
  277. If it is present, answer the value of evaluating the oneArgBlock with the value associated with the key,
  278. otherwise answer the value of absentBlock."
  279. ^(self includesKey: aKey)
  280. ifTrue: [ aBlock value: (self at: aKey) ]
  281. ifFalse: anotherBlock
  282. !
  283. at: aKey put: aValue
  284. ^self basicAt: aKey put: aValue
  285. !
  286. keys
  287. <
  288. if ('function'===typeof Object.keys) return Object.keys(self);
  289. var keys = [];
  290. for(var i in self) {
  291. if(self.hasOwnProperty(i)) {
  292. keys.push(i);
  293. }
  294. };
  295. return keys;
  296. >
  297. !
  298. size
  299. ^self keys size
  300. !
  301. values
  302. ^self keys collect: [:each | self at: each]
  303. ! !
  304. !HashedCollection methodsFor: 'adding/removing'!
  305. add: anAssociation
  306. self at: anAssociation key put: anAssociation value
  307. !
  308. addAll: aHashedCollection
  309. super addAll: aHashedCollection associations.
  310. ^aHashedCollection
  311. !
  312. remove: aKey ifAbsent: aBlock
  313. ^self removeKey: aKey ifAbsent: aBlock
  314. !
  315. removeKey: aKey
  316. ^self remove: aKey
  317. !
  318. removeKey: aKey ifAbsent: aBlock
  319. ^(self includesKey: aKey)
  320. ifFalse: [aBlock value]
  321. ifTrue: [self basicDelete: aKey]
  322. ! !
  323. !HashedCollection methodsFor: 'comparing'!
  324. = aHashedCollection
  325. self class = aHashedCollection class ifFalse: [^false].
  326. self size = aHashedCollection size ifFalse: [^false].
  327. ^self associations = aHashedCollection associations
  328. ! !
  329. !HashedCollection methodsFor: 'converting'!
  330. asDictionary
  331. ^Dictionary fromPairs: self associations
  332. !
  333. asJSON
  334. | c |
  335. c := self class new.
  336. self keysAndValuesDo: [:key :value |
  337. c at: key put: value asJSON].
  338. ^c
  339. ! !
  340. !HashedCollection methodsFor: 'copying'!
  341. , aCollection
  342. self shouldNotImplement
  343. !
  344. deepCopy
  345. | copy |
  346. copy := self class new.
  347. self keysAndValuesDo: [:key :value |
  348. copy at: key put: value deepCopy].
  349. ^copy
  350. !
  351. shallowCopy
  352. | copy |
  353. copy := self class new.
  354. self keysAndValuesDo: [:key :value |
  355. copy at: key put: value].
  356. ^copy
  357. ! !
  358. !HashedCollection methodsFor: 'enumerating'!
  359. associationsDo: aBlock
  360. self keysAndValuesDo: [:key :value |
  361. aBlock value: (Association key: key value: value)]
  362. !
  363. collect: aBlock
  364. | newDict |
  365. newDict := self class new.
  366. self keysAndValuesDo: [:key :value |
  367. newDict at: key put: (aBlock value: value)].
  368. ^newDict
  369. !
  370. detect: aBlock ifNone: anotherBlock
  371. ^self values detect: aBlock ifNone: anotherBlock
  372. !
  373. do: aBlock
  374. self valuesDo: aBlock
  375. !
  376. includes: anObject
  377. ^self values includes: anObject
  378. !
  379. keysAndValuesDo: aBlock
  380. self keysDo: [:each |
  381. aBlock value: each value: (self at: each)]
  382. !
  383. keysDo: aBlock
  384. self keys do: aBlock
  385. !
  386. select: aBlock
  387. | newDict |
  388. newDict := self class new.
  389. self keysAndValuesDo: [:key :value |
  390. (aBlock value: value) ifTrue: [newDict at: key put: value]].
  391. ^newDict
  392. !
  393. valuesDo: aBlock
  394. self keysAndValuesDo: [ :key :value | aBlock value: value ]
  395. ! !
  396. !HashedCollection methodsFor: 'printing'!
  397. printString
  398. "print the contents of the HashedCollection into a string and return the string"
  399. ^String streamContents: [:aStream |
  400. aStream nextPutAll: 'a ', self class name, '('.
  401. self associations
  402. do: [:each | each storeOn: aStream]
  403. separatedBy: [ aStream nextPutAll: ' , '].
  404. aStream nextPutAll: ')']
  405. !
  406. storeOn: aStream
  407. aStream nextPutAll: '#{'.
  408. self associations
  409. do: [:each | each storeOn: aStream]
  410. separatedBy: [ aStream nextPutAll: '. '].
  411. aStream nextPutAll: '}'
  412. ! !
  413. !HashedCollection methodsFor: 'testing'!
  414. includesKey: aKey
  415. <return self.hasOwnProperty(aKey)>
  416. ! !
  417. !HashedCollection class methodsFor: 'instance creation'!
  418. fromPairs: aCollection
  419. | dict |
  420. dict := self new.
  421. aCollection do: [:each | dict add: each].
  422. ^dict
  423. ! !
  424. HashedCollection subclass: #Dictionary
  425. instanceVariableNames: 'keys values'
  426. package: 'Kernel-Collections'!
  427. !Dictionary methodsFor: 'accessing'!
  428. at: aKey ifAbsent: aBlock
  429. <
  430. var index = self._positionOfKey_(aKey);
  431. return index >>=0 ? self['@values'][index] : aBlock();
  432. >
  433. !
  434. at: aKey put: aValue
  435. <
  436. var index = self._positionOfKey_(aKey);
  437. if(index === -1) {
  438. var keys = self['@keys'];
  439. index = keys.length;
  440. keys.push(aKey);
  441. }
  442. return self['@values'][index] = aValue;
  443. >
  444. !
  445. keyAtValue: anObject
  446. ^ (self associations
  447. detect:[:k :v| v == anObject]
  448. ifNone:[self error: 'Not found']) key
  449. !
  450. keys
  451. ^keys copy
  452. !
  453. values
  454. ^values copy
  455. ! !
  456. !Dictionary methodsFor: 'adding/removing'!
  457. removeKey: aKey ifAbsent: aBlock
  458. <
  459. var index = self._positionOfKey_(aKey);
  460. if(index === -1) {
  461. return aBlock()
  462. } else {
  463. var keys = self['@keys'], values = self['@values'];
  464. var value = values[index], l = keys.length;
  465. keys[index] = keys[l-1];
  466. keys.pop();
  467. values[index] = values[l-1];
  468. values.pop();
  469. return value;
  470. }
  471. >
  472. ! !
  473. !Dictionary methodsFor: 'converting'!
  474. asHashedCollection
  475. ^HashedCollection fromPairs: self associations
  476. !
  477. asJSON
  478. ^self asHashedCollection asJSON
  479. ! !
  480. !Dictionary methodsFor: 'enumerating'!
  481. keysAndValuesDo: aBlock
  482. ^keys with: values do: aBlock
  483. !
  484. keysDo: aBlock
  485. ^keys do: aBlock
  486. !
  487. valuesDo: aBlock
  488. ^values do: aBlock
  489. ! !
  490. !Dictionary methodsFor: 'initialization'!
  491. initialize
  492. super initialize.
  493. keys := #().
  494. values := #()
  495. ! !
  496. !Dictionary methodsFor: 'private'!
  497. positionOfKey: anObject
  498. <
  499. var keys = self['@keys'];
  500. for(var i=0;i<keys.length;i++){
  501. if(keys[i].__eq(anObject)) { return i;}
  502. }
  503. return -1;
  504. >
  505. ! !
  506. !Dictionary methodsFor: 'testing'!
  507. includesKey: aKey
  508. < return self._positionOfKey_(aKey) >>= 0; >
  509. ! !
  510. IndexableCollection subclass: #SequenceableCollection
  511. instanceVariableNames: ''
  512. package: 'Kernel-Collections'!
  513. !SequenceableCollection commentStamp!
  514. A SequencableCollection is an IndexableCollection
  515. with numeric indexes starting with 1.!
  516. !SequenceableCollection methodsFor: 'accessing'!
  517. allButFirst
  518. ^self copyFrom: 2 to: self size
  519. !
  520. allButLast
  521. ^self copyFrom: 1 to: self size - 1
  522. !
  523. at: anIndex
  524. ^self at: anIndex ifAbsent: [
  525. self errorNotFound]
  526. !
  527. at: anIndex ifAbsent: aBlock
  528. self subclassResponsibility
  529. !
  530. at: anIndex put: anObject
  531. self subclassResponsibility
  532. !
  533. atRandom
  534. ^ self at: self size atRandom
  535. !
  536. first
  537. ^self at: 1
  538. !
  539. first: n
  540. "Answer the first n elements of the receiver.
  541. Raise an error if there are not enough elements."
  542. ^ self copyFrom: 1 to: n
  543. !
  544. fourth
  545. ^self at: 4
  546. !
  547. indexOf: anObject
  548. ^self indexOf: anObject ifAbsent: [self errorNotFound]
  549. !
  550. indexOf: anObject ifAbsent: aBlock
  551. <
  552. for(var i=0;i<self.length;i++) {
  553. if(self[i].__eq(anObject)) {return i+1}
  554. };
  555. return aBlock();
  556. >
  557. !
  558. indexOf: anObject startingAt: start
  559. "Answer the index of the first occurence of anElement after start
  560. within the receiver. If the receiver does not contain anElement,
  561. answer 0."
  562. ^self indexOf: anObject startingAt: start ifAbsent: [0]
  563. !
  564. indexOf: anObject startingAt: start ifAbsent: aBlock
  565. <
  566. for(var i=start-1;i<self.length;i++){
  567. if(self[i].__eq(anObject)) {return i+1}
  568. }
  569. return aBlock();
  570. >
  571. !
  572. last
  573. ^self at: self size
  574. !
  575. second
  576. ^self at: 2
  577. !
  578. third
  579. ^self at: 3
  580. ! !
  581. !SequenceableCollection methodsFor: 'adding'!
  582. addLast: anObject
  583. self add: anObject
  584. !
  585. removeLast
  586. self remove: self last
  587. ! !
  588. !SequenceableCollection methodsFor: 'comparing'!
  589. = aCollection
  590. (self class = aCollection class and: [
  591. self size = aCollection size]) ifFalse: [^false].
  592. self withIndexDo: [:each :i |
  593. (aCollection at: i) = each ifFalse: [^false]].
  594. ^true
  595. ! !
  596. !SequenceableCollection methodsFor: 'converting'!
  597. reversed
  598. self subclassResponsibility
  599. ! !
  600. !SequenceableCollection methodsFor: 'copying'!
  601. copyFrom: anIndex to: anotherIndex
  602. | range newCollection |
  603. range := anIndex to: anotherIndex.
  604. newCollection := self class new: range size.
  605. range withIndexDo: [:each :i |
  606. newCollection at: i put: (self at: each)].
  607. ^newCollection
  608. !
  609. deepCopy
  610. | newCollection |
  611. newCollection := self class new: self size.
  612. self withIndexDo: [:each :index |
  613. newCollection at: index put: each deepCopy].
  614. ^newCollection
  615. !
  616. shallowCopy
  617. | newCollection |
  618. newCollection := self class new: self size.
  619. self withIndexDo: [ :each :index |
  620. newCollection at: index put: each].
  621. ^newCollection
  622. ! !
  623. !SequenceableCollection methodsFor: 'enumerating'!
  624. detect: aBlock ifNone: anotherBlock
  625. <
  626. for(var i = 0; i < self.length; i++)
  627. if(aBlock(self[i]))
  628. return self[i];
  629. return anotherBlock();
  630. >
  631. !
  632. do: aBlock
  633. <for(var i=0;i<self.length;i++){aBlock(self[i]);}>
  634. !
  635. with: anotherCollection do: aBlock
  636. <for(var i=0;i<self.length;i++){aBlock(self[i], anotherCollection[i]);}>
  637. !
  638. withIndexDo: aBlock
  639. <for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
  640. ! !
  641. !SequenceableCollection methodsFor: 'testing'!
  642. includes: anObject
  643. ^(self indexOf: anObject ifAbsent: [nil]) notNil
  644. ! !
  645. SequenceableCollection subclass: #Array
  646. instanceVariableNames: ''
  647. package: 'Kernel-Collections'!
  648. !Array methodsFor: 'accessing'!
  649. at: anIndex ifAbsent: aBlock
  650. <
  651. if((anIndex < 1) || (self.length < anIndex)) {return aBlock()};
  652. return self[anIndex - 1];
  653. >
  654. !
  655. at: anIndex put: anObject
  656. <return self[anIndex - 1] = anObject>
  657. !
  658. size
  659. <return self.length>
  660. ! !
  661. !Array methodsFor: 'adding/removing'!
  662. add: anObject
  663. <self.push(anObject); return anObject;>
  664. !
  665. remove: anObject ifAbsent: aBlock
  666. <
  667. for(var i=0;i<self.length;i++) {
  668. if(self[i] == anObject) {
  669. self.splice(i,1);
  670. return self;
  671. }
  672. };
  673. aBlock._value();
  674. >
  675. !
  676. removeFrom: aNumber to: anotherNumber
  677. <self.splice(aNumber - 1,anotherNumber - 1)>
  678. ! !
  679. !Array methodsFor: 'converting'!
  680. asJavascript
  681. ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
  682. !
  683. reversed
  684. <return self._copy().reverse()>
  685. ! !
  686. !Array methodsFor: 'enumerating'!
  687. join: aString
  688. <return self.join(aString)>
  689. !
  690. sort
  691. ^self basicPerform: 'sort'
  692. !
  693. sort: aBlock
  694. <
  695. return self.sort(function(a, b) {
  696. if(aBlock(a,b)) {return -1} else {return 1}
  697. })
  698. >
  699. !
  700. sorted
  701. ^self copy sort
  702. !
  703. sorted: aBlock
  704. ^self copy sort: aBlock
  705. ! !
  706. !Array class methodsFor: 'instance creation'!
  707. new: anInteger
  708. <return new Array(anInteger)>
  709. !
  710. with: anObject
  711. ^(self new: 1)
  712. at: 1 put: anObject;
  713. yourself
  714. !
  715. with: anObject with: anObject2
  716. ^(self new: 2)
  717. at: 1 put: anObject;
  718. at: 2 put: anObject2;
  719. yourself
  720. !
  721. with: anObject with: anObject2 with: anObject3
  722. ^(self new: 3)
  723. at: 1 put: anObject;
  724. at: 2 put: anObject2;
  725. at: 3 put: anObject3;
  726. yourself
  727. !
  728. withAll: aCollection
  729. | instance index |
  730. index := 1.
  731. instance := self new: aCollection size.
  732. aCollection do: [:each |
  733. instance at: index put: each.
  734. index := index + 1].
  735. ^instance
  736. ! !
  737. SequenceableCollection subclass: #CharacterArray
  738. instanceVariableNames: ''
  739. package: 'Kernel-Collections'!
  740. !CharacterArray methodsFor: 'accessing'!
  741. at: anIndex put: anObject
  742. self errorReadOnly
  743. ! !
  744. !CharacterArray methodsFor: 'adding'!
  745. add: anObject
  746. self errorReadOnly
  747. !
  748. remove: anObject
  749. self errorReadOnly
  750. ! !
  751. !CharacterArray methodsFor: 'converting'!
  752. asLowercase
  753. ^self class fromString: self asString asLowercase
  754. !
  755. asNumber
  756. ^self asString asNumber
  757. !
  758. asString
  759. ^self subclassResponsibility
  760. !
  761. asSymbol
  762. ^self subclassResponsibility
  763. !
  764. asUppercase
  765. ^self class fromString: self asString asUppercase
  766. ! !
  767. !CharacterArray methodsFor: 'copying'!
  768. , aString
  769. ^self asString, aString asString
  770. ! !
  771. !CharacterArray methodsFor: 'error handling'!
  772. errorReadOnly
  773. self error: 'Object is read-only'
  774. ! !
  775. !CharacterArray methodsFor: 'printing'!
  776. printString
  777. ^self asString printString
  778. ! !
  779. !CharacterArray class methodsFor: 'instance creation'!
  780. fromString: aString
  781. self subclassResponsibility
  782. ! !
  783. CharacterArray subclass: #String
  784. instanceVariableNames: ''
  785. package: 'Kernel-Collections'!
  786. !String methodsFor: 'accessing'!
  787. asciiValue
  788. <return self.charCodeAt(0);>
  789. !
  790. at: anIndex ifAbsent: aBlock
  791. <return String(self).charAt(anIndex - 1) || aBlock()>
  792. !
  793. escaped
  794. <return escape(self)>
  795. !
  796. size
  797. <return self.length>
  798. !
  799. unescaped
  800. <return unescape(self)>
  801. ! !
  802. !String methodsFor: 'comparing'!
  803. < aString
  804. <return String(self) < aString._asString()>
  805. !
  806. <= aString
  807. <return String(self) <= aString._asString()>
  808. !
  809. = aString
  810. <
  811. if(!! aString._isString || !! aString._isString()) {
  812. return false;
  813. }
  814. return String(self) === String(aString)
  815. >
  816. !
  817. == aString
  818. ^self = aString
  819. !
  820. > aString
  821. <return String(self) >> aString._asString()>
  822. !
  823. >= aString
  824. <return String(self) >>= aString._asString()>
  825. ! !
  826. !String methodsFor: 'converting'!
  827. asJSON
  828. ^self
  829. !
  830. asJavaScriptSelector
  831. ^(self asSelector replace: '^_' with: '') replace: '_.*' with: ''.
  832. !
  833. asJavascript
  834. <
  835. if(self.search(/^[a-zA-Z0-9_:.$ ]*$/) == -1)
  836. return "\"" + self.replace(/[\x00-\x1f"\\\x7f-\x9f]/g, function(ch){var c=ch.charCodeAt(0);return "\\x"+("0"+c.toString(16)).slice(-2)}) + "\"";
  837. else
  838. return "\"" + self + "\"";
  839. >
  840. !
  841. asLowercase
  842. <return self.toLowerCase()>
  843. !
  844. asNumber
  845. <return Number(self)>
  846. !
  847. asRegexp
  848. ^ RegularExpression fromString: self
  849. !
  850. asSelector
  851. <return smalltalk.selector(self)>
  852. !
  853. asString
  854. ^self
  855. !
  856. asSymbol
  857. ^Symbol lookup: self
  858. !
  859. asUppercase
  860. <return self.toUpperCase()>
  861. !
  862. reversed
  863. <return self.split("").reverse().join("")>
  864. !
  865. tokenize: aString
  866. <return self.split(aString)>
  867. ! !
  868. !String methodsFor: 'copying'!
  869. , aString
  870. <return self + aString>
  871. !
  872. copyFrom: anIndex to: anotherIndex
  873. <return self.substring(anIndex - 1, anotherIndex)>
  874. !
  875. deepCopy
  876. ^self shallowCopy
  877. !
  878. shallowCopy
  879. ^self class fromString: self
  880. ! !
  881. !String methodsFor: 'enumerating'!
  882. do: aBlock
  883. <for(var i=0;i<self.length;i++){aBlock(self.charAt(i));}>
  884. !
  885. withIndexDo: aBlock
  886. <for(var i=0;i<self.length;i++){aBlock(self.charAt(i), i+1);}>
  887. ! !
  888. !String methodsFor: 'printing'!
  889. printNl
  890. <console.log(self)>
  891. !
  892. printString
  893. ^'''', self, ''''
  894. ! !
  895. !String methodsFor: 'regular expressions'!
  896. match: aRegexp
  897. <return self.search(aRegexp) !!= -1>
  898. !
  899. matchesOf: aRegularExpression
  900. <return self.match(aRegularExpression)>
  901. !
  902. replace: aString with: anotherString
  903. ^self replaceRegexp: (RegularExpression fromString: aString flag: 'g') with: anotherString
  904. !
  905. replaceRegexp: aRegexp with: aString
  906. <return self.replace(aRegexp, aString)>
  907. !
  908. trimBoth
  909. ^self trimBoth: '\s'
  910. !
  911. trimBoth: separators
  912. ^(self trimLeft: separators) trimRight: separators
  913. !
  914. trimLeft
  915. ^self trimLeft: '\s'
  916. !
  917. trimLeft: separators
  918. ^self replaceRegexp: (RegularExpression fromString: '^[', separators, ']+' flag: 'g') with: ''
  919. !
  920. trimRight
  921. ^self trimRight: '\s'
  922. !
  923. trimRight: separators
  924. ^self replaceRegexp: (RegularExpression fromString: '[', separators, ']+$' flag: 'g') with: ''
  925. ! !
  926. !String methodsFor: 'split join'!
  927. join: aCollection
  928. ^ String
  929. streamContents: [:stream | aCollection
  930. do: [:each | stream nextPutAll: each asString]
  931. separatedBy: [stream nextPutAll: self]]
  932. !
  933. lineIndicesDo: aBlock
  934. "execute aBlock with 3 arguments for each line:
  935. - start index of line
  936. - end index of line without line delimiter
  937. - end index of line including line delimiter(s) CR, LF or CRLF"
  938. | cr lf start sz nextLF nextCR |
  939. start := 1.
  940. sz := self size.
  941. cr := String cr.
  942. nextCR := self indexOf: cr startingAt: 1.
  943. lf := String lf.
  944. nextLF := self indexOf: lf startingAt: 1.
  945. [ start <= sz ] whileTrue: [
  946. (nextLF = 0 and: [ nextCR = 0 ])
  947. ifTrue: [ "No more CR, nor LF, the string is over"
  948. aBlock value: start value: sz value: sz.
  949. ^self ].
  950. (nextCR = 0 or: [ 0 < nextLF and: [ nextLF < nextCR ] ])
  951. ifTrue: [ "Found a LF"
  952. aBlock value: start value: nextLF - 1 value: nextLF.
  953. start := 1 + nextLF.
  954. nextLF := self indexOf: lf startingAt: start ]
  955. ifFalse: [ 1 + nextCR = nextLF
  956. ifTrue: [ "Found a CR-LF pair"
  957. aBlock value: start value: nextCR - 1 value: nextLF.
  958. start := 1 + nextLF.
  959. nextCR := self indexOf: cr startingAt: start.
  960. nextLF := self indexOf: lf startingAt: start ]
  961. ifFalse: [ "Found a CR"
  962. aBlock value: start value: nextCR - 1 value: nextCR.
  963. start := 1 + nextCR.
  964. nextCR := self indexOf: cr startingAt: start ]]]
  965. !
  966. lineNumber: anIndex
  967. "Answer a string containing the characters in the given line number."
  968. | lineCount |
  969. lineCount := 0.
  970. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  971. (lineCount := lineCount + 1) = anIndex ifTrue: [^self copyFrom: start to: endWithoutDelimiters]].
  972. ^nil
  973. !
  974. lines
  975. "Answer an array of lines composing this receiver without the line ending delimiters."
  976. | lines |
  977. lines := Array new.
  978. self linesDo: [:aLine | lines add: aLine].
  979. ^lines
  980. !
  981. linesDo: aBlock
  982. "Execute aBlock with each line in this string. The terminating line
  983. delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock"
  984. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  985. aBlock value: (self copyFrom: start to: endWithoutDelimiters)]
  986. ! !
  987. !String methodsFor: 'testing'!
  988. includesSubString: subString
  989. < return self.indexOf(subString) !!= -1 >
  990. !
  991. isString
  992. ^true
  993. ! !
  994. !String class methodsFor: 'accessing'!
  995. cr
  996. <return '\r'>
  997. !
  998. crlf
  999. <return '\r\n'>
  1000. !
  1001. lf
  1002. <return '\n'>
  1003. !
  1004. space
  1005. <return ' '>
  1006. !
  1007. streamClass
  1008. ^StringStream
  1009. !
  1010. tab
  1011. <return '\t'>
  1012. ! !
  1013. !String class methodsFor: 'instance creation'!
  1014. fromCharCode: anInteger
  1015. <return String.fromCharCode(anInteger)>
  1016. !
  1017. fromString: aString
  1018. <return new self.fn(aString)>
  1019. !
  1020. streamContents: blockWithArg
  1021. |stream|
  1022. stream := (self streamClass on: String new).
  1023. blockWithArg value: stream.
  1024. ^ stream contents
  1025. !
  1026. value: aUTFCharCode
  1027. <return String.fromCharCode(aUTFCharCode);>
  1028. ! !
  1029. CharacterArray subclass: #Symbol
  1030. instanceVariableNames: ''
  1031. package: 'Kernel-Collections'!
  1032. !Symbol methodsFor: 'accessing'!
  1033. at: anIndex ifAbsent: aBlock
  1034. ^self asString at: anIndex ifAbsent: aBlock
  1035. !
  1036. size
  1037. ^self asString size
  1038. ! !
  1039. !Symbol methodsFor: 'comparing'!
  1040. < aSymbol
  1041. ^self asString < aSymbol asString
  1042. !
  1043. <= aSymbol
  1044. ^self asString <= aSymbol asString
  1045. !
  1046. = aSymbol
  1047. aSymbol class = self class ifFalse: [^false].
  1048. ^self asString = aSymbol asString
  1049. !
  1050. > aSymbol
  1051. ^self asString > aSymbol asString
  1052. !
  1053. >= aSymbol
  1054. ^self asString >= aSymbol asString
  1055. ! !
  1056. !Symbol methodsFor: 'converting'!
  1057. asJSON
  1058. ^self asString asJSON
  1059. !
  1060. asJavascript
  1061. ^'smalltalk.symbolFor(', self asString asJavascript, ')'
  1062. !
  1063. asSelector
  1064. ^self asString asSelector
  1065. !
  1066. asString
  1067. <return self.value>
  1068. !
  1069. asSuperSelector
  1070. ^self asString asSuperSelector
  1071. !
  1072. asSymbol
  1073. ^self
  1074. ! !
  1075. !Symbol methodsFor: 'copying'!
  1076. copyFrom: anIndex to: anotherIndex
  1077. ^self class fromString: (self asString copyFrom: anIndex to: anotherIndex)
  1078. !
  1079. deepCopy
  1080. ^self
  1081. !
  1082. shallowCopy
  1083. ^self
  1084. ! !
  1085. !Symbol methodsFor: 'enumerating'!
  1086. collect: aBlock
  1087. ^ (self asString collect: aBlock) asSymbol
  1088. !
  1089. detect: aBlock
  1090. ^ self asString detect: aBlock
  1091. !
  1092. do: aBlock
  1093. self asString do: aBlock
  1094. !
  1095. select: aBlock
  1096. ^ (self asString select: aBlock) asSymbol
  1097. !
  1098. withIndexDo: aBlock
  1099. self asString withIndexDo: aBlock
  1100. ! !
  1101. !Symbol methodsFor: 'evaluating'!
  1102. value: anObject
  1103. ^anObject perform: self
  1104. ! !
  1105. !Symbol methodsFor: 'printing'!
  1106. isSymbol
  1107. ^true
  1108. !
  1109. printString
  1110. ^'#', self asString
  1111. ! !
  1112. !Symbol class methodsFor: 'instance creation'!
  1113. basicNew
  1114. self shouldNotImplement
  1115. !
  1116. fromString: aString
  1117. ^self lookup: aString
  1118. !
  1119. lookup: aString
  1120. <return smalltalk.symbolFor(aString);>
  1121. ! !
  1122. Collection subclass: #Set
  1123. instanceVariableNames: 'elements'
  1124. package: 'Kernel-Collections'!
  1125. !Set methodsFor: 'accessing'!
  1126. size
  1127. ^elements size
  1128. ! !
  1129. !Set methodsFor: 'adding/removing'!
  1130. add: anObject
  1131. <
  1132. var found;
  1133. for(var i=0; i < self['@elements'].length; i++) {
  1134. if(anObject == self['@elements'][i]) {
  1135. found = true;
  1136. break;
  1137. }
  1138. }
  1139. if(!!found) {self['@elements'].push(anObject)}
  1140. >
  1141. !
  1142. remove: anObject
  1143. elements remove: anObject
  1144. ! !
  1145. !Set methodsFor: 'comparing'!
  1146. = aCollection
  1147. self class = aCollection class ifFalse: [ ^ false ].
  1148. self size = aCollection size ifFalse: [ ^ false ].
  1149. self do: [:each | (aCollection includes: each) ifFalse: [ ^ false ] ].
  1150. ^ true
  1151. ! !
  1152. !Set methodsFor: 'converting'!
  1153. asArray
  1154. ^elements copy
  1155. ! !
  1156. !Set methodsFor: 'enumerating'!
  1157. collect: aBlock
  1158. ^self class withAll: (elements collect: aBlock)
  1159. !
  1160. detect: aBlock ifNone: anotherBlock
  1161. ^elements detect: aBlock ifNone: anotherBlock
  1162. !
  1163. do: aBlock
  1164. elements do: aBlock
  1165. !
  1166. select: aBlock
  1167. | collection |
  1168. collection := self class new.
  1169. self do: [:each |
  1170. (aBlock value: each) ifTrue: [
  1171. collection add: each]].
  1172. ^collection
  1173. ! !
  1174. !Set methodsFor: 'initialization'!
  1175. initialize
  1176. super initialize.
  1177. elements := #()
  1178. ! !
  1179. !Set methodsFor: 'testing'!
  1180. includes: anObject
  1181. ^elements includes: anObject
  1182. ! !
  1183. Object subclass: #Queue
  1184. instanceVariableNames: 'read readIndex write'
  1185. package: 'Kernel-Collections'!
  1186. !Queue commentStamp!
  1187. A Queue am a one-sided queue.
  1188. A Queue uses two OrderedCollections inside,
  1189. `read` is at the front, is not modified and only read using `readIndex`.
  1190. `write` is at the back and is appended new items.
  1191. When `read` is exhausted, `write` is promoted to `read` and new `write` is created.
  1192. As a consequence, no data moving is done by the Queue; write appending may do data moving
  1193. when growing `write`, but this is left to engine to implement as good as it chooses to.!
  1194. !Queue methodsFor: 'accessing'!
  1195. back: anObject
  1196. write add: anObject
  1197. !
  1198. front
  1199. ^self frontIfAbsent: [ self error: 'Cannot read from empty Queue.' ]
  1200. !
  1201. frontIfAbsent: aBlock
  1202. | result |
  1203. result := read at: readIndex ifAbsent: [
  1204. write isEmpty ifTrue: [
  1205. readIndex > 1 ifTrue: [ read := #(). readIndex := 1 ].
  1206. ^aBlock value ].
  1207. read := write.
  1208. readIndex := 1.
  1209. write := OrderedCollection new.
  1210. read first ].
  1211. read at: readIndex put: nil.
  1212. readIndex := readIndex + 1.
  1213. ^result
  1214. ! !
  1215. !Queue methodsFor: 'initialization'!
  1216. initialize
  1217. super initialize.
  1218. read := OrderedCollection new.
  1219. write := OrderedCollection new.
  1220. readIndex := 1
  1221. ! !
  1222. Object subclass: #RegularExpression
  1223. instanceVariableNames: ''
  1224. package: 'Kernel-Collections'!
  1225. !RegularExpression methodsFor: 'evaluating'!
  1226. compile: aString
  1227. <return self.compile(aString)>
  1228. !
  1229. exec: aString
  1230. <return self.exec(aString) || nil>
  1231. !
  1232. test: aString
  1233. <return self.test(aString)>
  1234. ! !
  1235. !RegularExpression class methodsFor: 'instance creation'!
  1236. fromString: aString
  1237. ^self fromString: aString flag: ''
  1238. !
  1239. fromString: aString flag: anotherString
  1240. <return new RegExp(aString, anotherString)>
  1241. ! !
  1242. Object subclass: #Stream
  1243. instanceVariableNames: 'collection position streamSize'
  1244. package: 'Kernel-Collections'!
  1245. !Stream methodsFor: 'accessing'!
  1246. collection
  1247. ^collection
  1248. !
  1249. contents
  1250. ^self collection
  1251. copyFrom: 1
  1252. to: self streamSize
  1253. !
  1254. position
  1255. ^position ifNil: [position := 0]
  1256. !
  1257. position: anInteger
  1258. position := anInteger
  1259. !
  1260. setCollection: aCollection
  1261. collection := aCollection
  1262. !
  1263. setStreamSize: anInteger
  1264. streamSize := anInteger
  1265. !
  1266. size
  1267. ^self streamSize
  1268. !
  1269. streamSize
  1270. ^streamSize
  1271. ! !
  1272. !Stream methodsFor: 'actions'!
  1273. close
  1274. !
  1275. flush
  1276. !
  1277. reset
  1278. self position: 0
  1279. !
  1280. resetContents
  1281. self reset.
  1282. self setStreamSize: 0
  1283. ! !
  1284. !Stream methodsFor: 'enumerating'!
  1285. do: aBlock
  1286. [self atEnd] whileFalse: [aBlock value: self next]
  1287. ! !
  1288. !Stream methodsFor: 'positioning'!
  1289. setToEnd
  1290. self position: self size
  1291. !
  1292. skip: anInteger
  1293. self position: ((self position + anInteger) min: self size max: 0)
  1294. ! !
  1295. !Stream methodsFor: 'reading'!
  1296. next
  1297. ^self atEnd
  1298. ifTrue: [nil]
  1299. ifFalse: [
  1300. self position: self position + 1.
  1301. collection at: self position]
  1302. !
  1303. next: anInteger
  1304. | tempCollection |
  1305. tempCollection := self collection class new.
  1306. anInteger timesRepeat: [
  1307. self atEnd ifFalse: [
  1308. tempCollection add: self next]].
  1309. ^tempCollection
  1310. !
  1311. peek
  1312. ^self atEnd ifFalse: [
  1313. self collection at: self position + 1]
  1314. ! !
  1315. !Stream methodsFor: 'testing'!
  1316. atEnd
  1317. ^self position = self size
  1318. !
  1319. atStart
  1320. ^self position = 0
  1321. !
  1322. isEmpty
  1323. ^self size = 0
  1324. ! !
  1325. !Stream methodsFor: 'writing'!
  1326. nextPut: anObject
  1327. self position: self position + 1.
  1328. self collection at: self position put: anObject.
  1329. self setStreamSize: (self streamSize max: self position)
  1330. !
  1331. nextPutAll: aCollection
  1332. aCollection do: [:each |
  1333. self nextPut: each]
  1334. ! !
  1335. !Stream class methodsFor: 'instance creation'!
  1336. on: aCollection
  1337. ^self new
  1338. setCollection: aCollection;
  1339. setStreamSize: aCollection size;
  1340. yourself
  1341. ! !
  1342. Stream subclass: #StringStream
  1343. instanceVariableNames: ''
  1344. package: 'Kernel-Collections'!
  1345. !StringStream methodsFor: 'reading'!
  1346. next: anInteger
  1347. | tempCollection |
  1348. tempCollection := self collection class new.
  1349. anInteger timesRepeat: [
  1350. self atEnd ifFalse: [
  1351. tempCollection := tempCollection, self next]].
  1352. ^tempCollection
  1353. ! !
  1354. !StringStream methodsFor: 'writing'!
  1355. cr
  1356. ^self nextPutAll: String cr
  1357. !
  1358. crlf
  1359. ^self nextPutAll: String crlf
  1360. !
  1361. lf
  1362. ^self nextPutAll: String lf
  1363. !
  1364. nextPut: aString
  1365. self nextPutAll: aString
  1366. !
  1367. nextPutAll: aString
  1368. self setCollection:
  1369. (self collection copyFrom: 1 to: self position),
  1370. aString,
  1371. (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
  1372. self position: self position + aString size.
  1373. self setStreamSize: (self streamSize max: self position)
  1374. !
  1375. space
  1376. self nextPut: ' '
  1377. ! !