Skip to content

Commit

Permalink
Merge pull request #35 from ArkScript-lang/feat/coding-style
Browse files Browse the repository at this point in the history
fix: coding style
  • Loading branch information
SuperFola authored Oct 24, 2022
2 parents fc8e2e9 + cd238b8 commit 4fa96f9
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 204 deletions.
14 changes: 5 additions & 9 deletions Events.ark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -75,8 +73,7 @@
(list:filter _listeners (fun (element) (!= typ (@ element 0)))))
(let deleted (!= newlist _listeners))
(set _listeners newlist)
deleted
}))
deleted }))

(fun (
# listeners
Expand All @@ -89,6 +86,5 @@
&on
&emit
&emitWith
&removeListenersOfType
) ())
}))
&removeListenersOfType)
() )}))
7 changes: 2 additions & 5 deletions Lazy.ark
Original file line number Diff line number Diff line change
Expand Up @@ -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 })}))
104 changes: 34 additions & 70 deletions List.ark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }))
13 changes: 4 additions & 9 deletions Macros.ark
Original file line number Diff line number Diff line change
@@ -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}}}
6 changes: 2 additions & 4 deletions Math.ark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))}))
37 changes: 11 additions & 26 deletions Range.ark
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }))
Loading

0 comments on commit 4fa96f9

Please sign in to comment.