IncrementalFunction[fun]
represents a compilable function that can pause its execution, storing its state to be resumed later.


IncrementalFunction
IncrementalFunction[fun]
represents a compilable function that can pause its execution, storing its state to be resumed later.
Details

- Incremental functions have to be processed by compiler functions such as FunctionCompile.
- An active incremental function is held with a data structure of type "IncrementalFunction".
- In compiled code, an incremental function is held as an "IncrementalFunction" type.
- Incremental functions can return incremental results with IncrementalYield.
- When the "Send" operation is used to resume an incremental function, the value is accepted with IncrementalReceive.
- Incremental functions can receive incremental values with IncrementalReceive.
- An incremental function does not ever need to finish executing.
- An incremental function can incrementally return a sequence of results.
- An incremental function that reaches the end of its code cannot be resumed.
- When the data structure that holds a running incremental function is no longer used, the function is terminated and any resources it holds are released.
- Any number of instances of an incremental function can be active at any one time.
- An incremental function can recursively call itself or other incremental functions.
- An active incremental function ds can be restarted with ds["Next"] and ds["Send",x].
Examples
open all close allBasic Examples (2)
An incremental function that has one yield:
A CompiledCodeFunction that returns an "IncrementalFunction" data structure:
Create an instance of the incremental function:
Run the incremental function to the IncrementalYield and return the partial result:
The incremental function has finished, so calling the "Next" operation results in a failure:
An incremental function that returns a sequence of multiples of its argument:
An instance of the incremental function that returns multiples of 7:
The first result from the incremental function:
A different instance of the incremental function that returns multiples of 17:
The first 100 multiples of 17:
The function that is returning multiples of 7 is still waiting to be woken up and return results:
Scope (2)
An incremental function can be used in a FunctionDeclaration, and in this way can call itself:
Create a running incremental function with an expression input:
This function will yield the elements of the input expression in a depth-first fashion:
An incremental function must use the Wolfram Compiler, but it can work with Wolfram expressions:
A running incremental function that will open a file and yield increments of data:
A different running instance of the same incremental function that reads data in a different way:
See Also
Function Typed FunctionCompile FunctionDeclaration IncrementalYield IncrementalReceive
Compiled Types: IncrementalFunction
Tech Notes
Related Guides
History
Text
Wolfram Research (2025), IncrementalFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/IncrementalFunction.html.
CMS
Wolfram Language. 2025. "IncrementalFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/IncrementalFunction.html.
APA
Wolfram Language. (2025). IncrementalFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/IncrementalFunction.html
BibTeX
@misc{reference.wolfram_2025_incrementalfunction, author="Wolfram Research", title="{IncrementalFunction}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/IncrementalFunction.html}", note=[Accessed: 04-August-2025]}
BibLaTeX
@online{reference.wolfram_2025_incrementalfunction, organization={Wolfram Research}, title={IncrementalFunction}, year={2025}, url={https://reference.wolfram.com/language/ref/IncrementalFunction.html}, note=[Accessed: 04-August-2025]}