Skip to content

Commit 78a6038

Browse files
committed
feat(macros): expanding -> so that it can take partial functions
1 parent 18894b9 commit 78a6038

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

Macros.ark

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
($ -> (arg fn1 ...fn) {
2-
($if (> (len fn) 0)
3-
(-> (fn1 arg) ...fn)
4-
(fn1 arg)) })
1+
# internal, do not use
2+
($ __replace_all_placeholders_with (replacement x ...xs) {
3+
($if (empty? xs)
4+
($if (= "_" ($repr x))
5+
replacement
6+
x)
7+
($if (= "_" ($repr x))
8+
{
9+
replacement
10+
(__replace_all_placeholders_with replacement ...xs) }
11+
{
12+
x
13+
(__replace_all_placeholders_with replacement ...xs) })) })
14+
15+
($ -> (arg fn1 ...fns) {
16+
($if (= "Symbol" ($type fn1))
17+
($ call (fn1 arg))
18+
($ call ((__replace_all_placeholders_with arg ...fn1))))
19+
($if (> (len fns) 0)
20+
(-> call ...fns)
21+
call) })
522

623
# internal, do not use
724
($ __suffix-dup (sym x) {
@@ -40,3 +57,9 @@
4057
($ arg_bloc (__suffix-dup arg length))
4158
($ all_args (__replace_placeholders [arg_bloc] ...args))
4259
(fun (arg_bloc) (call all_args)) })
60+
61+
($ unless (cond body)
62+
(if (not cond) body))
63+
64+
($ until (cond body)
65+
(while (not cond) body))

tests/macros-tests.ark

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
(+ data "-f2")))
88
(let f3 (fun (data)
99
(+ data "-f3")))
10+
(let apply (fun (data f)
11+
(f data)))
1012

1113
(let test_func (fun (a b c) (* a b c)))
1214
(let test_func1 (partial test_func 1))
@@ -16,6 +18,7 @@
1618
(test:suite macros {
1719
(test:eq (-> "f0" f1) "f0-f1")
1820
(test:eq (-> "f0" f1 f2 f3) "f0-f1-f2-f3")
21+
(test:eq (-> "f0" f1 (apply _ f2) (apply _ f3)) "f0-f1-f2-f3")
1922

2023
(test:eq (test_func1 2 3) 6)
2124
(test:eq ($argcount test_func1) 2)

0 commit comments

Comments
 (0)