Merge: Proposal for lambda expression syntax
authorJean Privat <jean@pryen.org>
Fri, 23 Aug 2019 13:25:28 +0000 (09:25 -0400)
committerJean Privat <jean@pryen.org>
Fri, 23 Aug 2019 13:25:28 +0000 (09:25 -0400)
This extends the Nit syntax with lambdas expressions.

Lambdas are basically anonymous functions, so just accept functions without a name as expressions.

~~~nit
var x = fun(i: Int): Int do
    return i + 1
end
# or on a single line
var x = fun(i: Int): Int do return i + 1 end
~~~

`fun`, `do` and `end` are mandatory, the rest is optional

~~~nit
var x = fun do end
~~~

The main weirdness is the mandatory `end` that makes the following invalid

~~~nit
# invalid:
var x = (fun(i: Int): Int do return i + 1) # missing `end`, unexpected `)`
~~~

There is no semantic yet, nor implementation, this might come in some future PR

Pull-Request: #2758
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>


Trivial merge