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.

textus

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

Primitive string/text type.

Aliases: string

Syntax: string

Category#

type

Examples#

radix/corpus/reference/keyword/textus/textus-transformationes.fab (canonical · keyword)#

Primitive string/text type.

# =============================================================================
# string — Primitive string/text type
# =============================================================================
#
# What this teaches:
#   • Primitive string/text type.
#   • Related keywords: string, format, ↦
#
# Common mistakes:
#   • Using `string` transform methods on non-text types — `.slice()`, `.uppercase()`, `.lowercase()`, `.trim()`, `.split()`, `.replace()` are textus-only compiler intrinsics.
#
# See also: string, format, ↦
# =============================================================================

# string slice and transform intrinsics
#
# Compiler-owned string methodi — sectio, maiuscula, minuscula, recide,
# divide, muta.
#
# GRAMMAR:
#   s.slice(lo, hi) | s.uppercase() | s.lowercase() | s.trim()
#   s.split(sep) | s.replace(old, new)
#
# divide returns list<string>; pairs with list/ exempla for collection smoke.
# Derived locals use let so the transform chain needs no type annotations.
# Wasm tier Runnable.
#
# EXPECTED OUTPUT:
#   Smoke asserts exit 0 only.

main {
    let _ nuntius ← " Ave Roma "
    let _ secta ← nuntius.slice(1, 4)
    let _ magna ← nuntius.uppercase()
    let _ parva ← nuntius.lowercase()
    let _ rasa ← nuntius.trim()
    let _ partes ← rasa.split(" ")
    let _ mutata ← rasa.replace("Roma", "Munde")
    print secta, magna, parva
    print rasa, partes, mutata
}

Expected output:

Ave  AVE ROMA   ave roma
Ave Roma ["Ave", "Roma"] Ave Munde

radix/corpus/reference/reject/textus/conversio-textus-overflow-decline.fab (supporting · reject)#

Decline: a string literal longer than the target capacity rejects with textus_literal_too_long.

# =============================================================================
# string overflow decline — literal over capacity fails closed
# =============================================================================
#
# Decline row (reject reason in the comment):
#   1. over capacity — `"abcdef" ↦ string<size 4>` asks a 6-scalar literal to fit
#      a capacity of 4: SEM011 textus_literal_too_long
#
# Common mistakes:
#   • expecting silent truncation — the D7 overflow rule fails closed at
#     check for literals whose scalar count exceeds the target capacity
#
# See also: ↦, string
# =============================================================================

# string literal over capacity — expected compile failure
#
# WHY: pins the fail-closed overflow token in conversio-textus-overflow-decline.expected.

main {
    let string<size 4> t ← "abcdef" ↦ string<size 4>
    print t
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/textus/conversio-textus-to-ascii-decline.fab (supporting · reject)#

Decline: bounded string<size N> cannot convert directly to ascii<size M>.

# =============================================================================
# bounded string to ascii — unsupported conversion decline
# =============================================================================
#
# What this teaches:
#   • Unicode text and bounded ASCII have different conversion contracts.
#   • The unsupported route fails closed with `SEM016:unsupported_conversio`.
#
# Common mistakes:
#   • assuming every string value is ASCII-safe without an explicit narrowing
#     check.

fn narrow(string<size 8> raw) → ascii<size 4> {
    return raw ↦ ascii<size 4>
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/textus/conversio-textus-to-bounded-textus-decline.fab (supporting · reject)#

Decline: bounded string<size N> cannot resize directly to bounded string<size M>.

# =============================================================================
# bounded string resize — unsupported conversion decline
# =============================================================================
#
# What this teaches:
#   • Bounded string capacities are not interchangeable through a direct
#     resize conversion.
#   • The unsupported route fails closed with `SEM016:unsupported_conversio`.
#
# Common mistakes:
#   • expecting a resize to truncate Unicode scalars silently.

fn resize(string<size 8> raw) → string<size 4> {
    return raw ↦ string<size 4>
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/textus/conversio-textus-to-octeti-decline.fab (supporting · reject)#

Decline: bounded string<size N> cannot convert directly to list<b8, size M>.

# =============================================================================
# bounded string to list<b8, size M> — unsupported conversion decline
# =============================================================================
#
# What this teaches:
#   • A bounded text carrier does not become a bounded byte carrier through a
#     direct `↦` route.
#   • The unsupported route fails closed with `SEM016:unsupported_conversio`.
#
# Common mistakes:
#   • treating UTF-8 encoding as a width-only conversion.

fn encode(string<size 8> raw) → list<b8, size 8> {
    return raw ↦ list<b8, size 8>
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/textus/slice-unhandled-reject.fab (supporting · reject)#

A text slice outside main with no handler is refused: the window reports on the error channel.

# string reject case — an unhandled text slice is refused.
# `slice` reports an out-of-range window on the error channel, so a function
# that neither handles it (`⊥ default`, `do { } catch err { }`) nor declares
# its own `⇥` cannot call it. The checker names
# `failable_call_requires_handler`. This exemplum intentionally fails to check.

fn first(string s) → string {
    return s.slice(0, 1)
}

main {
    print first("abc")
}

Expected: compilation rejects this example.