@@ -42,18 +42,19 @@ identifier; `` `x` `` and `x` has the same meaning.
42
42
### Keywords
43
43
44
44
The following keywords are reserved and can’t be used as identifiers, unless they’re escaped with backticks, as
45
- described above in [ Identifiers] ( #identifiers ) . Keywords other than ` let ` can be used as field or variant names in
46
- data types, as parameter names in a function declaration or function call without being escaped with backticks.
45
+ described above in [ Identifiers] ( #identifiers ) . Keywords other than ` let ` and ` lambda ` can be used as field or variant
46
+ names in data types, as parameter names in a function declaration or function call without being escaped with backticks.
47
47
48
48
- ` data ` : defines new data type
49
+ - ` class ` : defines a new data type class
49
50
- ` fx ` : defines new function (prefix function)
50
51
- ` infx ` : defines new infix function
52
+ - ` lambda ` : defines a lambda function
51
53
- ` alias ` : defines a new alias for a function
52
- - ` let ` : defines new value with some data type
53
- - ` class ` : defines a new type class
54
+ - ` let ` : defines new value
54
55
55
- The following tokens are reserved as punctuation and can’t be used as custom operators: ` ( ` , ` ) ` , ` { ` , ` } ` , ` [ ` , ` ] ` ,
56
- ` . ` , ` , ` , ` | ` , ` : ` , ` ; ` , ` # ` , ` => ` , ` -> ` , ` <- ` , ` <| ` , ` |> ` , ` >| ` , ` |? ` , ` |: ` , `` ` `` , ` ~ ` .
56
+ The following tokens are reserved as built-in operators and can’t be used in custom operators: ` ( ` , ` ) ` , ` { ` , ` } ` ,
57
+ ` [ ` , ` ] ` , ` . ` , ` , ` , ` : ` , ` ; ` , ` # ` , ` => ` , ` -> ` , ` <- ` , ` <| ` , ` |> ` , ` >| ` , ` |? ` , ` |: ` , ` .\ ` , `` ` ` ` .
57
58
58
59
### Literals
59
60
@@ -228,6 +229,73 @@ or reverse the order of the expressions:
228
229
229
230
mulTry 2 <| 0..<100
230
231
232
+ #### Lambda operator
233
+
234
+ <dfn >Lambda operator</dfn > ` .\ ` , with alias ` λ ` (Greek letter lambda) is a shorthand for creating lambda expressions.
235
+ It has four forms:
236
+ - single-line, end of line (trailing lambda):
237
+ ```
238
+ .\args -> ret: expr
239
+ ```
240
+ - single-line, alongside other expressions:
241
+ ```
242
+ .\(args -> ret: expr), _
243
+ ```
244
+ - multi-line, end of line (trailing lambda block):
245
+ ```
246
+ .\args -> ret
247
+ expr1
248
+ expr2
249
+ -- ...
250
+ ```
251
+ - multi-line, alongside other expressions:
252
+ ```
253
+ .\(args -> ret
254
+ expr1
255
+ expr2
256
+ -- ...
257
+ ), _
258
+ ```
259
+
260
+ All forms may skip the return type ` -> ret ` part; in this case the return type is inferred by the compiler:
261
+ ```
262
+ .\args: expr
263
+
264
+ .\(args: expr), _
265
+
266
+ .\args
267
+ expr1
268
+ expr2
269
+ -- ...
270
+
271
+ .\(args
272
+ expr1
273
+ expr2
274
+ -- ...
275
+ ), _
276
+ ```
277
+
278
+ If the lambda expression has no inputs, lambda operator must be simply followed by the expression itself with no
279
+ colon used:
280
+ ```
281
+ .\expr
282
+
283
+ .\(expr), _
284
+
285
+ .\
286
+ expr1
287
+ expr2
288
+ -- ...
289
+
290
+ .\(
291
+ expr1
292
+ expr2
293
+ -- ...
294
+ ), _
295
+ ```
296
+
297
+ See also [ lambda specifier] ( #lambda-specifier ) .
298
+
231
299
### Standard library
232
300
233
301
#### Monadic operators
@@ -368,6 +436,10 @@ instantiated using a shorthand [range expressions](#range-expressions).
368
436
369
437
### Expressions
370
438
439
+ #### Lambda expressions
440
+
441
+ Lambda expressions have two forms: [ operator] ( #lambda-operator ) and [ specifier] ( #lambda-specifier ) .
442
+
371
443
#### Collection comprehension
372
444
373
445
Grouping operator is ` ( ` ..` ) ` constructs an anonymous data type.
@@ -406,7 +478,26 @@ iterations, like with `$-1`, accessing the previous iteration result, or
406
478
407
479
#### Data class
408
480
409
- #### Value
481
+ #### Value specifier
482
+
483
+ #### Lambda specifier
484
+
485
+ <dfn >Lambda specifier</dfn > starts with a ` lambda ` keyword, followed by a value name, colon, argument and return type
486
+ definition and body:
487
+
488
+ ```
489
+ let local: U8 = random
490
+ lambda sq: x U8 -> U32
491
+ pow 2 + local
492
+ ```
493
+
494
+ As any other specifier it can be put into a single line:
495
+ ```
496
+ let local: U8 = random
497
+ lambda sq: x U8 -> U32 := pow 2 + local
498
+ ```
499
+
500
+ See also [ lambda operator] ( #lambda-operator ) .
410
501
411
502
## Generics
412
503
0 commit comments