Skip to content

feat: adding proxied builtins to the standard library #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions IO.ark
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# @brief Write content to a file. Return nil
# @param filename path to the file to write to (will be overwritten if it exists)
# @param content can be any valid ArkScript value
# =begin
# (io:writeFile "hello.json" "{\"key\": 12}")
# =end
# @author https://github.com/SuperFola
(let writeFile (fun (_name _content) (builtin__io:writeFile _name _content)))

# @brief Append content to a file. Return nil
# @param filename path to the file to append to
# @param content can be any valid ArkScript value
# =begin
# (io:writeFile "hello.json" "{\"key\": 12}")
# =end
# @author https://github.com/SuperFola
(let appendToFile (fun (_name _content) (builtin__io:appendToFile _name _content)))

# @brief Read the content from a file as a String
# @param filename the path of the file to read
# =begin
# (io:readFile "hello.json")
# =end
# @author https://github.com/SuperFola
(let readFile (fun (_name) (builtin__io:readFile _name)))

# @brief Check if a file exists, return True or False
# @param filename the path of the file
# =begin
# (io:fileExists? "hello.json")
# =end
# @author https://github.com/SuperFola
(let fileExists? (fun (_name) (builtin__io:fileExists? _name)))

# @brief List files in a folder, as a List of String
# @param path A directory
# =begin
# (io:listFiles "/tmp/hello")
# =end
# @author https://github.com/SuperFola
(let listFiles (fun (_path) (builtin__io:listFiles _path)))

# @brief Check if a path represents a directory
# @param path A directory
# =begin
# (io:dir? "/tmp/hello")
# =end
# @author https://github.com/SuperFola
(let dir? (fun (_path) (builtin__io:dir? _path)))

# @brief Create a directory
# @param path A directory
# =begin
# (io:makeDir "/tmp/myDir")
# =end
# @author https://github.com/SuperFola
(let makeDir (fun (_path) (builtin__io:makeDir _path)))

# @brief Delete file
# @param filename path to file
# =begin
# (io:removeFile "/tmp/test.ark")
# =end
# @author https://github.com/SuperFola
(let removeFile (fun (_path) (builtin__io:removeFile _path)))
61 changes: 61 additions & 0 deletions List.ark
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
# @brief Reverse a given list and return a new one
# @details The original list is not modified
# @param list the list to reverse
# =begin
# (list:reverse [1 2 3]) # [3 2 1]
# =end
# @author https://github.com/SuperFola
(let reverse (fun (_L) (builtin__list:reverse _L)))

# @brief Search an element in a List
# @details The original list is not modified
# @param list the List to search in
# @param value the element to search
# =begin
# (list:find [1 2 3] 1) # 0
# (list:find [1 2 3] 0) # -1
# =end
# @author https://github.com/SuperFola
(let find (fun (_L _x) (builtin__list:find _L _x)))

# @brief Get a slice from a List
# @details The original list is not modified
# @param list the list to reverse
# @param start included, must be positive
# @param end not included, must be positive and smaller than the list
# @param step must be greater than 0
# =begin
# (list:slice [1 2 3 4 5] 1 4 2) # [2 4]
# =end
# @author https://github.com/SuperFola
(let slice (fun (_L _start _end _step) (builtin__list:slice _L _start _end _step)))

# @brief Sort a List and return a new one
# @details The original list is not modified
# @param list the list to sort
# =begin
# (list:sort [4 2 3]) # [1 2 4]
# =end
# @author https://github.com/SuperFola
(let sort (fun (_L) (builtin__list:sort _L)))

# @brief Generate a List of n copies of an element
# @param count the number of copies
# @param value the element to copy
# =begin
# (list:fill 4 nil) # [nil nil nil nil]
# =end
# @author https://github.com/SuperFola
(let fill (fun (_val _count) (builtin__list:fill _val _count)))

# @brief Modify a given list and return a new one
# @details The original list is not modified
# @param list the list to modify
# @param index the index of the element to modify
# @param value the new element
# =begin
# (list:setAt [1 2 3] 0 5) # [5 2 3]
# =end
# @author https://github.com/SuperFola
(let setAt (fun (_L _index _x) (builtin__list:setAt _L _index _x)))

# @brief Iterate over a given list and run a given function on every element.
# @param _L the list to iterate over
# @param _func the function to call on each element
Expand Down
172 changes: 166 additions & 6 deletions Math.ark
Original file line number Diff line number Diff line change
@@ -1,3 +1,163 @@
# @brief Calculate e^number
# @param value the Number
# =begin
# (math:exp 1) # 2.7182...
# =end
# @author https://github.com/SuperFola
(let exp (fun (_x) (builtin__math:exp _x)))

# @brief Calculate the logarithm of a number
# @param value the Number
# =begin
# (math:ln 1) # 0
# =end
# @author https://github.com/SuperFola
(let ln (fun (_x) (builtin__math:ln _x)))

# @brief Get the smallest possible integer greater than the number
# @param value the Number
# =begin
# (math:ceil 0.2) # 1
# =end
# @author https://github.com/SuperFola
(let ceil (fun (_x) (builtin__math:ceil _x)))

# @brief Get the smallest possible integer equal to the given number
# @param value the Number
# =begin
# (math:floor 1.7) # 1
# =end
# @author https://github.com/SuperFola
(let floor (fun (_x) (builtin__math:floor _x)))

