Closed rdje closed 2 years ago
But it doesn't seem to have support for the so called trailing closure syntax.
I am thinking about this from time to time and don't know how to solve syntactic ambiguity that this would cause:
if CONDITION YES_BODY NO_BODY
, for example: if 1 my_func() { A + 1 }
. Is {A + 1}
the NO_BODY here or last argument to my_func()
.
NGS has a way to supply arguments after the my_func()
parenthesis using with
or do
syntax:
test("my test") with { ... }
my_func(1,2) do { ... }
with
and do
are repeatable so you can my_func() do { ... } do { ...}
with
and do
can be followed by anything, not just closure: my_func() with 1 with 2 with { ... }
with
and do
for the same functionality is very likely a mistakewith
and do
have roughly zero observed real use cases.with
and do
not with closures also have roughly zero observed real use cases.with
and do
less and less over time.Ok then, it seems you already had this trailing closure syntax feature in mind for some time now.
So feel free to close my FR then.
Let's break our heads on that if/when there is more demand.
NGS supports Closures.
But it doesn't seem to have support for the so called trailing closure syntax.
It is when calling a function and the last argument of that function is a closure, one may pop it out of the function's parentheses and have it dangling outside of it after the closing parenthesis of the function, like this
When dangling outside of the function's argument list, the closure has the following form
Ruby, Groovy, Kotlin, Swift and Raku support this syntactic sugar feature.