this documentation is work-in-progress, edit here (md).

Dicts

sections in this chapter:
[ Dict ] type »
[ Dict ] put: [ Object ] at: [ Object ] »
[ Dict ] [ String ]: [ Object ] »
[ Dict ] - [ Object ] »
[ Dict ] entries »
[ Dict ] values »
[ Dict ] at: [ Object ] »
[ Dict ] count »
[ Dict ] each: [ Block ] »
[ Dict ] has: [ Object ] »
[ Dict ] string »

**Both List and Dict are collections. However, contrary to a list, a dict has no order. Another distinction between the two is that a dict consists of object pairs. One object acts as entry (or keyword) in order to search for the other object. A good example of a list is a price list, such as:

>> menu := Dict new
    put: ['£5'] at: ['apple pie'],
    put: ['£6'] at: ['carrot cake'],
    put: ['£3'] at: ['fudge'].

Similar to a list, the message put:at: is used to add an object to a list. The difference is that, contrary to a list, two objects are being linked. The first object is, similar to a list, the object that you will store in a list. The second object is not its position within the collection, but the entry which enables the previous object to be retrieved at a later time. In short, a dict works a bit like a dictionary; so, by using the keyword the meaning can be found. For instance, to retrieve from the above-mentioned list the price of a fudge:

>> price := menu at: ['fudge'].

You may also use the concise notation:

>> price := menu ? ['fudge'].

Should the entries that you apply to store objects be without spaces (and not collide with other predefined messages), the next notation can be also be used:

>> menu := Dict new
    pie:   ['£5'],
    cake:  ['£6'],
    fudge: ['£3'].

No doubt that the above notation reads a bit more natural. To request the price of a fudge, the following simplified notation can be used:

>> price := menu fudge.

[ Dict ] type

Example:


 >> x := Dict new.
 Out write: x type, stop.
 
	

Result:

Dict

	

[ Dict ] put: [ Object ] at: [ Object ]

Example:


 >> x := Dict new.
 x put: ['aaa'] at: ['bbb'].
 Out write: x, stop.
 
	

Result:

(Dict new) put:['aaa'] at:['bbb']

	

[ Dict ] [ String ]: [ Object ]

Example:


 >> x :=
 Dict new
 aaa: 11.90,
 bbb: 12.99,
 ccc: 13.00.
 Out write: ( x ? ['aaa'] ), stop.
 Out write: ( x ccc ), stop.
 
	

Result:

11.9
13

	

[ Dict ] - [ Object ]

Example:


 >> x := Dict new.
 x aaa: ['bbb'], ccc: ['ddd'].
 x - ['ccc'].
 Out write: x, stop.
 
	

Result:

(Dict new) put:['bbb'] at:['aaa']

	

[ Dict ] entries

Example:


 >> x := Dict new.
 x aaa: ['bbb'], ccc: ['ddd'].
 Out write: x entries, stop.
 
	

Result:

List ← ['ccc'] ; ['aaa']

	

[ Dict ] values

Example:


 >> x := Dict new.
 x aaa: ['bbb'], ccc: ['ddd'].
 Out write: x values, stop.
 
	

Result:

List ← ['ddd'] ; ['bbb']

	

[ Dict ] at: [ Object ]

Example:


 >> x := Dict new.
 x put: ['a'] at: ['b'].
 x put: ['xxx'] at: ['yyy'].
 Out write: (x at: ['b']), stop.
 Out write: (x yyy), stop.
 Out write: (x ? ['b']), stop.
 
	

Result:

a
xxx
a

	

[ Dict ] count

Example:


 >> x := Dict new.
 x
 put: ['a'] at: ['b'],
 put: ['c'] at: ['d'].
 Out write: x count, stop.
 
	

Result:

2

	

[ Dict ] each: [ Block ]

Example:


 (Dict new I: 1, II: 2, III: 3) each: { :a :b
   Out write: a + b, stop.
 }.
 
	

Result:

I1
II2
III3

	

[ Dict ] has: [ Object ]

Example:


 >> x := Dict new.
 x China: ['CN'], Russia: ['RU'].
 Out write: (x has: ['CN']), stop.
 Out write: (x has: ['NL']), stop.
 
	

Result:

True
False

	

[ Dict ] string

Example:


 >> x := Dict new.
 x put: ['a'] at: ['b'].
 >> y := x string.
 Out write: y, stop.
 
	

Result:

(Dict new) put:['a'] at:['b']