-
Notifications
You must be signed in to change notification settings - Fork 4
/
Exceptions.ark
33 lines (31 loc) · 1.05 KB
/
Exceptions.ark
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# @brief throw takes a value as its argument and return it to be used by try
# @param _x the value to return
# =begin
# (let error (throw "cannot divide by zero"))
# =end
# @author https://github.com/SuperFola
(let throw (fun (_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
# =begin
# (let value (return (/ 1 x)))
# =end
# @author https://github.com/SuperFola
(let return (fun (_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
# @param _continue the success handler
# @param _handle the error handler
# =begin
# (let invert (fun (x)
# (if (= x 0)
# (throw "cannot divide by zero")
# (return (/ 1 x)))))
# (try (invert 0)
# (fun (inverted) (print inverted))
# (fun (err) (print err)))
# =end
# @author https://github.com/SuperFola
(let try (fun (_either _continue _handle) (_either _handle _continue)))