Basic expression tutorial

The expression is the central entity of KFR framework.

Input expressions can be read from and output expressions can be written to. Class can be an input and output expression at same time. univector is an example of such class.

Data type of an input expressions can be determined by calling value_type_of. However, not all expressions have their types specified. In such cases value_type_of will return special type generic.

Size (length) of an expression also can be specified or not. counter is an example of generic (untyped) expression without the size.

Calling functions

Passing an expression into a function doesn’t calculate value immediately. Instead, new expression will be created.

Example:

In the example above, only the last line does actual calculations.
This is similar to concept of lazy evaluation.

counter()

counter() is an expression which outputs values from 0 to infinity.
This expression have no type specified, so can be used in any expression.

We will use the following simple function to print the first ten values of an expression:

Examples:

Leave a Reply

Your email address will not be published. Required fields are marked *