Skip to content

Commit c005616

Browse files
committed
feat: adding proxied builtins to the standard library
1 parent 278d3ad commit c005616

File tree

14 files changed

+520
-32
lines changed

14 files changed

+520
-32
lines changed

IO.ark

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# @brief Write content to a file. Return nil
2+
# @param filename path to the file to write to (will be overwritten if it exists)
3+
# @param content can be any valid ArkScript value
4+
# =begin
5+
# (io:writeFile "hello.json" "{\"key\": 12}")
6+
# =end
7+
# @author https://github.com/SuperFola
8+
(let writeFile (fun (_name _content) (builtin__io:writeFile _name _content)))
9+
10+
# @brief Append content to a file. Return nil
11+
# @param filename path to the file to append to
12+
# @param content can be any valid ArkScript value
13+
# =begin
14+
# (io:writeFile "hello.json" "{\"key\": 12}")
15+
# =end
16+
# @author https://github.com/SuperFola
17+
(let appendToFile (fun (_name _content) (builtin__io:appendToFile _name _content)))
18+
19+
# @brief Read the content from a file as a String
20+
# @param filename the path of the file to read
21+
# =begin
22+
# (io:readFile "hello.json")
23+
# =end
24+
# @author https://github.com/SuperFola
25+
(let readFile (fun (_name) (builtin__io:readFile _name)))
26+
27+
# @brief Check if a file exists, return True or False
28+
# @param filename the path of the file
29+
# =begin
30+
# (io:fileExists? "hello.json")
31+
# =end
32+
# @author https://github.com/SuperFola
33+
(let fileExists? (fun (_name) (builtin__io:fileExists? _name)))
34+
35+
# @brief List files in a folder, as a List of String
36+
# @param path A directory
37+
# =begin
38+
# (io:listFiles "/tmp/hello")
39+
# =end
40+
# @author https://github.com/SuperFola
41+
(let listFiles (fun (_path) (builtin__io:listFiles _path)))
42+
43+
# @brief Check if a path represents a directory
44+
# @param path A directory
45+
# =begin
46+
# (io:dir? "/tmp/hello")
47+
# =end
48+
# @author https://github.com/SuperFola
49+
(let dir? (fun (_path) (builtin__io:dir? _path)))
50+
51+
# @brief Create a directory
52+
# @param path A directory
53+
# =begin
54+
# (io:makeDir "/tmp/myDir")
55+
# =end
56+
# @author https://github.com/SuperFola
57+
(let makeDir (fun (_path) (builtin__io:makeDir _path)))
58+
59+
# @brief Delete file
60+
# @param filename path to file
61+
# =begin
62+
# (io:removeFile "/tmp/test.ark")
63+
# =end
64+
# @author https://github.com/SuperFola
65+
(let removeFile (fun (_path) (builtin__io:removeFile _path)))

List.ark

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,64 @@
1+
# @brief Reverse a given list and return a new one
2+
# @details The original list is not modified
3+
# @param list the list to reverse
4+
# =begin
5+
# (list:reverse [1 2 3]) # [3 2 1]
6+
# =end
7+
# @author https://github.com/SuperFola
8+
(let reverse (fun (_L) (builtin__list:reverse _L)))
9+
10+
# @brief Search an element in a List
11+
# @details The original list is not modified
12+
# @param list the List to search in
13+
# @param value the element to search
14+
# =begin
15+
# (list:find [1 2 3] 1) # 0
16+
# (list:find [1 2 3] 0) # -1
17+
# =end
18+
# @author https://github.com/SuperFola
19+
(let find (fun (_L _x) (builtin__list:find _L _x)))
20+
21+
# @brief Get a slice from a List
22+
# @details The original list is not modified
23+
# @param list the list to reverse
24+
# @param start included, must be positive
25+
# @param end not included, must be positive and smaller than the list
26+
# @param step must be greater than 0
27+
# =begin
28+
# (list:slice [1 2 3 4 5] 1 4 2) # [2 4]
29+
# =end
30+
# @author https://github.com/SuperFola
31+
(let slice (fun (_L _start _end _step) (builtin__list:slice _L _start _end _step)))
32+
33+
# @brief Sort a List and return a new one
34+
# @details The original list is not modified
35+
# @param list the list to sort
36+
# =begin
37+
# (list:sort [4 2 3]) # [1 2 4]
38+
# =end
39+
# @author https://github.com/SuperFola
40+
(let sort (fun (_L) (builtin__list:sort _L)))
41+
42+
# @brief Generate a List of n copies of an element
43+
# @param count the number of copies
44+
# @param value the element to copy
45+
# =begin
46+
# (list:fill 4 nil) # [nil nil nil nil]
47+
# =end
48+
# @author https://github.com/SuperFola
49+
(let fill (fun (_val _count) (builtin__list:fill _val _count)))
50+
51+
# @brief Modify a given list and return a new one
52+
# @details The original list is not modified
53+
# @param list the list to modify
54+
# @param index the index of the element to modify
55+
# @param value the new element
56+
# =begin
57+
# (list:setAt [1 2 3] 0 5) # [5 2 3]
58+
# =end
59+
# @author https://github.com/SuperFola
60+
(let setAt (fun (_L _index _x) (builtin__list:setAt _L _index _x)))
61+
162
# @brief Iterate over a given list and run a given function on every element.
263
# @param _L the list to iterate over
364
# @param _func the function to call on each element

