-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSwitch.ark
More file actions
26 lines (25 loc) · 812 Bytes
/
Switch.ark
File metadata and controls
26 lines (25 loc) · 812 Bytes
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
(macro _switch_impl (var case then ...cases) {
($if (= "_" ($repr case))
then
(if (= var case)
then
($if (>= ($len cases) 2) (_switch_impl var ...cases)))) })
# @brief Takes a value to match against a list of (possible value, code to run)...
# @param value value to match
# @param case first case
# @param then value when first case matches
# @param ...cases more (case, then)
# @details Once the value is matched, it stops and doesn't try any other values.
# =begin
# (switch 4
# 1 (print "hello")
# 2 (print "bye")
# 12 (print "jackpot")
# (+ 1 4) (print "computation")
# _ (print "default"))
# =end
# @author https://github.com/SuperFola
(macro switch (value case then ...cases) {
(macro var ($gensym))
(let var value)
(_switch_impl var case then ...cases) })