12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <html lang="en">
- <head>
- <title>Byte Transducers - avram - a virtual machine code interpreter</title>
- <meta http-equiv="Content-Type" content="text/html">
- <meta name="description" content="avram - a virtual machine code interpreter">
- <meta name="generator" content="makeinfo 4.13">
- <link title="Top" rel="start" href="index.html#Top">
- <link rel="up" href="Filter-Mode-Interface.html#Filter-Mode-Interface" title="Filter Mode Interface">
- <link rel="prev" href="Line-Maps.html#Line-Maps" title="Line Maps">
- <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
- <meta http-equiv="Content-Style-Type" content="text/css">
- <style type="text/css"><!--
- pre.display { font-family:inherit }
- pre.format { font-family:inherit }
- pre.smalldisplay { font-family:inherit; font-size:smaller }
- pre.smallformat { font-family:inherit; font-size:smaller }
- pre.smallexample { font-size:smaller }
- pre.smalllisp { font-size:smaller }
- span.sc { font-variant:small-caps }
- span.roman { font-family:serif; font-weight:normal; }
- span.sansserif { font-family:sans-serif; font-weight:normal; }
- --></style>
- </head>
- <body>
- <div class="node">
- <a name="Byte-Transducers"></a>
- <p>
- Previous: <a rel="previous" accesskey="p" href="Line-Maps.html#Line-Maps">Line Maps</a>,
- Up: <a rel="up" accesskey="u" href="Filter-Mode-Interface.html#Filter-Mode-Interface">Filter Mode Interface</a>
- <hr>
- </div>
- <h4 class="subsection">2.5.3 Byte Transducers</h4>
- <p>The interface used when the <code>--byte-transducer</code> option is selected
- <a name="index-g_t_0040code_007bbyte_002dtransducer_007d-command-line-option-197"></a>allows an application to serve as a persistent stream processor suitable
- <a name="index-infinite-streams-198"></a>for finite or infinite streams. The interface can be summarized by the
- following points.
- <ul>
- <li>When it is first invoked, the function in the virtual code file is
- applied to an argument of <code>nil</code>, and is expected to return a pair
- <code>(</code><var>state</var><code>,</code><var>output</var><code>)</code>. The <var>state</var> format is
- unconstrained. The <var>output</var> must be a character string that will
- be written to standard output, but it may be the empty string.
- <li>For each byte read from standard input, <code>avram</code> applies the function
- to the pair <code>(</code><var>state</var><code>,</code><var>character</var><code>)</code>, using the state
- obtained from previous evaluation, and the character whose code is the
- byte. The purpose of the <var>state</var> field is therefore to provide a
- way for the application to remember something from one invocation to
- the next.
- <li>The function is usually expected to return a pair
- <code>(</code><var>state</var><code>,</code><var>output</var><code>)</code> 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.
- <li>If the function ever returns a value of <code>nil</code>, the computation
- terminates.
- <li>If standard input comes to an end before the computation terminates,
- the function will be applied to a pair of the form
- <code>(</code><var>state</var><code>,nil)</code> thereafter, but may continue to return
- <code>(</code><var>state</var><code>,</code><var>output</var><code>)</code> pairs for arbitrarily many more iterations.
- The <code>EOF</code> character is not explicitly passed to the function, but
- the end is detectable insofar as <code>nil</code> is not a representation for
- any character.
- </ul>
- <p>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
- <a name="index-Unix-199"></a>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 <a href="Character-Table.html#Character-Table">Character Table</a> for the
- <a name="index-character-codes-200"></a>representations of characters having these codes.
- </body></html>
|