1
1
# Language Definition
2
2
3
- ** Expr** is an expression evaluation language for Go.
3
+ <table >
4
+ <tr ><th colspan =" 2 " >Built-in Functions</th ></tr >
5
+ <tr >
6
+ <td>
7
+ <a href="#allarray-predicate">all()</a><br>
8
+ <a href="#anyarray-predicate">any()</a><br>
9
+ <a href="#lenarray-predicate">one()</a><br>
10
+ <a href="#nonearray-predicate">none()</a><br>
11
+ </td>
12
+ <td>
13
+ <a href="#lenv">len()</a><br>
14
+ <a href="#maparray-predicate">map()</a><br>
15
+ <a href="#filterarray-predicate">filter()</a><br>
16
+ <a href="#countarray-predicate">count()</a><br>
17
+ </td>
18
+ </tr >
19
+ </table >
4
20
5
21
## Supported Literals
6
22
@@ -15,7 +31,8 @@ The package supports:
15
31
16
32
## Digit separators
17
33
18
- Integer literals may contain digit separators to allow digit grouping into more legible forms.
34
+ Integer literals may contain digit separators to allow digit grouping into more
35
+ legible forms.
19
36
20
37
Example:
21
38
@@ -25,7 +42,8 @@ Example:
25
42
26
43
## Fields
27
44
28
- Struct fields and map elements can be accessed by using the ` . ` or the ` [] ` syntax.
45
+ Struct fields and map elements can be accessed by using the ` . ` or the ` [] `
46
+ syntax.
29
47
30
48
``` js
31
49
foo .Field
@@ -107,7 +125,7 @@ user.Group in ["human_resources", "marketing"]
107
125
" foo" in {foo: 1 , bar: 2 }
108
126
```
109
127
110
- ### Numeric Operators
128
+ ### Range Operator
111
129
112
130
* ` .. ` (range)
113
131
@@ -123,7 +141,24 @@ The range is inclusive:
123
141
1..3 == [1 , 2 , 3 ]
124
142
```
125
143
126
- ### Ternary Operators
144
+ ### Slice Operator
145
+
146
+ * ` array[:] ` (slice)
147
+
148
+ Slices can work with arrays or strings.
149
+
150
+ Example:
151
+
152
+ Variable ` array ` is ` [1,2,3,4,5] ` .
153
+
154
+ ``` js
155
+ array[1 : 4 ] == [2 ,3 ,4 ]
156
+ array[: 3 ] == [1 ,2 ,3 ]
157
+ array[3 : ] == [4 ,5 ]
158
+ array[: ] == array
159
+ ```
160
+
161
+ ### Ternary Operator
127
162
128
163
* ` foo ? 'yes' : 'no' `
129
164
@@ -135,98 +170,69 @@ user.Age > 30 ? "mature" : "immature"
135
170
136
171
## Built-in Functions
137
172
138
- <table >
139
- <tr >
140
- <td >
141
- <a href="#allarray-predicate">all()</a><br>
142
- <a href="#anyarray-predicate">any()</a><br>
143
- <a href="#lenarray-predicate">one()</a><br>
144
- <a href="#nonearray-predicate">none()</a><br>
145
- </td >
146
- <td >
147
- <a href="#lenv">len()</a><br>
148
- <a href="#maparray-closure">map()</a><br>
149
- <a href="#filterarray-predicate">filter()</a><br>
150
- <a href="#countarray-predicate">count()</a><br>
151
- </td >
152
- </tr >
153
- </table >
154
-
155
-
156
173
### ` all(array, predicate) `
157
174
158
- Returns ** true** if all elements satisfies the predicate (or if the array is empty).
175
+ Returns ** true** if all elements satisfies the [ predicate] ( #predicate ) .
176
+ If the array is empty, returns ** true** .
159
177
160
178
``` js
161
179
all (Tweets, {.Size < 280 })
162
180
```
163
181
164
182
### ` any(array, predicate) `
165
183
166
- Returns ** true** if any elements satisfies the predicate. If the array is empty, returns ** false** .
184
+ Returns ** true** if any elements satisfies the [ predicate] ( #predicate ) .
185
+ If the array is empty, returns ** false** .
167
186
168
187
169
188
### ` one(array, predicate) `
170
189
171
- Returns ** true** if _ exactly one_ element satisfies the predicate. If the array is empty, returns ** false** .
190
+ Returns ** true** if _ exactly one_ element satisfies the [ predicate] ( #predicate ) .
191
+ If the array is empty, returns ** false** .
172
192
173
193
``` js
174
194
one (Participants, {.Winner })
175
195
```
176
196
177
197
### ` none(array, predicate) `
178
198
179
- Returns ** true** if _ all elements does not_ satisfy the predicate. If the array is empty, returns ** true** .
199
+ Returns ** true** if _ all elements does not_ satisfy the [ predicate] ( #predicate ) .
200
+ If the array is empty, returns ** true** .
180
201
181
202
### ` len(v) `
182
203
183
204
Returns the length of an array, a map or a string.
184
205
185
- ### ` map(array, closure ) `
206
+ ### ` map(array, predicate ) `
186
207
187
- Returns new array by applying the closure to each element of the array.
208
+ Returns new array by applying the [ predicate] ( #predicate ) to each element of
209
+ the array.
188
210
189
211
### ` filter(array, predicate) `
190
212
191
- Returns new array by filtering elements of the array by predicate.
213
+ Returns new array by filtering elements of the array by [ predicate] ( #predicate ) .
192
214
193
215
### ` count(array, predicate) `
194
216
195
- Returns the number of elements what satisfies the predicate. Equivalent to:
217
+ Returns the number of elements what satisfies the [ predicate] ( #predicate ) .
218
+ Equivalent to:
196
219
197
220
``` js
198
221
len (filter (array, predicate))
199
222
```
200
223
201
- ## Closures
224
+ ## Predicate
202
225
203
- The closure is an expression that accepts a single argument. To access
226
+ The predicate is an expression that accepts a single argument. To access
204
227
the argument use the ` # ` symbol.
205
228
206
229
``` js
207
230
map (0..9 , {# / 2 })
208
231
```
209
232
210
- If the item of array is struct, it is possible to access fields of struct with
233
+ If items of the array is a struct or a map , it is possible to access fields with
211
234
omitted ` # ` symbol (` #.Value ` becomes ` .Value ` ).
212
235
213
236
``` js
214
237
filter (Tweets, {len (.Value ) > 280 })
215
238
```
216
-
217
- ## Slices
218
-
219
- * ` array[:] ` (slice)
220
-
221
- Slices can work with arrays or strings.
222
-
223
- Example:
224
-
225
- Variable ` array ` is ` [1,2,3,4,5] ` .
226
-
227
- ``` js
228
- array[1 : 4 ] == [2 ,3 ,4 ]
229
- array[: 3 ] == [1 ,2 ,3 ]
230
- array[3 : ] == [4 ,5 ]
231
- array[: ] == array
232
- ```
0 commit comments