Skip to content

Dictionary

Giorgio Garofalo edited this page May 18, 2025 · 8 revisions

In Quarkdown, a dictionary is a collection of key-value pairs, without duplicate keys. A key is always a string value, while a value can be of any type.

The syntax for dictionaries recalls the YAML one, as it uses Markdown lists:

- key1: value1
- key2: value2
- key3: value3

Since its syntax clashes with Iterable's, wrapping the dictionary declaration in a .dictionary function ensures no ambiguity is present, in cases where both dictionaries and iterables are accepted.
In the following example, .foreach is suitable for both, so we enforce to run it on a dictionary to iterate over key-value pairs:

.var {mydictionary}
  .dictionary
    - key1: value1
    - key2: value2
    - key3: value3

.foreach {.mydictionary}
  ...

 

Dictionaries can be nested if accepted by the called function (.localization for instance).

- English:
  - greeting: Hello
  - food: Fish and chips
- Italian:
  - greeting: Ciao
  - food: Pasta

Trailing colons that precede nested dictionaries are not mandatory and can be omitted:

- English
  - greeting: Hello
  - food: Fish and chips
- Italian
  - greeting: Ciao
  - food: Pasta

Operations

A dictionary can be passed to any function that accepts an iterable (it is treated as an iterable of pairs).

For a complete list of dictionary operations, please refer to the stdlib's Dictionary documentation.

Clone this wiki locally