-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpredicates.html
301 lines (301 loc) · 9.93 KB
/
predicates.html
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<html dir="ltr">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<title>Arc: Predicates</title>
<link rel="shortcut icon" href="/assets/favicon.png">
<link rel="stylesheet" type="text/css" href="code.css">
<link href="/assets/bootstrap.css" rel="stylesheet">
</head>
<body style='margin:12px 50px 0'>
<div class="navbar navbar-inverse">
<div class="navbar-inner">
<ul class="nav navbar-nav">
<li><a href="/ref/">Arc 3.1</a>
<li><a href="http://tryarc.org">Try it</a></li>
<li><a href="http://github.com/arclanguage/anarki">Get it</a></li>
<li><a href="http://ycombinator.com/arc/tut.txt">Tutorial</a></li>
<li><a href="http://arclanguage.org/forum">Forum</a></li>
</ul>
</div>
</div> <!-- end of navbar -->
<div class="links">Previous: <a href="math.html">Math</a>
Up: <a href="index.html">Contents</a>
Next: <a href="string.html">String operations</a>
</div>
<h1 class="links">Predicates</h1>
<h2>Predicates</h2>
Arc includes multiple predicates. The dead and ssyntax predicates are
listed elsewhere.
<p><table class='arc'>
<tr>
<td class='arc'><a name='<'></a>
<img src='foundation.gif' title='Foundation'/>
<span class='op'><</span> <span class='args'>arg arg [...]</span>
<div class='desc'>Less than comparison. Applies to numbers, strings, symbols, or
chars. If multiple arguments are given, the sequence must be monotonically
increasing.</div>
</td>
<td class='arc'><pre>
>(< 1 2)
<span class="return">t
</span></pre>
<pre>
>(< 1 2 3)
<span class="return">t
</span></pre>
<pre>
>(< 1 3 2)
<span class="return">nil
</span></pre>
<pre>
>(< "a" "b")
<span class="return">t
</span></pre>
<pre>
>(< 'a 'b)
<span class="return">t
</span></pre>
<pre>
>(< #\a #\b)
<span class="return">t
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='>'></a>
<img src='foundation.gif' title='Foundation'/>
<span class='op'>></span> <span class='args'>arg arg [...]</span>
<div class='desc'>Greater than comparison. Applies to numbers, strings, symbols, or
chars. If multiple arguments are given, the sequence must be monotonically
decreasing.</div>
</td>
<td class='arc'><pre>
>(> 1 2)
<span class="return">nil
</span></pre>
<pre>
>(> 3 1 2)
<span class="return">nil
</span></pre>
<pre>
>(> "a" "b")
<span class="return">nil
</span></pre>
<pre>
>(> 'a 'b)
<span class="return">nil
</span></pre>
<pre>
>(> #\a #\b)
<span class="return">nil
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='bound'></a>
<img src='foundation.gif' title='Foundation'/>
<span class='op'>bound</span> <span class='args'>symbol</span>
<div class='desc'>Tests is a symbol is bound.</div>
</td>
<td class='arc'><pre>
>(bound 'foo)
<span class="return">nil
</span></pre>
<pre>
>(do
(assign y 1)
(bound 'y))
<span class="return">t
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='exact'></a>
<img src='foundation.gif' title='Foundation'/>
<span class='op'>exact</span> <span class='args'>value</span>
<div class='desc'>Tests if the value is an exact integer.</div>
</td>
<td class='arc'><pre>
>(exact 3)
<span class="return">t
</span></pre>
<pre>
>(exact 3.14)
<span class="return">nil
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='is'></a>
<img src='foundation.gif' title='Foundation'/>
<span class='op'>is</span> <span class='args'>val [val ...] </span>
<div class='desc'>Tests equality with eqv?</div>
</td>
<td class='arc'><pre>
>(is 1 2)
<span class="return">nil
</span></pre>
<pre>
>(is "a" "a")
<span class="return">t
</span></pre>
<pre>
>(is '(1) '(1))
<span class="return">nil
</span></pre>
<pre>
>(is 1 1 1 1)
<span class="return">t
</span></pre>
<pre>
>(is nil '())
<span class="return">t
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='<%3d'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'><=</span> <span class='args'>[arg ...]</span>
<div class='desc'>The less-than-or-equal predicate. It can take an arbitrary number of arguments. There is no short-circuiting; all arguments are evaluated. Arguments must be comparable. Arguments can be numbers, characters or strings, but all arguments must be of the same type.</div>
</td>
<td class='arc'><pre>
>(<= 2 2.0)
<span class="return">t
</span></pre>
<pre>
>(<= #\a #\c #\e)
<span class="return">t
</span></pre>
<pre>
>(<= "foo" "bar")
<span class="return">nil
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='>%3d'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>>=</span> <span class='args'>[arg ...]</span>
<div class='desc'>The greater-than-or-equal predicate. It can take an arbitrary number of arguments. There is no short-circuiting; all arguments are evaluated. Arguments must be comparable. Arguments can be numbers, characters or strings, but all arguments must be of the same type.</div>
</td>
<td class='arc'><pre>
>(>= 2 3)
<span class="return">nil
</span></pre>
<pre>
>(>= #\a #\c #\e)
<span class="return">nil
</span></pre>
<pre>
>(>= "baz" "bar")
<span class="return">t
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='dotted'></a>
<img src='proc.gif' title='Procedure'/>
<img src='predicate.gif' title='Predicate'/>
<span class='op'>dotted</span> <span class='args'>x</span>
<div class='desc'>Returns true if x is a dotted list.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='isa'></a>
<img src='proc.gif' title='Procedure'/>
<img src='predicate.gif' title='Predicate'/>
<span class='op'>isa</span> <span class='args'>x y</span>
<div class='desc'>Tests if x has type y.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='orf'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>orf</span> <span class='args'>function ...</span>
<div class='desc'>Creates a function on one variable that tests if any of the original functions are true when applied to the variable.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='andf'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>andf</span> <span class='args'>function ...</span>
<div class='desc'>Creates a function on one variable that tests if all of the original functions are true when applied to the variable.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='atend'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>atend</span> <span class='args'>i s</span>
<div class='desc'>Tests if index i is at the end or beyond in sequence or string s.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='testify'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>testify</span> <span class='args'>test</span>
<div class='desc'>Creates a predicate from test. If test is a function, it is used as the predicate. Otherwise, a function is created to test equality with test using 'is'.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='acons'></a>
<img src='proc.gif' title='Procedure'/>
<img src='predicate.gif' title='Predicate'/>
<span class='op'>acons</span> <span class='args'>x</span>
<div class='desc'>Tests if x is of type 'cons, i.e. if x is a non-nil list.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='atom'></a>
<img src='proc.gif' title='Procedure'/>
<img src='predicate.gif' title='Predicate'/>
<span class='op'>atom</span> <span class='args'>x</span>
<div class='desc'>Tests if x is an atom, that is anything other than type 'cons. Note that atom and acons are opposites.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='alist'></a>
<img src='proc.gif' title='Procedure'/>
<img src='predicate.gif' title='Predicate'/>
<span class='op'>alist</span> <span class='args'>x</span>
<div class='desc'>Tests if x is a list, i.e. nil or of type 'cons. The alist and acons predicates are the same except for nil, which is a list but an atom, not acons.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='some'></a>
<img src='proc.gif' title='Procedure'/>
<img src='predicate.gif' title='Predicate'/>
<span class='op'>some</span> <span class='args'>test seq</span>
<div class='desc'>Tests if any element of seq satisfies test. The sequence is either a list or a string. The test is a predicate or value, which is wrapped in testify.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='all'></a>
<img src='proc.gif' title='Procedure'/>
<img src='predicate.gif' title='Predicate'/>
<span class='op'>all</span> <span class='args'>test seq</span>
<div class='desc'>Tests if all elements of seq satisfies test. The sequence is either a list or a string. The test is a predicate or value, which is wrapped in testify.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='isnt'></a>
<img src='proc.gif' title='Procedure'/>
<img src='predicate.gif' title='Predicate'/>
<span class='op'>isnt</span> <span class='args'>x y</span>
<div class='desc'>Tests inequality; opposite of is.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='iso'></a>
<img src='proc.gif' title='Procedure'/>
<img src='predicate.gif' title='Predicate'/>
<span class='op'>iso</span> <span class='args'>x y</span>
<div class='desc'>Compares x and y. If they are lists, they are compared element-by-element.</div>
</td>
<td class='arc'> </td></tr>
<tr>
<td class='arc'><a name='empty'></a>
<img src='proc.gif' title='Procedure'/>
<img src='predicate.gif' title='Predicate'/>
<span class='op'>empty</span> <span class='args'>seq</span>
<div class='desc'>Tests if seq is empty. Works on lists, strings, and tables.</div>
</td>
<td class='arc'> </td></tr>
</table>
<p>
Copyright 2008 Ken Shirriff.
</body>
</html>