digitalmars.D - with(auto x = ...)
- Shammah Chancellor (4/4) Jul 24 2015 This operation doesn't seem to work. It would be a pretty handy
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (3/7) Jul 24 2015 This limitation could probably be lifted easily.
- Adam D. Ruppe (16/17) Jul 24 2015 You can make your parameters into a struct or tuple and fill them
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (2/13) Jul 24 2015 Nice!
- Kapps (23/40) Jul 26 2015 The with statement is one where I think it would be interesting
- Idan Arye (3/27) Jul 26 2015 Sadly it'll break all the code that currently use it, since we'll
- Timon Gehr (3/36) Jul 26 2015 Well, no. That does not follow. We can have both a with statement and a
- Idan Arye (10/49) Jul 26 2015 Mmm... but how will we differ them? The style in Kapps' example
- Artur Skawina via Digitalmars-d (7/11) Jul 26 2015 There's no need for that. (hint: "mixin"). But, unlike
- Martin Nowak (6/10) Jul 26 2015 It would make sense to extend the if statement rule [¹] to with [²] an...
- ketmar (2/6) Jul 25 2015 https://issues.dlang.org/show_bug.cgi?id=3D13526=
This operation doesn't seem to work. It would be a pretty handy thing to work since we don't support named parameters at this time. Comments?
Jul 24 2015
On Friday, 24 July 2015 at 14:12:39 UTC, Shammah Chancellor wrote:This operation doesn't seem to work. It would be a pretty handy thing to work since we don't support named parameters at this time. Comments?This limitation could probably be lifted easily. But I fail to see the relation to named parameters?
Jul 24 2015
On Friday, 24 July 2015 at 14:48:30 UTC, Marc Schütz wrote:But I fail to see the relation to named parameters?You can make your parameters into a struct or tuple and fill them in with normal assignment. The with(auto) thing will conveniently limit the scope of the temporary argument object and give a bit of syntax sugar for it: with(auto args = ParameterTypeTuple!foo) { argname = cool; argname2 = whatever; foo(args); } .....ironically, given the other thread about statements as expressions where i said 'meh', this is actually a decent case for them too, to get the return value of foo out of that scope while still allowing auto. But that's a separate issue, the main point here is just that you can use it to prepare the arguments with a bit of sugar.
Jul 24 2015
On Friday, 24 July 2015 at 15:01:29 UTC, Adam D. Ruppe wrote:On Friday, 24 July 2015 at 14:48:30 UTC, Marc Schütz wrote:Nice!But I fail to see the relation to named parameters?You can make your parameters into a struct or tuple and fill them in with normal assignment. The with(auto) thing will conveniently limit the scope of the temporary argument object and give a bit of syntax sugar for it: with(auto args = ParameterTypeTuple!foo) { argname = cool; argname2 = whatever; foo(args); }
Jul 24 2015
On Friday, 24 July 2015 at 15:01:29 UTC, Adam D. Ruppe wrote:On Friday, 24 July 2015 at 14:48:30 UTC, Marc Schütz 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();But I fail to see the relation to named parameters?You can make your parameters into a struct or tuple and fill them in with normal assignment. The with(auto) thing will conveniently limit the scope of the temporary argument object and give a bit of syntax sugar for it: with(auto args = ParameterTypeTuple!foo) { argname = cool; argname2 = whatever; foo(args); } .....ironically, given the other thread about statements as expressions where i said 'meh', this is actually a decent case for them too, to get the return value of foo out of that scope while still allowing auto. But that's a separate issue, the main point here is just that you can use it to prepare the arguments with a bit of sugar.
Jul 26 2015
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:Sadly it'll break all the code that currently use it, since we'll now need to terminate it with a semicolon.[...]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();
Jul 26 2015
On 07/26/2015 01:04 PM, Idan Arye wrote:On Sunday, 26 July 2015 at 07:28:45 UTC, Kapps wrote:Well, no. That does not follow. We can have both a with statement and a with expression.On Friday, 24 July 2015 at 15:01:29 UTC, Adam D. Ruppe wrote:Sadly it'll break all the code that currently use it, since we'll now need to terminate it with a semicolon.[...]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();
Jul 26 2015
On Sunday, 26 July 2015 at 14:49:40 UTC, Timon Gehr wrote:On 07/26/2015 01:04 PM, Idan Arye wrote: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.On Sunday, 26 July 2015 at 07:28:45 UTC, Kapps wrote:Well, no. That does not follow. We can have both a with statement and a with expression.On Friday, 24 July 2015 at 15:01:29 UTC, Adam D. Ruppe wrote:Sadly it'll break all the code that currently use it, since we'll now need to terminate it with a semicolon.[...]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();
Jul 26 2015
On 07/26/15 17:56, Idan Arye via Digitalmars-d wrote:On Sunday, 26 July 2015 at 14:49:40 UTC, Timon Gehr wrote: Well, no. That does not follow. We can have both a with statement and a with expression. Mmm... but how will we differ them?There's no need for that. (hint: "mixin"). But, unlike support for with-declarations (which would be a significant improvement) I'm not sure if with-expression would make sense (and the lifetimes might be too unintuitive -- they'd be different for with-statements and -expressions). artur
Jul 26 2015
On 07/24/2015 05:01 PM, Adam D. Ruppe wrote:.....ironically, given the other thread about statements as expressions where i said 'meh', this is actually a decent case for them too, to get the return value of foo out of that scope while still allowing auto.It would make sense to extend the if statement rule [¹] to with [²] and switch [³]. [¹]: http://dlang.org/grammar.html#IfStatement [²]: https://issues.dlang.org/show_bug.cgi?id=13526 [³]: https://issues.dlang.org/show_bug.cgi?id=11070
Jul 26 2015
On Fri, 24 Jul 2015 14:12:39 +0000, Shammah Chancellor wrote:This operation doesn't seem to work. It would be a pretty handy thing to work since we don't support named parameters at this time. =20 Comments?https://issues.dlang.org/show_bug.cgi?id=3D13526=
Jul 25 2015