Skip to content
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
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
143 changes: 70 additions & 73 deletions Events.ark
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typ>
# =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 <typ>
# =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) ()) }))
7 changes: 3 additions & 4 deletions Exceptions.ark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)))
8 changes: 4 additions & 4 deletions Functional.ark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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))))
18 changes: 8 additions & 10 deletions Lazy.ark
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) }))
Loading