Math.ark

Lines changed: 166 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,163 @@
1+
# @brief Calculate e^number
2+
# @param value the Number
3+
# =begin
4+
# (math:exp 1) # 2.7182...
5+
# =end
6+
# @author https://github.com/SuperFola
7+
(let exp (fun (_x) (builtin__math:exp _x)))
8+
9+
# @brief Calculate the logarithm of a number
10+
# @param value the Number
11+
# =begin
12+
# (math:ln 1) # 0
13+
# =end
14+
# @author https://github.com/SuperFola
15+
(let ln (fun (_x) (builtin__math:ln _x)))
16+
17+
# @brief Get the smallest possible integer greater than the number
18+
# @param value the Number
19+
# =begin
20+
# (math:ceil 0.2) # 1
21+
# =end
22+
# @author https://github.com/SuperFola
23+
(let ceil (fun (_x) (builtin__math:ceil _x)))
24+
25+
# @brief Get the smallest possible integer equal to the given number
26+
# @param value the Number
27+
# =begin
28+
# (math:floor 1.7) # 1
29+
# =end
30+
# @author https://github.com/SuperFola
31+
(let floor (fun (_x) (builtin__math:floor _x)))
32+
33+
# @brief Get the smallest possible integer equal to or greater than the given number
34+
# @param value the Number
35+
# =begin
36+
# (math:round 0.2) # 0
37+
# (math:round 0.6) # 1
38+
# =end
39+
# @author https://github.com/SuperFola
40+
(let round (fun (_x) (builtin__math:round _x)))
41+
42+
# @brief Check if a Number is NaN
43+
# @param value the Number
44+
# =begin
45+
# (math:NaN? 2) # false
46+
# (math:NaN? nan) # true
47+
# =end
48+
# @author https://github.com/SuperFola
49+
(let NaN? (fun (_x) (builtin__math:NaN? _x)))
50+
51+
# @brief Check if a Number if Inf
52+
# @param value the Number
53+
# =begin
54+
# (math:Inf? 1) # false
55+
# (math:Inf? nan) # false
56+
# =end
57+
# @author https://github.com/SuperFola
58+
(let Inf? (fun (_x) (builtin__math:Inf? _x)))
59+
60+
# @brief Calculate the cosinus of a number
61+
# @param value the Number (radians)
62+
# =begin
63+
# (math:cos 0) # 1
64+
# (math:cos math:pi) # -1
65+
# =end
66+
# @author https://github.com/SuperFola
67+
(let cos (fun (_x) (builtin__math:cos _x)))
68+
69+
# @brief Calculate the sinus of a number
70+
# @param value the Number (radians)
71+
# =begin
72+
# (math:sin 0) # 0
73+
# (math:cos (/ math:pi 2)) # 1
74+
# =end
75+
# @author https://github.com/SuperFola
76+
(let sin (fun (_x) (builtin__math:sin _x)))
77+
78+
# @brief Calculate the tangent of a number
79+
# @param value the Number (radians)
80+
# =begin
81+
# (math:tan 0) # 0
82+
# (math:cos (/ math:pi 4)) # 1
83+
# =end
84+
# @author https://github.com/SuperFola
85+
(let tan (fun (_x) (builtin__math:tan _x)))
86+
87+
# @brief Calculate the arc cosinus of a number
88+
# @param value the Number
89+
# =begin
90+
# (math:arccos 1) # 0
91+
# =end
92+
# @author https://github.com/SuperFola
93+
(let arccos (fun (_x) (builtin__math:arccos _x)))
94+
95+
# @brief Calculate the arc sinus of a number
96+
# @param value the Number
97+
# =begin
98+
# (math:arcsin 1) # 1.570796326794897 (/ math:pi 2)
99+
# =end
100+
# @author https://github.com/SuperFola
101+
(let arcsin (fun (_x) (builtin__math:arcsin _x)))
102+
103+
# @brief Calculate the arc tangent of a number
104+
# @param value the Number
105+
# =begin
106+
# (math:arctan 0) # 0
107+
# =end
108+
# @author https://github.com/SuperFola
109+
(let arctan (fun (_x) (builtin__math:arctan _x)))
110+
111+
# @brief Calculate the hyperbolic cosinus of a number
112+
# @param value the Number
113+
# @author https://github.com/Gryfenfer97
114+
(let cosh (fun (_x) (builtin__math:cosh _x)))
115+
116+
# @brief Calculate the hyperbolic sinus of a number
117+
# @param value the Number
118+
# @author https://github.com/Gryfenfer97
119+
(let sinh (fun (_x) (builtin__math:sinh _x)))
120+
121+
# @brief Calculate the hyperbolic tangent of a number
122+
# @param value the Number
123+
# @author https://github.com/Gryfenfer97
124+
(let tanh (fun (_x) (builtin__math:tanh _x)))
125+
126+
# @brief Calculate the hyperbolic arc cosinus of a number
127+
# @param value the Number
128+
# @author https://github.com/Gryfenfer97
129+
(let acosh (fun (_x) (builtin__math:acosh _x)))
130+
131+
# @brief Calculate the hyperbolic arc sinus of a number
132+
# @param value the Number
133+
# @author https://github.com/Gryfenfer97
134+
(let asinh (fun (_x) (builtin__math:asinh _x)))
135+
136+
# @brief Calculate the hyperbolic arc tangent of a number
137+
# @param value the Number
138+
# @author https://github.com/Gryfenfer97
139+
(let atanh (fun (_x) (builtin__math:atanh _x)))
140+
141+
# @brief Pi value (3.14159...)
142+
# @author https://github.com/SuperFola
143+
(let pi builtin__math:pi)
144+
145+
# @brief E value (2.7182...)
146+
# @author https://github.com/SuperFola
147+
(let e builtin__math:e)
148+
149+
# @brief Tau, the ratio of the circumference to the radius of a circle, which is equal to 2*pi (6.28318...)
150+
# @author https://github.com/SuperFola
151+
(let tau builtin__math:tau)
152+
153+
# @brief Float infinite value
154+
# @author https://github.com/SuperFola
155+
(let Inf builtin__math:Inf)
156+
157+
# @brief Float not-a-number value
158+
# @author https://github.com/SuperFola
159+
(let NaN builtin__math:NaN)
160+
1161
# @brief Return the absolute value of a number
2162
# @param _x the number to get the absolute value of
3163
# @author https://github.com/rstefanic
@@ -39,13 +199,13 @@
39199
# @param _x the number to pow
40200
# @param _a the exponent
41201
# @author https://github.com/SuperFola
42-
(let pow (fun (_x _a) (math:exp (* _a (math:ln _x)))))
202+
(let pow (fun (_x _a) (exp (* _a (ln _x)))))
43203

