Byte-Transducers.html 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <html lang="en">
  2. <head>
  3. <title>Byte Transducers - avram - a virtual machine code interpreter</title>
  4. <meta http-equiv="Content-Type" content="text/html">
  5. <meta name="description" content="avram - a virtual machine code interpreter">
  6. <meta name="generator" content="makeinfo 4.13">
  7. <link title="Top" rel="start" href="index.html#Top">
  8. <link rel="up" href="Filter-Mode-Interface.html#Filter-Mode-Interface" title="Filter Mode Interface">
  9. <link rel="prev" href="Line-Maps.html#Line-Maps" title="Line Maps">
  10. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  11. <meta http-equiv="Content-Style-Type" content="text/css">
  12. <style type="text/css"><!--
  13. pre.display { font-family:inherit }
  14. pre.format { font-family:inherit }
  15. pre.smalldisplay { font-family:inherit; font-size:smaller }
  16. pre.smallformat { font-family:inherit; font-size:smaller }
  17. pre.smallexample { font-size:smaller }
  18. pre.smalllisp { font-size:smaller }
  19. span.sc { font-variant:small-caps }
  20. span.roman { font-family:serif; font-weight:normal; }
  21. span.sansserif { font-family:sans-serif; font-weight:normal; }
  22. --></style>
  23. </head>
  24. <body>
  25. <div class="node">
  26. <a name="Byte-Transducers"></a>
  27. <p>
  28. Previous:&nbsp;<a rel="previous" accesskey="p" href="Line-Maps.html#Line-Maps">Line Maps</a>,
  29. Up:&nbsp;<a rel="up" accesskey="u" href="Filter-Mode-Interface.html#Filter-Mode-Interface">Filter Mode Interface</a>
  30. <hr>
  31. </div>
  32. <h4 class="subsection">2.5.3 Byte Transducers</h4>
  33. <p>The interface used when the <code>--byte-transducer</code> option is selected
  34. <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
  35. <a name="index-infinite-streams-198"></a>for finite or infinite streams. The interface can be summarized by the
  36. following points.
  37. <ul>
  38. <li>When it is first invoked, the function in the virtual code file is
  39. applied to an argument of <code>nil</code>, and is expected to return a pair
  40. <code>(</code><var>state</var><code>,</code><var>output</var><code>)</code>. The <var>state</var> format is
  41. unconstrained. The <var>output</var> must be a character string that will
  42. be written to standard output, but it may be the empty string.
  43. <li>For each byte read from standard input, <code>avram</code> applies the function
  44. to the pair <code>(</code><var>state</var><code>,</code><var>character</var><code>)</code>, using the state
  45. obtained from previous evaluation, and the character whose code is the
  46. byte. The purpose of the <var>state</var> field is therefore to provide a
  47. way for the application to remember something from one invocation to
  48. the next.
  49. <li>The function is usually expected to return a pair
  50. <code>(</code><var>state</var><code>,</code><var>output</var><code>)</code> for each input byte, so that the state
  51. can be used on the next iteration, and the output can be written to standard
  52. output as a character string.
  53. <li>If the function ever returns a value of <code>nil</code>, the computation
  54. terminates.
  55. <li>If standard input comes to an end before the computation terminates,
  56. the function will be applied to a pair of the form
  57. <code>(</code><var>state</var><code>,nil)</code> thereafter, but may continue to return
  58. <code>(</code><var>state</var><code>,</code><var>output</var><code>)</code> pairs for arbitrarily many more iterations.
  59. The <code>EOF</code> character is not explicitly passed to the function, but
  60. the end is detectable insofar as <code>nil</code> is not a representation for
  61. any character.
  62. </ul>
  63. <p>Unlike the situation with line maps, the output character strings
  64. do not have line breaks automatically appended, and the application must
  65. include them explicitly if required. The convention for
  66. <a name="index-Unix-199"></a>line breaks is system dependent. On Unix and GNU/Linux systems, character
  67. code 10 indicates a line break, but other systems may use character code
  68. 13 followed by character code 10. See <a href="Character-Table.html#Character-Table">Character Table</a> for the
  69. <a name="index-character-codes-200"></a>representations of characters having these codes.
  70. </body></html>