Representation-of-Numeric-and-Textual-Data.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.4 Representation of Numeric and Textual Data</title>
  14. <meta name="description" content="avram - a virtual machine code interpreter: 2.4 Representation of Numeric and Textual Data">
  15. <meta name="keywords" content="avram - a virtual machine code interpreter: 2.4 Representation of Numeric and Textual Data">
  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="Representation-of-Numeric-and-Textual-Data"></a>
  40. <table cellpadding="1" cellspacing="1" border="0">
  41. <tr><td valign="middle" align="left">[<a href="Data-Section.html#Data-Section" title="Previous section in reading order"> &lt; </a>]</td>
  42. <td valign="middle" align="left">[<a href="Filter-Mode-Interface.html#Filter-Mode-Interface" 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-Machine-Specification.html#Virtual-Machine-Specification" 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="Representation-of-Numeric-and-Textual-Data-1"></a>
  58. <h2 class="section">2.4 Representation of Numeric and Textual Data</h2>
  59. <p>As noted already, virtual code applications are specified by functions
  60. operating on elements of a set having the properties described in
  61. <a href="Raw-Material.html#Raw-Material">Raw Material</a>, which are convenient to envision as ordered binary trees or
  62. <a name="index-trees-2"></a>
  63. <a name="index-nil-1"></a>
  64. pairs of <code>nil</code>. However, virtual code applications normally deal
  65. with numeric or textual data, for example when they refer to the
  66. contents of a text file. It is therefore necessary for the application
  67. and the virtual machine emulator to agree on a way of describing textual
  68. or numeric data with these trees.
  69. </p>
  70. <p>The purpose of this section is to explain the basic data structures used
  71. in the exchange of information between <code>avram</code> and a virtual code
  72. application. For example, an explanation is needed for statements like
  73. &ldquo;an application invoked with the &lsquo;<samp>--baz</samp>&rsquo; option is expected to
  74. return a pair <code>(<var>foo</var>,<var>bar</var>)</code>, where <code><var>foo</var></code> is a
  75. <a name="index-strings"></a>
  76. <a name="index-character-strings"></a>
  77. <a name="index-lists-2"></a>
  78. list of character strings &hellip;&rdquo;, that are made subsequently in this
  79. document. Such statements should be understood as referring to the trees
  80. representing the pairs, lists, character strings, etc., according to the
  81. conventions explained below.
  82. </p>
  83. <dl compact="compact">
  84. <dt> <em>Characters</em></dt>
  85. <dd><a name="index-character-codes-1"></a>
  86. <p>An arbitrarily chosen set of 256 trees is used to represent the
  87. character set. They are listed in <a href="Character-Table.html#Character-Table">Character Table</a>. For example,
  88. the letter <code>A</code> is represented by
  89. <code>(nil,(((nil,(nil,(nil,nil))),nil),(nil,nil)))</code>. That means that
  90. when an application wants the letter <code>A</code> written to a text file, it
  91. returns something with this tree in it.
  92. </p></dd>
  93. <dt> <em>Booleans</em></dt>
  94. <dd><a name="index-booleans"></a>
  95. <p>The value of <code>false</code> is represented by <code>nil</code>, and the value of
  96. <code>true</code> is represented by <code>(nil,nil)</code>.
  97. </p></dd>
  98. <dt> <em>Pairs</em></dt>
  99. <dd><a name="index-pairs"></a>
  100. <p>Given any two items of data <var>x1</var> and <var>x2</var>, having the respective
  101. representations <var>r1</var> and <var>r2</var>, the pair <code>(<var>x1</var>,<var>x2</var>)</code> has the
  102. representation <code>cons(<var>r1</var>,<var>r2</var>)</code>.
  103. </p></dd>
  104. <dt> <em>Lists</em></dt>
  105. <dd><a name="index-lists-3"></a>
  106. <p>A list of the items <var>x1</var>, <var>x2</var> &hellip; <var>xn</var> with respective
  107. representations <var>r1</var> through <var>rn</var> is represented by the tree
  108. <code>cons(<var>r1</var>,cons(<var>r2</var>&hellip;cons(<var>rn</var>,nil)&hellip;))</code>. In other words,
  109. lists are represented as pairs whose left sides are the heads and whose
  110. right sides are the tails. The empty list is identified with
  111. <code>nil</code>. Lists of arbitrary finite length can be accommodated.
  112. </p></dd>
  113. <dt> <em>Naturals</em></dt>
  114. <dd><a name="index-naturals"></a>
  115. <p>A number of the form <code><var>b0</var> + 2<var>b1</var> + 4<var>b2</var> + &hellip; +
  116. 2^n <var>bn</var></code>, where each <code><var>b</var>i</code> is <code>0</code> or <code>1</code>, is
  117. represented by a tree of the form
  118. <code>cons(<var>t0</var>,cons(<var>t1</var>&hellip;cons(<var>tn</var>,nil)&hellip;))</code>
  119. where each <code><var>t</var>i</code> is <code>nil</code> if the corresponding
  120. <code><var>b</var>i</code> is <code>0</code>, and <code>(nil,nil)</code> otherwise. Note that
  121. the numbers <code><var>b</var>i</code> are exactly the bits written in the binary
  122. expansion of the number, with <code><var>b0</var></code> being the least significant
  123. bit.
  124. </p></dd>
  125. <dt> <em>Strings</em></dt>
  126. <dd><a name="index-strings-1"></a>
  127. <a name="index-character-strings-1"></a>
  128. <p>are represented as lists of characters.
  129. </p></dd>
  130. </dl>
  131. <a name="index-types"></a>
  132. <p><code>avram</code> imposes no more of a &ldquo;type discipline&rdquo; than necessary to
  133. a workable interface between it and an application. This selection of
  134. types and constructors should not be seen as constraining what a
  135. compiler writer may wish to have in a source language.
  136. </p>
  137. <hr size="1">
  138. <table cellpadding="1" cellspacing="1" border="0">
  139. <tr><td valign="middle" align="left">[<a href="Data-Section.html#Data-Section" title="Previous section in reading order"> &lt; </a>]</td>
  140. <td valign="middle" align="left">[<a href="Filter-Mode-Interface.html#Filter-Mode-Interface" title="Next section in reading order"> &gt; </a>]</td>
  141. <td valign="middle" align="left"> &nbsp; </td>
  142. <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>
  143. <td valign="middle" align="left">[<a href="Virtual-Machine-Specification.html#Virtual-Machine-Specification" title="Up section"> Up </a>]</td>
  144. <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Next chapter"> &gt;&gt; </a>]</td>
  145. <td valign="middle" align="left"> &nbsp; </td>
  146. <td valign="middle" align="left"> &nbsp; </td>
  147. <td valign="middle" align="left"> &nbsp; </td>
  148. <td valign="middle" align="left"> &nbsp; </td>
  149. <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
  150. <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
  151. <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
  152. <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
  153. </tr></table>
  154. <p>
  155. <font size="-1">
  156. This document was generated on <i>December 10, 2012</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 1.82</i></a>.
  157. </font>
  158. <br>
  159. </p>
  160. </body>
  161. </html>