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.

←

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

Assigns a value to a binding, field, or assignable expression.

Aliases: assignment, assign

Syntax: <place> ← <expression>

Category#

binding

Examples#

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

Assigns a value to a binding, field, or assignable expression.

# =============================================================================
# ← — Assigns a value to a binding, field, or assignable expression.
# =============================================================================
#
# What this teaches:
#   • Explicit assignment — `place ← expression` rebinds a mutable variable
#     to a new value
#   • Compound operations — arithmetic expressions like `x ← x + 5` replace
#     removed compound assignment glyphs
#   • Postfix increment — `↑` and `↓` provide unit increment/decrement as
#     standalone statements
#
# Common mistakes:
#   • using `=` instead of `←` for assignment — `=` is structural field initialization in records, `←` is value assignment
#
# See also: =, const, mut, ↑, ↓
# =============================================================================

# assignatio — simple explicit assignment
#
# <place> ← <expression>
#
# Compound assignment glyphs were removed. Use explicit assignment, or postfix
# ↑ / ↓ for unit increment/decrement (see incrementa/incrementa.fab).
#
# EXPECTED OUTPUT:
#   20
#   25
#   15
#   30
#   10
#   salve munde

main {
    mut int x ← 10
    x ← 20
    # 20
    print x
    x ← x + 5
    # 25
    print x
    x ← x - 10
    # 15
    print x
    x ← x * 2
    # 30
    print x
    x ← x / 3
    # 10
    print x
    mut string s ← "salve"
    s ← s + " munde"
    # salve munde
    print s
}

Expected output:

20
25
15
30
10
salve munde

radix/corpus/reference/reject/assign/assignment-type-reject.fab (supporting · reject)#

Assigning a value of the wrong type is refused by name.

# =============================================================================
# ← — Assigning a value of the wrong type is refused by name.
# =============================================================================
#
# What this teaches:
#   • the declared type of a binding is the type of every later store
#   • `←` checks the value against the place; it does not retype the place
#
# Common mistakes:
#   • storing a string into an `int` binding — `assignment_type_mismatch`
#
# See also: assignatio, const
# =============================================================================

# assignatio reject case — expected compile failure
#
# This exemplum intentionally fails to compile.

main {
    mut int x ← 1
    x ← "s"
    print x
}

Expected: compilation rejects this example.