Generators

Efficiently process streams of data using lazy evaluation and bidirectional communication.

Basic Generator

KEIKAKU Protocol
1sequence count_up(start, end):
2 cycle from start to end as i:
3 yield i
4
5# Usage
6cycle through count_up(1, 5) as n:
7 declare("Count:", n)

Delegate (yield from)

KEIKAKU Protocol
1sequence subtask():
2 yield "a"
3 yield "b"
4
5sequence maintask():
6 yield "start"
7 delegate subtask() # Yields "a", "b"
8 yield "end"
9
10# Output: start, a, b, end

Generating Expressions

KEIKAKU Protocol
1items := [1, 2, 3, 4, 5]
2
3# Lazy squares
4squares := (x * x for x through items)
5
6# Filtered
7evens := (x for x through items where x % 2 == 0)
8
9cycle through evens as e:
10 declare(e)