渲染zh-Hant

傳入

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

Marks a mutable borrowed parameter.

Syntax: in <type> <name>

Category#

function

Examples#

radix/corpus/in/in.fab (canonical · keyword)#

Marks a mutable borrowed parameter.

# =============================================================================
# in — Marks a mutable borrowed parameter
# =============================================================================
#
# What this teaches:
#   • Marks a mutable borrowed parameter.
#   • Related keywords: 從, 取自
#
# Common mistakes:
#   • Mode mismatch — passing a `從` (read-only) value to an `傳入` position, or using `傳入` to mutate a parameter declared as `從` (SEM057).
#
# See also: 從, 取自
# =============================================================================

# in — value parameter passing mode
#
# GRAMMAR:
#   paramMode :← 'in' type
#
# EXPECTED OUTPUT:
#   Scalar stdout smoke (see body).
#
# BACKEND:
#   Cross-ref: 函式/in-ex.fab.
#

fn 求和(mut list<int> values) → int {
    return values.sum()
}

main {
    const _ xs ← [1, 2, 3]
    print 求和(xs)
}

Expected output:

6