configureDictionary

Creates an empty dictionary with fixed key and value types.

Category: Language Fundamentals > Data Types

Syntax

d = configureDictionary(keyType, valueType)

Returns an empty dictionary whose keys and values must be of the given classes.

Description

A dictionary created with no arguments has unset types and takes them from the first entry. configureDictionary fixes them in advance, so that an empty dictionary can be created in a function and filled later with d(key) = value, and a later entry of the wrong type is rejected.

Input arguments

keyType
Class name of the keys, for example 'string' or 'double'.
valueType
Class name of the values, for example 'double', 'string' or 'cell'.

Output arguments

d
Empty dictionary configured for those types.

Example

Typed empty dictionary

d = configureDictionary('string', 'double');
d("a") = 1;
d("b") = 2;
d
Output
d = 
  dictionary (string --> double) with 2 entries:

    "a" --> 1
    "b" --> 2

See also

dictionary containers.Map isKey keys values