Is there an Ordered Dictionary?

Bert Freudenberg bert at
Thu Jan 9 21:39:55 UTC 2003

On Thu, 9 Jan 2003, Derek Brans wrote:

> Is there a dictionary that holds its associations in the same order you 
> add them in?
> So, if I do
> 	dict at: 'first field' put: firstValue
> 	dict at: 'secondfield' put: secondValue
> 	dict associationsDo: [ ... ]
> it will do them in order?

You can use an OrderedCollection:

	odict := OrderedCollection new.
 	odict add: 'first field' -> firstValue.
 	odict add: 'secondfield' -> secondValue.
 	odict do: [:asso | ... ]

> BTW, on the subject of dictionaries, are you supposed to use 
> associationsDo to iterate over all key - value pairs? 

	dict keysAndValuesDo: [:key :value | ... ]

> If so, why is the name for such a common operation so long and specific

Because it exactly describes what it does.	

-- Bert

More information about the Squeak-dev mailing list