-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcombining.html
104 lines (102 loc) · 3.89 KB
/
combining.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
<html dir="ltr">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<title>Arc: Boolean operations</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="assignment.html">Assignment and places</a>
Up: <a href="index.html">Contents</a>
Next: <a href="iteration.html">Iteration</a>
</div>
<h1 class="links">Boolean operations</h1>
<h2>Booleans</h2>
Arc provides basic Boolean operations.
Only nil and empty list are false; any other value, including 0 and empty string, is true. The operations provide short-circuit evaluation, so only the necessary arguments are evaluated, left-to-right.
<p>
See also the <a href="anaphoric.html">Anaphoric operations </a> <code>aand</code> and <code>aor</code>.
<p><table class='arc'>
<tr>
<td class='arc'><a name='no'></a>
<img src='proc.gif' title='Procedure'/>
<img src='predicate.gif' title='Predicate'/>
<span class='op'>no</span> <span class='args'>expr</span>
<div class='desc'>Complement: returns true if <code>expr</code> is false, and false if <code>expr</code> is true.</div>
</td>
<td class='arc'><pre>
>(no 1)
<span class="return">nil
</span></pre>
<pre>
>(no nil)
<span class="return">t
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='and'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>and</span> <span class='args'>[arg ...]</span>
<div class='desc'>The and boolean operator tests if all the arguments are true. It evaluates its arguments in turn until a false argument is found.
If all arguments are true, the last argument is returned. If all arguments are false, nil is returned. The and operator performs 'short-circuit' evaluation, and doesn't evaluate arguments that follow a false one.</div>
</td>
<td class='arc'><pre>
>(and 1 t 0 "x")
<span class="return">"x"
</span></pre>
<pre>
>(and nil t)
<span class="return">nil
</span></pre>
<pre>
>(and nil (/ 1 0))
<span class="return">nil
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='or'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>or</span> <span class='args'>[arg ...]</span>
<div class='desc'>The or boolean operator tests if any of the arguments are true. It evaluates its arguments in turn until a true argument is found. If any argument is true, the first true argument is returned. If all arguments are false, nil is returned. The or operator performs 'short-circuit' evaluation, and doesn't evaluate arguments that follow a true one.</div>
</td>
<td class='arc'><pre>
>(or nil 42 '() (/ 1 0))
<span class="return">42
</span></pre>
<pre>
>(or nil '())
<span class="return">nil
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='nor'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>nor</span> <span class='args'>[arg ...]</span>
<div class='desc'>The nor boolean operator tests if all of the arguments are false. It returns t if all arguments are false, and nil if any arguments are true. It performs 'short-circuit' evaluation, and doesn't evaluate arguments that follow a true one.</div>
</td>
<td class='arc'><pre>
>(nor nil nil)
<span class="return">t
</span></pre>
<pre>
>(nor nil 1 (/ 1 0))
<span class="return">nil
</span></pre>
</td></tr>
</table>
<p>
Copyright 2008 Ken Shirriff.
</body>
</html>