blob: 2e23daf0954852790fca185e70793934d9dd9bcc (
plain) (
blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
[type closure_ [func arity arg_c args]]
[dec = [x y]]
[dec left [x]]
[dec right [x]]
[dec is_right [x]]
[dec right.val [x]]
[dec run_func [f a as]]
[dec cons [x xs]]
[dec append [xs x]]
[dec nil []]
[dec head [xs]]
[dec tail [xs]]
[dec is_nil [xs]]
[def add_arg [c a]
[closure_ [closure_.func c]
[closure_.arity c]
[+ [closure_.arg_c c] 1]
[append [closure_.args c] a]]]
[def run_closure [h]
[run_func [closure_.func h] [closure_.arity h] [closure_.args h]]]
[def maybe_run_closure [h]
[if [= [closure_.arity h] [closure_.arg_c h]]
[left [run_func [closure_.func h] [closure_.arity h] [closure_.args h]]]
[right h]]]
[def closure [f v]
[if v
[right [closure_ f v 0 [nil]]]
[left [run_func f 0 [nil]]]]]
[def !> [c a]
[if [is_right c]
[maybe_run_closure [add_arg [right.val c] a]]
c]]
[def !>> [c as]
[if [is_nil as]
c
[!>> [!> c [head as]]
[tail as]]]]
|