11# Language Definition
22
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 >
420
521## Supported Literals
622
@@ -15,7 +31,8 @@ The package supports:
1531
1632## Digit separators
1733
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.
1936
2037Example:
2138
@@ -25,7 +42,8 @@ Example:
2542
2643## Fields
2744
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.
2947
3048``` js
3149foo .Field
@@ -107,7 +125,7 @@ user.Group in ["human_resources", "marketing"]
107125" foo" in {foo: 1 , bar: 2 }
108126```
109127
110- ### Numeric Operators
128+ ### Range Operator
111129
112130* ` .. ` (range)
113131
@@ -123,7 +141,24 @@ The range is inclusive:
1231411..3 == [1 , 2 , 3 ]
124142```
125143
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
127162
128163* ` foo ? 'yes' : 'no' `
129164
@@ -135,98 +170,69 @@ user.Age > 30 ? "mature" : "immature"
135170
136171## Built-in Functions
137172
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-
156173### ` all(array, predicate) `
157174
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** .
159177
160178``` js
161179all (Tweets, {.Size < 280 })
162180```
163181
164182### ` any(array, predicate) `
165183
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** .
167186
168187
169188### ` one(array, predicate) `
170189
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** .
172192
173193``` js
174194one (Participants, {.Winner })
175195```
176196
177197### ` none(array, predicate) `
178198
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** .
180201
181202### ` len(v) `
182203
183204Returns the length of an array, a map or a string.
184205
185- ### ` map(array, closure ) `
206+ ### ` map(array, predicate ) `
186207
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.
188210
189211### ` filter(array, predicate) `
190212
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 ) .
192214
193215### ` count(array, predicate) `
194216
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:
196219
197220``` js
198221len (filter (array, predicate))
199222```
200223
201- ## Closures
224+ ## Predicate
202225
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
204227the argument use the ` # ` symbol.
205228
206229``` js
207230map (0..9 , {# / 2 })
208231```
209232
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
211234omitted ` # ` symbol (` #.Value ` becomes ` .Value ` ).
212235
213236``` js
214237filter (Tweets, {len (.Value ) > 280 })
215238```
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