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

📄 r5rs-z-h-9.html

📁 scheme 标准(r5rs)。Scheme是MIT发布的基于Lambda运算的语言
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<blockquote><em>Rationale:&nbsp;&nbsp;</em> The above definition of <tt>eqv?</tt> allows implementations latitude intheir treatment of procedures and literals:  implementations are freeeither to detect or to fail to detect that two procedures or two literalsare equivalent to each other, and can decide whether or not tomerge representations of equivalent objects by using the same pointer orbit pattern to represent both.</blockquote><p><p><p><p><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_216"></a>eq?<i> <i>obj<sub>1</sub></i> <i>obj<sub>2</sub></i></i>)</tt>&nbsp;</div><p><tt>Eq?</tt> is similar to <tt>eqv?</tt> except that in some cases it iscapable of discerning distinctions finer than those detectable by<tt>eqv?</tt>.<p><tt>Eq?</tt> and <tt>eqv?</tt> are guaranteed to have the samebehavior on symbols, booleans, the empty list, pairs, procedures,and non-emptystrings and vectors.  <tt>Eq?</tt>'s behavior on numbers and characters isimplementation-dependent, but it will always return either true orfalse, and will return true only when <tt>eqv?</tt> would also returntrue.  <tt>Eq?</tt> may also behave differently from <tt>eqv?</tt> on emptyvectors and empty strings.<p><tt><p>(eq?&nbsp;'a&nbsp;'a)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;&nbsp;<tt>#t</tt><br>(eq?&nbsp;'(a)&nbsp;'(a))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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sp;p&nbsp;p))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;&nbsp;<tt>#t</tt><p></tt><p><p><blockquote><em>Rationale:&nbsp;&nbsp;</em> It will usually be possible to implement <tt>eq?</tt> muchmore efficiently than <tt>eqv?</tt>, for example, as a simple pointercomparison instead of as some more complicated operation.  One reason isthat it may not be possible to compute <tt>eqv?</tt> of two numbers inconstant time, whereas <tt>eq?</tt> implemented as pointer comparison willalways finish in constant time.  <tt>Eq?</tt> may be used like <tt>eqv?</tt>in applications using procedures to implement objects with state sinceit obeys the same constraints as <tt>eqv?</tt>.</blockquote><p><p><p><p><div align=left><u>library procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_218"></a>equal?<i> <i>obj<sub>1</sub></i> <i>obj<sub>2</sub></i></i>)</tt>&nbsp;</div><p><tt>Equal?</tt> recursively compares the contents of pairs, vectors, andstrings, applying <tt>eqv?</tt> on other objects such as numbers and symbols.A rule of thumb is that objects are generally <tt>equal?</tt> if they printthe same.  <tt>Equal?</tt> may fail to terminate if its arguments arecircular data structures.<p><tt><p>(equal?&nbsp;'a&nbsp;'a)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;&nbsp;<tt>#t</tt><br>(equal?&nbsp;'(a)&nbsp;'(a))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;&nbsp;<tt>#t</tt><br>(equal?&nbsp;'(a&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bsp;&nbsp;<i>unspecified</i><p></tt><p><p><p><a name="%_sec_6.2"></a><h2><a href="r5rs-Z-H-2.html#%_toc_%_sec_6.2">6.2&nbsp;&nbsp;Numbers</a></h2><p><a name="%_idx_220"></a><p><p>Numerical computation has traditionally been neglected by the Lispcommunity.  Until Common Lisp there was no carefully thought outstrategy for organizing numerical computation, and with the exception ofthe MacLisp system [<a href="r5rs-Z-H-14.html#%_sec_7.3">20</a>] little effort was made toexecute numerical code efficiently.  This report recognizes the excellent workof the Common Lisp committee and accepts many of their recommendations.In some ways this report simplifies and generalizes their proposals in a mannerconsistent with the purposes of Scheme.<p>It is important to distinguish between the mathematical numbers, theScheme numbers that attempt to model them, the machine representationsused to implement the Scheme numbers, and notations used to write numbers.This report uses the types <i>number</i>, <i>complex</i>, <i>real</i>,<i>rational</i>, and <i>integer</i> to refer to both mathematical numbersand Scheme numbers.  Machine representations such as fixed point andfloating point are referred to by names such as <i>fixnum</i> and<i>flonum</i>.<p><a name="%_sec_6.2.1"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_6.2.1">6.2.1&nbsp;&nbsp;Numerical types</a></h3><p><a name="%_idx_222"></a><p>Mathematically, numbers may be arranged into a tower of subtypesin which each level is a subset of the level above it:<p>         number <br>&nbsp;&nbsp;&nbsp; complex <br>&nbsp;&nbsp;&nbsp; real <br>&nbsp;&nbsp;&nbsp; rational <br>&nbsp;&nbsp;&nbsp; integer <p><p>For example, 3 is an integer.  Therefore 3 is also a rational,a real, and a complex.  The same is true of the Scheme numbersthat model 3.  For Scheme numbers, these types are defined by thepredicates <tt>number?</tt>, <tt>complex?</tt>, <tt>real?</tt>, <tt>rational?</tt>,and <tt>integer?</tt>.<p>There is no simple relationship between a number's type and itsrepresentation inside a computer.  Although most implementations ofScheme will offer at least two different representations of 3, thesedifferent representations denote the same integer.<p>Scheme's numerical operations treat numbers as abstract data, asindependent of their representation as possible.  Although an implementationof Scheme may use fixnum, flonum, and perhaps other representations fornumbers, this should not be apparent to a casual programmer writingsimple programs.<p>It is necessary, however, to distinguish between numbers that arerepresented exactly and those that may not be.  For example, indexesinto data structures must be known exactly, as must some polynomialcoefficients in a symbolic algebra system.  On the other hand, theresults of measurements are inherently inexact, and irrational numbersmay be approximated by rational and therefore inexact approximations.In order to catch uses of inexact numbers where exact numbers arerequired, Scheme explicitly distinguishes exact from inexact numbers.This distinction is orthogonal to the dimension of type.<p><a name="%_sec_6.2.2"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_6.2.2">6.2.2&nbsp;&nbsp;Exactness</a></h3><p><a name="%_idx_224"></a> Scheme numbers are either <i>exact</i> or <i>inexact</i>.  A number isexact if it was written as an exact constant or was derived fromexact numbers using only exact operations.  A number isinexact if it was written as an inexact constant,if it wasderived using inexact ingredients, or if it was derived usinginexact operations. Thus inexactness is a contagiousproperty of a number.If two implementations produce exact results for acomputation that did not involve inexact intermediate results,the two ultimate results will be mathematically equivalent.  This isgenerally not true of computations involving inexact numberssince approximate methods such as floating point arithmetic may be used,but it is the duty of each implementation to make the result as close aspractical to the mathematically ideal result.<p>Rational operations such as <tt>+</tt> should always produceexact results when given exact arguments.If the operation is unable to produce an exact result,then it may either report the violation of an implementation restrictionor it may silently coerce itsresult to an inexact value.See section&nbsp;<a href="#%_sec_6.2.3">6.2.3</a>.<p>With the exception of <tt>inexact-&gt;exact</tt>, the operations described inthis section must generally return inexact results when given any inexactarguments.  An operation may, however, return an exact result if it canprove that the value of the result is unaffected by the inexactness of itsarguments.  For example, multiplication of any number by an exact zeromay produce an exact zero result, even if the other argument isinexact.<p><a name="%_sec_6.2.3"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_6.2.3">6.2.3&nbsp;&nbsp;Implementation restrictions</a></h3><p><a name="%_idx_226"></a><p>Implementations of Scheme are not required to implement the wholetower of subtypes given in section&nbsp;<a href="#%_sec_6.2.1">6.2.1</a>,but they must implement a coherent subset consistent with both thepurposes of the implementation and the spirit of the Scheme language.For example, an implementation in which all numbers are realmay still be quite useful.<p>

⌨️ 快捷键说明

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