# @brief Get the smallest possible integer equal to or greater than the given number
# @param value the Number
# =begin
# (math:round 0.2) # 0
# (math:round 0.6) # 1
# =end
# @author https://github.com/SuperFola
(let round (fun (_x) (builtin__math:round _x)))

# @brief Check if a Number is NaN
# @param value the Number
# =begin
# (math:NaN? 2) # false
# (math:NaN? nan) # true
# =end
# @author https://github.com/SuperFola
(let NaN? (fun (_x) (builtin__math:NaN? _x)))

# @brief Check if a Number if Inf
# @param value the Number
# =begin
# (math:Inf? 1) # false
# (math:Inf? nan) # false
# =end
# @author https://github.com/SuperFola
(let Inf? (fun (_x) (builtin__math:Inf? _x)))

# @brief Calculate the cosinus of a number
# @param value the Number (radians)
# =begin
# (math:cos 0) # 1
# (math:cos math:pi) # -1
# =end
# @author https://github.com/SuperFola
(let cos (fun (_x) (builtin__math:cos _x)))

# @brief Calculate the sinus of a number
# @param value the Number (radians)
# =begin
# (math:sin 0) # 0
# (math:cos (/ math:pi 2)) # 1
# =end
# @author https://github.com/SuperFola
(let sin (fun (_x) (builtin__math:sin _x)))

# @brief Calculate the tangent of a number
# @param value the Number (radians)
# =begin
# (math:tan 0) # 0
# (math:cos (/ math:pi 4)) # 1
# =end
# @author https://github.com/SuperFola
(let tan (fun (_x) (builtin__math:tan _x)))

# @brief Calculate the arc cosinus of a number
# @param value the Number
# =begin
# (math:arccos 1) # 0
# =end
# @author https://github.com/SuperFola
(let arccos (fun (_x) (builtin__math:arccos _x)))

# @brief Calculate the arc sinus of a number
# @param value the Number
# =begin
# (math:arcsin 1) # 1.570796326794897 (/ math:pi 2)
# =end
# @author https://github.com/SuperFola
(let arcsin (fun (_x) (builtin__math:arcsin _x)))

# @brief Calculate the arc tangent of a number
# @param value the Number
# =begin
# (math:arctan 0) # 0
# =end
# @author https://github.com/SuperFola
(let arctan (fun (_x) (builtin__math:arctan _x)))

# @brief Calculate the hyperbolic cosinus of a number
# @param value the Number
# @author https://github.com/Gryfenfer97
(let cosh (fun (_x) (builtin__math:cosh _x)))

# @brief Calculate the hyperbolic sinus of a number
# @param value the Number
# @author https://github.com/Gryfenfer97
(let sinh (fun (_x) (builtin__math:sinh _x)))

# @brief Calculate the hyperbolic tangent of a number
# @param value the Number
# @author https://github.com/Gryfenfer97
(let tanh (fun (_x) (builtin__math:tanh _x)))

# @brief Calculate the hyperbolic arc cosinus of a number
# @param value the Number
# @author https://github.com/Gryfenfer97
(let acosh (fun (_x) (builtin__math:acosh _x)))

# @brief Calculate the hyperbolic arc sinus of a number
# @param value the Number
# @author https://github.com/Gryfenfer97
(let asinh (fun (_x) (builtin__math:asinh _x)))

# @brief Calculate the hyperbolic arc tangent of a number
# @param value the Number
# @author https://github.com/Gryfenfer97
(let atanh (fun (_x) (builtin__math:atanh _x)))

# @brief Pi value (3.14159...)
# @author https://github.com/SuperFola
(let pi builtin__math:pi)

# @brief E value (2.7182...)
# @author https://github.com/SuperFola
(let e builtin__math:e)

# @brief Tau, the ratio of the circumference to the radius of a circle, which is equal to 2*pi (6.28318...)
# @author https://github.com/SuperFola
(let tau builtin__math:tau)

# @brief Float infinite value
# @author https://github.com/SuperFola
(let Inf builtin__math:Inf)

# @brief Float not-a-number value
# @author https://github.com/SuperFola
(let NaN builtin__math:NaN)

# @brief Return the absolute value of a number
# @param _x the number to get the absolute value of
# @author https://github.com/rstefanic
Expand Down Expand Up @@ -39,13 +199,13 @@
# @param _x the number to pow
# @param _a the exponent
# @author https://github.com/SuperFola
(let pow (fun (_x _a) (math:exp (* _a (math:ln _x)))))
(let pow (fun (_x _a) (exp (* _a (ln _x)))))

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

# @brief Run the fibonacci function on a number
# @param n the number
Expand All @@ -71,7 +231,7 @@
(if (or (= 0 (mod n 2)) (= 1 n))
false
{
(let k (math:ceil (+ 1 (sqrt n))))
(let k (ceil (+ 1 (sqrt n))))
(mut i 3)
(mut continue true)

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

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

# @brief Returns the logarithm base 2 of a number
# @param x the number
Expand All @@ -134,7 +294,7 @@
# =begin
# (floordiv 14 6) # Returns 2
# =end
(let floordiv (fun (a b) (math:floor (/ a b))))
(let floordiv (fun (a b) (floor (/ a b))))

# @brief Create a complex number
# @param real the real part of the complex number
Expand Down
Loading