渲染zh-Hant

讓出

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

Yields one value from a generator.

Aliases: yield

Syntax: 讓出 <expression>

Category#

async

Examples#

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

Yields one value from a generator.

# =============================================================================
# 讓出 — Yields one value from a generator.
# =============================================================================
#
# What this teaches:
#   • Yield — `讓出 <expression>` emits one item from a `流` or `異流`
#     callable
#   • Async values use `等定`, `等變`, `等返`, or `等棄`; `讓出`
#     is not an await form
#
# Common mistakes:
#   • using `讓出` outside a generator body
#
# See also: 迭代器, 流, 異流
# =============================================================================

# 讓出 — yield from a stream function
#
# 函式 stream() 流 → T { 讓出 value }
#
# GRAMMAR:
#   yieldStmt :← '讓出' expr
#
# EXPECTED OUTPUT:
#   [1, 2]
#
# BACKEND:
#   Cursor stream materialization smoke.

fn stream() generator → int {
    yield 1
    yield 2
}

main {
    print stream()
}

Expected output:

[1, 2]