Debian Codegraph @

docsrc/xlisp/xlisp-doc/examples/common-lisp/equalp.htm

raw
1 <html><head>
2
3 <title>cl:equalp</title>
4
5 <style type="text/css">
6 .example {
7 color: #000000;
8 background-color: #F5F5F5;
9 padding: 8px;
10 border: #808080;
11 border-style: solid;
12 border-width: 1px;
13 width:auto;
14 }
15 .button {
16 color: #000000;
17 background-color: #F5F5F5;
18 padding-top: 1px;
19 padding-bottom: 1px;
20 padding-left: 4px;
21 padding-right: 8px;
22 border: #808080;
23 border-style: solid;
24 border-width: 1px;
25 white-space: pre;
26 }
27 .box {
28 color: #000000;
29 padding-top: 4px;
30 padding-bottom: 4px;
31 padding-left: 16px;
32 padding-right: 16px;
33 border: #808080;
34 border-style: solid;
35 border-width: 1px;
36 }
37 </style>
38
39 </head>
40
41 <body>
42
43 <a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
44 <a href="../../manual/contents.htm">Contents</a> |
45 <a href="../../tutorials/tutorials.htm">Tutorials</a> |
46 <a href="../examples.htm">Examples</a> |
47 <a href="../../reference/reference-index.htm">Reference</a>
48
49 <hr>
50
51 <h1>cl:equalp</h1>
52
53 <hr>
54
55 <p><div class="box">
56
57 <dl>
58 <dt>(<b>equalp</b> <i>expr1 expr2</i>)</dt>
59 <dd><i>exprN</i> - arbitrary Lisp expressions<br>
60 returns - <a href="t.htm">&nbsp;T&nbsp;</a> if the expressions
61 are structurally equal, <a href="nil.htm">NIL</a> otherwise</dd>
62 </dl>
63
64 </div></p>
65
66 <p>Two expressions are 'equalp':</p>
67
68 <ul>
69
70 <li><p>If the expressions
71 <nobr>are <a href="../../reference/equal.htm">equal</a></nobr>.</p></li>
72
73 <li><p>If two numbers of arbitrary type <nobr>are
74 <a href="../../reference/number-equal.htm">&nbsp;=&nbsp;</a></nobr>.</p></li>
75
76 <li><p>If two characters are
77 <nobr><a href="../../reference/char-equal-i.htm">char-equal</a></nobr>.</p></li>
78
79 <li><p>If two strings are <nobr><a
80 href="../../reference/string-equal-i.htm">string-equal</a></nobr>.</p></li>
81
82 <li><p>If the two <a href="../../reference/car.htm">car</a>s in conses are
83 'equalp' and the two <a href="../../reference/cdr.htm">cdr</a>s in conses
84 are 'equalp'.</p></li>
85
86 <li><p>If two arrays have the same number of elements and dimensions, and
87 the corresponding elements in all dimensions are 'equalp'.</p></li>
88
89 </ul>
90
91 <p>Note that only 'equalp' can compare arrays.</p>
92
93 <pre class="example">
94 (defun <font color="#0000CC">cl:equalp</font> (expr-1 expr-2)
95 (or (equal expr-1 expr-2)
96 (and (numberp expr-1) (numberp expr-2) (= expr-1 expr-2))
97 (let ((type (type-of expr-1)))
98 (when (eq type (type-of expr-2))
99 (case type
100 (character (char-equal expr-1 expr-2))
101 (string (string-equal expr-1 expr-2))
102 (cons (do ((x (first expr-1)
103 (if (consp expr-1) (first expr-1) expr-1))
104 (y (first expr-2)
105 (if (consp expr-2) (first expr-2) expr-2)))
106 ((or (null expr-1)
107 (null expr-2)
108 (not (equalp x y)))
109 (and (null expr-1)
110 (null expr-2)))
111 (setq expr-1 (and (consp expr-1) (rest expr-1))
112 expr-2 (and (consp expr-2) (rest expr-2)))))
113 (array (let ((end (length expr-1)))
114 (when (eql end (length expr-2))
115 (dotimes (index end t)
116 (and (not (equalp (aref expr-1 index)
117 (aref expr-2 index)))
118 (return nil)))))))))))
119 </pre>
120
121 <p><b>cons:</b> <a href="../../reference/do.htm">do</a> is used instead of
122 recursion because XLISP has only two kilobytes stack size. <nobr>The
123 (<a href="../../reference/consp.htm">consp</a> <i>expr</i>)</nobr> tests are
124 necessary because in a dotted list the last
125 <a href="../../reference/rest.htm">rest</a> element is not a cons.</p>
126
127 <p>Examples:</p>
128
129 <pre class="example">
130 (cl:equalp 1 1.0) =&gt; T
131 (cl:equalp #\a #\A) =&gt; T
132 (cl:equalp "Abc" "aBc") =&gt; T
133 (cl:equalp '(1 #\a "Abc") '(1.0 #\A "aBc")) =&gt; T
134 (cl:equalp #(1 #\a "Abc") #(1.0 #\A "aBc")) =&gt; T
135 </pre>
136
137 <p>Nested expressions only match if the nesting matches:</p>
138
139 <pre class="example">
140 (cl:equalp '(1 <font color="#AA0000">(</font>2 3<font color="#AA0000">)</font>) '(1.0 <font color="#AA0000">(</font>2.0 3.0<font color="#AA0000">)</font>) =&gt; T
141 (cl:equalp '(1 <font color="#AA0000">(</font>2 3<font color="#AA0000">)</font>) '(<font color="#AA0000">(</font>1.0 2.0<font color="#AA0000">)</font> 3.0) =&gt; NIL
142 (cl:equalp '(<font color="#AA0000">(</font>1 2<font color="#AA0000">)</font> 3) '(<font color="#AA0000">(</font>1.0 2.0<font color="#AA0000">)</font> 3.0) =&gt; T
143 (cl:equalp '(<font color="#AA0000">(</font>1 2<font color="#AA0000">)</font> 3) '(1.0 <font color="#AA0000">(</font>2.0 3.0<font color="#AA0000">)</font>) =&gt; NIL
144 </pre>
145
146 <p>A character does not match a string with the same character:</p>
147
148 <pre class="example">
149 (cl:equalp #\a "a") =&gt; NIL
150 </pre>
151
152 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
153
154 <hr>
155
156 <a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
157 <a href="../../manual/contents.htm">Contents</a> |
158 <a href="../../tutorials/tutorials.htm">Tutorials</a> |
159 <a href="../examples.htm">Examples</a> |
160 <a href="../../reference/reference-index.htm">Reference</a>
161
162 </body></html>