165 lines
8.4 KiB
HTML
165 lines
8.4 KiB
HTML
|
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
||
|
<html>
|
||
|
<!-- Generated from TeX source by tex2page, v 4o4,
|
||
|
(c) Dorai Sitaram, http://www.cs.rice.edu/~dorai/tex2page -->
|
||
|
<head>
|
||
|
<title>
|
||
|
Revised^5 Report on the Algorithmic Language Scheme
|
||
|
</title>
|
||
|
<link rel="stylesheet" type="text/css" href="r5rs-Z-C.css" title=default>
|
||
|
<meta name=robots content="noindex,follow">
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<p><div class=navigation>[Go to <span><a href="r5rs.html">first</a>, <a href="r5rs-Z-H-4.html">previous</a></span><span>, <a href="r5rs-Z-H-6.html">next</a></span> page<span>; </span><span><a href="r5rs-Z-H-2.html#%_toc_start">contents</a></span><span><span>; </span><a href="r5rs-Z-H-15.html#%_index_start">index</a></span>]</div><p>
|
||
|
|
||
|
<a name="%_chap_2"></a>
|
||
|
<h1 class=chapter>
|
||
|
<div class=chapterheading><a href="r5rs-Z-H-2.html#%_toc_%_chap_2">Chapter 2</a></div><p>
|
||
|
<a href="r5rs-Z-H-2.html#%_toc_%_chap_2">Lexical conventions</a></h1><p>
|
||
|
|
||
|
This section gives an informal account of some of the lexical
|
||
|
conventions used in writing Scheme programs. For a formal syntax of
|
||
|
Scheme, see section <a href="r5rs-Z-H-10.html#%_sec_7.1">7.1</a>.<p>
|
||
|
|
||
|
Upper and lower case forms of a letter are never distinguished
|
||
|
except within character and string constants. For example, <tt>Foo</tt> is
|
||
|
the same identifier as <tt>FOO</tt>, and <tt>#x1AB</tt> is the same number as
|
||
|
<tt>#X1ab</tt>.<p>
|
||
|
|
||
|
<a name="%_sec_2.1"></a>
|
||
|
<h2><a href="r5rs-Z-H-2.html#%_toc_%_sec_2.1">2.1 Identifiers</a></h2><p>
|
||
|
|
||
|
<p>
|
||
|
|
||
|
Most identifiers<a name="%_idx_14"></a> allowed by other programming
|
||
|
languages are also acceptable to Scheme. The precise rules for forming
|
||
|
identifiers vary among implementations of Scheme, but in all
|
||
|
implementations a sequence of letters, digits, and ``extended alphabetic
|
||
|
characters'' that begins with a character that cannot begin a number is
|
||
|
an identifier. In addition, <tt>+</tt>, <tt>-</tt>, and <tt>...</tt> are identifiers.
|
||
|
Here are some examples of identifiers:<p>
|
||
|
|
||
|
<tt><p>lambda q<br>
|
||
|
list->vector soup<br>
|
||
|
+ V17a<br>
|
||
|
<=? a34kTMNs<br>
|
||
|
the-word-recursion-has-many-meanings<p></tt><p>
|
||
|
|
||
|
Extended alphabetic characters may be used within identifiers as if
|
||
|
they were letters. The following are extended alphabetic characters:<p>
|
||
|
|
||
|
<tt><p>! $ % <code class=verbatim>&</code> * + - . / : < = > ? @ <code class=verbatim>^</code> <code class=verbatim>_</code> <code class=verbatim>~</code> <p></tt><p>
|
||
|
|
||
|
See section <a href="r5rs-Z-H-10.html#%_sec_7.1.1">7.1.1</a> for a formal syntax of identifiers.<p>
|
||
|
|
||
|
Identifiers have two uses within Scheme programs:
|
||
|
<p><ul>
|
||
|
<li>Any identifier may be used as a variable<a name="%_idx_16"></a>
|
||
|
or as a syntactic keyword<a name="%_idx_18"></a>
|
||
|
(see sections <a href="r5rs-Z-H-6.html#%_sec_3.1">3.1</a> and <a href="r5rs-Z-H-7.html#%_sec_4.3">4.3</a>).<p>
|
||
|
|
||
|
<li>When an identifier appears as a literal or within a literal
|
||
|
(see section <a href="r5rs-Z-H-7.html#%_sec_4.1.2">4.1.2</a>), it is being used to denote a <em>symbol</em>
|
||
|
(see section <a href="r5rs-Z-H-9.html#%_sec_6.3.3">6.3.3</a>).<p>
|
||
|
|
||
|
</ul><p><p>
|
||
|
|
||
|
<p>
|
||
|
|
||
|
<a name="%_sec_2.2"></a>
|
||
|
<h2><a href="r5rs-Z-H-2.html#%_toc_%_sec_2.2">2.2 Whitespace and comments</a></h2><p>
|
||
|
|
||
|
<a name="%_idx_20"></a><em>Whitespace</em> characters are spaces and newlines.
|
||
|
(Implementations typically provide additional whitespace characters such
|
||
|
as tab or page break.) Whitespace is used for improved readability and
|
||
|
as necessary to separate tokens from each other, a token being an
|
||
|
indivisible lexical unit such as an identifier or number, but is
|
||
|
otherwise insignificant. Whitespace may occur between any two tokens,
|
||
|
but not within a token. Whitespace may also occur inside a string,
|
||
|
where it is significant.<p>
|
||
|
|
||
|
A semicolon (<tt>;</tt>) indicates the start of a
|
||
|
comment.<a name="%_idx_22"></a><a name="%_idx_24"></a> The comment continues to the
|
||
|
end of the line on which the semicolon appears. Comments are invisible
|
||
|
to Scheme, but the end of the line is visible as whitespace. This
|
||
|
prevents a comment from appearing in the middle of an identifier or
|
||
|
number.<p>
|
||
|
|
||
|
<tt><p>;;; The FACT procedure computes the factorial<br>
|
||
|
;;; of a non-negative integer.<br>
|
||
|
(define fact<br>
|
||
|
(lambda (n)<br>
|
||
|
(if (= n 0)<br>
|
||
|
1 ;Base case: return 1<br>
|
||
|
(* n (fact (- n 1))))))<p></tt><p>
|
||
|
|
||
|
<a name="%_sec_2.3"></a>
|
||
|
<h2><a href="r5rs-Z-H-2.html#%_toc_%_sec_2.3">2.3 Other notations</a></h2><p>
|
||
|
|
||
|
<p>
|
||
|
|
||
|
For a description of the notations used for numbers, see
|
||
|
section <a href="r5rs-Z-H-9.html#%_sec_6.2">6.2</a>.<p>
|
||
|
|
||
|
<p><ul><p>
|
||
|
|
||
|
<li><b><tt>. + -</tt></b>
|
||
|
These are used in numbers, and may also occur anywhere in an identifier
|
||
|
except as the first character. A delimited plus or minus sign by itself
|
||
|
is also an identifier.
|
||
|
A delimited period (not occurring within a number or identifier) is used
|
||
|
in the notation for pairs (section <a href="r5rs-Z-H-9.html#%_sec_6.3.2">6.3.2</a>), and to indicate a
|
||
|
rest-parameter in a formal parameter list (section <a href="r5rs-Z-H-7.html#%_sec_4.1.4">4.1.4</a>).
|
||
|
A delimited sequence of three successive periods is also an identifier.<p>
|
||
|
|
||
|
<li><b><tt>( )</tt></b>
|
||
|
Parentheses are used for grouping and to notate lists
|
||
|
(section <a href="r5rs-Z-H-9.html#%_sec_6.3.2">6.3.2</a>).<p>
|
||
|
|
||
|
<li><b><tt>'</tt></b>
|
||
|
The single quote character is used to indicate literal data (section <a href="r5rs-Z-H-7.html#%_sec_4.1.2">4.1.2</a>).<p>
|
||
|
|
||
|
<li><b><tt>`</tt></b>
|
||
|
The backquote character is used to indicate almost-constant
|
||
|
data (section <a href="r5rs-Z-H-7.html#%_sec_4.2.6">4.2.6</a>).<p>
|
||
|
|
||
|
<li><b><tt>, ,@</tt></b>
|
||
|
The character comma and the sequence comma at-sign are used in conjunction
|
||
|
with backquote (section <a href="r5rs-Z-H-7.html#%_sec_4.2.6">4.2.6</a>).<p>
|
||
|
|
||
|
<li><b><tt>"</tt></b>
|
||
|
The double quote character is used to delimit strings (section <a href="r5rs-Z-H-9.html#%_sec_6.3.5">6.3.5</a>).<p>
|
||
|
|
||
|
<li><b><tt>\</tt></b>
|
||
|
Backslash is used in the syntax for character constants
|
||
|
(section <a href="r5rs-Z-H-9.html#%_sec_6.3.4">6.3.4</a>) and as an escape character within string
|
||
|
constants (section <a href="r5rs-Z-H-9.html#%_sec_6.3.5">6.3.5</a>).<p>
|
||
|
|
||
|
<li><b><code class=verbatim>[ ] { } |</code></b>
|
||
|
Left and right square brackets and curly braces and vertical bar
|
||
|
are reserved for possible future extensions to the language.<p>
|
||
|
|
||
|
<li><b><tt>#</tt></b> Sharp sign is used for a variety of purposes depending on
|
||
|
the character that immediately follows it:<p>
|
||
|
|
||
|
<li><b><tt>#t</tt> <tt>#f</tt></b>
|
||
|
These are the boolean constants (section <a href="r5rs-Z-H-9.html#%_sec_6.3.1">6.3.1</a>).<p>
|
||
|
|
||
|
<li><b><tt>#</tt><tt>\</tt></b>
|
||
|
This introduces a character constant (section <a href="r5rs-Z-H-9.html#%_sec_6.3.4">6.3.4</a>).<p>
|
||
|
|
||
|
<li><b><tt>#</tt><tt>(</tt></b>
|
||
|
This introduces a vector constant (section <a href="r5rs-Z-H-9.html#%_sec_6.3.6">6.3.6</a>). Vector constants
|
||
|
are terminated by <tt>)</tt> .<p>
|
||
|
|
||
|
<li><b><tt>#e #i #b #o #d #x</tt></b>
|
||
|
These are used in the notation for numbers (section <a href="r5rs-Z-H-9.html#%_sec_6.2.4">6.2.4</a>).<p>
|
||
|
|
||
|
</ul><p>
|
||
|
<p>
|
||
|
<p><div class=navigation>[Go to <span><a href="r5rs.html">first</a>, <a href="r5rs-Z-H-4.html">previous</a></span><span>, <a href="r5rs-Z-H-6.html">next</a></span> page<span>; </span><span><a href="r5rs-Z-H-2.html#%_toc_start">contents</a></span><span><span>; </span><a href="r5rs-Z-H-15.html#%_index_start">index</a></span>]</div><p>
|
||
|
|
||
|
</body>
|
||
|
</html>
|