Renderingen-US

map

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Generic key/value map type.

Aliases: map, dictionary

Syntax: map<K,V>

Category#

collection

Examples#

radix/corpus/tabula/methodi-accessus.fab (canonical · keyword)#

Generic key/value map type.

# =============================================================================
# map — Generic key/value map type.
# =============================================================================
#
# What this teaches:
#   • Map access methods — `accipe`, `ponde`, `habet`, `dele`, `longitudo`, `empty`
#   • Null-safe access — using `vel` to supply defaults when a key is absent
#
# Common mistakes:
#   • attempting to access a missing key without a default and getting a ∪ none value — use vel for fallback
#
# See also: list, set, ∷, for
# =============================================================================




# map<K,V> access and mutation intrinsics
#
# puncta.put(k, v) | puncta.get(k) | puncta.has(k)   -- get/put
# puncta.delete(k) | puncta.length() | puncta.is_empty()      -- delete/size
#
# GRAMMAR:
#   mapMethod :← expr '.' ('pone' | 'accipe' | 'habet' | 'dele'
#                         | 'longitudo' | 'empty') '(' args? ')'
#
# EXPECTED OUTPUT:
#   No pinned stdout — smoke asserts exit 0; map/tabula.fab carries scalar contract.
#
# BACKEND: Wasm tier floor FrontendAnalyzed (method surface not yet Runnable;
# whitelist: map/methodi-accessus.fab).

main {
    var map<string, int> puncta ← empty
    puncta.put("aelia", 95)
    puncta.put("balbus", 87)
    const int ∪ none aelia ← puncta.get("aelia")
    const int ∪ none absens ← puncta.get("carus")
    const int carus ← puncta.get("carus") coalesce 0
    const bool habetbalbum ← puncta.has("balbus")
    const bool remotus ← puncta.delete("balbus")
    const int longitudo ← puncta.length()
    const bool vacuaest ← puncta.is_empty()
    print aelia, absens, carus, habetbalbum, remotus, longitudo, vacuaest
}

Expected output:

95 nihil 0 verum verum 1 falsum

radix/corpus/tabula/tabula.fab (canonical · keyword)#

Generic key/value map type.

# =============================================================================
# map — Generic key/value map type.
# =============================================================================
#
# What this teaches:
#   • Map declaration — `map<K,V>` with bracket syntax for keyed access
#   • Map literals — empty map via `empty`, then populating with index assignment
#
# Common mistakes:
#   • using bracket syntax with a key type that doesn't match the map declaration, or inserting duplicate keys
#
# See also: list, set, ∷, for
# =============================================================================




# map<K,V> declaration, empty, and keyed lookup
#
# var map<K,V> name ← empty   -- typed empty map (forma innata)
# name[key] ← value                -- index assignment
# name[key]                        -- keyed accipe
# nomen.length()                 -- entry count
#
# GRAMMAR:
#   mapDecl :← 'var' 'map<' type ',' type '>' ident '←' expr
#   mapAcc  :← expr '[' expr ']'
#
# EXPECTED OUTPUT:
#   longitudo() plus keyed lookups for alpha/beta/gamma (tabula.expected).

main {
    var map<string, int> puncta ← empty
    puncta["alpha"] ← 1
    puncta["beta"] ← 2
    puncta["gamma"] ← 3
    print puncta.length()
    print puncta["alpha"]
    print puncta["beta"]
    print puncta["gamma"]
}

Expected output:

3
1
2
3

radix/corpus/tabula/key-not-hashable.fab (supporting · reject)#

Map keys and set elements must be hashable: floats and mutable collections are rejected.

# =============================================================================
# key-not-hashable — map keys and set elements must be hashable.
# =============================================================================
#
# Decline rows (reject reason in each comment):
#   1. `map<f64, string>` — a float key (NaN is not equal to itself):
#      SEM010 tabula_key_not_hashable
#   2. `set<list<int>>` — a mutable collection as a set element:
#      SEM010 copia_element_not_hashable
#
# What is hashable: text, integers, booleans, and tuples or classes whose
# every part is hashable.
#
# Common mistakes:
#   • keying by a float measurement — round to an integer unit first
#
# See also: map, set, tuple
# =============================================================================

fn weights(map<f64, string> m) → int {
    return m.length()
}

fn members(set<list<int>> s) → int {
    return s.length()
}

Expected: compilation rejects this example.