A dictionary literal permits the specification of the keys and values of a dictionary as a literal value. Its syntax is very similar to the syntax of dynamic array literals.

Here's the EBNF for dictionary literals: 

DictionaryLiteral = "#{"  [{Statement, OptionalWhitespace, "."}, FinalStatement, ["."] "}";

dictionary literal must begin with the two characters "#{", which may optionally be followed by a sequence of Essence# statements separated from each other by a "." character. The final statement in the sequence may optionally be followed by a "." character. The final character of a dictionary literal must be a single "}" character.

Each statement in a dictionary literal must evaluate at run time to an association. The dictionary that will be constructed by a dictionary literal will contain all the associations specified by the statements in the dictionary literal. 

Here's an example of a dictionary literal:

#{#red -> [vehicle stop]. #yellow -> [vehicle prepareToStop; stop]. #green -> [vehicle continue]}


The dictionary that will be constructed at run time by the dictionary literal shown in the example will have the same keys and values as the one constructed by the following code:

| dictionary |
dictionary := Dictionary new.
        at: #red put: [vehicle stop];
        at: #yellow put: [vehicle prepareToStop; stop];
        at: #green put: [vehicle continue]

Last edited Aug 10, 2014 at 6:08 AM by Strategesis, version 5