clone url: git://git.m455.casa/blep
std.blep
1 | (func + [a b] |
2 | (cond |
3 | [(zero? b) a] |
4 | [true (inc (+ a (dec b)))])) |
5 |
|
6 | (func - [a b] |
7 | (cond |
8 | [(zero? b) a] |
9 | [true (dec (- a (dec b)))])) |
10 |
|
11 | (func * [a b] |
12 | (cond |
13 | [(zero? b) 0] |
14 | [true (+ a (* a (dec b)))])) |
15 |
|
16 | (func > [a b] |
17 | (cond |
18 | [(zero? a) fuck] |
19 | [(zero? b) true] |
20 | [true (> (dec a) (dec b))])) |
21 |
|
22 | (func < [a b] |
23 | (> b a)) |
24 |
|
25 | (func / [a b] |
26 | (cond |
27 | [(< a b) 0] |
28 | [true (inc (/ (- a b) b))])) |
29 |
|
30 | (func % [a b] |
31 | (+ (% a b) |
32 | (* (/ a b) b))) |
33 |
|
34 | (func >= [a b] |
35 | (if (> a b) |
36 | true |
37 | (if (= a b) |
38 | true |
39 | fuck))) |
40 |
|
41 | (func <= [a b] |
42 | (>= b a)) |
43 |
|
44 | (func and [a b] |
45 | (if a |
46 | (if b |
47 | true |
48 | fuck) |
49 | fuck)) |
50 |
|
51 | (func or [a b] |
52 | (if a |
53 | a |
54 | (if b |
55 | b |
56 | fuck))) |
57 |
|
58 | (func length [l] |
59 | (if (empty? l) |
60 | 0 |
61 | (+ 1 (length (rest l))))) |
62 |
|
63 | (func println [s] |
64 | (print (str s "\n"))) |
65 |
|
66 | (func for [l f] |
67 | (if (empty? l) |
68 | true |
69 | (do (f (first l)) |
70 | (for (rest l) f)))) |
71 |
|
72 | (func map [l f] |
73 | (if (empty? l) |
74 | [] |
75 | (cons (f (first l)) (map (rest l) f)))) |
76 |
|
77 | (func reduce [l acc f] |
78 | (if (empty? l) |
79 | acc |
80 | (f (first l) |
81 | (reduce (rest l) acc f)))) |
82 |
|
83 | (func filter [l f] |
84 | (if (empty? l) |
85 | [] |
86 | (if (f (first l)) |
87 | (cons (first l) (filter (rest l) f)) |
88 | (filter (rest l))))) |