-
Notifications
You must be signed in to change notification settings - Fork 0
/
agglib.joy
117 lines (94 loc) · 2.7 KB
/
agglib.joy
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
(* FILE: agglib.joy *)
LIBRA
_agglib == true;
(* - - - - - O P E R A T O R S - - - - - *)
unitset == {} cons;
unitstring == "" cons;
unitlist == [] cons;
pairset == {} cons cons;
pairstring == "" cons cons;
pairlist == [] cons cons;
unpair == uncons uncons pop;
second == rest first;
third == rest rest first;
fourth == 3 drop first;
fifth == 4 drop first;
string2set == {} swap shunt;
elements == {} swap [swons] step;
(*
set2string == "" swap [chr swons] step;
*)
set2string == "" [[chr] dip cons] foldr;
shunt == [swons] step;
(* "dipped" versions *)
nulld == [null] dip;
consd == [cons] dip;
swonsd == [swons] dip;
unconsd == [uncons] dip;
unswonsd == [unswons] dip;
firstd == [first] dip;
restd == [rest] dip;
secondd == [second] dip; (* R.W. *)
thirdd == [third] dip;
(* on two operands *)
null2 == nulld null or;
cons2 == swapd cons consd;
uncons2 == unconsd uncons swapd;
swons2 == swapd swons swonsd;
unswons2 == [unswons] dip unswons swapd;
zip == [null2] [pop2 []] [uncons2] [[pairlist] dip cons] linrec;
from-to == (* lo hi agg *)
[] cons [pop pop] swoncat
[>] swap
[ [dup succ] dip ]
[cons]
linrec;
from-to-list == [] from-to;
from-to-set == {} from-to;
from-to-string == "" from-to;
(* - - - - - C O M B I N A T O R S - - - - - *)
(* Left to Right *)
(* inbuilt: step map fold filter split *)
(* desirable: step2 map2 fold2 *)
(* cartesian product -like *)
pairstep == [dupd] swoncat [step pop] cons cons step;
(* Right to Left *)
mapr ==
[ [null] [] [uncons] ] dip (* P1 P2 P3 *)
[dip cons] cons (* P4 *)
linrec;
foldr ==
[ [ [null] ] dip (* P1 *)
[] cons [pop] swoncat (* P2 *)
[uncons] ] dip (* P3 *)
linrec;
stepr2 ==
[ [null2] [pop pop] ] dip (* P1 P2 *)
[dip] cons [dip] cons [uncons2] swoncat (* P3 *)
tailrec;
fold2 == rollupd stepr2;
mapr2 == (* == zipwith B&W p 57 *)
[ [null2] [pop2 []] [uncons2] ] dip (* P1 P2 P3 *)
[dip cons] cons (* P4 *)
linrec;
foldr2 ==
[ [ [null2] ] dip (* P1 *)
[] cons [pop2] swoncat (* P2 *)
[uncons2] ] dip (* P3 *)
linrec;
interleave2 == [cons cons] foldr2;
interleave2list == [] interleave2;
sum == 0 [+] fold;
average == [sum] [size] cleave / ;
variance == (* [..] variance *)
0 swap dup (* 0.0 [..] [..] *)
[sum] [size] cleave dup (* 0.0 [..] su n n *)
[ / (* 0.0 [..] av n *)
[ - dup * + ] cons (* 0.0 [..] [av - dup * +] n *)
step ] (* sumsq n *)
dip
pred / ;
AGGLIB == "agglib.joy - aggregate library\n".
(* end LIBRA *)
"agglib is loaded\n" putchars.
(* END agglib.joy *)