Skip to content

Commit 41580ad

Browse files
committed
working on the documentation
1 parent 7253499 commit 41580ad

File tree

5 files changed

+261
-92
lines changed

5 files changed

+261
-92
lines changed

Exceptions.ark

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,45 @@
1-
(import "Functional.ark")
1+
###
2+
# @meta Exceptions
3+
# @brief throw takes a value as its argument and return it to be used by try
4+
# ---
5+
# (let error (throw "cannot divide by zero"))
6+
# ---
7+
# @param _x the value to return
8+
# @author https://github.com/SuperFola
9+
###
10+
(let throw (fun (_x)
11+
(fun (_injl _injr &_x) (_injl _x))
12+
))
213

3-
(let throw left)
4-
(let return right)
14+
###
15+
# @meta Exceptions
16+
# @brief returns takes a value as its argument and return it to be used by try
17+
# ---
18+
# (let value (return (/ 1 x)))
19+
# ---
20+
# @param _x the value to return
21+
# @author https://github.com/SuperFola
22+
###
23+
(let return (fun (_y)
24+
(fun (_injl _injr &_y) (_injr _y))
25+
))
26+
27+
###
28+
# @meta Exceptions
29+
# @brief takes a value either returned by throw or return and apply a given on it if it's an error or not
30+
# ---
31+
# (let invert (fun (x)
32+
# (if (= x 0)
33+
# (throw "cannot divide by zero")
34+
# (return (/ 1 x)))))
35+
# (try (invert 0)
36+
# (fun (inverted) (print inverted))
37+
# (fun (err) (print err)))
38+
# ---
39+
# @param _either the value to test
40+
# @param _continue the success handler
41+
# @param _handle the error handler
42+
# @author https://github.com/SuperFola
43+
###
544
(let try (fun (_either _continue _handle)
645
(_either _handle _continue)))

Functional.ark

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,58 @@
1-
# @author: https://github.com/rstefanic
1+
###
2+
# @meta Functional
3+
# @brief compose function calls
4+
# ---
5+
# (let foo (fun (a) (* a a)))
6+
# (let bar (fun (b) (+ b b)))
7+
# (let composed (compose foo bar))
8+
# (print (composed 12)) # return value is (12 + 12) * (12 + 12)
9+
# ---
10+
# @param _f the first function
11+
# @param _g the second function
12+
# @author https://github.com/rstefanic
13+
###
214
(let compose (fun (_f _g)
315
(fun (_y &_f &_g) (_f (_g _y)))))
416

17+
###
18+
# @meta Functional
19+
# @brief take a value as its argument and return a function taking 2 arguments which will call the first function on the value
20+
# ---
21+
# (let val (left 12))
22+
# (val (fun (x) (print x " i am called")) (fun (x) (print x " i am NOT called")))
23+
# ---
24+
# @param _x the value
25+
# @author https://github.com/SuperFola
26+
###
527
(let left (fun (_x)
628
(fun (_injl _injr &_x) (_injl _x))
729
))
30+
31+
###
32+
# @meta Functional
33+
# @brief take a value as its argument and return a function taking 2 arguments which will call the second function on the value
34+
# ---
35+
# (let val (right 12))
36+
# (val (fun (x) (print x " i am NOT called")) (fun (x) (print x " i am called")))
37+
# ---
38+
# @param _y the value
39+
# @author https://github.com/SuperFola
40+
###
841
(let right (fun (_y)
942
(fun (_injl _injr &_y) (_injr _y))
1043
))
1144

12-
# @author: https://github.com/rstefanic
45+
###
46+
# @meta Functional
47+
# @brief flip arguments of a function
48+
# @details returns a function taking 1 argument: the second argument of the function to flip
49+
# ---
50+
# (let foo (fun (a b) (- a b)))
51+
# ((flip foo 14) 12) # will call (foo 12 14) instead of (foo 14 12)
52+
# ---
53+
# @param _f the function
54+
# @param _a the first argument
55+
# @author https://github.com/rstefanic
56+
###
1357
(let flip (fun (_f _a)
1458
(fun (_b &_f &_a) (_f _b _a))))

List.ark

Lines changed: 109 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# (([List]index)
2-
# !List
3-
# \list:forEach Iterate over a given list and run a given function on every element.
4-
# \list:forEach The original list is left unmodified. Example:
5-
# `
1+
###
2+
# @meta List
3+
# @brief Iterate over a given list and run a given function on every element.
4+
# @details The original list is left unmodified. Example:
5+
# ---
66
# (import "List.ark")
77
# (let collection [1 2 5 12])
88
# (let new (list:forEach collection (fun (element) {
99
# (print element)
1010
# })))
11-
# `
12-
# @_L the list to iterate over
13-
# @_func the function to call on each element
14-
# author: https://github.com/SuperFola
15-
# )
11+
# ---
12+
# @param _L the list to iterate over
13+
# @param _func the function to call on each element
14+
# @author https://github.com/SuperFola
15+
###
1616
(let list:forEach (fun (_L _func) {
1717
(mut _index 0)
1818
(while (< _index (len _L)) {
@@ -22,18 +22,18 @@
2222
})
2323
}))
2424

