-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlt-p.robin
61 lines (41 loc) · 1.2 KB
/
lt-p.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;'<<SPEC'
-> Tests for functionality "Evaluate Robin Expression (with Arith)"
### `lt?` ###
`lt?` evaluates both of its arguments to numbers, then evaluates to `#t`
if the first number is strictly less than the second.
| (lt? 6 4)
= #f
| (lt? 6 8)
= #t
| (lt? 6 6)
= #f
| (lt? 1610612736 (subtract 0 1610612736)))
= #f
| (lt? (subtract 0 1610612736) 1610612736)
= #t
| (lt? 2147483646 2147483647)
= #t
| (lt? 1 2147483647)
= #t
| (lt? (subtract 0 2147483647) (subtract 0 2147483646))
= #t
| (lt? (subtract 0 2147483647) (subtract 0 1))
= #t
| (lt? (subtract (subtract 0 1073741824) 1073741824) 0)
= #t
`lt?` expects exactly two arguments, both numbers.
| (lt? 14)
? abort (illegal-arguments
| (lt? 14 23 57)
? abort (illegal-arguments
| (lt? 14 #t)
? abort (expected-number #t)
| (lt? #t 51)
? abort (expected-number #t)
'<<SPEC'
(define lt? (fun (a b)
(bind cmp-same-sign? (fun (a b c)
(equal? (sign (subtract a b)) c))
(if (equal? (sign a) (sign b))
(cmp-same-sign? a b (subtract 0 1))
(cmp-same-sign? (subtract (sign a) 1) (subtract (sign b) 1) (subtract 0 1))))))