↤
Translation status: English reader-locale proof. Term names and code fences follow the en 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
Related#
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 — `const int n ↤ "42"` converts to the written
# type, then initializes the binding.
# • Inline recovery — `place ↤ value ⊥ fallback` stores the fallback only
# when the conversion fails.
# • Right-associated chains — `a ↤ b ↤ "42"` converts inner-to-outer and
# stores each link.
#
# Common mistakes:
# • using `↤` when the destination type is inferred — `const _ x ↤ …` is
# rejected (no concrete conversion target).
# • `⊥` default on ordinary `←` — legal only on `↤`; `⇥` never takes a value.
#
# See also: ←, ↦, ⊥, const, var
# =============================================================================
main {
# Expression assignment: "42" converts to int through the ↦ route.
var int count ← 0
count ↤ "42"
print count
# Typed initialization: convert to the written type, then initialize.
const int typed ↤ "7"
print typed
# Inline recovery: "x" cannot parse as int, so ⊥ 0 is stored.
var int recovered ← 0
recovered ↤ "x" ⊥ 0
print recovered
# Right-associated chain: inner b converts first, then the inner result
# feeds the outer conversion into a. Both links store 42.
var int a ← 0
var int b ← 0
a ↤ (b ↤ "42")
print a
print b
}Expected output:
42
7
0
42
42