การเรนเดอร์th-TH

primus_quem

Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH 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

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.