Variable-Freedom.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
  2. <html>
  3. <!-- Created on December 10, 2012 by texi2html 1.82
  4. texi2html was written by:
  5. Lionel Cons <[email protected]> (original author)
  6. Karl Berry <[email protected]>
  7. Olaf Bachmann <[email protected]>
  8. and many others.
  9. Maintained by: Many creative people.
  10. Send bugs and suggestions to <[email protected]>
  11. -->
  12. <head>
  13. <title>avram - a virtual machine code interpreter: 2.7.6 Variable Freedom</title>
  14. <meta name="description" content="avram - a virtual machine code interpreter: 2.7.6 Variable Freedom">
  15. <meta name="keywords" content="avram - a virtual machine code interpreter: 2.7.6 Variable Freedom">
  16. <meta name="resource-type" content="document">
  17. <meta name="distribution" content="global">
  18. <meta name="Generator" content="texi2html 1.82">
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <style type="text/css">
  21. <!--
  22. a.summary-letter {text-decoration: none}
  23. blockquote.smallquotation {font-size: smaller}
  24. pre.display {font-family: serif}
  25. pre.format {font-family: serif}
  26. pre.menu-comment {font-family: serif}
  27. pre.menu-preformatted {font-family: serif}
  28. pre.smalldisplay {font-family: serif; font-size: smaller}
  29. pre.smallexample {font-size: smaller}
  30. pre.smallformat {font-family: serif; font-size: smaller}
  31. pre.smalllisp {font-size: smaller}
  32. span.roman {font-family:serif; font-weight:normal;}
  33. span.sansserif {font-family:sans-serif; font-weight:normal;}
  34. ul.toc {list-style: none}
  35. -->
  36. </style>
  37. </head>
  38. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  39. <a name="Variable-Freedom"></a>
  40. <table cellpadding="1" cellspacing="1" border="0">
  41. <tr><td valign="middle" align="left">[<a href="How-avram-Thinks.html#How-avram-Thinks" title="Previous section in reading order"> &lt; </a>]</td>
  42. <td valign="middle" align="left">[<a href="Metrics-and-Maintenance.html#Metrics-and-Maintenance" title="Next section in reading order"> &gt; </a>]</td>
  43. <td valign="middle" align="left"> &nbsp; </td>
  44. <td valign="middle" align="left">[<a href="Virtual-Machine-Specification.html#Virtual-Machine-Specification" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  45. <td valign="middle" align="left">[<a href="Virtual-Code-Semantics.html#Virtual-Code-Semantics" title="Up section"> Up </a>]</td>
  46. <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Next chapter"> &gt;&gt; </a>]</td>
  47. <td valign="middle" align="left"> &nbsp; </td>
  48. <td valign="middle" align="left"> &nbsp; </td>
  49. <td valign="middle" align="left"> &nbsp; </td>
  50. <td valign="middle" align="left"> &nbsp; </td>
  51. <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
  52. <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
  53. <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
  54. <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
  55. </tr></table>
  56. <hr size="1">
  57. <a name="Variable-Freedom-1"></a>
  58. <h3 class="subsection">2.7.6 Variable Freedom</h3>
  59. <p>The virtual code semantics is easier to specify using the
  60. <code>silly</code> language than it would be without it, but still awkward in
  61. some cases. An example is the following declaration from the standard
  62. library,
  63. <a name="index-hired"></a>
  64. </p>
  65. <table><tr><td>&nbsp;</td><td><pre class="example">hired = compose(
  66. compose,
  67. couple(
  68. constant compose,
  69. compose(couple,couple(constant,constant couple))))
  70. </pre></td></tr></table>
  71. <p>which is constructed in such a way as to imply the following theorem,
  72. provable by routine computation.
  73. </p>
  74. <dl compact="compact">
  75. <dt> <em>T9</em></dt>
  76. <dd><p><code>(</code>[[<code>hired</code>]] <code><var>h</var>) (<var>f</var>,<var>g</var>)</code> = [[<code>compose</code>]]<code>(<var>h</var>,</code>[[<code>couple</code>]]<code>(<var>f</var>,<var>g</var>))</code>
  77. </p></dd>
  78. </dl>
  79. <p>Intuitively, <code>hired</code> represents a function that takes a given
  80. function to a higher order function. For example, if <code>f</code> were a
  81. function that adds two real numbers, <code>hired f</code> would be a function that
  82. takes two real valued functions to their pointwise sum.
  83. </p>
  84. <p>Apart from its cleverness, such an opaque way of defining a function has
  85. little to recommend it. The statement of the theorem about the function
  86. is more readable than the function definition itself, probably because
  87. the theorem liberally employs mathematical variables, whereas the
  88. <code>silly</code> language is variable free. On the other hand, it is not
  89. worthwhile to linger over further enhancements to the language, such as
  90. adding variables to it. The solution will be to indicate informally a
  91. general method of inferring a variable free function definition from an
  92. expression containing variables, and hereafter omit the more
  93. cumbersome definitions.
  94. </p>
  95. <a name="index-isolate"></a>
  96. <a name="index-variables"></a>
  97. <p>An algorithm called <code>isolate</code> does the job.
  98. The input to <code>isolate</code> is a pair <code>(<var>e</var>,<var>x</var>)</code>, where
  99. <code><var>e</var></code> is a syntactically correct <code>silly</code> expression in
  100. which the identifier <code><var>x</var></code> may occur, but no other identifiers
  101. dependent on <code><var>x</var></code> may occur (or else it&rsquo;s
  102. garbage-in/garbage-out). Output is a syntactically correct <code>silly</code>
  103. expression <code><var>f</var></code> in which the identifier <code><var>x</var></code> does
  104. not occur, such that [[<code><var>e</var></code>]] = [[<code><var>f</var> <var>x</var></code>]].
  105. The algorithm is as follows,
  106. </p>
  107. <table><tr><td>&nbsp;</td><td><pre class="display">
  108. if <code><var>e</var></code> = <code><var>x</var></code> then
  109. return <code>identity</code>
  110. else if <code><var>e</var></code> is of the form <code>(<var>u</var>,<var>v</var>)</code>
  111. return <code>couple(isolate(<var>u</var>,<var>x</var>),isolate(<var>v</var>,<var>x</var>))</code>
  112. else if <code><var>e</var></code> is of the form <code><var>u</var> <var>v</var></code>
  113. return <code>(hired apply)(isolate(<var>u</var>,<var>x</var>),isolate(<var>v</var>,<var>x</var>))</code>
  114. else
  115. return <code>constant <var>e</var></code>
  116. </pre></td></tr></table>
  117. <a name="index-equality-1"></a>
  118. <p>where equality is by literal comparison of expressions, and the
  119. definition of <code>apply</code> is
  120. <a name="index-apply"></a>
  121. </p>
  122. <table><tr><td>&nbsp;</td><td><pre class="example">apply = (hired meta)((hired compose)(left,constant right),right)
  123. </pre></td></tr></table>
  124. <p>which represents a function that does the same thing as the invisible
  125. operator.
  126. </p>
  127. <dl compact="compact">
  128. <dt> <em>T10</em></dt>
  129. <dd><p>[[<code>apply</code>]] <code>(<var>f</var>,<var>x</var>)</code> = <code><var>f</var> <var>x</var></code>
  130. </p></dd>
  131. </dl>
  132. <p>The <code>isolate</code> algorithm can be generalized to functions of
  133. arbitrarily many variables, but in this document we will need
  134. only a unary and a binary version. The latter takes an expression
  135. <code><var>e</var></code> and a pair of identifiers <code>(<var>x</var>,<var>y</var>)</code> as
  136. input, and returns an expression <code><var>f</var></code> such that
  137. [[<code><var>e</var></code>]] = [[<code><var>f</var> (<var>x</var>,<var>y</var>)</code>]].
  138. </p>
  139. <table><tr><td>&nbsp;</td><td><pre class="display">
  140. if <code><var>e</var></code> = <code><var>x</var></code> then
  141. return <code>left</code>
  142. else if <code><var>e</var></code> = <code><var>y</var></code> then
  143. return <code>right</code>
  144. else if <code><var>e</var></code> is of the form <code>(<var>u</var>,<var>v</var>)</code>
  145. return <code>couple(isolate(<var>u</var>,(<var>x</var>,<var>y</var>)),isolate(<var>v</var>,(<var>x</var>,<var>y</var>)))</code>
  146. else if <code><var>e</var></code> is of the form <code><var>u</var> <var>v</var></code>
  147. return <code>(hired apply)(isolate(<var>u</var>,(<var>x</var>,<var>y</var>)),isolate(<var>v</var>,(<var>x</var>,<var>y</var>)))</code>
  148. else
  149. return <code>constant <var>e</var></code>
  150. </pre></td></tr></table>
  151. <p>It might be noted in passing that something similar to these algorithms
  152. would be needed in a compiler targeted to <code>avram</code> if the source
  153. were a functional language with variables.
  154. </p>
  155. <hr size="1">
  156. <table cellpadding="1" cellspacing="1" border="0">
  157. <tr><td valign="middle" align="left">[<a href="How-avram-Thinks.html#How-avram-Thinks" title="Previous section in reading order"> &lt; </a>]</td>
  158. <td valign="middle" align="left">[<a href="Metrics-and-Maintenance.html#Metrics-and-Maintenance" title="Next section in reading order"> &gt; </a>]</td>
  159. <td valign="middle" align="left"> &nbsp; </td>
  160. <td valign="middle" align="left">[<a href="Virtual-Machine-Specification.html#Virtual-Machine-Specification" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  161. <td valign="middle" align="left">[<a href="Virtual-Code-Semantics.html#Virtual-Code-Semantics" title="Up section"> Up </a>]</td>
  162. <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Next chapter"> &gt;&gt; </a>]</td>
  163. <td valign="middle" align="left"> &nbsp; </td>
  164. <td valign="middle" align="left"> &nbsp; </td>
  165. <td valign="middle" align="left"> &nbsp; </td>
  166. <td valign="middle" align="left"> &nbsp; </td>
  167. <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
  168. <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
  169. <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
  170. <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
  171. </tr></table>
  172. <p>
  173. <font size="-1">
  174. This document was generated on <i>December 10, 2012</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 1.82</i></a>.
  175. </font>
  176. <br>
  177. </p>
  178. </body>
  179. </html>