44204
# @brief Get the square root of a number
45205
# @details Square roots can't be taken for negative numbers for obvious reasons.
46206
# @param _x the number
47207
# @author https://github.com/SuperFola
48-
(let sqrt (fun (_x) (math:exp (* 0.5 (math:ln _x)))))
208+
(let sqrt (fun (_x) (exp (* 0.5 (ln _x)))))
49209

50210
# @brief Run the fibonacci function on a number
51211
# @param n the number
@@ -71,7 +231,7 @@
71231
(if (or (= 0 (mod n 2)) (= 1 n))
72232
false
73233
{
74-
(let k (math:ceil (+ 1 (sqrt n))))
234+
(let k (ceil (+ 1 (sqrt n))))
75235
(mut i 3)
76236
(mut continue true)
77237

@@ -91,7 +251,7 @@
91251
(assert (>= n 2) "divs: n must be greater or equal to 2")
92252
(mut i 2)
93253
(mut divisors [1])
94-
(let top (math:ceil (/ n 2)))
254+
(let top (ceil (/ n 2)))
95255

96256
(while (and (<= i top) (!= top n)) {
97257
(if (= (mod n i) 0)
@@ -109,7 +269,7 @@
109269
(let log (fun (x n) {
110270
(assert (> x 0) "log: x must be greater than 0")
111271
(assert (>= n 1) "log: n must be greater or equal to 1")
112-
(math:round (/ (math:ln x) (math:ln n))) }))
272+
(round (/ (ln x) (ln n))) }))
113273

114274
# @brief Returns the logarithm base 2 of a number
115275
# @param x the number
@@ -134,7 +294,7 @@
134294
# =begin
135295
# (floordiv 14 6) # Returns 2
136296
# =end
137-
(let floordiv (fun (a b) (math:floor (/ a b))))
297+
(let floordiv (fun (a b) (floor (/ a b))))
138298

139299
# @brief Create a complex number
140300
# @param real the real part of the complex number

0 commit comments

Comments
 (0)