diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af742ba..5f6227c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,18 @@ env: CLANG_VERSION: 16 jobs: + check_ark: + name: ArkScript formatting check + runs-on: ubuntu-24.04 + + steps: + - uses: actions/checkout@v4 + - name: Format check + uses: ArkScript-lang/action-format@master + with: + folder: . + exclude: tests + build: runs-on: ubuntu-24.04 diff --git a/Events.ark b/Events.ark index bf1f2ae..5620d42 100644 --- a/Events.ark +++ b/Events.ark @@ -8,83 +8,80 @@ # =end # @author https://github.com/fabien-zoccola (let events:manager:make (fun () { - # listeners list - (mut _listeners []) + # listeners list + (mut _listeners []) - # @brief Checks if a given callback is valid (is a function or a closure) - # @param callback the callback to check - # @details Returns true if the callback is a function/closure, false otherwise - # =begin - # (closure._check_valid (fun (param) ())) # => true - # (closure._check_valid (fun (param) {})) # => true - # (closure._check_valid 5) # => false - # =end - # @author https://github.com/fabien-zoccola - (let _check_valid (fun (callback) - (or (= "Function" (type callback)) (= "Closure" (type callback))))) + # @brief Checks if a given callback is valid (is a function or a closure) + # @param callback the callback to check + # @details Returns true if the callback is a function/closure, false otherwise + # =begin + # (closure._check_valid (fun (param) ())) # => true + # (closure._check_valid (fun (param) {})) # => true + # (closure._check_valid 5) # => false + # =end + # @author https://github.com/fabien-zoccola + (let _check_valid (fun (callback) (or (= "Function" (type callback)) (= "Closure" (type callback))))) - # @brief Registers an event listener - # @param typ the type of the event to listen for - # @param callback the function/closure that will be called when an event is emitted - # @details Adds a [type callback] list to the listeners list - # =begin - # (closure.on "myType" (fun (param) ()) - # =end - # @author https://github.com/fabien-zoccola - (let on (fun (typ callback) - (if (_check_valid callback) - (set _listeners (append _listeners [typ callback]))))) + # @brief Registers an event listener + # @param typ the type of the event to listen for + # @param callback the function/closure that will be called when an event is emitted + # @details Adds a [type callback] list to the listeners list + # =begin + # (closure.on "myType" (fun (param) ()) + # =end + # @author https://github.com/fabien-zoccola + (let on (fun (typ callback) + (if (_check_valid callback) + (set _listeners (append _listeners [typ callback]))))) - # @brief Emits an event with a value - # @param val the emitted value - # @param typ the type of the emitted event - # @details Makes a forEach on the listeners list, and calls the callback. Returns a boolean of whether we called at least one listener - # =begin - # (closure.emitWith 5 "myType") - # =end - # @author https://github.com/fabien-zoccola - (let emitWith (fun (val typ) { - (mut found false) - (list:forEach _listeners (fun (element) - (if (= typ (@ element 0)) { - ((@ element 1) val) - (set found true)}))) - found })) + # @brief Emits an event with a value + # @param val the emitted value + # @param typ the type of the emitted event + # @details Makes a forEach on the listeners list, and calls the callback. Returns a boolean of whether we called at least one listener + # =begin + # (closure.emitWith 5 "myType") + # =end + # @author https://github.com/fabien-zoccola + (let emitWith (fun (val typ) { + (mut found false) - # @brief Emits an event with no value - # @param typ the type of the emitted event - # @details Calls emitWith nil - # =begin - # (closure.emit "myType") - # =end - # @author https://github.com/fabien-zoccola - (let emit (fun (typ) - (emitWith nil typ))) + (list:forEach + _listeners + (fun (element) + (if (= typ (@ element 0)) { + ((@ element 1) val) + (set found true) }))) + found })) - # @brief Removes all listeners of a given type - # @param typ the type of event to remove from the list - # @details Returns if at least one listener has been removed - # =begin - # (closure.remove_listeners_of_type "myType") - # =end - # @author https://github.com/fabien-zoccola - (let removeListenersOfType (fun (typ) { - (let newlist - (list:filter _listeners (fun (element) (!= typ (@ element 0))))) - (let deleted (!= newlist _listeners)) - (set _listeners newlist) - deleted })) + # @brief Emits an event with no value + # @param typ the type of the emitted event + # @details Calls emitWith nil + # =begin + # (closure.emit "myType") + # =end + # @author https://github.com/fabien-zoccola + (let emit (fun (typ) (emitWith nil typ))) - (fun ( - # listeners - &_listeners + # @brief Removes all listeners of a given type + # @param typ the type of event to remove from the list + # @details Returns if at least one listener has been removed + # =begin + # (closure.remove_listeners_of_type "myType") + # =end + # @author https://github.com/fabien-zoccola + (let removeListenersOfType (fun (typ) { + (let newlist (list:filter _listeners (fun (element) (!= typ (@ element 0))))) + (let deleted (!= newlist _listeners)) + (set _listeners newlist) + deleted })) - # hidden methods - &_check_valid - - # methods - &on - &emit - &emitWith - &removeListenersOfType) - () )})) + (fun ( + # listeners + &_listeners + # hidden methods + &_check_valid + # methods + &on + &emit + &emitWith + &removeListenersOfType) ()) })) diff --git a/Exceptions.ark b/Exceptions.ark index 599ca6a..0ba1e07 100644 --- a/Exceptions.ark +++ b/Exceptions.ark @@ -5,7 +5,7 @@ # =end # @author https://github.com/SuperFola (let throw (fun (_x) - (fun (_injl _injr &_x) (_injl _x)))) + (fun (_injl _injr &_x) (_injl _x)))) # @brief return takes a value as its argument and return it to be used by try # @param _x the value to return @@ -14,7 +14,7 @@ # =end # @author https://github.com/SuperFola (let return (fun (_y) - (fun (_injl _injr &_y) (_injr _y)))) + (fun (_injl _injr &_y) (_injr _y)))) # @brief Takes a value either returned by throw or return and apply a given on it if it's an error or not # @param _either the value to test @@ -30,5 +30,4 @@ # (fun (err) (print err))) # =end # @author https://github.com/SuperFola -(let try (fun (_either _continue _handle) - (_either _handle _continue))) +(let try (fun (_either _continue _handle) (_either _handle _continue))) diff --git a/Functional.ark b/Functional.ark index b0fccfb..59e734d 100644 --- a/Functional.ark +++ b/Functional.ark @@ -9,7 +9,7 @@ # =end # @author https://github.com/rstefanic (let compose (fun (_f _g) - (fun (_y &_f &_g) (_f (_g _y))))) + (fun (_y &_f &_g) (_f (_g _y))))) # @brief Take a value as its argument and return a function taking 2 arguments which will call the first function on the value # @param _x the value @@ -19,7 +19,7 @@ # =end # @author https://github.com/SuperFola (let left (fun (_x) - (fun (_injl _injr &_x) (_injl _x)))) + (fun (_injl _injr &_x) (_injl _x)))) # @brief Take a value as its argument and return a function taking 2 arguments which will call the second function on the value # @param _y the value @@ -29,7 +29,7 @@ # =end # @author https://github.com/SuperFola (let right (fun (_y) - (fun (_injl _injr &_y) (_injr _y)))) + (fun (_injl _injr &_y) (_injr _y)))) # @brief Flip the arguments of a function # @param _f the function @@ -41,4 +41,4 @@ # =end # @author https://github.com/rstefanic (let flip (fun (_f _a) - (fun (_b &_f &_a) (_f _b _a)))) + (fun (_b &_f &_a) (_f _b _a)))) diff --git a/Lazy.ark b/Lazy.ark index 5fde4be..1d724ec 100644 --- a/Lazy.ark +++ b/Lazy.ark @@ -3,19 +3,17 @@ # =begin # (let complex_stuff (fun () { # # do complex work in the function -# 42 -# })) +# 42 })) # (let lazy (lazy:eval complex_stuff)) # (print (lazy)) # =end # @author https://github.com/SuperFola (let lazy:eval (fun (f) { - (mut _has_been_called false) - (mut _memorized_value nil) + (mut _has_been_called false) + (mut _memorized_value nil) - (fun (&f &_has_been_called &_memorized_value) { - (if (not _has_been_called) - { - (set _has_been_called true) - (set _memorized_value (f))}) - _memorized_value })})) + (fun (&f &_has_been_called &_memorized_value) { + (if (not _has_been_called) { + (set _has_been_called true) + (set _memorized_value (f)) }) + _memorized_value }) })) diff --git a/List.ark b/List.ark index 5596211..63be37e 100644 --- a/List.ark +++ b/List.ark @@ -11,11 +11,12 @@ # =end # @author https://github.com/SuperFola (let list:forEach (fun (_L _func) { - (mut _index 0) - (while (< _index (len _L)) { - (mut _element (@ _L _index)) - (_func _element) - (set _index (+ 1 _index))})})) + (mut _index 0) + + (while (< _index (len _L)) { + (mut _element (@ _L _index)) + (_func _element) + (set _index (+ 1 _index)) }) })) # @brief Iterate over a given list and multiply all the elements with the others. # @param _L the list to iterate over @@ -27,12 +28,13 @@ # =end # @author https://github.com/FrenchMasterSword (let list:product (fun (_L) { - (mut _index 0) - (mut _output 1) - (while (< _index (len _L)) { - (set _output (* _output (@ _L _index))) - (set _index (+ 1 _index))}) - _output })) + (mut _index 0) + (mut _output 1) + + (while (< _index (len _L)) { + (set _output (* _output (@ _L _index))) + (set _index (+ 1 _index)) }) + _output })) # @brief Iterate over a given list and sum all the elements. # @param _L the list to iterate over @@ -44,12 +46,13 @@ # =end # @author https://github.com/FrenchMasterSword (let list:sum (fun (_L) { - (mut _index 0) - (mut _output 0) - (while (< _index (len _L)) { - (set _output (+ _output (@ _L _index))) - (set _index (+ 1 _index))}) - _output })) + (mut _index 0) + (mut _output 0) + + (while (< _index (len _L)) { + (set _output (+ _output (@ _L _index))) + (set _index (+ 1 _index)) }) + _output })) (import std.Math :min :max) @@ -63,17 +66,18 @@ # =end # @author https://github.com/rstefanic, https://github.com/SuperFola (let list:drop (fun (_L _n) - (if (< _n (/ (len _L) 2)) - (if (> _n 0) - (list:drop (tail _L) (- _n 1)) - _L) - { - (mut _index (math:max 0 _n)) - (mut _output []) - (while (< _index (len _L)) { - (set _output (append _output (@ _L _index))) - (set _index (+ 1 _index))}) - _output }))) + (if (< _n (/ (len _L) 2)) + (if (> _n 0) + (list:drop (tail _L) (- _n 1)) + _L) + { + (mut _index (math:max 0 _n)) + (mut _output []) + + (while (< _index (len _L)) { + (set _output (append _output (@ _L _index))) + (set _index (+ 1 _index)) }) + _output }))) # @brief Drop the first elements of a list, while they match a given predicate # @param _L the list to work on @@ -85,16 +89,16 @@ # =end # @author https://github.com/SuperFola (let list:dropWhile (fun (_L _f) { - (mut _index 0) - (mut _output []) - (while (< _index (len _L)) - (if (_f (@ _L _index)) - (set _index (+ 1 _index)) + (mut _index 0) + (mut _output []) - (while (< _index (len _L)) { - (set _output (append _output (@ _L _index))) - (set _index (+ 1 _index))}))) - _output })) + (while (< _index (len _L)) + (if (_f (@ _L _index)) + (set _index (+ 1 _index)) + (while (< _index (len _L)) { + (set _output (append _output (@ _L _index))) + (set _index (+ 1 _index)) }))) + _output })) # @brief Keep elements in a given list if they follow a predicate # @param _L the list to work on @@ -106,13 +110,14 @@ # =end # @author https://github.com/rstefanic (let list:filter (fun (_L _f) { - (mut _index 0) - (mut _output []) - (while (< _index (len _L)) { - (if (_f (@ _L _index)) - (set _output (append _output (@ _L _index)))) - (set _index (+ 1 _index))}) - _output })) + (mut _index 0) + (mut _output []) + + (while (< _index (len _L)) { + (if (_f (@ _L _index)) + (set _output (append _output (@ _L _index)))) + (set _index (+ 1 _index)) }) + _output })) # @brief Apply a given function to each element of a list # @param _L the list to work on @@ -123,12 +128,13 @@ # =end # @author https://github.com/rstefanic (let list:map (fun (_L _f) { - (mut _index 0) - (mut _output []) - (while (< _index (len _L)) { - (set _output (append _output (_f (@ _L _index)))) - (set _index (+ 1 _index))}) - _output })) + (mut _index 0) + (mut _output []) + + (while (< _index (len _L)) { + (set _output (append _output (_f (@ _L _index)))) + (set _index (+ 1 _index)) }) + _output })) # @brief Apply a function to the elements of a list to reduce it # @param _L the list to work on @@ -140,12 +146,13 @@ # =end # @author https://github.com/FrenchMasterSword (let list:reduce (fun (_L _f) { - (mut _index 1) - (mut _output (@ _L 0)) - (while (< _index (len _L)) { - (set _output (_f _output (@ _L _index))) - (set _index (+ 1 _index))}) - _output })) + (mut _index 1) + (mut _output (@ _L 0)) + + (while (< _index (len _L)) { + (set _output (_f _output (@ _L _index))) + (set _index (+ 1 _index)) }) + _output })) # @brief Flatten a list # @param _L the list to work on @@ -156,15 +163,18 @@ # =end # @author https://github.com/SuperFola (let list:flatten (fun (_L) { - (mut _index 0) - (mut _output []) - (while (< _index (len _L)) { - (mut _sub (@ _L _index)) - (set _output (if (= "List" (type _sub)) - (concat _output _sub) - (append _output _sub))) - (set _index (+ 1 _index))}) - _output })) + (mut _index 0) + (mut _output []) + + (while (< _index (len _L)) { + (mut _sub (@ _L _index)) + + (set _output + (if (= "List" (type _sub)) + (concat _output _sub) + (append _output _sub))) + (set _index (+ 1 _index)) }) + _output })) # @brief Apply a given function to each element of a list and then flatten it # @param _L the list to work on @@ -176,15 +186,18 @@ # =end # @author https://github.com/SuperFola (let list:flatMap (fun (_L _f) { - (mut _index 0) - (mut _output []) - (while (< _index (len _L)) { - (mut _res (_f (@ _L _index))) - (set _output (if (= "List" (type _res)) - (concat _output _res) - (append _output _res))) - (set _index (+ 1 _index))}) - _output })) + (mut _index 0) + (mut _output []) + + (while (< _index (len _L)) { + (mut _res (_f (@ _L _index))) + + (set _output + (if (= "List" (type _res)) + (concat _output _res) + (append _output _res))) + (set _index (+ 1 _index)) }) + _output })) # @brief Take the first n elements of # @param _L the list to work on @@ -195,14 +208,14 @@ # =end # @author https://github.com/rstefanic (let list:take (fun (_L _n) { - (mut _index 0) - (mut _output []) - (set _n (math:min _n (len _L))) + (mut _index 0) + (mut _output []) + (set _n (math:min _n (len _L))) - (while (< _index _n) { - (set _output (append _output (@ _L _index))) - (set _index (+ 1 _index))}) - _output })) + (while (< _index _n) { + (set _output (append _output (@ _L _index))) + (set _index (+ 1 _index)) }) + _output })) # @brief Take the first n elements of a list, given a predicate # @param _L the list to work on @@ -213,16 +226,17 @@ # =end # @author https://github.com/rakista112 (let list:takeWhile (fun (_L _f) { - (mut _index 0) - (mut _output []) - (mut continue true) - (while (and (< _index (len _L)) continue) - (if (_f (@ _L _index)) - { - (set _output (append _output (@ _L _index))) - (set _index (+ 1 _index))} - (set continue false))) - _output })) + (mut _index 0) + (mut _output []) + (mut continue true) + + (while (and (< _index (len _L)) continue) + (if (_f (@ _L _index)) + { + (set _output (append _output (@ _L _index))) + (set _index (+ 1 _index)) } + (set continue false))) + _output })) # @brief Unzip a list of [[a b] [c d]...] into [[a c ...] [b d ...]] # @param _L the list to work on @@ -233,16 +247,17 @@ # =end # @author https://github.com/FrenchMasterSword (let list:unzip (fun (_L) { - (let _m (len _L)) - (mut _list1 []) - (mut _list2 []) - (mut _index 0) - (while (< _index _m) { - (mut current (@ _L _index)) - (set _list1 (append _list1 (@ current 0))) - (set _list2 (append _list2 (@ current 1))) - (set _index (+ 1 _index))}) - [_list1 _list2] })) + (let _m (len _L)) + (mut _list1 []) + (mut _list2 []) + (mut _index 0) + + (while (< _index _m) { + (mut current (@ _L _index)) + (set _list1 (append _list1 (@ current 0))) + (set _list2 (append _list2 (@ current 1))) + (set _index (+ 1 _index)) }) + [_list1 _list2] })) # @brief Zip two lists into one: [1 2 3 4] and [5 6 7 8] will give [[1 5] [2 6] [3 7] [4 8]] # @param _a the first list to work on @@ -255,13 +270,14 @@ # =end # @author https://github.com/FrenchMasterSword (let list:zip (fun (_a _b) { - (let _m (math:min (len _a) (len _b))) - (mut _c []) - (mut _index 0) - (while (< _index _m) { - (set _c (append _c [(@ _a _index) (@ _b _index)])) - (set _index (+ 1 _index))}) - _c })) + (let _m (math:min (len _a) (len _b))) + (mut _c []) + (mut _index 0) + + (while (< _index _m) { + (set _c (append _c [(@ _a _index) (@ _b _index)])) + (set _index (+ 1 _index)) }) + _c })) # @brief Fold a given list, starting from the left side # @param _L the list to work on @@ -274,12 +290,13 @@ # =end # @author https://github.com/SuperFola (let list:foldLeft (fun (_L _init _f) { - (mut _index 0) - (mut _val _init) - (while (< _index (len _L)) { - (set _val (_f _val (@ _L _index))) - (set _index (+ 1 _index))}) - _val })) + (mut _index 0) + (mut _val _init) + + (while (< _index (len _L)) { + (set _val (_f _val (@ _L _index))) + (set _index (+ 1 _index)) }) + _val })) # @brief Check if a condition is verified for all elements of a list # @param _L the list to work on @@ -291,13 +308,14 @@ # =end # @author https://github.com/Gryfenfer97 (let list:forAll (fun (_L _f) { - (mut _verified true) - (mut _index 0) - (while (and _verified (< _index (len _L))) { - (if (not (_f (@ _L _index))) - (set _verified false)) - (set _index (+ 1 _index))}) - _verified })) + (mut _verified true) + (mut _index 0) + + (while (and _verified (< _index (len _L))) { + (if (not (_f (@ _L _index))) + (set _verified false)) + (set _index (+ 1 _index)) }) + _verified })) # @brief Check if a condition if verified for one or more elements of a list # @param _L the list to work on @@ -309,10 +327,11 @@ # =end # @author https://github.com/Gryfenfer97 (let list:any (fun (_L _f) { - (mut _verified false) - (mut _index 0) - (while (and (not _verified) (< _index (len _L))) { - (if (_f (@ _L _index)) - (set _verified true)) - (set _index (+ 1 _index))}) - _verified })) + (mut _verified false) + (mut _index 0) + + (while (and (not _verified) (< _index (len _L))) { + (if (_f (@ _L _index)) + (set _verified true)) + (set _index (+ 1 _index)) }) + _verified })) diff --git a/Macros.ark b/Macros.ark index 5d5e796..cfe9258 100644 --- a/Macros.ark +++ b/Macros.ark @@ -1,15 +1,14 @@ ($ -> (arg fn1 ...fn) { - ($if (> (len fn) 0) - (-> (fn1 arg) ...fn) - (fn1 arg))}) + ($if (> (len fn) 0) + (-> (fn1 arg) ...fn) + (fn1 arg)) }) # internal, do not use ($ __suffix-dup (sym x) { - ($if (> x 1) - (__suffix-dup sym (- x 1))) - ($symcat sym x)}) + ($if (> x 1) (__suffix-dup sym (- x 1))) + ($symcat sym x) }) ($ partial (func ...defargs) { - ($ bloc (__suffix-dup a (- ($argcount func) (len defargs)))) - (fun (bloc) (func ...defargs bloc)) - ($undef bloc)}) \ No newline at end of file + ($ bloc (__suffix-dup a (- ($argcount func) (len defargs)))) + (fun (bloc) (func ...defargs bloc)) + ($undef bloc) }) diff --git a/Math.ark b/Math.ark index b673018..fec7d63 100644 --- a/Math.ark +++ b/Math.ark @@ -2,48 +2,50 @@ # @param _x the number to get the absolute value of # @author https://github.com/rstefanic (let math:abs (fun (_x) - (if (< _x 0) (* -1 _x) _x))) + (if (< _x 0) + (* -1 _x) + _x))) # @brief Return true if the number is even, false otherwise # @param _n the number # @author https://github.com/rstefanic -(let math:even (fun (_n) - (= 0 (mod _n 2)))) +(let math:even (fun (_n) (= 0 (mod _n 2)))) # @brief Return true if the number is odd, false otherwise # @param _n the number # @author https://github.com/rstefanic -(let math:odd (fun (_n) - (= 1 (math:abs (mod _n 2))))) +(let math:odd (fun (_n) (= 1 (math:abs (mod _n 2))))) # @brief Get the minimum between two numbers # @param _a the first number # @param _b the second number # @author https://github.com/rstefanic (let math:min (fun (_a _b) - (if (< _a _b) _a _b))) + (if (< _a _b) + _a + _b))) # @brief Get the maximum between two numbers # @param _a the first number # @param _b the second number # @author https://github.com/rstefanic (let math:max (fun (_a _b) - (if (> _a _b) _a _b))) + (if (> _a _b) + _a + _b))) # @brief Get a number to a given power # @details Note that it's defined as exp(a * ln(x)), thus won't work for negative numbers # @param _x the number to pow # @param _a the exponent # @author https://github.com/SuperFola -(let math:pow (fun (_x _a) - (math:exp (* _a (math:ln _x))))) +(let math:pow (fun (_x _a) (math:exp (* _a (math: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 math:sqrt (fun (_x) - (math:exp (* 0.5 (math:ln _x))))) +(let math:sqrt (fun (_x) (math:exp (* 0.5 (math:ln _x))))) # @brief Run the fibonacci function on a number # @param n the number @@ -52,11 +54,13 @@ # (math:fibo 45 0 1) # =end (let math:fibo (fun (n) { - (let impl (fun (n p c) - (if (<= n 0) 0 - (if (= n 1) c - (impl (- n 1) c (+ p c)))))) - (impl n 0 1)})) + (let impl (fun (n p c) + (if (<= n 0) + 0 + (if (= n 1) + c + (impl (- n 1) c (+ p c)))))) + (impl n 0 1) })) # @brief Returns the list of a number's divisors # @param n the number @@ -65,15 +69,16 @@ # (math:divs 6) # Returns [1 2 3 6] # =end (let math:divs (fun (n) { - (assert (>= n 2) "math:divs: n must be greater or equal to 2") - (mut i 2) - (mut divisors [1]) - (let top (math:ceil (/ n 2))) - (while (and (<= i top) (!= top n)) { - (if (= (mod n i) 0) - (set divisors (append divisors i))) - (set i (+ i 1))}) - (append divisors n)})) + (assert (>= n 2) "math:divs: n must be greater or equal to 2") + (mut i 2) + (mut divisors [1]) + (let top (math:ceil (/ n 2))) + + (while (and (<= i top) (!= top n)) { + (if (= (mod n i) 0) + (set divisors (append divisors i))) + (set i (+ i 1)) }) + (append divisors n) })) # @brief Returns the logarithm base n of a number # @param x the number @@ -83,9 +88,9 @@ # (math:log 81 3) # Returns 4 # =end (let math:log (fun (x n) { - (assert (> x 0) "math:log: x must be greater than 0") - (assert (>= n 1) "math:log: n must be greater or equal to 1") - (math:round (/ (math:ln x) (math:ln n)))})) + (assert (> x 0) "math:log: x must be greater than 0") + (assert (>= n 1) "math:log: n must be greater or equal to 1") + (math:round (/ (math:ln x) (math:ln n))) })) # @brief Returns the logarithm base 2 of a number # @param x the number @@ -93,8 +98,7 @@ # =begin # (math:log2 128) # Returns 7 # =end -(let math:log2 (fun (x) - (math:log x 2))) +(let math:log2 (fun (x) (math:log x 2))) # @brief Returns the logarithm base 10 of a number # @param x the number @@ -102,8 +106,7 @@ # =begin # (math:log10 1000) # Returns 3 # =end -(let math:log10 (fun (x) - (math:log x 10))) +(let math:log10 (fun (x) (math:log x 10))) # @brief Returns the quotient of the euclidian division of a and b # @param a the dividend @@ -112,8 +115,7 @@ # =begin # (math:floordiv 14 6) # Returns 2 # =end -(let math:floordiv (fun (a b) - (math:floor (/ a b)))) +(let math:floordiv (fun (a b) (math:floor (/ a b)))) # @brief Create a complex number # @param real the real part of the complex number @@ -124,7 +126,7 @@ # =end # @author https://github.com/SuperFola (let math:complex (fun (real imag) - (fun (&real &imag) ()))) + (fun (&real &imag) ()))) # @brief Compute the addition of two complex number # @param _c0 the first complex number @@ -134,8 +136,7 @@ # (print c.real " " c.imag) # 4 6 # =end # @author https://github.com/SuperFola -(let math:complex-add (fun (_c0 _c1) - (math:complex (+ _c0.real _c1.real) (+ _c0.imag _c1.imag)))) +(let math:complex-add (fun (_c0 _c1) (math:complex (+ _c0.real _c1.real) (+ _c0.imag _c1.imag)))) # @brief Compute the substraction of two complex number # @param _c0 the first complex number @@ -145,8 +146,7 @@ # (print c.real " " c.imag) # -2 -2 # =end # @author https://github.com/SuperFola -(let math:complex-sub (fun (_c0 _c1) - (math:complex (- _c0.real _c1.real) (- _c0.imag _c1.imag)))) +(let math:complex-sub (fun (_c0 _c1) (math:complex (- _c0.real _c1.real) (- _c0.imag _c1.imag)))) # @brief Compute the multiplication of two complex number # @param _c0 the first complex number @@ -156,9 +156,7 @@ # (print c.real " " c.imag) # -5 10 # =end # @author https://github.com/SuperFola -(let math:complex-mul (fun (_c0 _c1) - (math:complex (+ (* _c0.real _c1.real) (- 0 (* _c0.imag _c1.imag))) - (+ (* _c0.real _c1.imag) (* _c1.real _c0.imag))))) +(let math:complex-mul (fun (_c0 _c1) (math:complex (+ (* _c0.real _c1.real) (- 0 (* _c0.imag _c1.imag))) (+ (* _c0.real _c1.imag) (* _c1.real _c0.imag))))) # @brief Compute the conjugate of a complex number # @param _c the complex number @@ -167,8 +165,7 @@ # (print c.real " " c.imag) # 1 -2 # =end # @author https://github.com/SuperFola -(let math:complex-conjugate (fun (_c) - (math:complex _c.real (- 0 _c.imag)))) +(let math:complex-conjugate (fun (_c) (math:complex _c.real (- 0 _c.imag)))) # @brief Compute the module of a complex number # @param _c the complex number @@ -177,8 +174,7 @@ # (print c) # 2.2360679774997896964... # =end # @author https://github.com/SuperFola -(let math:complex-module (fun (_c) - (math:sqrt (+ (* _c.real _c.real) (* _c.imag _c.imag))))) +(let math:complex-module (fun (_c) (math:sqrt (+ (* _c.real _c.real) (* _c.imag _c.imag))))) # @brief Compute the division of two complex number # @param _c0 the first complex number @@ -189,7 +185,7 @@ # =end # @author https://github.com/SuperFola (let math:complex-div (fun (_c0 _c1) { - (let _conj (math:complex-conjugate _c1)) - (let _top (math:complex-mul _c0 _conj)) - (let _denom (+ (* _c1.real _c1.real) (* _c1.imag _c1.imag))) - (math:complex (/ _top.real _denom) (/ _top.imag _denom))})) + (let _conj (math:complex-conjugate _c1)) + (let _top (math:complex-mul _c0 _conj)) + (let _denom (+ (* _c1.real _c1.real) (* _c1.imag _c1.imag))) + (math:complex (/ _top.real _denom) (/ _top.imag _denom)) })) diff --git a/Range.ark b/Range.ark index eeafc8d..fde851f 100644 --- a/Range.ark +++ b/Range.ark @@ -13,23 +13,25 @@ # =end # @author https://github.com/SuperFola (let range (fun (i _b) { - (let asList (fun () { - # i and _b are going to be captured by the caller - (mut _output []) - (mut a_ i) - (while (< a_ _b) { - (set _output (append _output a_)) - (set a_ (+ 1 a_))}) - _output })) + (let asList (fun () { + # i and _b are going to be captured by the caller + (mut _output []) + (mut a_ i) + + (while (< a_ _b) { + (set _output (append _output a_)) + (set a_ (+ 1 a_)) }) + _output })) + + (let _a i) - (let _a i) - (let reset (fun () (set i _a))) + (let reset (fun () + (set i _a))) - (fun (&i &_a &_b &asList &reset) { - (if (< i _b) - { - (set i (+ i 1)) - (- i 1)})})})) + (fun (&i &_a &_b &asList &reset) { + (if (< i _b) { + (set i (+ i 1)) + (- i 1) }) }) })) # @brief Run a function on each element of the range # @param _r the range object @@ -41,11 +43,12 @@ # =end # @author https://github.com/SuperFola (let range:forEach (fun (_r _f) { - (mut _val (_r)) - (while (not (nil? _val)) { - (_f _val) - (set _val (_r))}) - (_r.reset)})) + (mut _val (_r)) + + (while (not (nil? _val)) { + (_f _val) + (set _val (_r)) }) + (_r.reset) })) # @brief Create a list based on a range and a filter function # @param _range the range object @@ -57,13 +60,15 @@ # =end # @author https://github.com/SuperFola (let range:filter (fun (_range _fun) { - (mut _value (_range)) - (mut _output []) - (while (not (nil? _value)) { - (if (_fun _value) (set _output (append _output _value))) - (set _value (_range))}) - (_range.reset) - _output })) + (mut _value (_range)) + (mut _output []) + + (while (not (nil? _value)) { + (if (_fun _value) + (set _output (append _output _value))) + (set _value (_range)) }) + (_range.reset) + _output })) # @brief Create a list based on a range and a function to apply to each elements # @param _range the range object @@ -75,13 +80,14 @@ # =end # @author https://github.com/SuperFola (let range:map (fun (_range _fun) { - (mut _value (_range)) - (mut _output []) - (while (not (nil? _value)) { - (set _output (append _output (_fun _value))) - (set _value (_range))}) - (_range.reset) - _output })) + (mut _value (_range)) + (mut _output []) + + (while (not (nil? _value)) { + (set _output (append _output (_fun _value))) + (set _value (_range)) }) + (_range.reset) + _output })) # @brief Create a reduced list based on a range and a reduction function # @param _range the range object @@ -93,10 +99,11 @@ # =end # @author https://github.com/SuperFola (let range:reduce (fun (_range _fun) { - (mut _output (_range)) - (mut _last (_range)) - (while (not (nil? _last)) { - (set _output (_fun _output _last)) - (set _last (_range))}) - (_range.reset) - _output })) + (mut _output (_range)) + (mut _last (_range)) + + (while (not (nil? _last)) { + (set _output (_fun _output _last)) + (set _last (_range)) }) + (_range.reset) + _output })) diff --git a/String.ark b/String.ark index c9d2fd0..c491a43 100644 --- a/String.ark +++ b/String.ark @@ -8,20 +8,20 @@ # =end # @author https://github.com/SuperFola (let str:toLower (fun (text) { - (mut _index 0) - (mut _e "") - (mut _output "") + (mut _index 0) + (mut _e "") + (mut _output "") - (let in_range (fun (val a b) - (and (>= val a) (<= val b)))) + (let in_range (fun (val a b) (and (>= val a) (<= val b)))) - (while (< _index (len text)) { - (set _e (@ text _index)) - (if (in_range (str:ord _e) 65 90) - (set _e (str:chr (+ (str:ord _e) 32)))) - (set _output (+ _output _e)) - (set _index (+ _index 1))}) - _output })) + (while (< _index (len text)) { + (set _e (@ text _index)) + + (if (in_range (str:ord _e) 65 90) + (set _e (str:chr (+ (str:ord _e) 32)))) + (set _output (+ _output _e)) + (set _index (+ _index 1)) }) + _output })) # @brief Converts the given character to uppercase. # @param _string the string to make uppercase @@ -33,20 +33,20 @@ # =end # @author https://github.com/SuperFola (let str:toUpper (fun (_string) { - (mut _index 0) - (mut _e "") - (mut _output "") + (mut _index 0) + (mut _e "") + (mut _output "") + + (let in_range (fun (val a b) (and (>= val a) (<= val b)))) - (let in_range (fun (val a b) - (and (>= val a) (<= val b)))) + (while (< _index (len _string)) { + (set _e (@ _string _index)) - (while (< _index (len _string)) { - (set _e (@ _string _index)) - (if (in_range (str:ord _e) 97 122) - (set _e (str:chr (- (str:ord _e) 32)))) - (set _output (+ _output _e)) - (set _index (+ _index 1))}) - _output })) + (if (in_range (str:ord _e) 97 122) + (set _e (str:chr (- (str:ord _e) 32)))) + (set _output (+ _output _e)) + (set _index (+ _index 1)) }) + _output })) # @brief Reverse a string. # @param _string the string to reverse @@ -58,12 +58,13 @@ # =end # @author https://github.com/Natendrtfm (let str:reverse (fun (_string) { - (mut _index (- (len _string) 1)) - (mut _returnedString "") - (while (> _index -1) { - (set _returnedString (+ _returnedString (@ _string _index))) - (set _index (- _index 1))}) - _returnedString })) + (mut _index (- (len _string) 1)) + (mut _returnedString "") + + (while (> _index -1) { + (set _returnedString (+ _returnedString (@ _string _index))) + (set _index (- _index 1)) }) + _returnedString })) # @brief Get a slice of a given string, from a given index with a given length # @param _string the string to get a slice of @@ -77,19 +78,23 @@ # =end # @author https://github.com/Natendrtfm (let str:slice (fun (_string _startingIndex _length) - (if (= _length 0) - "" - { - (assert (and (>= _startingIndex 0) (< _startingIndex (len _string))) "slice start index must be in range [0, string length[") + (if (= _length 0) + "" + { + (assert (and (>= _startingIndex 0) (< _startingIndex (len _string))) "slice start index must be in range [0, string length[") + + (mut _returnedString "") + (mut _index _startingIndex) - (mut _returnedString "") - (mut _index _startingIndex) - (let _end (if (> _length (len _string)) (len _string) (+ _index _length))) + (let _end + (if (> _length (len _string)) + (len _string) + (+ _index _length))) - (while (< _index _end) { - (set _returnedString (+ _returnedString (@ _string _index))) - (set _index (+ _index 1))}) - _returnedString }))) + (while (< _index _end) { + (set _returnedString (+ _returnedString (@ _string _index))) + (set _index (+ _index 1)) }) + _returnedString }))) # @brief Split a string in multiple substrings in a list, given a separator # @param _string the string to split @@ -102,22 +107,22 @@ # =end # @author https://github.com/Natendrtfm (let str:split (fun (_string _separator) { - (assert (!= "" _separator) "Separator of split can not be empty") - (assert (>= (len _separator) 1) "Separator length must be at least 1") + (assert (!= "" _separator) "Separator of split can not be empty") + (assert (>= (len _separator) 1) "Separator length must be at least 1") - (mut _index (str:find _string _separator)) - (mut _previous 0) - (mut _output []) - (let _seplen (len _separator)) + (mut _index (str:find _string _separator)) + (mut _previous 0) + (mut _output []) + (let _seplen (len _separator)) - (while (!= _index -1) { - (set _output (append _output (str:slice _string 0 (- _index _previous)))) - (set _string (str:slice _string (+ _index _seplen) (- (len _string) _index _seplen))) - (set _index (str:find _string _separator))}) + (while (!= _index -1) { + (set _output (append _output (str:slice _string 0 (- _index _previous)))) + (set _string (str:slice _string (+ _index _seplen) (- (len _string) _index _seplen))) + (set _index (str:find _string _separator)) }) - (if (empty? _string) - _output - (append _output _string))})) + (if (empty? _string) + _output + (append _output _string)) })) # @brief Replace a substring in a given string # @param _string base string who contain pattern to replace by new sub string given @@ -130,21 +135,19 @@ # (print (str:replace message "XXX" "Harry")) # hello Harry, do you like the name Harry? # =end (let str:replace (fun (_string _pattern _new) { - (mut _out _string) - (mut _idx (str:find _out _pattern)) - (let _pattern_sz (len _pattern)) - - (while (!= -1 _idx) { - (mut _first_segment (str:slice _out 0 _idx)) - (mut _next_segment (str:slice _out (+ _idx _pattern_sz) (- (len _out) (+ _idx _pattern_sz)))) - (set _out (+ - _first_segment - _new - _next_segment)) - (set _idx (str:find _next_segment _pattern)) - (if (!= -1 _idx) - (set _idx (+ _idx (len _first_segment) (len _new))))}) - _out })) + (mut _out _string) + (mut _idx (str:find _out _pattern)) + (let _pattern_sz (len _pattern)) + + (while (!= -1 _idx) { + (mut _first_segment (str:slice _out 0 _idx)) + (mut _next_segment (str:slice _out (+ _idx _pattern_sz) (- (len _out) (+ _idx _pattern_sz)))) + + (set _out (+ _first_segment _new _next_segment)) + (set _idx (str:find _next_segment _pattern)) + (if (!= -1 _idx) + (set _idx (+ _idx (len _first_segment) (len _new)))) }) + _out })) # @brief Join a list of elements with a given string delimiter # @param _list host the elements to join @@ -156,11 +159,15 @@ # (print (str:join data ";")) # 1;hello;3.14;true;world # =end (let str:join (fun (_list _delim) { - (mut _output "") - (mut _index 0) + (mut _output "") + (mut _index 0) - (while (< _index (len _list)) { - (set _output (+ _output (toString (@ _list _index)) (if (!= _index (- (len _list) 1)) _delim ""))) - (set _index (+ 1 _index))}) - - _output })) + (while (< _index (len _list)) { + (set _output (+ + _output + (toString (@ _list _index)) + (if (!= _index (- (len _list) 1)) + _delim + ""))) + (set _index (+ 1 _index)) }) + _output })) diff --git a/Switch.ark b/Switch.ark index fc5cb60..27811f5 100644 --- a/Switch.ark +++ b/Switch.ark @@ -14,9 +14,8 @@ # =end # @author https://github.com/SuperFola ($ switch (value case then ...cases) { - ($if (= "_" ($repr case)) - then - (if (= value case) - then - ($if (>= (len cases) 2) - (switch value ...cases))))}) + ($if (= "_" ($repr case)) + then + (if (= value case) + then + ($if (>= (len cases) 2) (switch value ...cases)))) }) diff --git a/Testing.ark b/Testing.ark index 8b82359..7449531 100644 --- a/Testing.ark +++ b/Testing.ark @@ -1,39 +1,40 @@ # internal, do not use (let _runner (fun (_name _callable) { - (mut _passed 0) - (mut _failed 0) - (mut _failures []) - (let _case_desc "") - (mut _cases []) - (mut _case_pointer 0) - (mut display_cases_success false) - - (let _start_time (time)) - # run test - (_callable) - (let _end_time (time)) - - # no newline, yet - (puts _name) - (if (> _passed 0) - (puts (str:format " - {} ✅" _passed))) - (if (> _failed 0) - (puts (str:format ", {} ❌" _failed))) - - (puts (str:format " in {:2.3f}ms\n" (* 1000 (- _end_time _start_time)))) - - (mut _i 0) - (let _failures_count (len _failures)) - (while (< _i _failures_count) { - (print " " (@ _failures _i)) - (set _i (+ 1 _i))}) - - [_passed _failed]})) + (mut _passed 0) + (mut _failed 0) + (mut _failures []) + (let _case_desc "") + (mut _cases []) + (mut _case_pointer 0) + (mut display_cases_success false) + + (let _start_time (time)) + + # run test + (_callable) + (let _end_time (time)) + + # no newline, yet + (puts _name) + + (if (> _passed 0) (puts (str:format " - {} ✅" _passed))) + + (if (> _failed 0) (puts (str:format ", {} ❌" _failed))) + + (puts (str:format " in {:2.3f}ms\n" (* 1000 (- _end_time _start_time)))) + + (mut _i 0) + (let _failures_count (len _failures)) + + (while (< _i _failures_count) { + (print " " (@ _failures _i)) + (set _i (+ 1 _i)) }) + [_passed _failed] })) (let _test_desc (fun (_desc) - (if (empty? _desc) - "" - (str:format " for test '{}'" (head _desc))))) + (if (empty? _desc) + "" + (str:format " for test '{}'" (head _desc))))) # internal, do not use # Has a _case_desc which also exists (empty) inside _runner so that tests without a @@ -41,11 +42,11 @@ # Add the test name to a pile so that we can nicely print all the case names later. # Update the pointer to current case to its old value later on (let _case (fun (_case_desc _callable) { - (let _old_pointer _case_pointer) - (append! _cases _case_desc) - (_callable) - (pop! _cases -1) - (set _case_pointer _old_pointer)})) + (let _old_pointer _case_pointer) + (append! _cases _case_desc) + (_callable) + (pop! _cases -1) + (set _case_pointer _old_pointer) })) # @brief Create a test case with a label to help with debugging when one or more tests fail # @details Test cases can be nested. @@ -59,8 +60,10 @@ # (test:eq 1 2 "1 is 2, this should fail")}) # =end # @author https://github.com/SuperFola -($ test:case (_desc _body) - (_case _desc (fun () {_body}))) +($ test:case (_desc _body) (_case + _desc + (fun () { + _body }))) # internal, do not use # Until _case_pointer isn't at the end of the pile (where our failing test case's is), @@ -68,66 +71,71 @@ # This way if we have CASE A>CASE B>CASE C and no test crashed in A nor in A>B, # we are still able to display the cascade A>B>C with the correct indentation. (let _add_case (fun () { - (let _target_len (len _cases)) - (while (< _case_pointer _target_len) { - (mut _indent (* 2 _case_pointer)) - (mut _fmt (if (> _indent 0) (+ "{: <" (toString _indent) "}{}") "{}{}")) - (append! _failures (str:format _fmt "" (@ _cases _case_pointer))) - (set _case_pointer (+ 1 _case_pointer))})})) + (let _target_len (len _cases)) + + (while (< _case_pointer _target_len) { + (mut _indent (* 2 _case_pointer)) + + (mut _fmt + (if (> _indent 0) + (+ "{: <" (toString _indent) "}{}") + "{}{}")) + (append! _failures (str:format _fmt "" (@ _cases _case_pointer))) + (set _case_pointer (+ 1 _case_pointer)) }) })) # internal, do not use # This can only be used within a (nested or not) call to test:suite # because it updates _failed and _failures, which are defined by # test:suite call to _runner (let _report_error (fun (_lhs _rhs _lhs_repr _rhs_repr _desc) { - (set _failed (+ 1 _failed)) - - # If we have a case description AND the pointer isn't up to date, display the case(s)' names - (if (and (not (empty? _case_desc)) (!= _case_pointer (len _cases))) - (_add_case)) - - # Compute global indent for the failing test resume - (let _indent_case_len (* 2 (len _cases))) - (let _indent (if (> _indent_case_len 0) - (str:format (+ "{: <" (toString _indent_case_len) "}") "") - "")) - # Add the error message - (append! _failures (str:format "{}expected '{}' but got '{}'{}" _indent _lhs_repr _rhs_repr (_test_desc _desc))) - - (let _rhs_start (+ (len _lhs_repr) (len "expected ''"))) - (let _lhs_align (len _lhs_repr)) - (let _rhs_align (len _rhs_repr)) - (let _show_expected (!= _lhs_repr (toString _lhs))) - (let _show_real (!= _rhs_repr (toString _rhs))) - - (if _show_real - (append! _failures - (str:format - (+ "{}{: <" (toString (len "expected ")) "}" "{: <" (toString _rhs_start) "}{:~<" (toString _rhs_align) "} {}") - _indent - # to position one char before the first ' surrounding the expected value - "" - # writes the | right under the first ' surrounding the expected value - (if _show_expected "|" "") - # begins the \~~~~ under the real value - (if _show_real "\\" "") - (if _show_real _rhs "")))) - (if _show_expected - (append! _failures - (str:format - (+ "{}{: <" (toString (len "expected ")) "}\\ {}") - _indent - "" - _lhs)))})) + (set _failed (+ 1 _failed)) + + # If we have a case description AND the pointer isn't up to date, display the case(s)' names + (if (and (not (empty? _case_desc)) (!= _case_pointer (len _cases))) (_add_case)) + + # Compute global indent for the failing test resume + (let _indent_case_len (* 2 (len _cases))) + + (let _indent + (if (> _indent_case_len 0) + (str:format (+ "{: <" (toString _indent_case_len) "}") "") + "")) + + # Add the error message + (append! _failures (str:format "{}expected '{}' but got '{}'{}" _indent _lhs_repr _rhs_repr (_test_desc _desc))) + + (let _rhs_start (+ (len _lhs_repr) (len "expected ''"))) + (let _lhs_align (len _lhs_repr)) + (let _rhs_align (len _rhs_repr)) + (let _show_expected (!= _lhs_repr (toString _lhs))) + (let _show_real (!= _rhs_repr (toString _rhs))) + + (if _show_real (append! + _failures + (str:format + (+ "{}{: <" (toString (len "expected ")) "}" "{: <" (toString _rhs_start) "}{:~<" (toString _rhs_align) "} {}") + _indent + # to position one char before the first ' surrounding the expected value + "" + # writes the | right under the first ' surrounding the expected value + (if _show_expected + "|" + "") + # begins the \~~~~ under the real value + (if _show_real + "\\" + "") + (if _show_real + _rhs + "")))) + (if _show_expected (append! _failures (str:format (+ "{}{: <" (toString (len "expected ")) "}\\ {}") _indent "" _lhs))) })) # internal, do not use # This can only be used within a (nested or not) call to test:suite # because it updates _passed, which is defined by test:suite call to _runner (let _report_success (fun () { - (set _passed (+ 1 _passed)) - (if display_cases_success - (_add_case)) -})) + (set _passed (+ 1 _passed)) + (if display_cases_success (_add_case)) })) # @brief Given a value or function call returning a boolean, generate a test case # @param _cond the value to test for truthiness @@ -139,9 +147,9 @@ # =end # @author https://github.com/SuperFola ($ test:expect (_cond ..._desc) { - (if (!= true ($paste _cond)) - (_report_error true ($paste _cond) "true" ($repr _cond) _desc) - (_report_success))}) + (if (!= true ($paste _cond)) + (_report_error true ($paste _cond) "true" ($repr _cond) _desc) + (_report_success)) }) # @brief Compare two values that should be equal and generate a test case # @param _expected expected value @@ -154,9 +162,9 @@ # =end # @author https://github.com/SuperFola ($ test:eq (_expected _expr ..._desc) { - (if (= ($paste _expected) ($paste _expr)) - (_report_success) - (_report_error ($paste _expected) ($paste _expr) ($repr _expected) ($repr _expr) _desc))}) + (if (= ($paste _expected) ($paste _expr)) + (_report_success) + (_report_error ($paste _expected) ($paste _expr) ($repr _expected) ($repr _expr) _desc)) }) # @brief Compare two values that should **not** be equal and generate a test case # @param _unexpected the value we don't want @@ -168,9 +176,9 @@ # =end # @author https://github.com/SuperFola ($ test:neq (_unexpected _value ..._desc) { - (if (!= ($paste _unexpected) ($paste _value)) - (_report_success) - (_report_error ($paste _unexpected) ($paste _value) ($repr _unexpected) ($repr _value) _desc))}) + (if (!= ($paste _unexpected) ($paste _value)) + (_report_success) + (_report_error ($paste _unexpected) ($paste _value) ($repr _unexpected) ($repr _value) _desc)) }) # @brief Generate the code for a test suite # @details Create two variables: _name-output (a list: [successes, failures]) and _name-status (boolean, true on success) @@ -184,5 +192,9 @@ # =end # @author https://github.com/SuperFola ($ test:suite (_name _body) { - (let ($symcat _name "-output") (_runner ($repr _name) (fun () ($paste {_body})))) - (let ($symcat _name "-status") (= 0 (@ ($symcat _name "-output") 1)))}) + (let ($symcat _name "-output") (_runner + ($repr _name) + (fun () ($paste + { + _body })))) + (let ($symcat _name "-status") (= 0 (@ ($symcat _name "-output") 1))) }) diff --git a/os.ark b/os.ark index 977fbb4..b3eda17 100644 --- a/os.ark +++ b/os.ark @@ -1,11 +1,11 @@ # @brief Returns the home dir of the current user # @author https://github.com/Wafelack, https://github.com/SuperFola (let os:home_dir (fun () - (if (or (= sys:platform "Linux") (= sys:platform "Mac OSX") (= sys:platform "Unix")) - { - (let username (sys:exec "whoami")) - (if (= username "root\n") - "/root/" - (+ "/home/" username))} - (if (= sys:platform "Windows") - (sys:exec "echo|set /p=%userprofile%"))))) + (if (or (= sys:platform "Linux") (= sys:platform "Mac OSX") (= sys:platform "Unix")) + { + (let username (sys:exec "whoami")) + + (if (= username "root\n") + "/root/" + (+ "/home/" username)) } + (if (= sys:platform "Windows") (sys:exec "echo|set /p=%userprofile%")))))