emacs.d/clones/lisp/HyperSpec-7-0/HyperSpec/Body/f_equal.htm
2023-01-18 20:30:47 +01:00

103 lines
11 KiB
HTML

<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Function EQUAL</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="f_eql.htm">
<LINK REL=UP HREF="c_data_a.htm">
<LINK REL=NEXT HREF="f_equalp.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="f_eql.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_data_a.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_equalp.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="equal"><I>Function</I> <B>EQUAL</B></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>equal</B> <I>x y</I> =&gt; <I>generalized-boolean</I><P>
<P>
<P><B>Arguments and Values:</B><P>
<P>
<I>x</I>---an <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. <P>
<I>y</I>---an <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. <P>
<I>generalized-boolean</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. <P>
<P><B>Description:</B><P>
<P>
Returns <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A> if <I>x</I> and <I>y</I> are structurally similar (isomorphic) <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A>. <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>Objects</I></A> are treated as follows by <A REL=DEFINITION HREF="#equal"><B>equal</B></A>. <P>
<P><DL><DT><A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>Symbols</I></A>, <A REL=DEFINITION HREF="26_glo_n.htm#number"><I>Numbers</I></A>, and <A REL=DEFINITION HREF="26_glo_c.htm#character"><I>Characters</I></A> <P><DD>
<A REL=DEFINITION HREF="#equal"><B>equal</B></A> is <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A> of two <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> if they are <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbols</I></A> that are <A REL=DEFINITION HREF="f_eq.htm#eq"><B>eq</B></A>, if they are <A REL=DEFINITION HREF="26_glo_n.htm#number"><I>numbers</I></A> that are <A REL=DEFINITION HREF="f_eql.htm#eql"><B>eql</B></A>, or if they are <A REL=DEFINITION HREF="26_glo_c.htm#character"><I>characters</I></A> that are <A REL=DEFINITION HREF="f_eql.htm#eql"><B>eql</B></A>. <P>
<DT><A REL=DEFINITION HREF="26_glo_c.htm#cons"><I>Conses</I></A> <P><DD>
For <A REL=DEFINITION HREF="26_glo_c.htm#cons"><I>conses</I></A>, <A REL=DEFINITION HREF="#equal"><B>equal</B></A> is defined recursively as the two <A REL=DEFINITION HREF="26_glo_c.htm#car"><I>cars</I></A> being <A REL=DEFINITION HREF="#equal"><B>equal</B></A> and the two <A REL=DEFINITION HREF="26_glo_c.htm#cdr"><I>cdrs</I></A> being <A REL=DEFINITION HREF="#equal"><B>equal</B></A>. <P>
<DT><A REL=DEFINITION HREF="26_glo_a.htm#array"><I>Arrays</I></A> <P><DD>
Two <A REL=DEFINITION HREF="26_glo_a.htm#array"><I>arrays</I></A> are <A REL=DEFINITION HREF="#equal"><B>equal</B></A> only if they are <A REL=DEFINITION HREF="f_eq.htm#eq"><B>eq</B></A>, with one exception: <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>strings</I></A> and <A REL=DEFINITION HREF="26_glo_b.htm#bit_vector"><I>bit vectors</I></A> are compared element-by-element (using <A REL=DEFINITION HREF="f_eql.htm#eql"><B>eql</B></A>). If either <I>x</I> or <I>y</I> has a <A REL=DEFINITION HREF="26_glo_f.htm#fill_pointer"><I>fill pointer</I></A>, the <A REL=DEFINITION HREF="26_glo_f.htm#fill_pointer"><I>fill pointer</I></A> limits the number of elements examined by <A REL=DEFINITION HREF="#equal"><B>equal</B></A>. Uppercase and lowercase letters in <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>strings</I></A> are considered by <A REL=DEFINITION HREF="#equal"><B>equal</B></A> to be different. <P>
<DT><A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>Pathnames</I></A> <P><DD>
Two <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathnames</I></A> are <A REL=DEFINITION HREF="#equal"><B>equal</B></A> if and only if all the corresponding components (host, device, and so on) are equivalent. Whether or not uppercase and lowercase letters are considered equivalent in <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>strings</I></A> appearing in components is <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A>. <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathnames</I></A> that are <A REL=DEFINITION HREF="#equal"><B>equal</B></A> should be functionally equivalent. <P>
<DT><B>Other (Structures, hash-tables, instances, ...)</B> <P><DD>
Two other <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> are <A REL=DEFINITION HREF="#equal"><B>equal</B></A> only if they are <A REL=DEFINITION HREF="f_eq.htm#eq"><B>eq</B></A>. <P>
<P>
<P></DL><P>
<A REL=DEFINITION HREF="#equal"><B>equal</B></A> does not descend any <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> other than the ones explicitly specified above. The next figure summarizes the information given in the previous list. In addition, the figure specifies the priority of the behavior of <A REL=DEFINITION HREF="#equal"><B>equal</B></A>, with upper entries taking priority over lower ones. <P>
<PRE>
Type Behavior
<A REL=DEFINITION HREF="26_glo_n.htm#number">number</A> uses <A REL=DEFINITION HREF="f_eql.htm#eql">eql</A>
<A REL=DEFINITION HREF="26_glo_c.htm#character">character</A> uses <A REL=DEFINITION HREF="f_eql.htm#eql">eql</A>
<A REL=DEFINITION HREF="26_glo_c.htm#cons">cons</A> descends
<A REL=DEFINITION HREF="26_glo_b.htm#bit_vector">bit vector</A> descends
<A REL=DEFINITION HREF="26_glo_s.htm#string">string</A> descends
<A REL=DEFINITION HREF="26_glo_p.htm#pathname">pathname</A> ``functionally equivalent''
<A REL=DEFINITION HREF="26_glo_s.htm#structure">structure</A> uses <A REL=DEFINITION HREF="f_eq.htm#eq">eq</A>
Other <A REL=DEFINITION HREF="26_glo_a.htm#array">array</A> uses <A REL=DEFINITION HREF="f_eq.htm#eq">eq</A>
<A REL=DEFINITION HREF="26_glo_h.htm#hash_table">hash table</A> uses <A REL=DEFINITION HREF="f_eq.htm#eq">eq</A>
Other <A REL=DEFINITION HREF="26_glo_o.htm#object">object</A> uses <A REL=DEFINITION HREF="f_eq.htm#eq">eq</A>
</PRE>
<P><B>Figure 5-12. Summary and priorities of behavior of <A REL=DEFINITION HREF="#equal"><B>equal</B></A></B> <P>
Any two <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> that are <A REL=DEFINITION HREF="f_eql.htm#eql"><B>eql</B></A> are also <A REL=DEFINITION HREF="#equal"><B>equal</B></A>. <P>
<A REL=DEFINITION HREF="#equal"><B>equal</B></A> may fail to terminate if <I>x</I> or <I>y</I> is circular. <P>
<P><B>Examples:</B><P>
<P>
<PRE>
(equal 'a 'b) =&gt; <A REL=DEFINITION HREF="26_glo_f.htm#false">false</A>
(equal 'a 'a) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(equal 3 3) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(equal 3 3.0) =&gt; <A REL=DEFINITION HREF="26_glo_f.htm#false">false</A>
(equal 3.0 3.0) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(equal #c(3 -4) #c(3 -4)) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(equal #c(3 -4.0) #c(3 -4)) =&gt; <A REL=DEFINITION HREF="26_glo_f.htm#false">false</A>
(equal (cons 'a 'b) (cons 'a 'c)) =&gt; <A REL=DEFINITION HREF="26_glo_f.htm#false">false</A>
(equal (cons 'a 'b) (cons 'a 'b)) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(equal #\A #\A) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(equal #\A #\a) =&gt; <A REL=DEFINITION HREF="26_glo_f.htm#false">false</A>
(equal &quot;Foo&quot; &quot;Foo&quot;) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(equal &quot;Foo&quot; (copy-seq &quot;Foo&quot;)) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(equal &quot;FOO&quot; &quot;foo&quot;) =&gt; <A REL=DEFINITION HREF="26_glo_f.htm#false">false</A>
(equal &quot;This-string&quot; &quot;This-string&quot;) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(equal &quot;This-string&quot; &quot;this-string&quot;) =&gt; <A REL=DEFINITION HREF="26_glo_f.htm#false">false</A>
</PRE>
</TT> <P>
<P><B>Side Effects:</B> None.
<P>
<P><B>Affected By:</B> None.
<P>
<P><B>Exceptional Situations:</B> None.
<P>
<P><B>See Also:</B><P>
<P>
<A REL=DEFINITION HREF="f_eq.htm#eq"><B>eq</B></A>, <A REL=DEFINITION HREF="f_eql.htm#eql"><B>eql</B></A>, <A REL=DEFINITION HREF="f_equalp.htm#equalp"><B>equalp</B></A>, <A REL=DEFINITION HREF="f_eq_sle.htm#EQ"><B>=</B></A>, <A REL=DEFINITION HREF="f_stgeq_.htm#stringEQ"><B>string=</B></A>, <A REL=DEFINITION HREF="f_stgeq_.htm#string-equal"><B>string-equal</B></A>, <A REL=DEFINITION HREF="f_chareq.htm#charEQ"><B>char=</B></A>, <A REL=DEFINITION HREF="f_chareq.htm#char-equal"><B>char-equal</B></A>, <A REL=DEFINITION HREF="f_tree_e.htm#tree-equal"><B>tree-equal</B></A> <P>
<P><B>Notes:</B><P>
<P>
<A REL=DEFINITION HREF="26_glo_o.htm#object"><I>Object</I></A> equality is not a concept for which there is a uniquely determined correct algorithm. The appropriateness of an equality predicate can be judged only in the context of the needs of some particular program. Although these functions take any type of argument and their names sound very generic, <A REL=DEFINITION HREF="#equal"><B>equal</B></A> and <A REL=DEFINITION HREF="f_equalp.htm#equalp"><B>equalp</B></A> are not appropriate for every application. <P>
A rough rule of thumb is that two <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> are <A REL=DEFINITION HREF="#equal"><B>equal</B></A> if and only if their printed representations are the same. <P>
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issue</A>, <I>not part of the specification</I>, applies to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss143.htm">EQUAL-STRUCTURE:MAYBE-STATUS-QUO</A><P></UL><HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>