-
Notifications
You must be signed in to change notification settings - Fork 0
/
std.kr
63 lines (55 loc) · 1.15 KB
/
std.kr
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
[ [ fail ] [ not ] if ] :assert define
[ map eval unwrap ] :fold define
[ print "\n" print ] :println define
[
# on stack: <initial values> list number
[
# on stack: <initial values> list number
2 list clone
# on stack: <initial values> [ list number ] [ list number ]
[
# on stack: <initial values> [ list number ]
unwrap
# on stack: <initial values> list number
[
# on stack: <initial values> list
clone
# on stack: <initial values> list list
[
# on stack: <inivial values> list
eval unwrap
# on stack: <results of function>
]
dig
# on stack: <results of function> list
]
dig
# on stack: <results of function> list number
1 - times
]
dig
unwrap
]
[ clone 0 > ]
if
# At this point, we've recursively called ourselves, or done nothing. Either
# way, just drop the arguments and we're done.
drop drop
]
:times
define
[
[
# on stack: symbol
clone # => symbol symbol
to_list # => symbol [ word ]
swap wrap # => [ word ] [ symbol ]
swap prepend # => [ [ word ] symbol ]
]
map
unwrap
]
:export
define
[ :assert :fold :println :times :export ]
export