primus_quem
Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans pack; supporting prose may still be English.
Dedicated total first-match expression: first live element of a source satisfying the owned ubi predicate, 空类型 for no-match and empty sources.
Aliases: primus quem
Syntax: primus_quem(<source>, ubi <binder> { <predicate> })
Category#
collection
Related#
Examples#
radix/corpus/primus-quem/primus-quem.fab (canonical · concept)#
Dedicated total first-match expression: first live element of a source satisfying the owned ubi predicate, 空类型 for no-match and empty sources.
# =============================================================================
# primus_quem — dedicated total first-match selection over a bounded source.
# =============================================================================
#
# What this teaches:
# • dedicated head — `primus_quem(source, ubi x { predicate })` is its own
# expression (not a `中断`/`如果` reuse and not a method call); the `ubi`
# tail is owned by this head
# • total evaluation — the predicate is evaluated for EVERY candidate 车道
# (post-match lanes included); selection is dataflow first-live, never an
# early exit
# • `T ∪ 空类型` — no-match and empty sources return `空类型`, never an error;
# a predicate ERROR rides the error channel and is never converted to
# `空类型`
# • first-live — later live lanes never overwrite the first stored match
# ([1.0, 5.0, 3.0] over `> 2.0` picks 5.0, not 3.0)
# • declines — unbounded sources fail closed (SEM059
# first_match_unbounded_source, causa not_bounded) and multi-axis `在`
# coordinates stay unsupported in v1 (SEM059
# first_match_expression_unsupported); see primus-quem-decline.fab
#
# Common mistakes:
# • expecting an index/value pair — v1 returns only `T ∪ 空类型`; construct
# the explicit pair yourself if you need the index
# • expecting early exit — the predicate still runs after the first match
#
# See also: ubi, 空类型, filtrata, primus
# =============================================================================
# Route T — array literal source: first live 车道 over `> 0.0` is 1.0.
函数 elige_litteram() → 小数 ∪ 空类型 {
返回 primus_quem([1.0, -2.0, 3.0], ubi x { x > 0.0 })
}
# No-match — no live 车道 yields 空类型, never an error.
函数 elige_nullum() → 小数 ∪ 空类型 {
返回 primus_quem([1.0, 2.0], ubi x { x > 9.0 })
}
# Empty source — a statically zero-length array yields 空类型.
函数 elige_vacuum(列表<f32> xs) → 小数 ∪ 空类型 {
返回 primus_quem(xs, ubi x { x > 0.0 })
}
# First-live — with matches at 5.0 and 3.0, the FIRST live 车道 wins.
函数 elige_primum_viventem(列表<f32> xs) → 小数 ∪ 空类型 {
返回 primus_quem(xs, ubi x { x > 2.0 })
}
入口 {
常量 小数 ∪ 空类型 litteram ← elige_litteram()
常量 小数 ∪ 空类型 nullum ← elige_nullum()
常量 列表<f32> vacua_lista ← []
常量 小数 ∪ 空类型 无值 ← elige_vacuum(vacua_lista)
常量 列表<f32> xs ← [1.0, 5.0, 3.0]
常量 小数 ∪ 空类型 primum ← elige_primum_viventem(xs)
显示 litteram
显示 nullum
显示 无值
显示 primum
}Expected output:
1.0
nihil
nihil
5.0
radix/corpus/primus-quem/primus-quem-decline.fab (supporting · reject)#
primus_quem AIR decline rows: unbounded sources fail closed (not_bounded) and 在 coordinates on first-match stay unsupported in v1.
# =============================================================================
# primus_quem decline — bounded sources only on the AIR 车道.
# =============================================================================
#
# Decline rows (reject reason in each comment):
# 1. unbounded source — an unbounded `列表` parameter has no static
# extent; the AIR gate fails closed:
# SEM059 first_match_unbounded_source (causa not_bounded)
# 2. 在 coordinates — the multi-axis `在 [i]` form on the first-match
# head stays unsupported in v1 (honest decline, not a silent pass):
# SEM059 first_match_expression_unsupported
#
# Common mistakes:
# • expecting an unbounded `列表` local to admit because its initializer
# is a literal — the route classifier sees the unbounded path type
# • expecting early-exit semantics to excuse the bound — admission needs
# the static extent for the first-live mask, not an unroll
#
# See also: primus_quem, ubi, 列表, 在
# =============================================================================
# 1. unbounded — 列表 parameter has no static extent, declines not_bounded
@ radix 车道 "air"
函数 elige_infinita(列表<f32> xs) → 小数 ∪ 空类型 {
返回 primus_quem(xs, ubi v { v > 0.0 })
}
# 2. 在 coordinates — multi-axis first-match stays unsupported in v1
@ radix 车道 "air"
函数 elige_apud(tf32[4] a) → 小数 ∪ 空类型 {
返回 primus_quem(a 在 [i], ubi v { v > 0.0 })
}Expected: compilation rejects this example.