-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmaeel.maeel
124 lines (87 loc) · 1.77 KB
/
maeel.maeel
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
fun inline print (dup puts)
fun inline println (print "\n" puts)
fun inline putsln (puts "\n" puts)
fun inline drop __ ()
fun inline dup __a (__a __a)
fun inline rot __a __b __c (__c __a __b)
fun inline swap __a __b (__b __a)
fun inline over __a __b (__a __b __a)
fun inline true ((drop))
fun inline false ((swap drop))
fun inline ifelse (rot rot!!)
fun inline then (() ifelse)
fun inline bool_to_string (("true") ("false") ifelse)
fun inline bool_to_int ((1) (0) ifelse)
fun inline neg (0 swap -)
fun inline not ((false) (true) ifelse)
fun mod a b (
a 0 < ((a b +: a) (a 0 <) while) then
(a b -: a) (a b > a b = or) while
a
)
fun and p q (
1 0 p! 1=
(1 0 q! 1= (true) (false) ifelse)
(false)
ifelse
)
fun or p q (
1 0 p! 1=
(true)
(1 0 q! 1= (true) (false) ifelse)
ifelse
)
fun inline while __while_fn __pr (__pr! (__while_fn! __while_fn __pr while) then)
fun inline for __xs __for_fn (
__xs len :__xs_len 0 :__idx
(__xs __idx get __for_fn! __idx 1+ :__idx) (__idx __xs_len <)
while
)
fun take1 (list+)
fun take2 (list++)
fun take3 (list+++)
fun inline List ("__maeel_list_start")
fun inline end_aux (
list
(+)
(over List= not)
while swap drop
)
fun inline reverse (List swap () for end_aux)
fun inline end (
end_aux reverse
)
fun map xs fn (
List
xs (fn!) for
end
)
fun filter xs fn (
List
xs (
dup fn!
() (drop)
ifelse
) for
end
)
fun inline reduce (rot for)
fun inline sum ((+) 0 reduce)
fun inline product ((*) 1 reduce)
fun range a b (
List
a
(dup 1+)
(dup 1+ b <)
while
end
)
fun factorial n (1 n range product)
fun inline unpack (
fun inline unpack_aux (
dup 0= (get) (
over over get rot 1- unpack_aux
) ifelse
)
dup len 1- unpack_aux
)