On 10/21/16 10:38 AM, mogu wrote:
On Friday, 21 October 2016 at 14:22:27 UTC, Steven Schveighoffer wrote:
On 10/21/16 10:12 AM, Temtaime wrote:
On Friday, 21 October 2016 at 13:42:49 UTC, Adam D. Ruppe wrote:
On Friday, 21 October 2016 at 13:33:26 UTC, Stefan Koch wrote:
[...]

Eh, that's exactly what the language rules say should happen, and it
actually does make sense to me... you might even want to use an
immediately-called lambda to group several statements together into
one expression.

[...]

Please, no.
It's fully clear that { stmts } createa a lambda, just () is ommited.

No, it's not.

{ int x; x = 2; }

Is not a lambda. It's a scope.

So the meaning changes based on where it's used. I totally agree that
we should remove that feature.


{} in swift is a lambda too.

Swift doesn't have arbitrary scopes. So there is no ambiguity.

I think swift has better lambda syntax.
Maybe could help for a better syntax in d.

We likely are not going to change the lambda syntax. However, it's possible we could remove the ambiguous cases.

reversedNames = names.sorted(by: { (s1: String, s2: String) -> Bool in
    return s1 > s2
})
reversedNames = names.sorted(by: { (s1: String, s2: String) -> Bool in
return s1 > s2 } )
reversedNames = names.sorted(by: { s1, s2 in return s1 > s2 } )
reversedNames = names.sorted(by: { s1, s2 in s1 > s2 } )

(s1, s2) => s1 > s2

Seems pretty good to me

reversedNames = names.sorted(by: { $0 > $1 } )

With the original string lambdas, this was possible as "a > b". I'm not sure this case is worth much effort to add.

reversedNames = names.sorted(by: >)

Not sure if we'll ever get this in D :)


someFunctionThatTakesAClosure(closure: {
    // closure's body goes here
})
someFunctionThatTakesAClosure() {
    // trailing closure's body goes here
}

Yes, I've seen and used this. I think this is actually a little confusing.

-Steve

Reply via email to