⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r5rs-z-h-6.html

📁 scheme 标准(r5rs)。Scheme是MIT发布的基于Lambda运算的语言
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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-5.html">previous</a></span><span>, <a href="r5rs-Z-H-7.html">next</a></span> page<span>; &nbsp;&nbsp;</span><span><a href="r5rs-Z-H-2.html#%_toc_start">contents</a></span><span><span>; &nbsp;&nbsp;</span><a href="r5rs-Z-H-15.html#%_index_start">index</a></span>]</div><p><a name="%_chap_3"></a><h1 class=chapter><div class=chapterheading><a href="r5rs-Z-H-2.html#%_toc_%_chap_3">Chapter 3</a></div><p><a href="r5rs-Z-H-2.html#%_toc_%_chap_3">Basic concepts</a></h1><p><p><a name="%_sec_3.1"></a><h2><a href="r5rs-Z-H-2.html#%_toc_%_sec_3.1">3.1&nbsp;&nbsp;Variables, syntactic keywords, and regions</a></h2><p><p>An identifier<a name="%_idx_26"></a> may name a type of syntax, or it may namea location where a value can be stored.  An identifier that names a typeof syntax is called a <em>syntactic keyword</em><a name="%_idx_28"></a>and is said to be <em>bound</em> to that syntax.  An identifier that names alocation is called a <em>variable</em><a name="%_idx_30"></a> and is said to be<em>bound</em> to that location.  The set of all visiblebindings<a name="%_idx_32"></a> in effect at some point in a program isknown as the <em>environment</em> in effect at that point.  The valuestored in the location to which a variable is bound is called thevariable's value.  By abuse of terminology, the variable is sometimessaid to name the value or to be bound to the value.  This is not quiteaccurate, but confusion rarely results from this practice.<p><p><p>Certain expression types are used to create new kinds of syntaxand bind syntactic keywords to those new syntaxes, while otherexpression types create new locations and bind variables to thoselocations.  These expression types are called <em>binding constructs</em>.<a name="%_idx_34"></a>Those that bind syntactic keywords are listed in section&nbsp;<a href="r5rs-Z-H-7.html#%_sec_4.3">4.3</a>.The most fundamental of the variable binding constructs is the<tt>lambda</tt> expression, because all other variable binding constructscan be explained in terms of <tt>lambda</tt> expressions.  The othervariable binding constructs are <tt>let</tt>, <tt>let*</tt>, <tt>letrec</tt>,and <tt>do</tt> expressions (see sections&nbsp;<a href="r5rs-Z-H-7.html#%_sec_4.1.4">4.1.4</a>, <a href="r5rs-Z-H-7.html#%_sec_4.2.2">4.2.2</a>, and<a href="r5rs-Z-H-7.html#%_sec_4.2.4">4.2.4</a>).<p>Like Algol and Pascal, and unlike most other dialects of Lispexcept for Common Lisp, Scheme is a statically scoped language withblock structure.  To each place where an identifier is bound in a programthere corresponds a <a name="%_idx_36"></a><em>region</em> of the program text within whichthe binding is visible.  The region is determined by the particularbinding construct that establishes the binding; if the binding isestablished by a <tt>lambda</tt> expression, for example, then its regionis the entire <tt>lambda</tt> expression.  Every mention of an identifierrefers to the binding of the identifier that established theinnermost of the regions containing the use.  If there is no binding ofthe identifier whose region contains the use, then the use refers to thebinding for the variable in the top level environment, if any(chapters&nbsp;<a href="r5rs-Z-H-7.html#%_chap_4">4</a> and <a href="r5rs-Z-H-9.html#%_chap_6">6</a>); if there is nobinding for the identifier,it is said to be <a name="%_idx_38"></a><em>unbound</em>.<a name="%_idx_40"></a><a name="%_idx_42"></a><p><p><p><p><a name="%_sec_3.2"></a><h2><a href="r5rs-Z-H-2.html#%_toc_%_sec_3.2">3.2&nbsp;&nbsp;Disjointness of types</a></h2><p><p>No object satisfies more than one of the following predicates:<p><tt><p>boolean?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pair?<br>symbol?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;number?<br>char?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string?<br>vector?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port?<br>procedure?<p></tt><p>These predicates define the types <em>boolean</em>, <em>pair</em>, <em>symbol</em>, <em>number</em>, <em>char</em> (or <em>character</em>), <em>string</em>, <em>vector</em>, <em>port</em>, and <em>procedure</em>.  The empty list is a specialobject of its own type; it satisfies none of the above predicates.<a name="%_idx_44"></a><a name="%_idx_46"></a><a name="%_idx_48"></a><a name="%_idx_50"></a><a name="%_idx_52"></a><a name="%_idx_54"></a><a name="%_idx_56"></a><a name="%_idx_58"></a><a name="%_idx_60"></a><a name="%_idx_62"></a><a name="%_idx_64"></a><p>Although there is a separate boolean type,any Scheme value can be used as a boolean value for the purpose of aconditional test.  As explained in section&nbsp;<a href="r5rs-Z-H-9.html#%_sec_6.3.1">6.3.1</a>, allvalues count as true in such a test except for <tt>#f</tt>.This report uses the word ``true'' to refer to anyScheme value except <tt>#f</tt>, and the word ``false'' to refer to<tt>#f</tt>. <a name="%_idx_66"></a> <a name="%_idx_68"></a><p><a name="%_sec_3.3"></a><h2><a href="r5rs-Z-H-2.html#%_toc_%_sec_3.3">3.3&nbsp;&nbsp;External representations</a></h2><p><p>An important concept in Scheme (and Lisp) is that of the <em>externalrepresentation</em> of an object as a sequence of characters.  For example,an external representation of the integer 28 is the sequence ofcharacters ``<tt>28</tt>'', and an external representation of a list consistingof the integers 8 and 13 is the sequence of characters ``<tt>(8 13)</tt>''.<p>The external representation of an object is not necessarily unique.  Theinteger 28 also has representations ``<tt>#e28.000</tt>'' and ``<tt>#x1c</tt>'', and thelist in the previous paragraph also has the representations ``<tt>( 08 13)</tt>'' and ``<tt>(8 . (13 . ()))</tt>'' (see section&nbsp;<a href="r5rs-Z-H-9.html#%_sec_6.3.2">6.3.2</a>).<p>Many objects have standard external representations, but some, such asprocedures, do not have standard representations (although particularimplementations may define representations for them).<p>An external representation may be written in a program to obtain thecorresponding object (see <tt>quote</tt>, section&nbsp;<a href="r5rs-Z-H-7.html#%_sec_4.1.2">4.1.2</a>).<p>External representations can also be used for input and output.  Theprocedure <tt>read</tt> (section&nbsp;<a href="r5rs-Z-H-9.html#%_sec_6.6.2">6.6.2</a>) parses externalrepresentations, and the procedure <tt>write</tt> (section&nbsp;<a href="r5rs-Z-H-9.html#%_sec_6.6.3">6.6.3</a>)generates them.  Together, they provide an elegant and powerfulinput/output facility.<p>Note that the sequence of characters ``<tt>(+ 2 6)</tt>'' is <em>not</em> anexternal representation of the integer 8, even though it <em>is</em> anexpression evaluating to the integer 8; rather, it is an externalrepresentation of a three-element list, the elements of which are the symbol<tt>+</tt> and the integers 2 and 6.  Scheme's syntax has the property thatany sequence of characters that is an expression is also the externalrepresentation of some object.  This can lead to confusion, since it maynot be obvious out of context whether a given sequence of characters isintended to denote data or program, but it is also a source of power,since it facilitates writing programs such as interpreters andcompilers that treat programs as data (or vice versa).<p>The syntax of external representations of various kinds of objectsaccompanies the description of the primitives for manipulating theobjects in the appropriate sections of chapter&nbsp;<a href="r5rs-Z-H-9.html#%_chap_6">6</a>.<p><a name="%_sec_3.4"></a><h2><a href="r5rs-Z-H-2.html#%_toc_%_sec_3.4">3.4&nbsp;&nbsp;Storage model</a></h2><p><p>Variables and objects such as pairs, vectors, and strings implicitlydenote locations<a name="%_idx_70"></a> or sequences of locations.  A string, forexample, denotes as many locations as there are characters in the string. (These locations need not correspond to a full machine word.) A new value may bestored into one of these locations using the <tt>string-set!</tt> procedure, butthe string continues to denote the same locations as before.<p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -