Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

✓

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#

branch

Examples#

radix/corpus/reference/operator-group/check/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 none`
#     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 then return "A"
    if puncta ≥ 80 then return "B"
    if puncta ≥ 70 then return "C"
    return "F"
}

main {
    let int aetas ← 25

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

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

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

    # Narrowing: the ✓ branch sees a non-null string
    mut string ∪ none forsitan ← null ∷ string ∪ none
    let string solutum ← forsitan not is none ✓ forsitan ✗ "defectum"
    # "defectum"
    print solutum
    let string licentia ← aetas ≥ 21 ✓ "licet bibere" ✗ "bibere non licet"
    print licentia
}

Expected output:

adultus
B
maximum: 30
defectum
licet bibere

radix/corpus/reference/reject/check/nested-reject.fab (supporting · reject)#

A value conditional cannot be nested; the ✓ conditional has one level only.

# =============================================================================
# ✓ ✗ — nested value conditionals are refused
#
# Use a function or an `if` ladder when a value conditional needs more cases.
# =============================================================================

fn sign(int n) → int {
    return n ≺ 0 ✓ -1 ✗ n ≡ 0 ✓ 0 ✗ 1
}

main {
    print sign(-4)
}

Expected: compilation rejects this example.