渲染zh-Hans

让出

Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans 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]