File: equalp.htm

package info (click to toggle)
nyquist 3.05-2.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 31,172 kB
  • ctags: 22,924
  • sloc: ansic: 149,216; sh: 21,301; lisp: 17,746; cpp: 12,778; java: 8,006; makefile: 4,574; python: 39
file content (162 lines) | stat: -rw-r--r-- 5,515 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<html><head>

<title>cl:equalp</title>

<style type="text/css">
.example {
  color: #000000;
  background-color: #F5F5F5;
  padding: 8px;
  border: #808080;
  border-style: solid;
  border-width: 1px;
  width:auto;
}
.button {
  color: #000000;
  background-color: #F5F5F5;
  padding-top: 1px;
  padding-bottom: 1px;
  padding-left: 4px;
  padding-right: 8px;
  border: #808080;
  border-style: solid;
  border-width: 1px;
  white-space: pre;
}
.box {
  color: #000000;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 16px;
  padding-right: 16px;
  border: #808080;
  border-style: solid;
  border-width: 1px;
}
</style>

</head>

<body>

<a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
<a href="../../manual/contents.htm">Contents</a> |
<a href="../../tutorials/tutorials.htm">Tutorials</a> |
<a href="../examples.htm">Examples</a> |
<a href="../../reference/reference-index.htm">Reference</a>

<hr>

<h1>cl:equalp</h1>

<hr>

<p><div class="box">

<dl>
<dt>(<b>equalp</b> <i>expr1 expr2</i>)</dt>
<dd><i>exprN</i> - arbitrary Lisp expressions<br>
returns - <a href="t.htm">&nbsp;T&nbsp;</a> if the expressions
are structurally equal, <a href="nil.htm">NIL</a> otherwise</dd>
</dl>

</div></p>

<p>Two expressions are 'equalp':</p>

<ul>

<li><p>If the expressions
<nobr>are <a href="../../reference/equal.htm">equal</a></nobr>.</p></li>

<li><p>If two numbers of arbitrary type <nobr>are
<a href="../../reference/number-equal.htm">&nbsp;=&nbsp;</a></nobr>.</p></li>

<li><p>If two characters are
<nobr><a href="../../reference/char-equal-i.htm">char-equal</a></nobr>.</p></li>

<li><p>If two strings are <nobr><a
href="../../reference/string-equal-i.htm">string-equal</a></nobr>.</p></li>

<li><p>If the two <a href="../../reference/car.htm">car</a>s in conses are
'equalp' and the two <a href="../../reference/cdr.htm">cdr</a>s in conses
are 'equalp'.</p></li>

<li><p>If two arrays have the same number of elements and dimensions, and
the corresponding elements in all dimensions are 'equalp'.</p></li>

</ul>

<p>Note that only 'equalp' can compare arrays.</p>

<pre class="example">
(defun <font color="#0000CC">cl:equalp</font> (expr-1 expr-2)
  (or (equal expr-1 expr-2)
      (and (numberp expr-1) (numberp expr-2) (= expr-1 expr-2))
      (let ((type (type-of expr-1)))
        (when (eq type (type-of expr-2))
          (case type
            (character (char-equal expr-1 expr-2))
            (string    (string-equal expr-1 expr-2))
            (cons      (do ((x (first expr-1)
                               (if (consp expr-1) (first expr-1) expr-1))
                            (y (first expr-2)
                               (if (consp expr-2) (first expr-2) expr-2)))
                           ((or (null expr-1)
                                (null expr-2)
                                (not (equalp x y)))
                            (and (null expr-1)
                                 (null expr-2)))
                         (setq expr-1 (and (consp expr-1) (rest expr-1))
                               expr-2 (and (consp expr-2) (rest expr-2)))))
            (array     (let ((end (length expr-1)))
                         (when (eql end (length expr-2))
                           (dotimes (index end t)
                             (and (not (equalp (aref expr-1 index)
                                               (aref expr-2 index)))
                                  (return nil)))))))))))
</pre>

<p><b>cons:</b> <a href="../../reference/do.htm">do</a> is used instead of
recursion because XLISP has only two kilobytes stack size. <nobr>The
(<a href="../../reference/consp.htm">consp</a> <i>expr</i>)</nobr> tests are
necessary because in a dotted list the last
<a href="../../reference/rest.htm">rest</a> element is not a cons.</p>

<p>Examples:</p>

<pre class="example">
(cl:equalp 1 1.0)                            =&gt; T
(cl:equalp #\a #\A)                          =&gt; T
(cl:equalp "Abc" "aBc")                      =&gt; T
(cl:equalp '(1 #\a "Abc") '(1.0 #\A "aBc"))  =&gt; T
(cl:equalp #(1 #\a "Abc") #(1.0 #\A "aBc"))  =&gt; T
</pre>

<p>Nested expressions only match if the nesting matches:</p>

<pre class="example">
(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
(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
(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
(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
</pre>

<p>A character does not match a string with the same character:</p>

<pre class="example">
(cl:equalp #\a "a")  =&gt; NIL
</pre>

<p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>

<hr>

<a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
<a href="../../manual/contents.htm">Contents</a> |
<a href="../../tutorials/tutorials.htm">Tutorials</a> |
<a href="../examples.htm">Examples</a> |
<a href="../../reference/reference-index.htm">Reference</a>

</body></html>