Skip to content

Generate stream items from expressions - #19

Draft
scothis wants to merge 1 commit into
componentized:mainfrom
scothis:stream
Draft

scothis wants to merge 1 commit into
componentized:mainfrom
scothis:stream

Conversation

@scothis

@scothis scothis commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Functions can return a stream, its items listed with @value, written as
the caller reads them. Streams of integers, floats or bool can continue with
items generated by an @expression, a closure in a subset of Rust, from the
items before them, the function's arguments, and their position.

  • stream results: an empty stream from any function, a stream with items
    from an async function, written by a task lifted with a callback, nothing
    added to components without streams
  • @expression closures over the previous items, starting from the @value
    items, or from the function's arguments, as items or as inputs read by
    name or through $init, with $call for the closure's parameters and $i for
    the position
  • typed expressions: literals typed by context, as casts, wrapping
    operators (+% -% *% /% %% <<% >>% **% -%), ** for powers, methods,
    let and let mut bindings, assignments, if, while loops, and arrays
    or to_le_bytes/to_be_bytes generating several items at once
  • a stream ends when its next item can't be represented, as Rust's checked
    arithmetic would fail, or runs until the reader closes it
  • at most one @value and one @expression per doc comment
  • a tree-sitter grammar for expressions, tested against the same corpus as
    the parser, and a specification for language servers, with a guide in
    docs/expressions.md
  • math streams: odd, even, arithmetic, geometric, fibonacci, factorial,
    harmonic, figurate and prime, and new atomics and random components
  • test-cli, composing test-cli-core with the data components, to call their
    functions from the command line with wasmtime run, reading streams as
    stdin asks

Functions can return a stream<T>, its items listed with @value, written as
the caller reads them. Streams of integers, floats or bool can continue with
items generated by an @expression, a closure in a subset of Rust, from the
items before them, the function's arguments, and their position.

- stream<T> results: an empty stream from any function, a stream with items
  from an async function, written by a task lifted with a callback, nothing
  added to components without streams
- @expression closures over the previous items, starting from the @value
  items, or from the function's arguments, as items or as inputs read by
  name or through $init, with $call for the closure's parameters and $i for
  the position
- typed expressions: literals typed by context, `as` casts, wrapping
  operators (+% -% *% /% %% <<% >>% **% -%), `**` for powers, methods,
  `let` and `let mut` bindings, assignments, `if`, `while` loops, and arrays
  or to_le_bytes/to_be_bytes generating several items at once
- a stream ends when its next item can't be represented, as Rust's checked
  arithmetic would fail, or runs until the reader closes it
- at most one @value and one @expression per doc comment
- a tree-sitter grammar for expressions, tested against the same corpus as
  the parser, and a specification for language servers, with a guide in
  docs/expressions.md
- math streams: odd, even, arithmetic, geometric, fibonacci, factorial,
  harmonic, figurate and prime, and new atomics and random components
- test-cli, composing test-cli-core with the data components, to call their
  functions from the command line with wasmtime run, reading streams as
  stdin asks

Signed-off-by: Scott Andrews <scott@andrews.me>
@scothis scothis changed the title Allow top-level stream<T> values Generate stream items from expressions Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant