表格
Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant pack; supporting prose may still be English.
Generic key/value map type.
Aliases: map, dictionary
Syntax: 表格<K,V>
Category#
collection
Related#
Examples#
radix/corpus/tabula/methodi-accessus.fab (canonical · keyword)#
Generic key/value map type.
# =============================================================================
# 表格 — Generic key/value map type.
# =============================================================================
#
# What this teaches:
# • Map access methods — `accipe`, `ponde`, `habet`, `dele`, `longitudo`, `空集`
# • 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 ∪ 無 value — use vel for fallback
#
# See also: 列表, 副本, ∷, 遍歷
# =============================================================================
# 表格<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' | '空集') '(' args? ')'
#
# EXPECTED OUTPUT:
# No pinned stdout — smoke asserts exit 0; 表格/tabula.fab carries scalar contract.
#
# BACKEND: Wasm tier floor FrontendAnalyzed (method surface not yet Runnable;
# whitelist: 表格/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.
# =============================================================================
# 表格 — Generic key/value map type.
# =============================================================================
#
# What this teaches:
# • Map declaration — `表格<K,V>` with bracket syntax for keyed access
# • Map literals — empty map via `空集`, then populating with index assignment
#
# Common mistakes:
# • using bracket syntax with a key type that doesn't match the 表格 declaration, or inserting duplicate keys
#
# See also: 列表, 副本, ∷, 遍歷
# =============================================================================
# 表格<K,V> declaration, 空集, and keyed lookup
#
# 變值 表格<K,V> 名稱 ← 空集 -- typed empty map (forma innata)
# 名稱[key] ← value -- index assignment
# 名稱[key] -- keyed accipe
# nomen.length() -- entry count
#
# GRAMMAR:
# mapDecl :← '變值' '表格<' 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
3radix/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: 表格, 副本, 元組
# =============================================================================
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.