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

ลำดับ

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

Declares an enumeration.

Aliases: enum

Syntax: ลำดับ <name> <block>

Category#

type

Examples#

radix/corpus/ordo/ordo.fab (canonical · keyword)#

Declares an enumeration.

# =============================================================================
# ลำดับ — Declares an enumeration.
# =============================================================================
#
# What this teaches:
#   • Enumeration declaration — `ลำดับ <Name> { member, ... }` declares a set of ordered, named constants.
#   • Discriminant values — Members can have explicit numeric values with `= <number>`.
#   • Pattern matching — `เลือก` with `กรณี` branches selects on ลำดับ variants.
#
# Common mistakes:
#   • Confusing ลำดับ (enum with named constants) with สหภาพแยก (tagged union with payloads) — ลำดับ members carry no data.
#
# See also: สหภาพแยก
# =============================================================================

# ลำดับ — enumerated constants (ordered variants)
#
# ลำดับ <Nomen> { <membrum>, … }
# ลำดับ <Nomen> { <membrum> = <ค่า>, … }
#
# GRAMMAR:
#   ordoDecl :← 'ลำดับ' ident '{' ordoMember (',' ordoMember)* '}'
#
# EXPECTED OUTPUT:
#   rubrum
#   actum

enum Color {
    rubrum,
    viridis,
    caeruleum
}

enum Condicio {
    pendens = 0,
    actum = 1,
    finitum = 2
}

main {
    # Using ลำดับ values: members are qualified by their ลำดับ name
    const Color color ← Color.rubrum
    const Condicio condicio ← Condicio.actum

    # Select by ลำดับ
    switch color {
        case Color.rubrum {
            print "rubrum"
        }
        case Color.viridis {
            print "viridis"
        }
        case Color.caeruleum {
            print "caeruleum"
        }
    }

    # Select by ลำดับ with numeric values
    switch condicio {
        case Condicio.pendens {
            print "pendens"
        }
        case Condicio.actum {
            print "actum"
        }
        case Condicio.finitum {
            print "finitum"
        }
    }
}

Expected output:

rubrum
actum