On Sunday, 26 July 2015 at 14:49:40 UTC, Timon Gehr wrote:
On 07/26/2015 01:04 PM, Idan Arye wrote:
On Sunday, 26 July 2015 at 07:28:45 UTC, Kapps wrote:
On Friday, 24 July 2015 at 15:01:29 UTC, Adam D. Ruppe wrote:
[...]

The with statement is one where I think it would be interesting to
make it an expression.

For named parameters (admittedly, I find this one a bit ugly):
foo(with(ParameterTypeTuple!foo) {
    abc = 2,
    def = 3
});

Or just:
auto args = with(ParameterTypeTuple!foo) {
    abc = 2,
    def = 3
};
foo(args);


For initialization:
auto a = with(new FooBar()) {
    name = "Foo",
    bar = 3
};

Or:
with(new Thread(&foo) {
    isDaemon = true
}).start();

Sadly it'll break all the code that currently use it, since we'll now
need to terminate it with a semicolon.

Well, no. That does not follow. We can have both a with statement and a with expression.

Mmm... but how will we differ them? The style in Kapps' example can fit into Rust, but looks weird in D. How about something that resembles the difference between expression and block lambdas:

    with (...) { ... } // statement with
    with (...) => ... // expression with

While it may differ from lambdas since in lambdas both are expressions, it's similar in that the version without the => accepts a block of statements and the version with the => accepts an expression.

Reply via email to