渲染zh-Hant

ergo

Translation status: 繁體中文 reader-locale proof. Code fences render through the zh-Hant pipeline; prose is canonical Latin.

Introduces a compact statement consequent.

Aliases: ergo, therefore

Syntax: <head> ergo <statement>

Category#

control-flow

Examples#

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

Compact consequent after si/dum heads via ergo, with ∴ reserved for closure bodies.

# =============================================================================
# ergo — Compact consequent after si/dum heads via ergo, with ∴ reserved for closure bodies.
# =============================================================================
#
# What this teaches:
#   • Compact consequents — `ergo` follows `si`, `sin`, `secus`, or `dum` heads with a single consequent statement.
#   • Guard-return pattern — `si <cond> ergo redde <value>` is a concise guard clause.
#
# Common mistakes:
#   • Using -> instead of → for function return types — Faber uses the Unicode arrow.
#
# See also: si, redde, clausura, ergo
# =============================================================================

# operatores/control — ergo therefore consequent
#
# GRAMMAR:
#   consequentStmt :← ('si' | 'sin' | 'secus' | 'dum') expr 'ergo' stmt
#
# EXPECTED OUTPUT:
#   0, 100, 42
#
# BACKEND:
#   Cross-ref si/ergo-redde.fab for ergo-redde guard-return spelling.

fn clamp(int x)  int {
    if x < 0 then return 0
    if x > 100 then return 100
    return x
}

fn inveni(list<int> res, int quaesitum)  int  null {
    for from res const item {
        if item  quaesitum then return item
    }
    return null
}

main {
    print clamp(-5)
    print clamp(150)
    print inveni([10, 20, 42], 42)
}

Expected output:

0
100
42

radix/corpus/si/ergo-redde.fab (canonical · operator-group)#

Introduces a compact statement consequent.

# =============================================================================
# ergo — Introduces a compact statement consequent.
# =============================================================================
#
# What this teaches:
#   • Guard clauses — `si <cond> ergo redde <expr>` provides a compact
#     one-liner for early returns
#   • `sin` and `secus` also accept `ergo` for chained guard expressions
#   • Demonstrates guard-return patterns, optional returns, and linear search
#
# Common mistakes:
#   • TODO: using `ergo` with a block instead of a single statement
#
# See also: si, dum, clausura, redde, tacet
# =============================================================================

# Si with ergo redde syntax
#
# si <conditio> ergo redde <expressio>     -- guard return
# sin <conditio> ergo redde <expressio>    -- else-if guard
# secus ergo redde <expressio>             -- else return
#
# GRAMMAR:
#   guardReturn :← ('si' | 'sin' | 'secus') expr 'ergo' 'redde' expr
#
# EXPECTED OUTPUT:
#   Sign classes, division results, grades, and search hits.

fn classis(int x)  string {
    if x < 0 then return "negativus"
    if x  0 then return "nihil"
    return "positivus"
}

# Optional return: nihil when divisor is zero
fn divide(int a, int b)  int  null {
    if b  0 then return null
    return a / b
}

# sin chain with secus ergo redde fallback
fn gradus(int puncta)  string {
    if puncta  90 then return "A"
    elif puncta  80 then return "B"
    elif puncta  70 then return "C"
    elif puncta  60 then return "D"
    else then return "F"
}

# Early return inside itera ex loop
fn inveni(list<int> res, int quaesitum)  int  null {
    for from res const item {
        if item  quaesitum then return item
    }
    return null
}

fn habet(map<string, int> map, string clavis)  bool {
    for ref map const k {
        if k  clavis then return true
    }
    return false
}

main {
    # Sign classification
    print classis(-5)
    print classis(0)
    print classis(10)

    # Optional return on invalid divisor
    # 5
    print divide(10, 2)
    # nihil
    print divide(10, 0)

    # Letter grades via sin chain
    print gradus(95)
    print gradus(85)
    print gradus(55)

    # Linear search with early redde
    const _ numeri  [1, 2, 3, 4, 5]
    print inveni(numeri, 3)
    print inveni(numeri, 9)
}

Expected output:

negativus
nihil
positivus
5
nihil
A
B
F
3
nihil

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

Introduces a compact statement consequent.

# =============================================================================
# ergo — Introduces a compact statement consequent.
# =============================================================================
#
# What this teaches:
#   • Inline conditionals — `ergo` replaces a single-statement block body on
#     `si` and `secus` branches
#   • `si <cond> ergo <stmt> secus ergo <stmt>` forms a two-way one-liner
#     without braces
#
# Common mistakes:
#   • TODO: chaining multiple statements after `ergo` (it accepts only one
#     statement)
#
# See also: si, dum, clausura, redde, tacet
# =============================================================================

# One-liner conditionals with ergo
#
# si <condition> ergo <statement>                              -- single consequent
# si <condition> ergo <statement> secus ergo <statement>     -- if-else one-liner
#
# GRAMMAR:
#   ifStmt :← 'si' expr 'ergo' stmt ('secus' 'ergo' stmt)?
#
# EXPECTED OUTPUT:
#   Validation and grading lines for sample x, aetas, and puncta values.

main {
    # ergo replaces a one-statement block body
    const _ x  10

    if x > 5 then print "x magnum est"

    # secus ergo pairs else with a single consequent
    const _ aetas  25
    if aetas  18 then print "adultus"
    else then print "minor"

    # Two-way one-liner (85 < 90 → "non A")
    const _ puncta  85
    if puncta  90 then print "A"
    else then print "non A"

    # bivalens condition used directly
    const _ valet  true
    if valet then print "Recte"
}

Expected output:

x magnum est
adultus
non A
Recte