Transfer.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <html lang="en">
  2. <head>
  3. <title>Transfer - 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="List-Combinators.html#List-Combinators" title="List Combinators">
  9. <link rel="prev" href="Sort.html#Sort" title="Sort">
  10. <link rel="next" href="Mapcur.html#Mapcur" title="Mapcur">
  11. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  12. <meta http-equiv="Content-Style-Type" content="text/css">
  13. <style type="text/css"><!--
  14. pre.display { font-family:inherit }
  15. pre.format { font-family:inherit }
  16. pre.smalldisplay { font-family:inherit; font-size:smaller }
  17. pre.smallformat { font-family:inherit; font-size:smaller }
  18. pre.smallexample { font-size:smaller }
  19. pre.smalllisp { font-size:smaller }
  20. span.sc { font-variant:small-caps }
  21. span.roman { font-family:serif; font-weight:normal; }
  22. span.sansserif { font-family:sans-serif; font-weight:normal; }
  23. --></style>
  24. </head>
  25. <body>
  26. <div class="node">
  27. <a name="Transfer"></a>
  28. <p>
  29. Next:&nbsp;<a rel="next" accesskey="n" href="Mapcur.html#Mapcur">Mapcur</a>,
  30. Previous:&nbsp;<a rel="previous" accesskey="p" href="Sort.html#Sort">Sort</a>,
  31. Up:&nbsp;<a rel="up" accesskey="u" href="List-Combinators.html#List-Combinators">List Combinators</a>
  32. <hr>
  33. </div>
  34. <h5 class="subsubsection">2.7.13.5 Transfer</h5>
  35. <p><a name="index-g_t_0040code_007btransfer_007d-331"></a>A particular interpretation is given to virtual code in the following form.
  36. <dl>
  37. <dt><em>T26</em><dd>[[<code>transfer</code>]] <var>f</var> = <code>((nil,nil),(nil,(nil,</code><var>f</var><code>)))</code>
  38. </dl>
  39. <p class="noindent">When code in this form is evaluated with an argument, the tree
  40. <a name="index-state-transition-function-332"></a><var>f</var> is used as a state transition function, and the argument
  41. is used as a list to be traversed. The traversal begins with
  42. <var>f</var> being evaluated on <code>nil</code> to get the initial state
  43. and the initial output. Thereafter, each item of the list is paired with
  44. the current state to be evaluated with <var>f</var>, resulting in a
  45. list of output and the next state. The output resulting from the entire
  46. application is the cumulative concatenation of all outputs obtained in
  47. the course of evaluating <var>f</var>. The computation
  48. terminates when <var>f</var> yields a <code>nil</code> result. If the list
  49. of inputs runs out before the computation terminates, <code>nil</code> values
  50. are used as inputs.
  51. <p>This behavior is specified more precisely in the following property
  52. of the operator, which applies in the case of non-<code>nil</code> <var>f</var>.
  53. <a name="index-g_t_0040code_007btransition_007d-333"></a>
  54. <dl>
  55. <dt><em>P33</em><dd>([[<code>transfer</code>]] <var>f</var>) <var>x</var> =
  56. ([[<code>transition</code>]] <var>f</var>) <code>(nil,(</code><var>f</var><code> nil,</code><var>x</var><code>))</code>
  57. </dl>
  58. <p>Much of the <code>transfer</code> semantics is implicit in the meaning of
  59. <code>transition</code>. For any given application <var>f</var>,
  60. [[<code>transition</code>]] <var>f</var> is the virtual code for a function
  61. that takes the list traversal from one configuration to the next.
  62. A configuration is represented as a tuple, usually in the form
  63. <code>(</code><var>previous outputs</var><code>,((</code><var>state</var><code>,</code><var>output</var><code>),(</code><var>next input</var><code>,</code><var>subsequent
  64. inputs</var><code>)))</code>. A terminal configuration has the form
  65. <code>(</code><var>previous outputs</var><code>,(nil,(</code><var>next input</var><code>,</code><var>subsequent
  66. inputs</var><code>)))</code>. A configuration may also have <code>nil</code> in place of the
  67. pair <code>(</code><var>next input</var><code>,</code><var>subsequent inputs</var><code>)</code> if no more input
  68. remains.
  69. <p>In the non-degenerate case, the meaning of [[<code>transition</code>]]
  70. <var>f</var> is consistent with the following equation.
  71. <dl>
  72. <dt><em>E7</em><dd>([[<code>transition</code>]] <var>f</var>) <code>(</code><var>y</var><code>,((</code><var>s</var><code>,</code><var>o</var><code>),(</code><var>i</var><code>,</code><var>x</var><code>)))</code> =<br>
  73. &nbsp;<!-- /@w -->&nbsp;<!-- /@w -->&nbsp;<!-- /@w -->&nbsp;<!-- /@w -->([[<code>transition</code>]] <var>f</var>) <code>((</code><var>o</var><code>,</code><var>y</var><code>),(</code><var>f</var><code> (</code><var>s</var><code>,</code><var>i</var><code>),</code><var>x</var><code>))</code>
  74. </dl>
  75. <p class="noindent">That is, the current output <var>o</var> is stored with previous outputs <var>y</var>, the next
  76. input <var>i</var> is removed from the configuration, and the next state and output
  77. are obtained from the evaluation of <var>f</var> with the state <var>s</var> and
  78. the next input <var>i</var>.
  79. <p>In the case where no input remains, the transition function is
  80. consistent with the following equation.
  81. <dl>
  82. <dt><em>E8</em><dd>([[<code>transition</code>]] <var>f</var>) <code>(</code><var>y</var><code>,((</code><var>s</var><code>,</code><var>o</var><code>),nil))</code> = <br>
  83. &nbsp;<!-- /@w -->&nbsp;<!-- /@w -->&nbsp;<!-- /@w -->&nbsp;<!-- /@w -->([[<code>transition</code>]] <var>f</var>) <code>((</code><var>o</var><code>,</code><var>y</var><code>),(</code><var>f</var><code> (</code><var>s</var><code>,nil),nil))</code>
  84. </dl>
  85. <p class="noindent">This case is similar to the previous one except that the <code>nil</code>
  86. value is used in place of the next input. Note that in either case,
  87. nothing about <var>f</var> depends on the particular way
  88. configurations are represented, except that it should have a state as
  89. its left argument and an input as its right argument.
  90. <p>Finally, in the case of a terminal configuration, the transition
  91. function returns the cumulative output.
  92. <dl>
  93. <dt><em>E9</em><dd>([[<code>transition</code>]] <var>f</var>) <code>(</code><var>y</var><code>,(nil,</code><var>x</var><code>))</code> =
  94. [[<code>reduce(cat,nil)</code>]] [[<code>reverse</code>]] <var>y</var>
  95. </dl>
  96. <p class="noindent">The <code>silly</code> code <code>reduce(cat,nil)</code> has the effect of
  97. <a name="index-g_t_0040code_007bcat_007d-334"></a><a name="index-concatenation-335"></a>flattening a list of lists into one long list, which is necessary
  98. insofar as the transition function will have generated not necessarily a
  99. single output but a list of outputs on each iteration. The <code>cat</code>
  100. mnemonic stands for list concatenation and is explained in <a href="Cat.html#Cat">Cat</a>.
  101. The reversal is necessary to cause the first generated output to be at
  102. the head of the list. List reversal is a built in operation of the
  103. virtual machine and is described in <a href="Reverse.html#Reverse">Reverse</a>.
  104. <p>If such a function as <code>transition</code> seems implausible, its
  105. implementation in <code>silly</code> can be found in <a href="Transition.html#Transition">Transition</a>.
  106. <p>It is usually more awkward to express a function in terms of
  107. a <code>transfer</code> than to code it directly using recursion or other list
  108. operations. However, this feature is provided by the virtual machine for
  109. several reasons.
  110. <ul>
  111. <li>Functions in this form may be an easier translation target if the
  112. source is an imperative language.
  113. <li>Translating from virtual code to asynchronous circuits or process
  114. <a name="index-asynchronous-circuits-336"></a>networks has been a research interest of the author, and code in this
  115. <a name="index-author-337"></a>form lends itself to easy recognition and mapping onto discrete components.
  116. <li>The <samp><span class="option">--byte-transducer</span></samp> and <samp><span class="option">--interactive</span></samp> command
  117. line options to <code>avram</code> cause an application to be invoked in a
  118. <a name="index-state-transition-function-338"></a>similar manner to the transition function in a <code>transfer</code>
  119. function, so this feature allows for easy simulation and troubleshooting
  120. of these applications without actually deploying them.
  121. </ul>
  122. </body></html>