A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-cbc.689.mcz ==================== Summary ==================== Name: Collections-cbc.689 Author: cbc Time: 13 April 2016, 3:28:58.221861 pm UUID: 84ae8fa7-91ee-4f47-8bdf-eadcac286a1e Ancestors: Collections-mt.688 Fix comment in Dictioanry class>>newFrom: so that the examples actually work. =============== Diff against Collections-mt.688 =============== Item was changed: ----- Method: Dictionary class>>newFrom: (in category 'instance creation') ----- newFrom: aDict "Answer an instance of me containing the same associations as aDict. Error if any key appears twice." | newDictionary | newDictionary := self new: aDict size. aDict associationsDo: [:x | (newDictionary includesKey: x key) ifTrue: [self error: 'Duplicate key: ', x key printString] ifFalse: [newDictionary add: x copy]]. ^ newDictionary + " Dictionary newFrom: {1->#a. 2->#b. 3->#c} + {1->#a. 2->#b. 3->#c} as: Dictionary + Dictionary newFrom: {1->#a. 2->#b. 1->#c} + {1->#a. 2->#b. 1->#c} as: Dictionary - " NewDictionary newFrom: {1->#a. 2->#b. 3->#c} - {1->#a. 2->#b. 3->#c} as: NewDictionary - NewDictionary newFrom: {1->#a. 2->#b. 1->#c} - {1->#a. 2->#b. 1->#c} as: NewDictionary "! |
Could someone move this to trunk? Just fixed the comment (since we don't have a NewDictionary in trunk currently). I do have a mostly unrelated question. This method (newFrom:) checks to see if there is a duplicate key that in the source when making the new Dictionary, and fails if there is. But #newFromPairs: doesn't check - just happily writes over the previous value. Dictionary newFromPairs: {'Red' . Color red . 'Blue' . Color blue . 'Green' . Color green. 'Blue' . Color green. }. Is there a good, valid reason they are consistent? -cbc On Wed, Apr 13, 2016 at 3:29 PM, <[hidden email]> wrote: A new version of Collections was added to project The Inbox: |
Free forum by Nabble | Edit this page |