The proposal is substantively unchanged from the preceding pitch, so I will reiterate my comment:
I see the appeal of trying to make a feature more general, but in this case I have doubts about whether this pulls its own weight.
In the animation example, for instance, the status quo is--
transition(with: view, duration: 2.0,
animations: {
...
},
completion: {
...
}
)
/* versus the pitch here:
transition(with: view, duration: 2.0) {
animations: {
...
}
completion: {
...
}
}
*/
--so the pitch offers a second spelling that isn't any lighter at all, just different. (By contrast, in the case of single trailing closure syntax, it's sugar that does make the call site lighter both by dropping the label and by avoiding nesting two 'layers' of punctuation: neither is achieved here.)
One other advantage of the trailing closure syntax is that it gets us closer to something approximating native control flow syntax, useful for DSL-related situations.
However, as you show with your example of when
, the else
block is counterintuitively nested within the condition that it's supposed to contradict using your proposed spelling, which far from approximating native if...else
is totally alien to it.
Moreover, it seems these blocks are easily confusable with labeled do
blocks; I imagine it could actually inhibit the compiler error we have today to remind users to add the missing keyword do
when they label naked braces. Granted, this isn't a commonly used feature, but I think it's a double drawback that when...else
both can't resemble native control flow syntax that ideally it would resemble and must resemble native control flow syntax that ideally it wouldn't resemble.
Ultimately, what's pitched here suffers from not having a solution that actually offers multiple trailing closure expressions, but rather a single trailing expression that contains multiple closures.
But enough of bikeshedding the actual spelling. I think overall my bigger concern is related to the first thing I've commented on. The idea imposes the burden of learning a second syntax for something that's already expressible, a syntax that isn't purely a natural extension of the single trailing closure expressions we already have.