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#
map
Related#
Examples#
radix/corpus/reference/keyword/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 {
mut map<string, int> puncta ← empty
puncta.put("aelia", 95)
puncta.put("balbus", 87)
let int ∪ none aelia ← puncta.get("aelia")
let int ∪ none absens ← puncta.get("carus")
let int carus ← puncta.get("carus") coalesce 0
let bool habetbalbum ← puncta.has("balbus")
let bool remotus ← puncta.delete("balbus")
let int longitudo ← puncta.length()
let bool vacuaest ← puncta.is_empty()
print aelia, absens, carus, habetbalbum, remotus, longitudo, vacuaest
}Expected output:
95 none 0 true true 1 false
radix/corpus/reference/keyword/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
#
# mut map<K,V> nomen ← empty -- typed empty map (forma innata)
# nomen[key] ← value -- index assignment
# nomen[key] -- keyed accipe
# nomen.length() -- entry count
#
# GRAMMAR:
# mapDecl :← 'mut' 'map<' type ',' type '>' ident '←' expr
# mapAcc :← expr '[' expr ']'
#
# EXPECTED OUTPUT:
# longitudo() plus keyed lookups for alpha/beta/gamma (tabula.expected).
main {
mut 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"]
let int ∪ none absens ← puncta.get("missing")
print absens
}Expected output:
3
1
2
3
none
radix/corpus/reference/reject/tabula/arity-reject.fab (supporting · reject)#
A map type takes two type parameters: key and value.
# Rejects a map declaration with only one type parameter.
# A map type must specify both its key type and its value type.
# The checker refuses the malformed collection type at check time.
# This exercises the tabula_arity diagnostic.
main {
let map<int> scores ← empty
}Expected: compilation rejects this example.
radix/corpus/reference/reject/tabula/brace-text-key-reject.fab (supporting · reject)#
A brace literal's text keys cannot key a map whose key type is not text.
# Brace literal text-key rejection
# A brace literal uses text keys, so it cannot initialize a map<int, int>.
# This exemplum is refused during semantic checking.
#
main {
let map<int, int> bad ← { "a": 1 }
print bad
}Expected: compilation rejects this example.
radix/corpus/reference/reject/tabula/duplicate-key-reject.fab (supporting · reject)#
A brace literal with a repeated key is refused at the second occurrence.
# Rejects a brace literal that repeats an object key.
# Duplicate keys are refused at the second occurrence.
# The checker reports the repeated key as an error.
# This exercises the json_duplicate_key diagnostic.
main {
let _ d ← { "alpha": 1, "beta": 2, "alpha": 3 }
}Expected: compilation rejects this example.
radix/corpus/reference/reject/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.
radix/corpus/reference/reject/tabula/map-index-type-reject.fab (supporting · reject)#
A map read is indexed by the declared key type, not by an integer.
# Map index-type rejection
# Map reads require an index matching the map's declared key type.
# An integer index is refused for map<string, int>.
#
main {
let map<string, int> m ← empty
print m[1]
}Expected: compilation rejects this example.