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)
commitd875a470ceb74c4078df830bd765037bda9ead42
tree816f8b08aa0479f69677057973e107d861aaee5b
parentd5b3ef0cbef3f679e6d1a27064d3136e5ea34a67
parent28ec822b49a5ccf3289a6cf12eea4829c0a66602
Merge: Proposal for lambda expression syntax

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>