-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathand.robin
46 lines (30 loc) · 886 Bytes
/
and.robin
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
;'<<SPEC'
-> Tests for functionality "Evaluate Robin Expression (with Boolean)"
`and` evaluates both of its arguments to booleans, and evaluates to the
logical conjunction (boolean "and") of these two values.
| (and #t #t)
= #t
| (and #t #f)
= #f
| (and #f #t)
= #f
| (and #f #f)
= #f
`and` expects exactly two arguments.
| (and #f)
? abort
| (and #t #f #f)
? abort (illegal-arguments
`and` expects both of its arguments to be booleans.
| (and 100 #t)
? abort (expected-boolean 100)
| (and #t 99)
? abort (expected-boolean 99)
`and` is short-circuiting in the sense that no arguments after the first
`#f` argument will be evaluated. Fully testing this requires side-effects,
but it can be demonstrated as follows.
| (and #f 100)
= #f
'<<SPEC'
(define and (fun (a b)
(if a (if b #t #f) #f)))