989 lines
49 KiB
HTML
989 lines
49 KiB
HTML
|
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
|
<html>
|
||
|
<!--
|
||
|
|
||
|
Generated from r6rs.tex by tex2page, v 20100828
|
||
|
(running on MzScheme 4.2.4, :unix),
|
||
|
(c) Dorai Sitaram,
|
||
|
http://evalwhen.com/tex2page/index.html
|
||
|
|
||
|
-->
|
||
|
<head>
|
||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
|
<title>
|
||
|
Revised^6 Report on the Algorithmic Language Scheme
|
||
|
</title>
|
||
|
<link rel="stylesheet" type="text/css" href="r6rs-Z-S.css" title=default>
|
||
|
<meta name=robots content="index,follow">
|
||
|
</head>
|
||
|
<body>
|
||
|
<div id=slidecontent>
|
||
|
<div align=right class=navigation>[Go to <span><a href="r6rs.html">first</a>, <a href="r6rs-Z-H-6.html">previous</a></span><span>, <a href="r6rs-Z-H-8.html">next</a></span> page<span>; </span><span><a href="r6rs-Z-H-2.html#node_toc_start">contents</a></span><span><span>; </span><a href="r6rs-Z-H-21.html#node_index_start">index</a></span>]</div>
|
||
|
<p></p>
|
||
|
<a name="node_chap_4"></a>
|
||
|
<h1 class=chapter>
|
||
|
<div class=chapterheading><a href="r6rs-Z-H-2.html#node_toc_node_chap_4">Chapter 4</a></div><br>
|
||
|
<a href="r6rs-Z-H-2.html#node_toc_node_chap_4">Lexical syntax and datum syntax</a></h1>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
The syntax of Scheme code is organized in three levels:
|
||
|
</p>
|
||
|
<ol>
|
||
|
<li><p>the <i>lexical syntax</i> that describes how a program text is split
|
||
|
into a sequence of lexemes,
|
||
|
</p>
|
||
|
<li><p>the <i>datum syntax</i>, formulated in terms of the lexical
|
||
|
syntax, that structures the lexeme sequence as a sequence of
|
||
|
<i>syntactic data<a name="node_idx_102"></a><a name="node_idx_104"></a></i>, where a syntactic datum is
|
||
|
a recursively structured entity,
|
||
|
</p>
|
||
|
<li><p>the <i>program syntax</i> formulated in terms of the read
|
||
|
syntax, imposing further structure and assigning meaning to
|
||
|
syntactic data.
|
||
|
</p>
|
||
|
</ol><p>
|
||
|
Syntactic data (also called <i>external
|
||
|
representations<a name="node_idx_106"></a></i>) double
|
||
|
as a notation for objects, and Scheme's <tt>(rnrs io ports (6))</tt> library
|
||
|
(library section on “Port I/O”)
|
||
|
provides the <tt>get-datum</tt> and <tt>put-datum</tt> procedures
|
||
|
for reading and writing syntactic data, converting between their
|
||
|
textual representation and the corresponding objects.
|
||
|
Each syntactic datum represents a corresponding <a name="node_idx_108"></a><em>datum value</em>.
|
||
|
A syntactic datum can be used in a program to obtain the corresponding
|
||
|
datum value using <tt>quote</tt> (see section <a href="r6rs-Z-H-14.html#node_sec_11.4.1">11.4.1</a>).</p>
|
||
|
<p>
|
||
|
Scheme source code consists of syntactic data and (non-significant) comments.
|
||
|
Syntactic data in Scheme source code are called
|
||
|
<i>forms</i><a name="node_idx_110"></a>.
|
||
|
(A form nested inside another form is
|
||
|
called a <a name="node_idx_112"></a><em>subform</em>.)
|
||
|
Consequently, Scheme's syntax has the property that any sequence of
|
||
|
characters that is a form is also a syntactic datum representing
|
||
|
some object. This can lead to confusion, since it may not be obvious
|
||
|
out of context whether a given sequence of characters is intended to
|
||
|
be a representation of objects or the text of a program.
|
||
|
It is also a source of power, since it
|
||
|
facilitates writing programs such as interpreters or compilers that
|
||
|
treat programs as objects (or vice versa).</p>
|
||
|
<p>
|
||
|
A datum value may have several different external representations.
|
||
|
For example, both “<tt>#e28.000</tt>” and
|
||
|
“<tt>#x1c</tt>” are syntactic data representing the exact integer
|
||
|
object 28, and the syntactic data “<tt>(8 13)</tt>”, “<tt>( 08 13 )</tt>”, “<tt>(8 .
|
||
|
(13 . ()))</tt>”
|
||
|
all represent a list containing the exact integer objects 8 and 13.
|
||
|
Syntactic data that represent equal objects (in the sense of <tt>equal?</tt>; see section <a href="r6rs-Z-H-14.html#node_sec_11.5">11.5</a>) are always equivalent
|
||
|
as forms of a program.</p>
|
||
|
<p>
|
||
|
Because of the close correspondence between syntactic data and datum
|
||
|
values, this report sometimes uses the term <a name="node_idx_114"></a><em>datum</em> for
|
||
|
either a syntactic datum or a datum value when the exact meaning
|
||
|
is apparent from the context.</p>
|
||
|
<p>
|
||
|
An implementation must not extend the lexical or datum syntax in
|
||
|
any way, with one exception: it need not treat the syntax
|
||
|
<tt><tt>#</tt>!<identifier></tt>, for any <identifier> (see
|
||
|
section <a href="r6rs-Z-H-7.html#node_sec_4.2.4">4.2.4</a>) that is not <tt>r6rs</tt>, as a syntax
|
||
|
violation, and it may use specific <tt><tt>#</tt>!</tt>-prefixed
|
||
|
identifiers as flags indicating that subsequent input contains extensions
|
||
|
to the standard lexical or datum syntax.
|
||
|
The syntax <tt><tt>#</tt>!r6rs</tt> may be used to signify that
|
||
|
the input afterward is written with the lexical syntax and
|
||
|
datum syntax described by
|
||
|
this report.
|
||
|
<tt><tt>#</tt>!r6rs</tt> is otherwise treated as a comment; see section <a href="r6rs-Z-H-7.html#node_sec_4.2.3">4.2.3</a>.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.1"></a>
|
||
|
<h2 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.1">4.1 Notation</a></h2>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
The formal syntax for Scheme is written in an extended BNF.
|
||
|
Non-terminals are written using angle brackets. Case is insignificant
|
||
|
for non-terminal names.</p>
|
||
|
<p>
|
||
|
All spaces in the grammar are for legibility.
|
||
|
<Empty> stands for the empty string.</p>
|
||
|
<p>
|
||
|
The following extensions to BNF are used to make the description more
|
||
|
concise: <thing>* means zero or more occurrences of
|
||
|
<thing>, and <thing><sup>+</sup> means at least one
|
||
|
<thing>.</p>
|
||
|
<p>
|
||
|
Some non-terminal names refer to the Unicode scalar values of the same
|
||
|
name: <character tabulation> (U+0009), <linefeed> (U+000A),
|
||
|
<carriage return> (U+000D), <line tabulation> (U+000B),
|
||
|
<form feed> (U+000C), <carriage return> (U+000D),
|
||
|
<space> (U+0020), <next line> (U+0085), <line
|
||
|
separator> (U+2028), and <paragraph separator> (U+2029).</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.2"></a>
|
||
|
<h2 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.2">4.2 Lexical syntax</a></h2>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
The lexical syntax determines how a character sequence is split into a
|
||
|
sequence of lexemes<a name="node_idx_116"></a>, omitting non-significant portions
|
||
|
such as comments and whitespace. The character sequence is assumed to
|
||
|
be text according to the Unicode standard [<a href="r6rs-Z-H-21.html#node_bib_27">27</a>]. Some of
|
||
|
the lexemes, such as identifiers, representations of number objects, strings etc., of the lexical
|
||
|
syntax are syntactic data in the datum syntax, and thus represent objects.
|
||
|
Besides the formal account of the syntax, this section also describes
|
||
|
what datum values are represented by these syntactic data.</p>
|
||
|
<p>
|
||
|
The lexical syntax, in the description of comments, contains
|
||
|
a forward reference to <datum>, which is described as part of the
|
||
|
datum syntax. Being comments, however, these <datum>s do not play
|
||
|
a significant role in the syntax.</p>
|
||
|
<p>
|
||
|
Case is significant except in representations of booleans, number objects, and
|
||
|
in hexadecimal numbers specifying Unicode scalar values. For example, <tt>#x1A</tt>
|
||
|
and <tt>#X1a</tt> are equivalent. The identifier <tt>Foo</tt> is, however,
|
||
|
distinct from the identifier <tt>FOO</tt>.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.2.1"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.2.1">4.2.1 Formal account</a></h3>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
<Interlexeme space> may occur on either side of any lexeme, but not
|
||
|
within a lexeme.</p>
|
||
|
<p>
|
||
|
<Identifier>s, <tt>.</tt>, <number>s, <character>s, and
|
||
|
<boolean>s, must be terminated by a <delimiter> or by the
|
||
|
end of the input.</p>
|
||
|
<p>
|
||
|
The following two characters are reserved for future extensions to the
|
||
|
language: <tt><code class=verbatim>{</code> <code class=verbatim>}</code></tt></p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<tt><lexeme> → <identifier> ∣ <boolean> ∣ <number><a name="node_idx_118"></a>
|
||
|
<p class=nopadding><span style="margin-left: 2em">‌</span> ∣ <character> ∣ <string></p>
|
||
|
|
||
|
<p class=nopadding> ∣ ( ∣ ) ∣ <tt>[</tt> ∣ <tt>]</tt> ∣ <tt>#</tt>( ∣ <tt>#</tt>vu8( | <tt>'</tt> ∣ <tt>`</tt> ∣ , ∣ ,@ ∣ <strong>.</strong></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <tt>#</tt><tt>'</tt> ∣ <tt>#</tt><tt>`</tt> ∣ <tt>#</tt>, ∣ <tt>#</tt>,@</p>
|
||
|
|
||
|
<p class=nopadding><delimiter> → ( ∣ ) ∣ <tt>[</tt> ∣ <tt>]</tt> ∣ " ∣ ; ∣ <tt>#</tt></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <whitespace></p>
|
||
|
|
||
|
<p class=nopadding><whitespace> → <character tabulation></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <linefeed> ∣ <line tabulation> ∣ <form feed></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <carriage return> ∣ <next line></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <any character whose category is Zs, Zl, or Zp></p>
|
||
|
|
||
|
<p class=nopadding><line ending> → <linefeed> ∣ <carriage return></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <carriage return> <linefeed> ∣ <next line></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <carriage return> <next line> ∣ <line separator></p>
|
||
|
|
||
|
<p class=nopadding><comment> → ; ⟨all subsequent characters up to a</p>
|
||
|
|
||
|
<p class=nopadding> <line ending> or <paragraph separator>⟩<a name="node_idx_120"></a></p>
|
||
|
|
||
|
<p class=nopadding><span style="margin-left: 2em">‌</span> ∣ <nested comment></p>
|
||
|
|
||
|
<p class=nopadding> ∣ #; <interlexeme space> <datum></p>
|
||
|
|
||
|
<p class=nopadding> ∣ #!r6rs</p>
|
||
|
|
||
|
<p class=nopadding><nested comment> → #| <comment text></p>
|
||
|
|
||
|
<p class=nopadding> <comment cont>* |#</p>
|
||
|
|
||
|
<p class=nopadding><comment text> → ⟨character sequence not containing</p>
|
||
|
|
||
|
<p class=nopadding> <tt>#|</tt> or <tt>|#</tt>⟩</p>
|
||
|
|
||
|
<p class=nopadding><comment cont> → <nested comment> <comment text></p>
|
||
|
|
||
|
<p class=nopadding><atmosphere> → <whitespace> ∣ <comment></p>
|
||
|
|
||
|
<p class=nopadding><interlexeme space> → <atmosphere>*</p>
|
||
|
</tt><p>
|
||
|
|
||
|
</p>
|
||
|
<p>
|
||
|
|
||
|
</p>
|
||
|
<tt><identifier> → <initial> <subsequent>*
|
||
|
<p class=nopadding> <span style="margin-left: 2em">‌</span> ∣ <peculiar identifier></p>
|
||
|
|
||
|
<p class=nopadding><initial> → <constituent> ∣ <special initial></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <inline hex escape></p>
|
||
|
|
||
|
<p class=nopadding><letter> → a ∣ b ∣ c ∣ ... ∣ z</p>
|
||
|
|
||
|
<p class=nopadding> ∣ A ∣ B ∣ C ∣ ... ∣ Z</p>
|
||
|
|
||
|
<p class=nopadding><constituent> → <letter></p>
|
||
|
|
||
|
<p class=nopadding> ∣ ⟨any character whose Unicode scalar value is greater than</p>
|
||
|
|
||
|
<p class=nopadding> <span style="margin-left: 1em">‌</span>127, and whose category is Lu, Ll, Lt, Lm, Lo, Mn,</p>
|
||
|
|
||
|
<p class=nopadding> <span style="margin-left: 1em">‌</span>Nl, No, Pd, Pc, Po, Sc, Sm, Sk, So, or Co⟩</p>
|
||
|
|
||
|
<p class=nopadding><special initial> → ! ∣ $ ∣ % ∣ <code class=verbatim>&</code> ∣ * ∣ / ∣ : ∣ < ∣ =</p>
|
||
|
|
||
|
<p class=nopadding> ∣ > ∣ ? ∣ <code class=verbatim>^</code> ∣ <code class=verbatim>_</code> ∣ <code class=verbatim>~</code></p>
|
||
|
|
||
|
<p class=nopadding><subsequent> → <initial> ∣ <digit></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <any character whose category is Nd, Mc, or Me></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <special subsequent></p>
|
||
|
|
||
|
<p class=nopadding><digit> → 0 ∣ 1 ∣ 2 ∣ 3 ∣ 4 ∣ 5 ∣ 6 ∣ 7 ∣ 8 ∣ 9</p>
|
||
|
|
||
|
<p class=nopadding><hex digit> → <digit></p>
|
||
|
|
||
|
<p class=nopadding> ∣ a ∣ A ∣ b ∣ B ∣ c ∣ C ∣ d ∣ D ∣ e ∣ E ∣ f ∣ F</p>
|
||
|
|
||
|
<p class=nopadding><special subsequent> → + ∣ - ∣ . ∣ @</p>
|
||
|
|
||
|
<p class=nopadding><inline hex escape> → <tt>\</tt>x<hex scalar value>;</p>
|
||
|
|
||
|
<p class=nopadding><hex scalar value> → <hex digit><sup>+</sup></p>
|
||
|
|
||
|
<p class=nopadding><peculiar identifier> → + ∣ - ∣ ... ∣ -> <subsequent>*</p>
|
||
|
|
||
|
<p class=nopadding><boolean> → <tt>#t</tt> ∣ #T ∣ <tt>#f</tt> ∣ #F</p>
|
||
|
|
||
|
<p class=nopadding><character> → #<tt>\</tt><any character></p>
|
||
|
|
||
|
<p class=nopadding> ∣ #<tt>\</tt><character name></p>
|
||
|
|
||
|
<p class=nopadding> ∣ #<tt>\</tt>x<hex scalar value></p>
|
||
|
|
||
|
<p class=nopadding><character name> → nul ∣ alarm ∣ backspace ∣ tab</p>
|
||
|
|
||
|
<p class=nopadding> ∣ linefeed ∣ newline ∣ vtab ∣ page ∣ return</p>
|
||
|
|
||
|
<p class=nopadding> ∣ esc ∣ space ∣ delete</p>
|
||
|
|
||
|
<p class=nopadding><string> → " <string element>* "</p>
|
||
|
|
||
|
<p class=nopadding><string element> → <any character other than <tt>"</tt> or <tt>\</tt>></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <tt>\</tt>a ∣ <tt>\</tt>b ∣ <tt>\</tt>t ∣ <tt>\</tt>n ∣ <tt>\</tt>v ∣ <tt>\</tt>f ∣ <tt>\</tt>r</p>
|
||
|
|
||
|
<p class=nopadding> ∣ <tt>\</tt><tt>"</tt> ∣ <tt>\</tt><tt>\</tt></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <tt>\</tt><intraline whitespace><line ending></p>
|
||
|
|
||
|
<p class=nopadding> <intraline whitespace></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <inline hex escape></p>
|
||
|
|
||
|
<p class=nopadding><intraline whitespace> → <character tabulation></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <any character whose category is Zs></p>
|
||
|
</tt><p>
|
||
|
A <hex scalar value> represents a Unicode scalar value
|
||
|
between 0 and <tt>#</tt>x10FFFF, excluding the range
|
||
|
[<tt>#</tt><em>x</em>D800, <tt>#</tt><em>x</em>DFFF].</p>
|
||
|
<p>
|
||
|
The rules for <num <em>R</em>>, <complex <em>R</em>>, <real
|
||
|
<em>R</em>>, <ureal <em>R</em>>, <uinteger <em>R</em>>, and <prefix <em>R</em>> below
|
||
|
should be replicated for <em>R</em> = 2, 8, 10,
|
||
|
and 16. There are no rules for <decimal 2>, <decimal
|
||
|
8>, and <decimal 16>, which means that number representations containing
|
||
|
decimal points or exponents must be in decimal radix.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<tt><number> → <num 2> ∣ <num 8>
|
||
|
<p class=nopadding> <span style="margin-left: 2em">‌</span> ∣ <num 10> ∣ <num 16></p>
|
||
|
|
||
|
<p class=nopadding><num <em>R</em>> → <prefix <em>R</em>> <complex <em>R</em>></p>
|
||
|
|
||
|
<p class=nopadding><complex <em>R</em>> → <real <em>R</em>> ∣ <real <em>R</em>> @ <real <em>R</em>></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <real <em>R</em>> + <ureal <em>R</em>> i ∣ <real <em>R</em>> - <ureal <em>R</em>> i</p>
|
||
|
|
||
|
<p class=nopadding> ∣ <real <em>R</em>> + <naninf> i ∣ <real <em>R</em>> - <naninf> i</p>
|
||
|
|
||
|
<p class=nopadding> ∣ <real <em>R</em>> + i ∣ <real <em>R</em>> - i</p>
|
||
|
|
||
|
<p class=nopadding> ∣ + <ureal <em>R</em>> i ∣ - <ureal <em>R</em>> i </p>
|
||
|
|
||
|
<p class=nopadding> ∣ + <naninf> i ∣ - <naninf> i</p>
|
||
|
|
||
|
<p class=nopadding> ∣ + i ∣ - i</p>
|
||
|
|
||
|
<p class=nopadding><real <em>R</em>> → <sign> <ureal <em>R</em>></p>
|
||
|
|
||
|
<p class=nopadding> ∣ + <naninf> ∣ - <naninf></p>
|
||
|
|
||
|
<p class=nopadding><naninf> → nan.0 ∣ inf.0</p>
|
||
|
|
||
|
<p class=nopadding><ureal <em>R</em>> → <uinteger <em>R</em>></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <uinteger <em>R</em>> / <uinteger <em>R</em>></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <decimal <em>R</em>> <mantissa width></p>
|
||
|
|
||
|
<p class=nopadding><decimal 10> → <uinteger 10> <suffix></p>
|
||
|
|
||
|
<p class=nopadding> ∣ . <digit 10><sup>+</sup> <suffix></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <digit 10><sup>+</sup> . <digit 10>* <suffix></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <digit 10><sup>+</sup> . <suffix></p>
|
||
|
|
||
|
<p class=nopadding><uinteger <em>R</em>> → <digit <em>R</em>><sup>+</sup></p>
|
||
|
|
||
|
<p class=nopadding><prefix <em>R</em>> → <radix <em>R</em>> <exactness></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <exactness> <radix <em>R</em>></p>
|
||
|
|
||
|
<p class=nopadding></p>
|
||
|
</tt><p>
|
||
|
</p>
|
||
|
<tt><suffix> → <empty>
|
||
|
<p class=nopadding> <span style="margin-left: 2em">‌</span> ∣ <exponent marker> <sign> <digit 10><sup>+</sup></p>
|
||
|
|
||
|
<p class=nopadding><exponent marker> → e ∣ E ∣ s ∣ S ∣ f ∣ F</p>
|
||
|
|
||
|
<p class=nopadding> ∣ d ∣ D ∣ l ∣ L</p>
|
||
|
|
||
|
<p class=nopadding><mantissa width> → <empty></p>
|
||
|
|
||
|
<p class=nopadding> ∣ | <digit 10><sup>+</sup></p>
|
||
|
|
||
|
<p class=nopadding><sign> → <empty> ∣ + ∣ -</p>
|
||
|
|
||
|
<p class=nopadding><exactness> → <empty></p>
|
||
|
|
||
|
<p class=nopadding> ∣ #i<a name="node_idx_122"></a>∣ #I ∣ #e<a name="node_idx_124"></a>∣ #E</p>
|
||
|
|
||
|
<p class=nopadding><radix 2> → #b<a name="node_idx_126"></a>∣ #B</p>
|
||
|
|
||
|
<p class=nopadding><radix 8> → #o<a name="node_idx_128"></a>∣ #O</p>
|
||
|
|
||
|
<p class=nopadding><radix 10> → <empty> ∣ #d ∣ #D</p>
|
||
|
|
||
|
<p class=nopadding><radix 16> → #x<a name="node_idx_130"></a>∣ #X</p>
|
||
|
|
||
|
<p class=nopadding><digit 2> → 0 ∣ 1</p>
|
||
|
|
||
|
<p class=nopadding><digit 8> → 0 ∣ 1 ∣ 2 ∣ 3 ∣ 4 ∣ 5 ∣ 6 ∣ 7</p>
|
||
|
|
||
|
<p class=nopadding><digit 10> → <digit></p>
|
||
|
|
||
|
<p class=nopadding><digit 16> → <hex digit></p>
|
||
|
|
||
|
<p class=nopadding></p>
|
||
|
</tt><p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.2.2"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.2.2">4.2.2 Line endings</a></h3>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
Line endings are significant in Scheme in single-line comments (see
|
||
|
section <a href="r6rs-Z-H-7.html#node_sec_4.2.3">4.2.3</a>) and within string literals. In
|
||
|
Scheme source code, any of the line endings in <line ending>
|
||
|
marks the end of a line. Moreover, the two-character line endings
|
||
|
<carriage return> <linefeed> and <carriage return>
|
||
|
<next line> each count as a single line ending.</p>
|
||
|
<p>
|
||
|
In a string literal, a <line ending> not preceded by a <tt><tt>\</tt></tt>
|
||
|
stands for a linefeed character, which is the standard line-ending
|
||
|
character of Scheme.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.2.3"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.2.3">4.2.3 Whitespace and comments</a></h3>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
<a name="node_idx_132"></a><em>Whitespace</em> characters are spaces, linefeeds,
|
||
|
carriage returns, character tabulations, form feeds, line tabulations,
|
||
|
and any other character whose category is Zs, Zl, or Zp.
|
||
|
Whitespace is used for improved readability and
|
||
|
as necessary to separate lexemes from each other. Whitespace may
|
||
|
occur between any two lexemes,
|
||
|
but not within a lexeme. Whitespace may also occur inside a string,
|
||
|
where it is significant.</p>
|
||
|
<p>
|
||
|
The lexical syntax includes several comment forms. In all cases,
|
||
|
comments are invisible to Scheme, except that they act as delimiters,
|
||
|
so, for example, a comment cannot appear in the middle of an
|
||
|
identifier or representation of a number object.</p>
|
||
|
<p>
|
||
|
A semicolon (<tt>;</tt>) indicates the start of a line
|
||
|
comment.<a name="node_idx_134"></a><a name="node_idx_136"></a>The comment continues to
|
||
|
the end of the line on which the semicolon appears.</p>
|
||
|
<p>
|
||
|
Another way to indicate a comment is to prefix a <datum>
|
||
|
(cf. section <a href="r6rs-Z-H-7.html#node_sec_4.3.1">4.3.1</a>) with <tt>#;</tt><a name="node_idx_138"></a>, possibly with
|
||
|
<interlexeme space> before the <datum>. The comment consists of
|
||
|
the comment prefix <tt>#;</tt> and the <datum> together. This
|
||
|
notation is useful for “commenting out” sections of code.</p>
|
||
|
<p>
|
||
|
Block comments may be indicated with properly nested <tt>#|</tt><a name="node_idx_140"></a><a name="node_idx_142"></a>and <tt>|#</tt> pairs.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
|
||
|
<tt>#|
|
||
|
<p class=nopadding> The FACT procedure computes the factorial</p>
|
||
|
|
||
|
<p class=nopadding> of a non-negative integer.</p>
|
||
|
|
||
|
<p class=nopadding>|#</p>
|
||
|
|
||
|
<p class=nopadding>(define fact</p>
|
||
|
|
||
|
<p class=nopadding> (lambda (n)</p>
|
||
|
|
||
|
<p class=nopadding> ;; base case</p>
|
||
|
|
||
|
<p class=nopadding> (if (= n 0)</p>
|
||
|
|
||
|
<p class=nopadding> #;(= n 1)</p>
|
||
|
|
||
|
<p class=nopadding> 1 ; identity of *</p>
|
||
|
|
||
|
<p class=nopadding> (* n (fact (- n 1))))))</p>
|
||
|
<p></tt></p>
|
||
|
<p>
|
||
|
The lexeme <tt><tt>#</tt>!r6rs</tt>, which signifies that the program text
|
||
|
that follows is written with the lexical and datum syntax described in this
|
||
|
report, is also otherwise treated as a comment.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.2.4"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.2.4">4.2.4 Identifiers</a></h3>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
Most identifiers<a name="node_idx_144"></a>allowed by other programming
|
||
|
languages are also acceptable to Scheme. In general,
|
||
|
a sequence of letters, digits, and “extended alphabetic
|
||
|
characters” is
|
||
|
an identifier when it begins with a character that cannot begin a
|
||
|
representation of a number object.
|
||
|
In addition, <tt>+</tt>, <tt>-</tt>, and <tt>...</tt> are identifiers, as is
|
||
|
a sequence of letters, digits, and extended alphabetic
|
||
|
characters that begins with the two-character sequence <tt>-></tt>.
|
||
|
Here are some examples of identifiers:</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
|
||
|
<tt>lambda q soup
|
||
|
<p class=nopadding>list->vector + V17a</p>
|
||
|
|
||
|
<p class=nopadding><= a34kTMNs ->-</p>
|
||
|
|
||
|
<p class=nopadding>the-word-recursion-has-many-meanings</p>
|
||
|
<p></tt></p>
|
||
|
<p>
|
||
|
Extended alphabetic characters may be used within identifiers as if
|
||
|
they were letters. The following are extended alphabetic characters:</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
|
||
|
<tt>! $ % <code class=verbatim>&</code> * + - . / : < = > ? @ <code class=verbatim>^</code> <code class=verbatim>_</code> <code class=verbatim>~</code> <p></tt></p>
|
||
|
<p>
|
||
|
Moreover, all characters whose Unicode scalar values are greater than 127 and
|
||
|
whose Unicode category is Lu, Ll, Lt, Lm, Lo, Mn, Mc, Me, Nd, Nl, No, Pd,
|
||
|
Pc, Po, Sc, Sm, Sk, So, or Co can be used within identifiers.
|
||
|
In addition, any character can be used within an identifier
|
||
|
when specified via an <inline hex escape>. For example, the
|
||
|
identifier <code class=verbatim>H\x65;llo</code> is the same as the identifier
|
||
|
<code class=verbatim>Hello</code>, and the identifier <code class=verbatim>\x3BB;</code> is the same as the
|
||
|
identifier λ.</p>
|
||
|
<p>
|
||
|
Any identifier may be used as a variable<a name="node_idx_146"></a>or as a
|
||
|
syntactic keyword<a name="node_idx_148"></a>(see
|
||
|
sections <a href="r6rs-Z-H-8.html#node_sec_5.2">5.2</a> and <a href="r6rs-Z-H-12.html#node_sec_9.2">9.2</a>) in a Scheme
|
||
|
program.
|
||
|
Any identifier may also be used as a syntactic datum, in which case it
|
||
|
represents a <i>symbol</i><a name="node_idx_150"></a>(see section <a href="r6rs-Z-H-14.html#node_sec_11.10">11.10</a>).</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.2.5"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.2.5">4.2.5 Booleans</a></h3>
|
||
|
<p>The standard boolean objects for true and false have external representations
|
||
|
<tt>#t</tt> and <tt>#f</tt>.<a name="node_idx_152"></a><a name="node_idx_154"></a></p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.2.6"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.2.6">4.2.6 Characters</a></h3>
|
||
|
<p>Characters are represented using the notation
|
||
|
<tt>#</tt><tt>\</tt><character><a name="node_idx_156"></a>or
|
||
|
<tt>#</tt><tt>\</tt><character name> or
|
||
|
<tt>#</tt><tt>\</tt>x<hex scalar value>.</p>
|
||
|
<p>
|
||
|
For example:</p>
|
||
|
<p>
|
||
|
|
||
|
</p>
|
||
|
<table border=0><tr><td valign=top ><tt>#<tt>\</tt>a</tt> </td><td valign=top >lower case letter a</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>A</tt> </td><td valign=top >upper case letter A</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>(</tt> </td><td valign=top >left parenthesis</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt></tt> </td><td valign=top >space character</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>nul</tt> </td><td valign=top >U+0000</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>alarm</tt> </td><td valign=top >U+0007</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>backspace</tt> </td><td valign=top >U+0008</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>tab</tt> </td><td valign=top >U+0009</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>linefeed</tt> </td><td valign=top >U+000A</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>newline</tt> </td><td valign=top >U+000A</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>vtab</tt> </td><td valign=top >U+000B</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>page</tt> </td><td valign=top >U+000C</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>return</tt> </td><td valign=top >U+000D</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>esc</tt> </td><td valign=top >U+001B</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>space</tt> </td><td valign=top >U+0020</td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >preferred way to write a space</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>delete</tt> </td><td valign=top >U+007F</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>xFF</tt> </td><td valign=top >U+00FF</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>x03BB</tt> </td><td valign=top >U+03BB</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>x00006587</tt> </td><td valign=top >U+6587</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>λ</tt> </td><td valign=top >U+03BB</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>x0001z</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>λx</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>alarmx</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>alarm x</tt> </td><td valign=top >U+0007</td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >followed by <tt>x</tt></td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>Alarm</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>alert</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>xA</tt> </td><td valign=top >U+000A</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>xFF</tt> </td><td valign=top >U+00FF</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>xff</tt> </td><td valign=top >U+00FF</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>x ff</tt> </td><td valign=top >U+0078</td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >followed by another datum, <tt>ff</tt></td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>x(ff)</tt> </td><td valign=top >U+0078</td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >followed by another datum,</td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >a parenthesized <tt>ff</tt></td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>(x)</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>(x</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>((x)</tt> </td><td valign=top >U+0028</td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >followed by another datum,</td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >parenthesized <tt>x</tt></td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>x00110000</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >out of range</td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>x000000001</tt> </td><td valign=top >U+0001 </td></tr>
|
||
|
<tr><td valign=top ><tt>#<tt>\</tt>xD800</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >in excluded range
|
||
|
</td></tr></table>
|
||
|
<p>
|
||
|
(The notation <tt>&lexical</tt> <i>exception</i> means that the line in question is
|
||
|
a lexical syntax violation.)</p>
|
||
|
<p>
|
||
|
Case is significant in <tt>#</tt><tt>\</tt><character>, and in
|
||
|
<tt>#</tt><tt>\</tt>⟨character name⟩, but not in <tt><tt>#</tt><tt>\</tt>x</tt><hex scalar value>.
|
||
|
A <character> must be followed by a <delimiter> or by the end of the input.
|
||
|
This rule resolves various ambiguous cases involving named characters,
|
||
|
requiring, for
|
||
|
example, the sequence of characters “<tt><tt>#</tt><tt>\</tt>space</tt>”
|
||
|
to be interpreted as the space character rather than as
|
||
|
the character “<tt><tt>#</tt><tt>\</tt>s</tt>” followed
|
||
|
by the identifier “<tt>pace</tt>”.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<blockquote><em>Note:<span style="margin-left: .5em">‌</span></em>
|
||
|
The <tt><tt>#</tt><tt>\</tt>newline</tt> notation is retained for
|
||
|
backward compatibility. Its use is deprecated;
|
||
|
<tt><tt>#</tt><tt>\</tt>linefeed</tt> should be used instead.
|
||
|
</blockquote><p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.2.7"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.2.7">4.2.7 Strings</a></h3>
|
||
|
<p>String are represented by sequences of characters enclosed within doublequotes
|
||
|
(<tt>"</tt>). Within a string literal, various escape
|
||
|
sequences<a name="node_idx_158"></a>represent characters other than
|
||
|
themselves. Escape sequences always start with a backslash (<tt>\</tt>):</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<ul>
|
||
|
<li><p><tt><tt>\</tt>a</tt> : alarm, U+0007
|
||
|
</p>
|
||
|
<li><p><tt><tt>\</tt>b</tt> : backspace, U+0008
|
||
|
</p>
|
||
|
<li><p><tt><tt>\</tt>t</tt> : character tabulation, U+0009
|
||
|
</p>
|
||
|
<li><p><tt><tt>\</tt>n</tt> : linefeed, U+000A
|
||
|
</p>
|
||
|
<li><p><tt><tt>\</tt>v</tt> : line tabulation, U+000B
|
||
|
</p>
|
||
|
<li><p><tt><tt>\</tt>f</tt> : formfeed, U+000C
|
||
|
</p>
|
||
|
<li><p><tt><tt>\</tt>r</tt> : return, U+000D
|
||
|
</p>
|
||
|
<li><p><tt><tt>\</tt></tt><code class=verbatim>"</code> : doublequote, U+0022
|
||
|
</p>
|
||
|
<li><p><tt><tt>\</tt><tt>\</tt></tt> : backslash, U+005C
|
||
|
</p>
|
||
|
<li><p><tt><tt>\</tt></tt><intraline whitespace><line ending><br>
|
||
|
<intraline whitespace> : nothing
|
||
|
</p>
|
||
|
<li><p><tt><tt>\</tt>x<hex scalar value>;</tt> : specified character (note the
|
||
|
terminating semi-colon).
|
||
|
</p>
|
||
|
</ul><p></p>
|
||
|
<p>
|
||
|
These escape sequences are case-sensitive, except that the alphabetic
|
||
|
digits of a <hex scalar value> can be uppercase or lowercase.</p>
|
||
|
<p>
|
||
|
Any other character in a string after a backslash is a syntax violation. Except
|
||
|
for a line ending, any
|
||
|
character outside of an escape sequence and not a doublequote stands
|
||
|
for itself in the string literal. For example the single-character
|
||
|
string literal <tt>"λ"</tt> (doublequote, a lower case lambda, doublequote)
|
||
|
represents the same string as <tt>"<tt>\</tt>x03bb;"</tt>.
|
||
|
A line ending that does not follow a backslash stands for a linefeed character.</p>
|
||
|
<p>
|
||
|
Examples:</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<table border=0><tr><td valign=top ><tt>"abc"</tt> </td><td valign=top >U+0061, U+0062, U+0063</td></tr>
|
||
|
<tr><td valign=top ><tt>"<tt>\</tt>x41;bc"</tt> </td><td valign=top ><tt>"Abc"</tt> ; U+0041, U+0062, U+0063</td></tr>
|
||
|
<tr><td valign=top ><tt>"<tt>\</tt>x41; bc"</tt> </td><td valign=top ><tt>"A bc"</tt></td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >U+0041, U+0020, U+0062, U+0063</td></tr>
|
||
|
<tr><td valign=top ><tt>"<tt>\</tt>x41bc;"</tt> </td><td valign=top >U+41BC</td></tr>
|
||
|
<tr><td valign=top ><tt>"<tt>\</tt>x41"</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ><tt>"<tt>\</tt>x;"</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ><tt>"<tt>\</tt>x41bx;"</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ><tt>"<tt>\</tt>x00000041;"</tt> </td><td valign=top ><tt>"A"</tt> ; U+0041</td></tr>
|
||
|
<tr><td valign=top ><tt>"<tt>\</tt>x0010FFFF;"</tt> </td><td valign=top >U+10FFFF</td></tr>
|
||
|
<tr><td valign=top ><tt>"<tt>\</tt>x00110000;"</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >out of range</td></tr>
|
||
|
<tr><td valign=top ><tt>"<tt>\</tt>x000000001;"</tt> </td><td valign=top >U+0001</td></tr>
|
||
|
<tr><td valign=top ><tt>"<tt>\</tt>xD800;"</tt> </td><td valign=top ><tt>&lexical</tt> <i>exception</i></td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >in excluded range</td></tr>
|
||
|
<tr><td valign=top ><tt>"A</tt></td></tr>
|
||
|
<tr><td valign=top ><tt>bc"</tt> </td><td valign=top >U+0041, U+000A, U+0062, U+0063</td></tr>
|
||
|
<tr><td valign=top ></td><td valign=top >if no space occurs after the <tt>A</tt>
|
||
|
</td></tr></table>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.2.8"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.2.8">4.2.8 Numbers</a></h3>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
The syntax of external representations for number objects is described
|
||
|
formally by the <number> rule in the formal grammar.
|
||
|
Case is not significant in external representations of number objects.</p>
|
||
|
<p>
|
||
|
A representation of a number object may be written in binary, octal, decimal, or
|
||
|
hexadecimal by the use of a radix prefix. The radix prefixes are <tt>#b</tt><a name="node_idx_160"></a>(binary), <tt>#o</tt><a name="node_idx_162"></a>(octal), <tt>#d</tt><a name="node_idx_164"></a>(decimal), and <tt>#x</tt><a name="node_idx_166"></a>(hexadecimal). With
|
||
|
no radix prefix, a representation of a number object is assumed to be expressed in decimal.</p>
|
||
|
<p>
|
||
|
A representation of a number object may be specified to be either exact or
|
||
|
inexact by a prefix. The prefixes are <tt>#e</tt><a name="node_idx_168"></a>for exact, and <tt>#i</tt><a name="node_idx_170"></a>for inexact. An exactness
|
||
|
prefix may appear before or after any radix prefix that is used. If
|
||
|
the representation of a number object has no exactness prefix, the
|
||
|
constant is
|
||
|
inexact if it contains a decimal point, an
|
||
|
exponent, or
|
||
|
a nonempty mantissa width;
|
||
|
otherwise it is exact.</p>
|
||
|
<p>
|
||
|
In systems with inexact number objects
|
||
|
of varying precisions, it may be useful to specify
|
||
|
the precision of a constant. For this purpose, representations of
|
||
|
number objects
|
||
|
may be written with an exponent marker that indicates the
|
||
|
desired precision of the inexact
|
||
|
representation. The letters <tt>s</tt>, <tt>f</tt>,
|
||
|
<tt>d</tt>, and <tt>l</tt> specify the use of <i>short</i>, <i>single</i>,
|
||
|
<i>double</i>, and <i>long</i> precision, respectively. (When fewer
|
||
|
than four internal
|
||
|
inexact
|
||
|
representations exist, the four size
|
||
|
specifications are mapped onto those available. For example, an
|
||
|
implementation with two internal representations may map short and
|
||
|
single together and long and double together.) In addition, the
|
||
|
exponent marker <tt>e</tt> specifies the default precision for the
|
||
|
implementation. The default precision has at least as much precision
|
||
|
as <i>double</i>, but
|
||
|
implementations may wish to allow this default to be set by the user.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
|
||
|
<tt>3.1415926535898F0
|
||
|
<p class=nopadding> Round to single, perhaps 3.141593</p>
|
||
|
|
||
|
<p class=nopadding>0.6L0</p>
|
||
|
|
||
|
<p class=nopadding> Extend to long, perhaps .600000000000000</p>
|
||
|
<p></tt></p>
|
||
|
<p>
|
||
|
A representation of a number object with nonempty mantissa width,
|
||
|
<tt><i>x</i>|<i>p</i></tt>, represents the best binary
|
||
|
floating-point approximation of <i>x</i> using a <i>p</i>-bit significand.
|
||
|
For example, <tt>1.1|53</tt> is a
|
||
|
representation of the best approximation of 1.1 in IEEE double
|
||
|
precision.
|
||
|
If <i>x</i> is an external representation of an inexact real number object
|
||
|
that contains no vertical bar, then its numerical value should be computed
|
||
|
as though it had a mantissa width of 53 or more.</p>
|
||
|
<p>
|
||
|
Implementations that use binary floating-point representations
|
||
|
of real number objects should represent <tt><i>x</i>|<i>p</i></tt>
|
||
|
using a <i>p</i>-bit significand if practical, or by a greater
|
||
|
precision if a <i>p</i>-bit significand is not practical, or
|
||
|
by the largest available precision if <i>p</i> or more bits
|
||
|
of significand are not practical within the implementation.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<blockquote><em>Note:<span style="margin-left: .5em">‌</span></em>
|
||
|
The precision of a significand should not be confused with the
|
||
|
number of bits used to represent the significand. In the IEEE
|
||
|
floating-point standards, for example, the significand's most
|
||
|
significant bit is implicit in single and double precision but
|
||
|
is explicit in extended precision. Whether that bit is implicit
|
||
|
or explicit does not affect the mathematical precision.
|
||
|
In implementations that use binary floating point, the default
|
||
|
precision can be calculated by calling the following procedure:<p>
|
||
|
</p>
|
||
|
|
||
|
<tt>(define (precision)
|
||
|
<p class=nopadding> (do ((n 0 (+ n 1))</p>
|
||
|
|
||
|
<p class=nopadding> (x 1.0 (/ x 2.0)))</p>
|
||
|
|
||
|
<p class=nopadding> ((= 1.0 (+ 1.0 x)) n)))</p>
|
||
|
|
||
|
<p class=nopadding></p>
|
||
|
<p></tt>
|
||
|
</p>
|
||
|
</blockquote> <p>
|
||
|
</p>
|
||
|
<blockquote><em>Note:<span style="margin-left: .5em">‌</span></em>
|
||
|
When the underlying floating-point representation is IEEE double
|
||
|
precision, the <tt>|<i>p</i></tt> suffix should not always be omitted:
|
||
|
Denormalized floating-point numbers have diminished precision,
|
||
|
and therefore their external representations should
|
||
|
carry a <tt>|<i>p</i></tt> suffix with the actual width of the
|
||
|
significand.
|
||
|
</blockquote><p>
|
||
|
The literals <tt>+inf.0</tt> and <tt>-inf.0</tt> represent positive and
|
||
|
negative infinity, respectively. The <tt>+nan.0</tt>
|
||
|
literal represents the NaN that is the result of <tt>(/ 0.0 0.0)</tt>,
|
||
|
and may represent other NaNs as well.</p>
|
||
|
<p>
|
||
|
If <i>x</i> is an external representation of an inexact real number
|
||
|
object and
|
||
|
contains no vertical bar and no exponent marker
|
||
|
other than <tt>e</tt>, the inexact real number object it represents is a flonum
|
||
|
(see library section on “Flonums”).
|
||
|
Some or all of the other external representations of
|
||
|
inexact real number objects may also represent flonums, but that is not required by
|
||
|
this report.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.3"></a>
|
||
|
<h2 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.3">4.3 Datum syntax</a></h2>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
The datum syntax describes the syntax of
|
||
|
syntactic data<a name="node_idx_172"></a>in terms of a sequence of
|
||
|
<lexeme>s, as defined in the lexical syntax.</p>
|
||
|
<p>
|
||
|
Syntactic data include the lexeme data described in the
|
||
|
previous section as well as the following constructs for forming
|
||
|
compound data:
|
||
|
</p>
|
||
|
<ul>
|
||
|
<li><p>pairs and lists, enclosed by <code class=verbatim>( )</code> or <code class=verbatim>[ ]</code> (see
|
||
|
section <a href="r6rs-Z-H-7.html#node_sec_4.3.2">4.3.2</a>)
|
||
|
</p>
|
||
|
<li><p>vectors (see section <a href="r6rs-Z-H-7.html#node_sec_4.3.3">4.3.3</a>)
|
||
|
</p>
|
||
|
<li><p>bytevectors (see section <a href="r6rs-Z-H-7.html#node_sec_4.3.4">4.3.4</a>)
|
||
|
</p>
|
||
|
</ul><p></p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.3.1"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.3.1">4.3.1 Formal account</a></h3>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
The following grammar describes the syntax of syntactic data in terms
|
||
|
of various kinds of lexemes defined in the grammar in
|
||
|
section <a href="r6rs-Z-H-7.html#node_sec_4.2">4.2</a>:</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<tt><datum> → <lexeme datum>
|
||
|
<p class=nopadding><span style="margin-left: 2em">‌</span> ∣ <compound datum></p>
|
||
|
|
||
|
<p class=nopadding><lexeme datum> → <boolean> ∣ <number></p>
|
||
|
|
||
|
<p class=nopadding> ∣ <character> ∣ <string> ∣ <symbol></p>
|
||
|
|
||
|
<p class=nopadding><symbol> → <identifier></p>
|
||
|
|
||
|
<p class=nopadding><compound datum> → <list> ∣ <vector> ∣ <bytevector></p>
|
||
|
|
||
|
<p class=nopadding><list> → (<datum>*) ∣ [<datum>*]</p>
|
||
|
|
||
|
<p class=nopadding> ∣ (<datum><sup>+</sup> . <datum>) ∣ [<datum><sup>+</sup> . <datum>]</p>
|
||
|
|
||
|
<p class=nopadding> ∣ <abbreviation></p>
|
||
|
|
||
|
<p class=nopadding><abbreviation> → <abbrev prefix> <datum></p>
|
||
|
|
||
|
<p class=nopadding><abbrev prefix> → ' ∣ ` ∣ , ∣ ,@</p>
|
||
|
|
||
|
<p class=nopadding> ∣ #' | #` | #, | #,@</p>
|
||
|
|
||
|
<p class=nopadding><vector> → #(<datum>*)</p>
|
||
|
|
||
|
<p class=nopadding><bytevector> → #vu8(<u8>*)</p>
|
||
|
|
||
|
<p class=nopadding><u8> → ⟨any <number> representing an exact</p>
|
||
|
|
||
|
<p class=nopadding> <span style="margin-left: 1em">‌</span><span style="margin-left: 1em">‌</span>integer in {0, <tt>...</tt>, 255}⟩</p>
|
||
|
</tt><p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.3.2"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.3.2">4.3.2 Pairs and lists</a></h3>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
List and pair data, representing pairs and lists of values
|
||
|
(see section <a href="r6rs-Z-H-14.html#node_sec_11.9">11.9</a>) are represented using parentheses or brackets.
|
||
|
Matching pairs of brackets that occur in the rules of <list> are
|
||
|
equivalent to matching pairs of parentheses.</p>
|
||
|
<p>
|
||
|
The most general notation for Scheme pairs as syntactic data is
|
||
|
the “dotted” notation <tt>(<datum<sub>1</sub>> . <datum<sub>2</sub>>)</tt> where
|
||
|
<datum<sub>1</sub>> is the representation of the value of the car field and
|
||
|
<datum<sub>2</sub>> is the representation of the value of the
|
||
|
cdr field. For example <tt>(4 . 5)</tt> is a pair whose car is 4 and whose
|
||
|
cdr is 5.</p>
|
||
|
<p>
|
||
|
A more streamlined notation can be used for lists: the elements of the
|
||
|
list are simply enclosed in parentheses and separated by spaces. The
|
||
|
empty list<a name="node_idx_174"></a>is represented by <tt>()</tt> . For example,</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
|
||
|
<tt>(a b c d e)<p></tt></p>
|
||
|
<p>
|
||
|
and</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
|
||
|
<tt>(a . (b . (c . (d . (e . ())))))<p></tt></p>
|
||
|
<p>
|
||
|
are equivalent notations for a list of symbols.</p>
|
||
|
<p>
|
||
|
The general rule is that, if a dot is followed by an open parenthesis,
|
||
|
the dot, open parenthesis, and matching closing parenthesis
|
||
|
can be omitted in the external representation.</p>
|
||
|
<p>
|
||
|
The sequence of characters “<tt>(4 . 5)</tt>” is the external representation of a
|
||
|
pair, not an expression that evaluates to a pair.
|
||
|
Similarly, the sequence of characters “<tt>(+ 2 6)</tt>” is <em>not</em> an
|
||
|
external representation of the integer 8, even though it <em>is</em> an
|
||
|
expression (in the language of the <tt>(rnrs base (6))</tt> library)
|
||
|
evaluating to the integer 8; rather, it is a
|
||
|
syntactic datum representing a three-element list, the elements of which
|
||
|
are the symbol <tt>+</tt> and the integers 2 and 6.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.3.3"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.3.3">4.3.3 Vectors</a></h3>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
Vector data, representing vectors of objects (see
|
||
|
section <a href="r6rs-Z-H-14.html#node_sec_11.13">11.13</a>), are represented using the notation
|
||
|
<tt>#(<datum> <tt>...</tt>)</tt>. For example, a vector of length 3
|
||
|
containing the number object for zero in element 0, the list <tt>(2 2 2 2)</tt> in
|
||
|
element 1, and the string <tt>"Anna"</tt> in element 2 can be represented as
|
||
|
follows:</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
|
||
|
<tt>#(0 (2 2 2 2) "Anna")<p></tt></p>
|
||
|
<p>
|
||
|
This is the external representation of a vector, not an
|
||
|
expression that evaluates to a vector.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.3.4"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.3.4">4.3.4 Bytevectors</a></h3>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
Bytevector data, representing bytevectors (see
|
||
|
library chapter on “Bytevectors”), are represented using the notation
|
||
|
<tt>#vu8(<u8> <tt>...</tt>)</tt>, where the <u8>s represent the octets of
|
||
|
the bytevector. For example, a bytevector of length 3 containing the
|
||
|
octets 2, 24, and 123 can be represented as follows:</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
|
||
|
<tt>#vu8(2 24 123)<p></tt></p>
|
||
|
<p>
|
||
|
This is the external representation of a bytevector, and also an
|
||
|
expression that evaluates to a bytevector.</p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<a name="node_sec_4.3.5"></a>
|
||
|
<h3 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_4.3.5">4.3.5 Abbreviations</a></h3>
|
||
|
<p><div style="height: -9.0pt"></div>
|
||
|
<p style="margin-top: 0pt; margin-bottom: 0pt"></p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<p></p>
|
||
|
<div align=left><tt><tt>'</tt><datum></tt><span style="margin-left: .5em">‌</span><span style="margin-left: .5em">‌</span> </div>
|
||
|
|
||
|
<div align=left><tt><tt>`</tt><datum></tt><span style="margin-left: .5em">‌</span><span style="margin-left: .5em">‌</span> </div>
|
||
|
|
||
|
<div align=left><tt>,<datum></tt><span style="margin-left: .5em">‌</span><span style="margin-left: .5em">‌</span> </div>
|
||
|
|
||
|
<div align=left><tt>,<tt>@</tt><datum></tt><span style="margin-left: .5em">‌</span><span style="margin-left: .5em">‌</span> </div>
|
||
|
|
||
|
<div align=left><tt>#'<datum></tt><span style="margin-left: .5em">‌</span><span style="margin-left: .5em">‌</span> </div>
|
||
|
|
||
|
<div align=left><tt>#<tt>`</tt><datum></tt><span style="margin-left: .5em">‌</span><span style="margin-left: .5em">‌</span> </div>
|
||
|
|
||
|
<div align=left><tt>#,<datum></tt><span style="margin-left: .5em">‌</span><span style="margin-left: .5em">‌</span> </div>
|
||
|
|
||
|
<div align=left><tt>#,@<datum></tt><span style="margin-left: .5em">‌</span><span style="margin-left: .5em">‌</span> </div>
|
||
|
<p>
|
||
|
Each of these is an abbreviation:
|
||
|
<br>
|
||
|
<span style="margin-left: 1em">‌</span><a name="node_idx_176"></a><tt>'</tt><datum>
|
||
|
for <tt>(quote <datum>)</tt>,
|
||
|
<br>
|
||
|
<span style="margin-left: 1em">‌</span><a name="node_idx_178"></a><tt>`</tt><datum>
|
||
|
for <tt>(quasiquote <datum>)</tt>,
|
||
|
<br>
|
||
|
<span style="margin-left: 1em">‌</span><a name="node_idx_180"></a><tt>,</tt><datum>
|
||
|
for <tt>(unquote <datum>)</tt>,
|
||
|
<br>
|
||
|
<span style="margin-left: 1em">‌</span><a name="node_idx_182"></a><tt>,</tt><tt>@</tt><datum>
|
||
|
for <tt>(unquote-splicing <datum>)</tt>,
|
||
|
<br>
|
||
|
<span style="margin-left: 1em">‌</span><a name="node_idx_184"></a><tt>#'</tt><datum>
|
||
|
for <tt>(syntax <datum>)</tt>,
|
||
|
<br>
|
||
|
<span style="margin-left: 1em">‌</span><a name="node_idx_186"></a><tt>#`</tt><datum>
|
||
|
for <tt>(quasisyntax <datum>)</tt>,
|
||
|
<br>
|
||
|
<span style="margin-left: 1em">‌</span><a name="node_idx_188"></a><tt>#,</tt><datum>
|
||
|
for <tt>(unsyntax <datum>)</tt>, and
|
||
|
<br>
|
||
|
<span style="margin-left: 1em">‌</span><a name="node_idx_190"></a><tt>#,@</tt><datum>
|
||
|
for <tt>(unsyntax-splicing <datum>)</tt>.
|
||
|
</p>
|
||
|
<p></p>
|
||
|
<p>
|
||
|
</p>
|
||
|
<p></p>
|
||
|
<div class=smallskip></div>
|
||
|
<p style="margin-top: 0pt; margin-bottom: 0pt">
|
||
|
<div align=right class=navigation>[Go to <span><a href="r6rs.html">first</a>, <a href="r6rs-Z-H-6.html">previous</a></span><span>, <a href="r6rs-Z-H-8.html">next</a></span> page<span>; </span><span><a href="r6rs-Z-H-2.html#node_toc_start">contents</a></span><span><span>; </span><a href="r6rs-Z-H-21.html#node_index_start">index</a></span>]</div>
|
||
|
</p>
|
||
|
<p></p>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|