Skip to content

Commit ecf3ca7

Browse files
committed
docs: adding arkdocs to macros
1 parent c199357 commit ecf3ca7

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Macros.ark

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
x
1313
(__replace_all_placeholders_with replacement ...xs) })) })
1414

15+
# @brief Chain calls on a given value, for a nicer syntax
16+
# @param arg value to transform
17+
# @param ...fns series of functions to apply one by one to `arg`
18+
# =begin
19+
# (import std.Macros)
20+
# (-> "f0" f1) # equivalent to (f1 "f0")
21+
# (-> "f0" f1 f2 f3) # equivalent to (f3 (f2 (f1 "f0")))
22+
# (-> "f0" f1 (apply _ f2) (apply _ f3)) # equivalent to (apply (apply (f1 "f0") f2) f3)
23+
# =end
24+
# @author https://github.com/SuperFola
1525
(macro -> (arg fn1 ...fns) {
1626
($if (= "Symbol" ($type fn1))
1727
(macro call (fn1 arg))
@@ -25,6 +35,18 @@
2535
($if (> x 1) (__suffix-dup sym (- x 1)))
2636
($symcat sym x) })
2737

38+
# @brief Create a partial function with prefilled arguments
39+
# @param func function to make partial
40+
# @param ...defargs predefined arguments
41+
# =begin
42+
# (import std.Macros)
43+
# (let test_func (fun (a b c) (* a b c)))
44+
# (let test_func1 (partial test_func 1))
45+
# (let test_func2 (partial test_func1 2))
46+
# (print (test_func1 2 3)) # 6
47+
# (print (test_func2 3)) # 6
48+
# =end
49+
# @author https://github.com/SuperFola
2850
(macro partial (func ...defargs) {
2951
(macro bloc (__suffix-dup a (- ($argcount func) (len defargs))))
3052
(fun (bloc) (func ...defargs bloc))
@@ -52,14 +74,47 @@
5274

5375
(__replace_placeholders replacements ...xs) })) })
5476

77+
# @brief Create a partial function with prefilled arguments, allowing some arguments to be skipped
78+
# @param call function to make partial
79+
# @param ...args predefined arguments
80+
# =begin
81+
# (import std.Macros)
82+
# (let test_func (fun (a b c) (* a b c)))
83+
# (let test_func3 (partial2 test_func 1 _ 3))
84+
# (print (test_func3 2)) # 6
85+
# =end
86+
# @author https://github.com/SuperFola
5587
(macro partial2 (call ...args) {
5688
(macro length (__count_placeholders 0 ...args))
5789
(macro arg_bloc (__suffix-dup arg length))
5890
(macro all_args (__replace_placeholders [arg_bloc] ...args))
5991
(fun (arg_bloc) (call all_args)) })
6092

93+
# @brief Create a reversed condition
94+
# @param cond condition
95+
# @param body then node (or then/else nodes)
96+
# =begin
97+
# (import std.Macros)
98+
# (unless (canCall? dog)
99+
# (print "dog can't call")
100+
# (print "dog can actually call us!"))
101+
# (unless false
102+
# (print "this will always be executed"))
103+
# =end
104+
# @author https://github.com/SuperFola
61105
(macro unless (cond ...body)
62106
(if (not cond) ...body))
63107

108+
# @brief Iterate until the condition is truthy
109+
# @param cond condition
110+
# @param body loop body
111+
# =begin
112+
# (import std.Macros)
113+
# (mut data [0])
114+
# (until (= 10 (len data))
115+
# (append! data (+ 1 (@ data -1))))
116+
# (print data) # [0 1 2 3 4 5 6 7 8 9]
117+
# =end
118+
# @author https://github.com/SuperFola
64119
(macro until (cond body)
65120
(while (not cond) body))

0 commit comments

Comments
 (0)