Sidebar

Home



Expressions V4


Tutorials

How-To

Reference

  Lexical basics
  Type system
  Variables and assignment
  Operators
  Expression rules
  Control flow
  Functions
  Built-in functions
   None and NaN
   Arithmetic
   Algebra
   Logarithmic and Exponential
   Trigonometric
   Rounding and Centering
   Strings
   Output, Formatting, Clipboard, and Errors
   Dialog Functions
   Platform and Paths
  Methods and properties
  Built-in methods
   Common Value Methods
   Number Methods
   String Basic Methods
   String Slice Methods
   String Parsing Methods
   String Formatting Methods
   String Regex Methods
   String Trim and Case Methods
  Objects
  Built-in objects
   Global objects
    settings
    controller
    session
    python
   Collections
    array
    map
    bytes
   File Format I/O
    image_data
    image_stream
   Utils
    crypto
    timer
   Comm
    serial
   Dialogs
    file_open
    file_save
    msg_ok
    msg_ok_cancel
    msg_yes_no
    msg_password
   GUI objects
    window
    panel
    group
    splitpanel
    label
    textbutton
    drawablebutton
    togglebutton
    togglegroup
    textinput
    textedit
    numinput
    slider
    combobox
    listbox
    progressbar
    led
    separator
    menu
    image
    snake
  Classes and user-defined objects
  Include system
  Error model
  Execution model and sessions
  Host integration
  Limits and performance
  Formal reference
  Glossary

Cookbook

exprv4:reference:objects:map

map

A map is an ordered key/value object.

Create a map with `map(…)`.

lookup = map();
lookup = map('x', 10, 'y', 20);

Keys are converted to strings.

Constructor

map()

Creates an empty map.

Item Description
Syntax `map()`
Arguments none
Returns map object

Example:

lookup = map();
lookup.empty();       // true

map(key, value, ...)

Creates a map initialized with key/value pairs.

Argument Type Description
`key` any Key converted to string.
`value` any Value stored for the key.
`…` any Additional key/value pairs.

Returns: map object.

The number of arguments must be even.

Example:

lookup = map('x', 10, 'y', 20);
lookup.get('x');      // 10

Properties

Map keys can be read as properties when the key is a valid property name.

lookup = map('x', 10);
lookup.x;             // 10

Property access is read-only. Use `set(key, value)` to change a map entry.

lookup.set('x', 20);

Common Object Methods

to_string()

Returns a display string for the object.

Item Description
Syntax `value.to_string()`
Arguments none
Returns string

Example:

text = value.to_string();

clone()

Returns a new map object with the same key/value pairs.

Item Description
Syntax `map.clone()`
Arguments none
Returns map object

Example:

lookup = map('x', 10);
copy = lookup.clone();

Methods

size()

Returns the number of key/value pairs in the map.

Item Description
Syntax `map.size()`
Arguments none
Returns number

Example:

map('x', 10, 'y', 20).size();  // 2

count()

Alias for `size()`.

Item Description
Syntax `map.count()`
Arguments none
Returns number

Example:

map('x', 10).count();          // 1

empty()

Returns true when the map has no entries.

Item Description
Syntax `map.empty()`
Arguments none
Returns boolean-style number

Example:

lookup = map();
lookup.empty();                // true

clear()

Removes all entries from the map.

Item Description
Syntax `map.clear()`
Arguments none
Returns boolean-style number

Example:

lookup = map('x', 10);
lookup.clear();
lookup.size();                 // 0

has(key)

Checks whether a key exists.

Argument Type Description
`key` any Key converted to string.

Returns: boolean-style number.

Example:

lookup = map('x', 10);
lookup.has('x');               // true
lookup.has('z');               // false

get(key)

Returns the value for a key.

Argument Type Description
`key` any Key converted to string.

Returns: stored value, or `none()` when the key does not exist.

Example:

lookup = map('x', 10);
lookup.get('x');               // 10
lookup.get('z').is_none();     // true

set(key, value)

Stores a value for a key.

Argument Type Description
`key` any Key converted to string.
`value` any Value to store.

Returns: boolean-style number.

Example:

lookup = map();
lookup.set('x', 10);
lookup.get('x');               // 10

remove(key)

Removes a key/value pair.

Argument Type Description
`key` any Key converted to string.

Returns: true if a value was removed, false when the key did not exist.

Example:

lookup = map('x', 10);
lookup.remove('x');            // true
lookup.remove('x');            // false

keys()

Returns an array of keys in insertion order.

Item Description
Syntax `map.keys()`
Arguments none
Returns array object

Example:

lookup = map('x', 10, 'y', 20);
lookup.keys().to_string();     // ["x", "y"]

values()

Returns an array of values in insertion order.

Item Description
Syntax `map.values()`
Arguments none
Returns array object

Example:

lookup = map('x', 10, 'y', 20);
lookup.values().to_string();   // [10, 20]

Previous: array

Next: bytes

exprv4/reference/objects/map.txt · Last modified: by andrej

Page Tools