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

ดังนั้น

Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH pack; supporting prose may still be English.

Introduces a compact statement consequent.

Aliases: ergo, therefore

Syntax: <head> ดังนั้น <statement>

Category#

control-flow

Examples#

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

Compact consequent after ถ้า/dum heads via ดังนั้น, with ∴ reserved for closure bodies.

# =============================================================================
# ดังนั้น — Compact consequent after ถ้า/dum heads via ดังนั้น, with ∴ reserved for closure bodies.
# =============================================================================
#
# What this teaches:
#   • Compact consequents — `ดังนั้น` follows `ถ้า`, `ถ้าไม่ก็`, `มิฉะนั้น`, or `ขณะ` heads with a single consequent statement.
#   • Guard-return pattern — `ถ้า <cond> ดังนั้น คืน <value>` is a concise guard clause.
#
# Common mistakes:
#   • Using -> instead of → for function return types — Faber uses the Unicode arrow.
#
# See also: ถ้า, คืน, ปิดล้อม, ดังนั้น
# =============================================================================

# operatores/control — ดังนั้น therefore consequent
#
# GRAMMAR:
#   consequentStmt :← ('ถ้า' | 'ถ้าไม่ก็' | 'มิฉะนั้น' | 'ขณะ') expr 'ดังนั้น' stmt
#
# EXPECTED OUTPUT:
#   0, 100, 42
#
# BACKEND:
#   Cross-ref ถ้า/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 ∪ none {
    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.

# =============================================================================
# ดังนั้น — Introduces a compact statement consequent.
# =============================================================================
#
# What this teaches:
#   • Guard clauses — `ถ้า <cond> ดังนั้น คืน <expr>` provides a compact
#     one-liner for early returns
#   • `ถ้าไม่ก็` and `มิฉะนั้น` also accept `ดังนั้น` for chained guard expressions
#   • Demonstrates guard-return patterns, optional returns, and linear search
#
# Common mistakes:
#   • TODO: using `ดังนั้น` with a block instead of a single statement
#
# See also: ถ้า, ขณะ, ปิดล้อม, คืน, เงียบ
# =============================================================================

# Si with ดังนั้น คืน syntax
#
# ถ้า <conditio> ดังนั้น คืน <expressio>     -- guard return
# ถ้าไม่ก็ <conditio> ดังนั้น คืน <expressio>    -- else-if guard
# มิฉะนั้น ดังนั้น คืน <expressio>             -- else return
#
# GRAMMAR:
#   guardReturn :← ('ถ้า' | 'ถ้าไม่ก็' | 'มิฉะนั้น') expr 'ดังนั้น' 'คืน' 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: นัล when divisor is zero
fn divide(int a, int b) → int ∪ none {
    if b ≡ 0 then return null
    return a / b
}

# ถ้าไม่ก็ chain with มิฉะนั้น ดังนั้น คืน 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 วน ออก loop
fn inveni(list<int> res, int quaesitum) → int ∪ none {
    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)
    # นัล
    print divide(10, 0)

    # Letter grades via ถ้าไม่ก็ chain
    print gradus(95)
    print gradus(85)
    print gradus(55)

    # Linear search with early คืน
    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.

# =============================================================================
# ดังนั้น — Introduces a compact statement consequent.
# =============================================================================
#
# What this teaches:
#   • Inline conditionals — `ดังนั้น` replaces a single-statement block body on
#     `ถ้า` and `มิฉะนั้น` branches
#   • `ถ้า <cond> ดังนั้น <stmt> มิฉะนั้น ดังนั้น <stmt>` forms a two-way one-liner
#     without braces
#
# Common mistakes:
#   • TODO: chaining multiple statements after `ดังนั้น` (it accepts only one
#     statement)
#
# See also: ถ้า, ขณะ, ปิดล้อม, คืน, เงียบ
# =============================================================================

# One-liner conditionals with ดังนั้น
#
# ถ้า <condition> ดังนั้น <statement>                              -- single consequent
# ถ้า <condition> ดังนั้น <statement> มิฉะนั้น ดังนั้น <statement>     -- if-else one-liner
#
# GRAMMAR:
#   ifStmt :← 'ถ้า' expr 'ดังนั้น' stmt ('มิฉะนั้น' 'ดังนั้น' stmt)?
#
# EXPECTED OUTPUT:
#   Validation and grading lines for sample x, aetas, and puncta values.

main {
    # ดังนั้น replaces a one-statement block body
    const _ x ← 10

    if x ≻ 5 then print "x magnum est"

    # มิฉะนั้น ดังนั้น 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 → "ไม่ A")
    const _ puncta ← 85
    if puncta ≥ 90 then print "A"
    else then print "non A"

    # ตรรกะ condition used directly
    const _ valet ← true
    if valet then print "Recte"
}

Expected output:

x magnum est
adultus
non A
Recte