Renderingen-US

✓

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

The value conditional: c ✓ a ✗ b, one level only.

Aliases: ✗

Syntax: <condition> ✓ <then-expr> ✗ <else-expr>

Category#

control-flow

Examples#

radix/corpus/ternarius/ternarius.fab (canonical · operator-group)#

The value conditional: c ✓ a ✗ b, one level only.

# =============================================================================
# ✓ ✗ — The value conditional: `c ✓ a ✗ b`, one level only.
# =============================================================================
#
# What this teaches:
#   • The value conditional — `c ✓ a ✗ b` yields `a` when `c` holds, else `b`.
#     The glyphs are U+2713 CHECK MARK and U+2717 BALLOT X, the same in every
#     locale; there is no word spelling.
#   • Narrowing — the branches narrow like `if` branches: after `x not is null`
#     the `✓` branch sees `x` as non-null.
#   • One level only — a `✓ ✗` inside another `✓ ✗` (in the condition or in
#     either branch) is rejected. More than two outcomes read better as
#     `if`/`elif`/`else`, a `match`, or a small function that `return`s each
#     case (shown below with early returns).
#
# Common mistakes:
#   • Writing `c ? a : b` or `c yields a else b` — both were removed; the
#     compiler points to `c ✓ a ✗ b`.
#   • Using the heavy emoji `✔` / `✘` — the lexer suggests `✓` / `✗`.
#   • Chaining `c ✓ a ✗ d ✓ b ✗ e` — nesting is rejected; use a function.
#
# See also: if, elif, match
# =============================================================================

# ✓ ✗ — value conditional
#
# "fab_file", "program", "statement", "statement_core", "block_stmt", "incipit_stmt", "fixum_decl", "hole_type", "type_annotation", "owned_type", "base_type", "qualified_type", "ternary", "comparison", "equality", "equality_tail", "cast_expr", "assignment", "place", "call_expr", "call_suffix", "argument_list", "argument", "expression", "literal", "nota_stmt", "functio_decl", "param_list", "parameter", "return_clause", "si_stmt", "secus_clause", "redde_stmt", "unary_expr":
#   ternary := or ['✓' expression '✗' ternary]   (one level only)
#
# EXPECTED OUTPUT:
#   ternarius.expected — one-level conditionals and the function alternative.

# More than two outcomes: a function that returns each case, not a chain.
fn gradus(int puncta) → string {
    if puncta ≥ 90 { return "A" }
    if puncta ≥ 80 { return "B" }
    if puncta ≥ 70 { return "C" }
    return "F"
}

main {
    const int aetas ← 25

    # One level: two outcomes
    const string gradusaetatis ← aetas ≥ 18 ✓ "adultus" ✗ "minor"
    # "adultus"
    print gradusaetatis

    # Several outcomes go through a function
    # "B"
    print gradus(85)

    # In expressions
    const int maximum ← aetas ≻ 30 ✓ aetas ✗ 30
    print "maximum: §"(maximum)

    # Narrowing: the ✓ branch sees a non-null string
    var string ∪ none forsitan ← null ∷ string ∪ none
    const string solutum ← forsitan not is none ✓ forsitan ✗ "defectum"
    # "defectum"
    print solutum

    const string licentia ← aetas ≥ 21 ✓ "licet bibere" ✗ "bibere non licet"
    print licentia
}

Expected output:

adultus
B
maximum: 30
defectum
licet bibere