-
Notifications
You must be signed in to change notification settings - Fork 0
/
final.txt
191 lines (133 loc) · 3.7 KB
/
final.txt
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
-count = >> {
+res
<= self {.res = res + 1}
} {.res = 0}
-stream >> -counter = {
}
-stream
-> {} // Map operator. Distributive. (1, 2) -> func === (1 -> func), (2 -> func)
>> {} // Reduce operator. Not distributive.
> {} // Simple forwarding operator. Output goes to input. Not distributive.
// A distributive function can be called with -> or >
// A non-distributive function can only be called with >
// When assigning a non-distributive function, it must be prefixed with |
// When calling a function, each statement is sent a Shy as input. If Shy is accessed, an error occurs.
// Assignments statements do not return anything, unless explicit.
widget.log_event[.load, .url = req.fullUrl]
// 2 separate events involved in function execution:
// function running
// function streaming to "in"
-pack = >> {
+res, -in
<= self {.res = (res, in)}
} -> {-in, =[in.res]}
-func = >> pack -> {-in}
-inc_by_count = >> [-in + (in >> Stream.count)] packed
stream >> func
stream -> {in + 1}
-not = {
-in
<= in ?= True -> False
<= in ?= False -> True
}
(1, 2, 3) >> [True] // Returns True
(1, 2, 3) -> [True] // Returns (True, True, True)
-uncaught:Error:Stream.unique
-caught:Error:Stream.unique
caught:["Caught unthrown exception: %in", +in] Stream.subset_of[/uncaught]
uncaught:["Uncaught exception: %in", +in] Stream.subset_of[/caught]
+throw = {
uncaught <= +in:Error
}
+catch = {
caught <= +in:Error
}
+pg = {
}
+throwing_function = {
-> .err = Error 'My Error'
if something {
throw Error 'My error'
} else {
123
}
}
// It is an error if a named stream can never get data
+sum = />> {
+acc, +in
= self {.acc = acc + in}
} {.acc = 0} -> /.acc
+sum = />> {
.acc = +acc + +in
} < {.acc = 0} > [+acc]
(1, 2, 3) > sum
// > [+acc] sum [3] sum [2] sum [1] {.acc = 0}
// As above:
(1, 2) -> func === > func ([1], [2]) // Calls func twice
(1, 2) > func === > func [1, 2] // Calls func once
Every function's side effects must be distributive over its input.
Thus, ()>func must have NO side effects.
Basically, anything after a ">" must be pure.
.prop searches for a declaration first left, then right
[+prop] [.prop = 123] [+prop] // Will set the left +prop
... // This is a special value. If accessed, throws an error
// Property access:
+obj = {+prop = 123}
obj.prop
> [.prop]obj
> obj > [.prop]
> obj -> [.prop]
// When assigned to a variable, a function decays to its output
+sum = />> {
+num = +in
<= self [+in + num]
} < 0
func // Does not run func
abc -> func // Runs func for each element of abc
abc > func // Runs func once, same as ()>func[abc]
func < abc // Runs func once, same as ()>func[abc]
func[abc] // Does not run func
> func[abc] // Runs func once
-> func[abc] // Runs func for each element of the input
/abc -> func \n bla // Lazy, same as [abc] -> func \n bla
/-> abc -> func \n bla // A little less lazy, same as [-> abc -> func] \n bla
\abc -> func \n bla // Greedy, same as [abc -> func \n bla]
+filter = {
+func = +in
<= [+in -> func -> [in]]
}
throwing_function -> pg\ -> {
}
-> func // Returns a mapping function
>> func // Returns a reducing function
sum[1, 2]
+dsl = ".a + 1 / (4 + .b)"
dsl >> {
+in, +out, +self
+tokens
in -> Variable -> [in.value | Number] => tokens
in -> Char -> (
{.first = '0', .last = '9'}
) -> {
// Sub-processor for numbers
out <= {
in -> Char -> Range{.first = '0', .last = '9'}
}
}
}
1 ?> 2
1 .+ 2
+fs = #require fs
+fs.open = {
+name = +in
+chars = ...
+lines = (
{+columns = ...}
{+columns = ...}
{+columns = ...}
...
)
}
-> fs.open['file.txt'] -> /.lines -> {
.columns
}