forked from carp-lang/Carp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interfaces.carp
76 lines (52 loc) · 1.36 KB
/
Interfaces.carp
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
(load "Macros.carp")
;; The 'copy' and 'str' interfaces are defined internally:
;;(definterface copy (λ [&a] a))
;;(definterface str (λ [a] String))
(definterface = (λ [a a] Bool))
(definterface /= (λ [a a] Bool))
(definterface add-ref (λ [&a &a] a))
(definterface sub-ref (λ [&a &a] a))
(definterface mul-ref (λ [&a &a] a))
(definterface div-ref (λ [&a &a] a))
(definterface + (λ [a a] a))
(definterface - (λ [a a] a))
(definterface * (λ [a a] a))
(definterface / (λ [a a] a))
(definterface mod (λ [a a] a))
(definterface < (λ [a a] Bool))
(definterface > (λ [a a] Bool))
(definterface inc (λ [a] a))
(definterface dec (λ [a] a))
(definterface format (λ [&String a] String))
(definterface from-string (λ [&String] a))
(definterface zero (λ [] a))
(definterface random (Fn [] a))
(definterface random-between (Fn [a a] a))
(definterface pi a)
(definterface neg (λ [a] a))
;; The following functions make use of the interfaces
(defn <= [a b]
(or (< a b)
(= a b)))
(defn >= [a b]
(or (> a b)
(= a b)))
(defn cmp [a b]
(if (= a b)
0
(if (< a b) -1 1)))
(defn max [a b]
(if (> a b) a b))
(defn min [a b]
(if (< a b) a b))
(defn zero? [x]
(= (zero) x))
(defn pos? [x]
(< (zero) x))
(defn neg? [x]
(< x (zero)))
(defn id [x] x)
(defn null? [p]
(Pointer.eq NULL (the (Ptr t) p)))
(defn not-null? [p]
(not (null? p)))