123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
- <html>
- <!-- Created on November 8, 2012 by texi2html 1.82
- texi2html was written by:
- Lionel Cons <[email protected]> (original author)
- Karl Berry <[email protected]>
- Olaf Bachmann <[email protected]>
- and many others.
- Maintained by: Many creative people.
- Send bugs and suggestions to <[email protected]>
- -->
- <head>
- <title>avram - a virtual machine code interpreter: 2.4 Representation of Numeric and Textual Data</title>
- <meta name="description" content="avram - a virtual machine code interpreter: 2.4 Representation of Numeric and Textual Data">
- <meta name="keywords" content="avram - a virtual machine code interpreter: 2.4 Representation of Numeric and Textual Data">
- <meta name="resource-type" content="document">
- <meta name="distribution" content="global">
- <meta name="Generator" content="texi2html 1.82">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <style type="text/css">
- <!--
- a.summary-letter {text-decoration: none}
- blockquote.smallquotation {font-size: smaller}
- pre.display {font-family: serif}
- pre.format {font-family: serif}
- pre.menu-comment {font-family: serif}
- pre.menu-preformatted {font-family: serif}
- pre.smalldisplay {font-family: serif; font-size: smaller}
- pre.smallexample {font-size: smaller}
- pre.smallformat {font-family: serif; font-size: smaller}
- pre.smalllisp {font-size: smaller}
- span.roman {font-family:serif; font-weight:normal;}
- span.sansserif {font-family:sans-serif; font-weight:normal;}
- ul.toc {list-style: none}
- -->
- </style>
- </head>
- <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
- <a name="Representation-of-Numeric-and-Textual-Data"></a>
- <table cellpadding="1" cellspacing="1" border="0">
- <tr><td valign="middle" align="left">[<a href="Data-Section.html#Data-Section" title="Previous section in reading order"> < </a>]</td>
- <td valign="middle" align="left">[<a href="Filter-Mode-Interface.html#Filter-Mode-Interface" title="Next section in reading order"> > </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="Virtual-Machine-Specification.html#Virtual-Machine-Specification" title="Beginning of this chapter or previous chapter"> << </a>]</td>
- <td valign="middle" align="left">[<a href="Virtual-Machine-Specification.html#Virtual-Machine-Specification" title="Up section"> Up </a>]</td>
- <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Next chapter"> >> </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
- <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
- <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
- <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
- </tr></table>
- <hr size="1">
- <a name="Representation-of-Numeric-and-Textual-Data-1"></a>
- <h2 class="section">2.4 Representation of Numeric and Textual Data</h2>
- <p>As noted already, virtual code applications are specified by functions
- operating on elements of a set having the properties described in
- <a href="Raw-Material.html#Raw-Material">Raw Material</a>, which are convenient to envision as ordered binary trees or
- <a name="index-trees-2"></a>
- <a name="index-nil-1"></a>
- pairs of <code>nil</code>. However, virtual code applications normally deal
- with numeric or textual data, for example when they refer to the
- contents of a text file. It is therefore necessary for the application
- and the virtual machine emulator to agree on a way of describing textual
- or numeric data with these trees.
- </p>
- <p>The purpose of this section is to explain the basic data structures used
- in the exchange of information between <code>avram</code> and a virtual code
- application. For example, an explanation is needed for statements like
- “an application invoked with the ‘<samp>--baz</samp>’ option is expected to
- return a pair <code>(<var>foo</var>,<var>bar</var>)</code>, where <code><var>foo</var></code> is a
- <a name="index-strings"></a>
- <a name="index-character-strings"></a>
- <a name="index-lists-2"></a>
- list of character strings …”, that are made subsequently in this
- document. Such statements should be understood as referring to the trees
- representing the pairs, lists, character strings, etc., according to the
- conventions explained below.
- </p>
- <dl compact="compact">
- <dt> <em>Characters</em></dt>
- <dd><a name="index-character-codes-1"></a>
- <p>An arbitrarily chosen set of 256 trees is used to represent the
- character set. They are listed in <a href="Character-Table.html#Character-Table">Character Table</a>. For example,
- the letter <code>A</code> is represented by
- <code>(nil,(((nil,(nil,(nil,nil))),nil),(nil,nil)))</code>. That means that
- when an application wants the letter <code>A</code> written to a text file, it
- returns something with this tree in it.
- </p></dd>
- <dt> <em>Booleans</em></dt>
- <dd><a name="index-booleans"></a>
- <p>The value of <code>false</code> is represented by <code>nil</code>, and the value of
- <code>true</code> is represented by <code>(nil,nil)</code>.
- </p></dd>
- <dt> <em>Pairs</em></dt>
- <dd><a name="index-pairs"></a>
- <p>Given any two items of data <var>x1</var> and <var>x2</var>, having the respective
- representations <var>r1</var> and <var>r2</var>, the pair <code>(<var>x1</var>,<var>x2</var>)</code> has the
- representation <code>cons(<var>r1</var>,<var>r2</var>)</code>.
- </p></dd>
- <dt> <em>Lists</em></dt>
- <dd><a name="index-lists-3"></a>
- <p>A list of the items <var>x1</var>, <var>x2</var> … <var>xn</var> with respective
- representations <var>r1</var> through <var>rn</var> is represented by the tree
- <code>cons(<var>r1</var>,cons(<var>r2</var>…cons(<var>rn</var>,nil)…))</code>. In other words,
- lists are represented as pairs whose left sides are the heads and whose
- right sides are the tails. The empty list is identified with
- <code>nil</code>. Lists of arbitrary finite length can be accommodated.
- </p></dd>
- <dt> <em>Naturals</em></dt>
- <dd><a name="index-naturals"></a>
- <p>A number of the form <code><var>b0</var> + 2<var>b1</var> + 4<var>b2</var> + … +
- 2^n <var>bn</var></code>, where each <code><var>b</var>i</code> is <code>0</code> or <code>1</code>, is
- represented by a tree of the form
- <code>cons(<var>t0</var>,cons(<var>t1</var>…cons(<var>tn</var>,nil)…))</code>
- where each <code><var>t</var>i</code> is <code>nil</code> if the corresponding
- <code><var>b</var>i</code> is <code>0</code>, and <code>(nil,nil)</code> otherwise. Note that
- the numbers <code><var>b</var>i</code> are exactly the bits written in the binary
- expansion of the number, with <code><var>b0</var></code> being the least significant
- bit.
- </p></dd>
- <dt> <em>Strings</em></dt>
- <dd><a name="index-strings-1"></a>
- <a name="index-character-strings-1"></a>
- <p>are represented as lists of characters.
- </p></dd>
- </dl>
- <a name="index-types"></a>
- <p><code>avram</code> imposes no more of a “type discipline” than necessary to
- a workable interface between it and an application. This selection of
- types and constructors should not be seen as constraining what a
- compiler writer may wish to have in a source language.
- </p>
- <hr size="1">
- <table cellpadding="1" cellspacing="1" border="0">
- <tr><td valign="middle" align="left">[<a href="Data-Section.html#Data-Section" title="Previous section in reading order"> < </a>]</td>
- <td valign="middle" align="left">[<a href="Filter-Mode-Interface.html#Filter-Mode-Interface" title="Next section in reading order"> > </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="Virtual-Machine-Specification.html#Virtual-Machine-Specification" title="Beginning of this chapter or previous chapter"> << </a>]</td>
- <td valign="middle" align="left">[<a href="Virtual-Machine-Specification.html#Virtual-Machine-Specification" title="Up section"> Up </a>]</td>
- <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Next chapter"> >> </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
- <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
- <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
- <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
- </tr></table>
- <p>
- <font size="-1">
- This document was generated on <i>November 8, 2012</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 1.82</i></a>.
- </font>
- <br>
- </p>
- </body>
- </html>
|