Renderingen-US

↦

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

Converts a value with explicit runtime parsing or coercion semantics.

Aliases: convert, conversio

Syntax: <expression> ↦ <type> [⊥ <recovery>]

Category#

conversion

  • ∷
  • ⊥

Examples#

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

Converts a value with explicit runtime parsing or coercion semantics.

# =============================================================================
# ↦ — Converts a value with explicit runtime parsing or coercion semantics.
# =============================================================================
#
# What this teaches:
#   • Core conversion — the `↦` operator converts between types with explicit parsing (string→int) and coercion (int→string).
#   • Default with `⊥` — the `⊥` operator supplies a default value when conversion fails at runtime (`⇥` only names error types).
#   • Chaining — `↦` composes left-to-right for roundtrip conversions.
#
# Common mistakes:
#   • Confusing `∷` (compile-time type ascription) with `↦` (runtime conversion) and using `vel` instead of `⊥` for conversion recovery.
#
# See also: ∷, ⊥
# =============================================================================

# conversion — type conversion operator (↦)
#
# <expr> ↦ <type>
# <expr> ↦ <type><params>
#
# GRAMMAR:
#   convertExpr :← expr '↦' type
#
# EXPECTED OUTPUT:
#   conversio.expected
#
# BACKEND:
#   Siblings radix.fab and bivalens.fab compile-only until Go semantics align.

main {
    # ↦ converts string → int
    let n1 ← "42" ↦ int
    # ⊥ supplies a default on failure
    let n2 ← "invalid" ↦ int ⊥ 0
    let n3 ← "255" ↦ i32
    let f1 ← "3.14159" ↦ float
    let f2 ← "invalid" ↦ float ⊥ 0.0
    let s1 ← 42 ↦ string
    let s2 ← 3.14 ↦ string
    let s3 ← true ↦ string

    # chained ↦ left-to-right
    let roundtrip ← ("42" ↦ int) ↦ string
    print n1
    print n2
    print n3
    print f1
    print f2
    print s1
    print s2
    print s3
    print roundtrip
}

Expected output:

42
0
255
3.14159
0.0
42
3.14
true
42