diff --git a/Events.ark b/Events.ark index 0536fab..acb7ed3 100644 --- a/Events.ark +++ b/Events.ark @@ -48,10 +48,8 @@ (list:forEach _listeners (fun (element) (if (= typ (@ element 0)) { ((@ element 1) val) - (set found true) - }))) - found - })) + (set found true)}))) + found })) # @brief Emits an event with no value # @param typ the type of the emitted event @@ -75,8 +73,7 @@ (list:filter _listeners (fun (element) (!= typ (@ element 0))))) (let deleted (!= newlist _listeners)) (set _listeners newlist) - deleted - })) + deleted })) (fun ( # listeners @@ -89,6 +86,5 @@ &on &emit &emitWith - &removeListenersOfType - ) ()) -})) + &removeListenersOfType) + () )})) diff --git a/Lazy.ark b/Lazy.ark index 7eab9c4..5fde4be 100644 --- a/Lazy.ark +++ b/Lazy.ark @@ -17,8 +17,5 @@ (if (not _has_been_called) { (set _has_been_called true) - (set _memorized_value (f)) - }) - _memorized_value - }) -})) + (set _memorized_value (f))}) + _memorized_value })})) diff --git a/List.ark b/List.ark index 79ffb23..023d45d 100644 --- a/List.ark +++ b/List.ark @@ -15,9 +15,7 @@ (while (< _index (len _L)) { (mut _element (@ _L _index)) (_func _element) - (set _index (+ 1 _index)) - }) -})) + (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 @@ -33,10 +31,8 @@ (mut _output 1) (while (< _index (len _L)) { (set _output (* _output (@ _L _index))) - (set _index (+ 1 _index)) - }) - _output -})) + (set _index (+ 1 _index))}) + _output })) # @brief Iterate over a given list and sum all the elements. # @param _L the list to iterate over @@ -52,10 +48,8 @@ (mut _output 0) (while (< _index (len _L)) { (set _output (+ _output (@ _L _index))) - (set _index (+ 1 _index)) - }) - _output -})) + (set _index (+ 1 _index))}) + _output })) (import "Math.ark") # needed for math:min, math:max @@ -78,10 +72,8 @@ (mut _output []) (while (< _index (len _L)) { (set _output (append _output (@ _L _index))) - (set _index (+ 1 _index)) - }) - _output - }))) + (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 @@ -101,10 +93,8 @@ (while (< _index (len _L)) { (set _output (append _output (@ _L _index))) - (set _index (+ 1 _index)) - }))) - _output -})) + (set _index (+ 1 _index))}))) + _output })) # @brief Keep elements in a given list if they follow a predicate # @param _L the list to work on @@ -121,10 +111,8 @@ (while (< _index (len _L)) { (if (_f (@ _L _index)) (set _output (append _output (@ _L _index)))) - (set _index (+ 1 _index)) - }) - _output -})) + (set _index (+ 1 _index))}) + _output })) # @brief Apply a given function to each element of a list # @param _L the list to work on @@ -139,10 +127,8 @@ (mut _output []) (while (< _index (len _L)) { (set _output (append _output (_f (@ _L _index)))) - (set _index (+ 1 _index)) - }) - _output -})) + (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 @@ -158,10 +144,8 @@ (mut _output (@ _L 0)) (while (< _index (len _L)) { (set _output (_f _output (@ _L _index))) - (set _index (+ 1 _index)) - }) - _output -})) + (set _index (+ 1 _index))}) + _output })) # @brief Flatten a list # @param _L the list to work on @@ -179,10 +163,8 @@ (set _output (if (= "List" (type _sub)) (concat _output _sub) (append _output _sub))) - (set _index (+ 1 _index)) - }) - _output -})) + (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 @@ -201,10 +183,8 @@ (set _output (if (= "List" (type _res)) (concat _output _res) (append _output _res))) - (set _index (+ 1 _index)) - }) - _output -})) + (set _index (+ 1 _index))}) + _output })) # @brief Take the first n elements of # @param _L the list to work on @@ -221,10 +201,8 @@ (while (< _index _n) { (set _output (append _output (@ _L _index))) - (set _index (+ 1 _index)) - }) - _output -})) + (set _index (+ 1 _index))}) + _output })) # @brief Take the first n elements of a list, given a predicate # @param _L the list to work on @@ -242,13 +220,9 @@ (if (_f (@ _L _index)) { (set _output (append _output (@ _L _index))) - (set _index (+ 1 _index)) - } - (set continue false) - ) - ) - _output -})) + (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 @@ -267,10 +241,8 @@ (mut current (@ _L _index)) (set _list1 (append _list1 (@ current 0))) (set _list2 (append _list2 (@ current 1))) - (set _index (+ 1 _index)) - }) - [_list1 _list2] -})) + (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 @@ -288,10 +260,8 @@ (mut _index 0) (while (< _index _m) { (set _c (append _c [(@ _a _index) (@ _b _index)])) - (set _index (+ 1 _index)) - }) - _c -})) + (set _index (+ 1 _index))}) + _c })) # @brief Fold a given list, starting from the left side # @param _L the list to work on @@ -308,10 +278,8 @@ (mut _val _init) (while (< _index (len _L)) { (set _val (_f _val (@ _L _index))) - (set _index (+ 1 _index)) - }) - _val -})) + (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 @@ -328,10 +296,8 @@ (while (and _verified (< _index (len _L))) { (if (not (_f (@ _L _index))) (set _verified false)) - (set _index (+ 1 _index)) - }) - _verified -})) + (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 @@ -348,7 +314,5 @@ (while (and (not _verified) (< _index (len _L))) { (if (_f (@ _L _index)) (set _verified true)) - (set _index (+ 1 _index)) - }) - _verified -})) + (set _index (+ 1 _index))}) + _verified })) diff --git a/Macros.ark b/Macros.ark index 5c4570e..a34c0ac 100644 --- a/Macros.ark +++ b/Macros.ark @@ -1,20 +1,15 @@ !{-> (arg fn1 ...fn) { !{if (> (len fn) 0) (-> (fn1 arg) ...fn) - (fn1 arg) - } -}} + (fn1 arg)}}} # internal, do not use !{__suffix-dup (sym x) { !{if (> x 1) - (__suffix-dup sym (- x 1)) - } - (symcat sym x) -}} + (__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} -}} + !{undef bloc}}} diff --git a/Math.ark b/Math.ark index 525db75..b673018 100644 --- a/Math.ark +++ b/Math.ark @@ -72,8 +72,7 @@ (while (and (<= i top) (!= top n)) { (if (= (mod n i) 0) (set divisors (append divisors i))) - (set i (+ i 1)) - }) + (set i (+ i 1))}) (append divisors n)})) # @brief Returns the logarithm base n of a number @@ -193,5 +192,4 @@ (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)) -})) + (math:complex (/ _top.real _denom) (/ _top.imag _denom))})) diff --git a/Range.ark b/Range.ark index a3b1921..eeafc8d 100644 --- a/Range.ark +++ b/Range.ark @@ -19,10 +19,8 @@ (mut a_ i) (while (< a_ _b) { (set _output (append _output a_)) - (set a_ (+ 1 a_)) - }) - _output - })) + (set a_ (+ 1 a_))}) + _output })) (let _a i) (let reset (fun () (set i _a))) @@ -31,10 +29,7 @@ (if (< i _b) { (set i (+ i 1)) - (- i 1) - }) - }) -})) + (- i 1)})})})) # @brief Run a function on each element of the range # @param _r the range object @@ -49,10 +44,8 @@ (mut _val (_r)) (while (not (nil? _val)) { (_f _val) - (set _val (_r)) - }) - (_r.reset) -})) + (set _val (_r))}) + (_r.reset)})) # @brief Create a list based on a range and a filter function # @param _range the range object @@ -68,12 +61,9 @@ (mut _output []) (while (not (nil? _value)) { (if (_fun _value) (set _output (append _output _value))) - (set _value (_range)) - }) + (set _value (_range))}) (_range.reset) - - _output -})) + _output })) # @brief Create a list based on a range and a function to apply to each elements # @param _range the range object @@ -89,12 +79,9 @@ (mut _output []) (while (not (nil? _value)) { (set _output (append _output (_fun _value))) - (set _value (_range)) - }) + (set _value (_range))}) (_range.reset) - - _output -})) + _output })) # @brief Create a reduced list based on a range and a reduction function # @param _range the range object @@ -110,8 +97,6 @@ (mut _last (_range)) (while (not (nil? _last)) { (set _output (_fun _output _last)) - (set _last (_range)) - }) + (set _last (_range))}) (_range.reset) - _output -})) + _output })) diff --git a/String.ark b/String.ark index df8a777..5d5b0a1 100644 --- a/String.ark +++ b/String.ark @@ -20,10 +20,8 @@ (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 -})) + (set _index (+ _index 1))}) + _output })) # @brief Converts the given character to uppercase. # @param _string the string to make uppercase @@ -47,10 +45,8 @@ (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 -})) + (set _index (+ _index 1))}) + _output })) # @brief Reverse a string. # @param _string the string to reverse @@ -66,10 +62,8 @@ (mut _returnedString "") (while (> _index -1) { (set _returnedString (+ _returnedString (@ _string _index))) - (set _index (- _index 1)) - }) - _returnedString -})) + (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 @@ -94,11 +88,8 @@ (while (< _index _end) { (set _returnedString (+ _returnedString (@ _string _index))) - (set _index (+ _index 1)) - }) - _returnedString - }) -)) + (set _index (+ _index 1))}) + _returnedString }))) # @brief Split a string in multiple substrings in a list, given a separator # @param _string the string to split @@ -122,13 +113,11 @@ (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)) - }) + (set _index (str:find _string _separator))}) (if (empty? _string) _output - (append _output _string)) -})) + (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 @@ -150,10 +139,8 @@ (str:slice _out 0 _idx) _new (str:slice _out (+ _idx _pattern_sz) (- (len _out) (+ _idx _pattern_sz))))) - (set _idx (str:find _out _pattern)) - }) - _out -})) + (set _idx (str:find _out _pattern))}) + _out })) # @brief Join a list of elements with a given string delimiter # @param _list host the elements to join @@ -170,8 +157,6 @@ (while (< _index (len _list)) { (set _output (+ _output (toString (@ _list _index)) (if (!= _index (- (len _list) 1)) _delim ""))) - (set _index (+ 1 _index)) - }) + (set _index (+ 1 _index))}) - _output -})) + _output })) diff --git a/Switch.ark b/Switch.ark index 27cd3bb..9766976 100644 --- a/Switch.ark +++ b/Switch.ark @@ -20,8 +20,5 @@ (if (= _bis _value) { ((@ _r 1)) - (set _acc (- _end 1)) - }) - (set _acc (+ 1 _acc)) - }) -})) + (set _acc (- _end 1))}) + (set _acc (+ 1 _acc))})})) diff --git a/os.ark b/os.ark index ac162fa..977fbb4 100644 --- a/os.ark +++ b/os.ark @@ -6,7 +6,6 @@ (let username (sys:exec "whoami")) (if (= username "root\n") "/root/" - (+ "/home/" username)) - } + (+ "/home/" username))} (if (= sys:platform "Windows") (sys:exec "echo|set /p=%userprofile%"))))) diff --git a/tests/events-tests.ark b/tests/events-tests.ark index 5c6498a..e759c50 100644 --- a/tests/events-tests.ark +++ b/tests/events-tests.ark @@ -35,7 +35,6 @@ (recap "Events tests passed" tests (- (time) start-time)) - tests -})) + tests })) (let passed-events (events-tests)) \ No newline at end of file diff --git a/tests/exceptions-tests.ark b/tests/exceptions-tests.ark index 356b0b0..1f8a490 100644 --- a/tests/exceptions-tests.ark +++ b/tests/exceptions-tests.ark @@ -9,8 +9,7 @@ (let invert (fun (x) { (if (= x 0) (throw "cannot divide by zero") - (return (/ 1 x)) - )})) + (return (/ 1 x)))})) (try (invert 0) (fun (inverted) (assert-val false "Exception test" tests)) @@ -22,7 +21,6 @@ (recap "Exceptions tests passed" tests (- (time) start-time)) - tests -})) + tests })) (let passed-exceptions (exceptions-tests)) \ No newline at end of file diff --git a/tests/functional-tests.ark b/tests/functional-tests.ark index 15fd95d..ac48359 100644 --- a/tests/functional-tests.ark +++ b/tests/functional-tests.ark @@ -18,7 +18,6 @@ (recap "Functional tests passed" tests (- (time) start-time)) - tests -})) + tests })) (let passed-functional (functional-tests)) \ No newline at end of file diff --git a/tests/lazy-tests.ark b/tests/lazy-tests.ark index d91a3b0..dd4a154 100644 --- a/tests/lazy-tests.ark +++ b/tests/lazy-tests.ark @@ -19,7 +19,6 @@ (recap "Lazy tests passed" tests (- (time) start-time)) - tests -})) + tests })) (let passed-lazy (lazy-tests)) \ No newline at end of file diff --git a/tests/list-tests.ark b/tests/list-tests.ark index 863049c..846c89d 100644 --- a/tests/list-tests.ark +++ b/tests/list-tests.ark @@ -13,8 +13,7 @@ (list:forEach a (fun (e) { # just assert we have something, basically it's just a while + @ - (set tests (assert-neq e nil "forEach" tests)) - })) + (set tests (assert-neq e nil "forEach" tests))})) (set tests (assert-eq (list:product b) (* 4 5 6) "product" tests)) (set tests (assert-eq (list:product []) 1 "product" tests)) @@ -78,7 +77,6 @@ (recap "List tests passed" tests (- (time) start-time)) - tests -})) + tests })) (let passed-list (list-tests)) \ No newline at end of file diff --git a/tests/macros-tests.ark b/tests/macros-tests.ark index a78f6ff..7873e02 100644 --- a/tests/macros-tests.ark +++ b/tests/macros-tests.ark @@ -26,7 +26,6 @@ (recap "Macros tests passed" tests (- (time) start-time)) - tests -})) + tests })) (let passed-macros (macros-tests)) \ No newline at end of file diff --git a/tests/math-tests.ark b/tests/math-tests.ark index 69f21b5..22b1d11 100644 --- a/tests/math-tests.ark +++ b/tests/math-tests.ark @@ -91,7 +91,6 @@ (recap "Math tests passed" tests (- (time) start-time)) - tests -})) + tests })) (let passed-math (math-tests)) \ No newline at end of file diff --git a/tests/range-tests.ark b/tests/range-tests.ark index a1b6494..034d030 100644 --- a/tests/range-tests.ark +++ b/tests/range-tests.ark @@ -11,8 +11,7 @@ (mut i 0) (while (< i 10) { (set tests (assert-eq i (r) "range" tests)) - (set i (+ 1 i)) - }) + (set i (+ 1 i))}) (set tests (assert-eq r.i 10 "range" tests)) (set tests (assert-eq (r) nil "range" tests)) @@ -33,7 +32,6 @@ (recap "Range tests passed" tests (- (time) start-time)) - tests -})) + tests })) (let passed-range (range-tests)) \ No newline at end of file diff --git a/tests/string-tests.ark b/tests/string-tests.ark index 70932c4..18a8fae 100644 --- a/tests/string-tests.ark +++ b/tests/string-tests.ark @@ -36,7 +36,6 @@ (recap "String tests passed" tests (- (time) start-time)) - tests -})) + tests })) (let passed-string (string-tests)) \ No newline at end of file diff --git a/tests/switch-tests.ark b/tests/switch-tests.ark index 0e72c68..ce8afc9 100644 --- a/tests/switch-tests.ark +++ b/tests/switch-tests.ark @@ -13,8 +13,7 @@ ["12" '(assert-val false "switch 12" tests)] [[12] '(assert-val false "switch 12" tests)] [12 '(set tests (assert-val true "switch 12" tests))] - [true '(assert-val false "switch 12" tests)] - ]) + [true '(assert-val false "switch 12" tests)]]) # FIXME: this is crashing the GCC8 and GCC11 builds # (switch 0 [ @@ -24,7 +23,6 @@ (recap "Switch tests passed" tests (- (time) start-time)) - tests -})) + tests })) (let passed-switch (switch-tests)) \ No newline at end of file diff --git a/tests/tests-tools.ark b/tests/tests-tools.ark index 145c9db..eccc3f6 100644 --- a/tests/tests-tools.ark +++ b/tests/tests-tools.ark @@ -2,43 +2,38 @@ (let assert-eq (fun (val1 val2 message tests) { (assert (= val1 val2) (str:format "%% (%%) - %% SHOULD BE EQUAL TO %%" message tests val1 val2)) - (+ 1 tests) -})) + (+ 1 tests)})) (let assert-neq (fun (val1 val2 message tests) { (assert (!= val1 val2) (str:format "%% (%%) - %% SHOULD BE NOT EQUAL TO %%" message tests val1 val2)) - (+ 1 tests) -})) + (+ 1 tests)})) (let assert-gt (fun (val1 val2 message tests) { (assert (> val1 val2) (str:format "%% (%%) - %% SHOULD BE GREATER THAN %%" message tests val1 val2)) - (+ 1 tests) -})) + (+ 1 tests)})) (let assert-ge (fun (val1 val2 message tests) { (assert (>= val1 val2) (str:format "%% (%%) - %% SHOULD BE GREATER OR EQUAL TO %%" message tests val1 val2)) - (+ 1 tests) -})) + (+ 1 tests)})) (let assert-lt (fun (val1 val2 message tests) { (assert (< val1 val2) (str:format "%% (%%) - %% SHOULD BE LESSER THAN %%" message tests val1 val2)) - (+ 1 tests) -})) + (+ 1 tests)})) (let assert-le (fun (val1 val2 message tests) { (assert (<= val1 val2) (str:format "%% (%%) - %% SHOULD BE LESSER OR EQUAL TO %%" message tests val1 val2)) - (+ 1 tests) -})) + (+ 1 tests)})) (let assert-val (fun (val0 message tests) { (assert val0 (str:format "%% (%%) - %% SHOULD BE TRUTHY" message tests val0)) - (+ 1 tests) -})) + (+ 1 tests)})) (let recap (fun (test-name tests time_) { (console:color "yellow") (puts " " test-name " ") - (if (<= (len test-name) 20) (puts "\t\t") (puts "\t")) + (if (<= (len test-name) 20) + (puts "\t\t") + (puts "\t")) (console:color "reset") (puts "(") @@ -52,5 +47,4 @@ (console:color "green") (puts (* 1000 time_) "ms\n") - (console:color "reset") -})) \ No newline at end of file + (console:color "reset")})) \ No newline at end of file