渲染zh-Hant

迭代器

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

Compatibility annotation for stream/generator posture.

Syntax: @ 迭代器

Category#

async

Examples#

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

Compatibility annotation for stream/generator posture.

# =============================================================================
# 迭代器 — Compatibility annotation for stream/generator posture.
# =============================================================================
#
# What this teaches:
#   • Preferred stream posture — write `流` for a synchronous stream or
#     `異流` for an asynchronous stream.
#   • Compatibility annotation — `@ 迭代器` remains accepted and preserved as
#     the legacy spelling for stream/generator posture.
#
# Common mistakes:
#   • Using `讓出` outside a stream body — `讓出` is valid only inside `流`
#     or `異流` bodies, including compatible `@ 迭代器` declarations.
#
# See also: 流, 異流, 讓出
# =============================================================================

# 迭代器 — compatibility stream annotation
#
# GRAMMAR:
#   annotation :← '@' '迭代器'
#   callablePosture :← '流' | '異流'
#
# EXPECTED OUTPUT:
#   Scalar stdout smoke (see body).
#
# BACKEND:
#   Cross-ref: 未來/futura.fab, 遍歷/cursor-iteratio.fab; Go whitelist: 迭代器/cursor.fab.
#

@ 迭代器 { }
fn stream() → int {
    yield 1
    yield 2
}

main {
    print stream()
}

Expected output:

[1, 2]