25-
# (([List]index)
26-
# !List
27-
# \list:product Iterate over a given list and multiply all the elements with the others.
28-
# \list:product The original list is left unmodified. Example:
29-
# `
25+
###
26+
# @meta List
27+
# @brief Iterate over a given list and multiply all the elements with the others.
28+
# @details The original list is left unmodified. Example:
29+
# ---
3030
# (import "List.ark")
3131
# (let collection [1 2 5 12])
3232
# (let p (list:product collection)) # => 120
33-
# `
34-
# @_L the list to iterate over
35-
# author: https://github.com/FrenchMasterSword
36-
# )
33+
# ---
34+
# @param _L the list to iterate over
35+
# @author https://github.com/FrenchMasterSword
36+
###
3737
(let list:product (fun (_L) {
3838
(mut _index 0)
3939
(mut _output 1)
@@ -44,18 +44,18 @@
4444
_output
4545
}))
4646

47-
# (([List]index)
48-
# !List
49-
# \list:sum Iterate over a given list and sum all the elements.
50-
# \list:sum The original list is left unmodified. Example:
51-
# `
47+
###
48+
# @meta List
49+
# @brief Iterate over a given list and sum all the elements.
50+
# @details The original list is left unmodified. Example:
51+
# ---
5252
# (import "List.ark")
5353
# (let collection [1 2 5 12])
5454
# (let p (list:sum collection)) # => 20
55-
# `
56-
# @_L the list to iterate over
57-
# author: https://github.com/FrenchMasterSword
58-
# )
55+
# ---
56+
# @param _L the list to iterate over
57+
# @author https://github.com/FrenchMasterSword
58+
###
5959
(let list:sum (fun (_L) {
6060
(mut _index 0)
6161
(mut _output 0)
@@ -66,7 +66,15 @@
6666
_output
6767
}))
6868

69-
# @author: https://github.com/rstefanic
69+
###
70+
# @meta List
71+
# @brief
72+
# @details
73+
# ---
74+
# ---
75+
# @param _L the list to work on
76+
# @author https://github.com/rstefanic
77+
###
7078
(let list:drop (fun (_L _n) {
7179
(mut _index _n)
7280
(mut _output [])
@@ -77,7 +85,15 @@
7785
_output
7886
}))
7987

80-
# @author: https://github.com/rstefanic
88+
###
89+
# @meta List
90+
# @brief
91+
# @details
92+
# ---
93+
# ---
94+
# @param _L the list to work on
95+
# @author https://github.com/rstefanic
96+
###
8197
(let list:dropWhile (fun (_L _f) {
8298
(mut _index 0)
8399
(mut _output [])
@@ -93,7 +109,15 @@
93109
_output
94110
}))
95111

96-
# @author: https://github.com/rstefanic
112+
###
113+
# @meta List
114+
# @brief
115+
# @details
116+
# ---
117+
# ---
118+
# @param _L the list to work on
119+
# @author https://github.com/rstefanic
120+
###
97121
(let list:filter (fun (_L _f) {
98122
(mut _index 0)
99123
(mut _output [])
@@ -105,7 +129,15 @@
105129
_output
106130
}))
107131

108-
# @author: https://github.com/rstefanic
132+
###
133+
# @meta List
134+
# @brief
135+
# @details
136+
# ---
137+
# ---
138+
# @param _L the list to work on
139+
# @author https://github.com/rstefanic
140+
###
109141
(let list:map (fun (_L _f) {
110142
(mut _index 0)
111143
(mut _output [])
@@ -116,7 +148,15 @@
116148
_output
117149
}))
118150

119-
# @author: https://github.com/FrenchMasterSword
151+
###
152+
# @meta List
153+
# @brief
154+
# @details
155+
# ---
156+
# ---
157+
# @param _L the list to work on
158+
# @author https://github.com/FrenchMasterSword
159+
###
120160
(let list:reduce (fun (_L _f) {
121161
(mut _index 1)
122162
(mut _output (@ _L 0))
@@ -127,7 +167,15 @@
127167
_output
128168
}))
129169

130-
# @author: https://github.com/rstefanic
170+
###
171+
# @meta List
172+
# @brief
173+
# @details
174+
# ---
175+
# ---
176+
# @param _L the list to work on
177+
# @author https://github.com/rstefanic
178+
###
131179
(let list:take (fun (_L _n) {
132180
(mut _index 0)
133181
(mut _output [])
@@ -138,7 +186,15 @@
138186
_output
139187
}))
140188

141-
# @author: https://github.com/rstefanic
189+
###
190+
# @meta List
191+
# @brief
192+
# @details
193+
# ---
194+
# ---
195+
# @param _L the list to work on
196+
# @author https://github.com/rstefanic
197+
###
142198
(let list:takeWhile (fun (_L _f) {
143199
(mut _index 0)
144200
(mut _output [])
@@ -155,7 +211,15 @@
155211
_output
156212
}))
157213

158-
# @author: https://github.com/FrenchMasterSword
214+
###
215+
# @meta List
216+
# @brief
217+
# @details
218+
# ---
219+
# ---
220+
# @param _L the list to work on
221+
# @author https://github.com/FrenchMasterSword
222+
###
159223
(let list:unzip (fun (_L) {
160224
(let _m (len _L))
161225
(mut _list1 [])
@@ -172,7 +236,15 @@
172236

173237
(import "Math.ark") # needed for (math:min a b)
174238

175-
# @author: https://github.com/FrenchMasterSword
239+
###
240+
# @meta List
241+
# @brief
242+
# @details
243+
# ---
244+
# ---
245+
# @param _L the list to work on
246+
# @author https://github.com/FrenchMasterSword
247+
###
176248
(let list:zip (fun (_a _b) {
177249
(let _m (math:min (len _a) (len _b)))
178250
(mut _c [])

0 commit comments

Comments
 (0)