aboutsummaryrefslogtreecommitdiff
path: root/stdlib.slip
blob: 593dc14bc0fe639fe81200f2f289ddcd98833db4 (plain)
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
(let if
     (fn (cond iftrue iffalse) (Bool T T) T
         (case cond
             (true iftrue)
             (_ iffalse))
     )
)


(let ++
     (fn x Int Int
         (+ x 1)
     )
)


(let --
    (fn x Int Int
        (- x 1)
    )
)


(let sum (fix
	(fn sum' ((Vector (Int ...)) -> Int)
	         ((Vector (Int ...)) -> Int)
		(fn vec (Vector (Int ...)) Int
			(case vec
				((h ..t) (+ h (sum' t)))
				(_ 0))
		)
	)
))


(let map-i->i (fix
	(fn map' (((Vector (Int ...)) (Int -> Int)) -> (Vector (Int ...)))
	         (((Vector (Int ...)) (Int -> Int)) -> (Vector (Int ...)))
		(fn (vec fun) ((Vector (Int ...)) (Int -> Int)) (Vector (Int ...))
			(case vec
				((h ..t) (<> (vector (fun h)) (map' t fun)))
				(_ (() Int)))
		)
	)
))


(let filter-int (fix
	(fn filter' (((Vector (Int ...)) (Int -> Bool)) -> (Vector (Int ...)))
	            (((Vector (Int ...)) (Int -> Bool)) -> (Vector (Int ...)))
		(fn (vec pred) ((Vector (Int ...)) (Int -> Bool)) (Vector (Int ...))
			(case vec
				((h ..t) (if (pred h) (<> (vector h) (filter' t pred)) (filter' t pred)))
				(_ (() Int))
			)
		)
	)
))