[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 2.5.3 Byte Transducers

The interface used when the `--byte-transducer` option is selected allows an application to serve as a persistent stream processor suitable for finite or infinite streams. The interface can be summarized by the following points.

- When it is first invoked, the function in the virtual code file is applied to an argument of `nil`, and is expected to return a pair `(state,output)`. The state format is unconstrained. The output must be a character string that will be written to standard output, but it may be the empty string.
- For each byte read from standard input, `avram` applies the function to the pair `(state,character)`, using the state obtained from previous evaluation, and the character whose code is the byte. The purpose of the state field is therefore to provide a way for the application to remember something from one invocation to the next.
- The function is usually expected to return a pair `(state,output)` for each input byte, so that the state can be used on the next iteration, and the output can be written to standard output as a character string.
- If the function ever returns a value of `nil`, the computation terminates.
- If standard input comes to an end before the computation terminates, the function will be applied to a pair of the form `(state,nil)` thereafter, but may continue to return `(state,output)` pairs for arbitrarily many more iterations. The `EOF` character is not explicitly passed to the function, but the end is detectable insofar as `nil` is not a representation for any character.

Unlike the situation with line maps, the output character strings do not have line breaks automatically appended, and the application must include them explicitly if required. The convention for line breaks is system dependent. On Unix and GNU/Linux systems, character code 10 indicates a line break, but other systems may use character code 13 followed by character code 10. See Character Table for the representations of characters having these codes.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated on November 8, 2012 using texi2html 1.82.