Re: Bug or logic error in if with auto?

2012-12-07 Thread deadalnix
On Friday, 7 December 2012 at 14:21:51 UTC, Nick Treleaven wrote: On 03/12/2012 14:22, Nick Treleaven wrote: Most programmers would probably just pollute the existing scope: auto x = "thing" in arr; if (x && *x == 45) { ... } I expect this is because wrapping the above in {} for a new sc

Re: Bug or logic error in if with auto?

2012-12-07 Thread Nick Treleaven
On 03/12/2012 14:22, Nick Treleaven wrote: Most programmers would probably just pollute the existing scope: auto x = "thing" in arr; if (x && *x == 45) { ... } I expect this is because wrapping the above in {} for a new scope is just too ugly, introducing more nesting and indentation. It

Re: Bug or logic error in if with auto?

2012-12-04 Thread Nick Treleaven
On 03/12/2012 20:17, Rob T wrote: On Monday, 3 December 2012 at 14:22:28 UTC, Nick Treleaven wrote: Most programmers would probably just pollute the existing scope: auto x = "thing" in arr; if (x && *x == 45) { ... } You can always wrap it inside its own scope Yes, that's why I wrote:

Re: Bug or logic error in if with auto?

2012-12-03 Thread Rob T
On Monday, 3 December 2012 at 14:22:28 UTC, Nick Treleaven wrote: Most programmers would probably just pollute the existing scope: auto x = "thing" in arr; if (x && *x == 45) { ... } You can always wrap it inside its own scope main() { // temp scope { auto x = "thing" in arr;

Re: Bug or logic error in if with auto?

2012-12-03 Thread Nick Treleaven
On 02/12/2012 15:09, js.mdnq wrote: Can this be made to work in D? Error in D, x not found: if (auto x = "thing" in arr && x == 45) { } Works: if (auto x = "thing" in arr) if (x == 45) { } Most programmers would probably just pollute the existing scope: auto x = "thing" in

Re: Bug or logic error in if with auto?

2012-12-02 Thread Peter Alexander
On Sunday, 2 December 2012 at 15:09:17 UTC, js.mdnq wrote: Can this be made to work in D? Error in D, x not found: if (auto x = "thing" in arr && x == 45) { } You can't have both a declaration and expression in an if-statement. http://dlang.org/statement.html#IfStatement IfStatement:

Re: Bug or logic error in if with auto?

2012-12-02 Thread Peter Alexander
And no, it cannot be made to work, because the grammar would be ambiguous: if (auto x = y && z) Does this mean? if (auto x = (y && z)) or if (auto x = y) if (x && z) You could make it work with new syntax, but given you can just use two if-statements, I don't see any point.

Bug or logic error in if with auto?

2012-12-02 Thread js.mdnq
Can this be made to work in D? Error in D, x not found: if (auto x = "thing" in arr && x == 45) { } Works: if (auto x = "thing" in arr) if (x == 45) { }