📄 r5rs-z-h-5.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 lexicalconventions used in writing Scheme programs. For a formal syntax ofScheme, 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 distinguishedexcept within character and string constants. For example, <tt>Foo</tt> isthe 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 programminglanguages are also acceptable to Scheme. The precise rules for formingidentifiers vary among implementations of Scheme, but in allimplementations a sequence of letters, digits, and ``extended alphabeticcharacters'' that begins with a character that cannot begin a number isan 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 ifthey 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 suchas tab or page break.) Whitespace is used for improved readability andas necessary to separate tokens from each other, a token being anindivisible lexical unit such as an identifier or number, but isotherwise 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 acomment.<a name="%_idx_22"></a><a name="%_idx_24"></a> The comment continues to theend of the line on which the semicolon appears. Comments are invisibleto Scheme, but the end of the line is visible as whitespace. Thisprevents a comment from appearing in the middle of an identifier ornumber.<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, seesection <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 identifierexcept as the first character. A delimited plus or minus sign by itselfis also an identifier.A delimited period (not occurring within a number or identifier) is usedin the notation for pairs (section <a href="r5rs-Z-H-9.html#%_sec_6.3.2">6.3.2</a>), and to indicate arest-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-constantdata (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 conjunctionwith 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 stringconstants (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 barare reserved for possible future extensions to the language.<p><li><b><tt>#</tt></b> Sharp sign is used for a variety of purposes depending onthe 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 constantsare 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -