渲染zh-Hant

↤

Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant pack; supporting prose may still be English.

Conversion-directed assignment: evaluate the right side, convert it to the statically known type of the left place through the ↦ route, then assign.

Aliases: conversion-directed-assignment, conversio assign

Syntax: <place> ↤ <expression> [⊥ <recovery>]

Category#

assignment

Examples#

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

Conversion-directed assignment: evaluate the right side, convert it to the statically known type of the left place through the ↦ route, then assign.

# =============================================================================
# ↤ — Conversion-directed assignment (U+21A4).
# =============================================================================
#
# What this teaches:
#   • Expression assignment — `place ↤ value` converts `value` to the place's
#     type through the existing `↦` route, then stores it exactly once.
#   • Typed initialization — `定值 整數 n ↤ "42"` converts to the written
#     type, then initializes the binding.
#   • Inline recovery — `place ↤ value ⊥ fallback` stores the fallback only
#     when the 變換 fails.
#   • Right-associated chains — `a ↤ b ↤ "42"` converts inner-to-outer and
#     stores each link.
#
# Common mistakes:
#   • using `↤` when the destination type is inferred — `定值 _ x ↤ …` is
#     rejected (no concrete 變換 target).
#   • `⊥` default on ordinary `←` — legal only on `↤`; `⇥` never takes a value.
#
# See also: ←, ↦, ⊥, 定值, 變值
# =============================================================================

入口 {
    # Expression assignment: "42" converts to 整數 through the ↦ route.
    變值 整數 count ← 0
    count ↤ "42"
    註記 count

    # Typed initialization: convert to the written type, then initialize.
    定值 整數 typed ↤ "7"
    註記 typed

    # Inline recovery: "x" cannot parse as 整數, so ⊥ 0 is stored.
    變值 整數 recovered ← 0
    recovered ↤ "x" ⊥ 0
    註記 recovered

    # Right-associated chain: inner b converts first, then the inner result
    # feeds the outer 變換 into a. Both links store 42.
    變值 整數 a ← 0
    變值 整數 b ← 0
    a ↤ (b ↤ "42")
    註記 a
    註記 b
}

Expected output:

42
7
0
42
42