Re: Parenthesis around if/for/while condition is not necessary

2018-07-05 Thread Basile B. via Digitalmars-d
On Thursday, 5 July 2018 at 09:45:44 UTC, Basile B. wrote: On Wednesday, 4 July 2018 at 14:37:49 UTC, Timon Gehr wrote: On 24.06.2018 13:27, Basile B. wrote: FYI this works fine, as expected it's just some small parser changes. I didn't touch to for and foreach for now. I think that

Re: Parenthesis around if/for/while condition is not necessary

2018-07-05 Thread Basile B. via Digitalmars-d
On Wednesday, 4 July 2018 at 14:37:49 UTC, Timon Gehr wrote: On 24.06.2018 13:27, Basile B. wrote: FYI this works fine, as expected it's just some small parser changes. I didn't touch to for and foreach for now. I think that SwitchStatement is a candidate too.

Re: Parenthesis around if/for/while condition is not necessary

2018-07-05 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 4 July 2018 at 14:37:49 UTC, Timon Gehr wrote: if (a+b)*c == d { ... } Error: found `{` when expecting `;` following statement Adding the semi-colon, `*c == d;` would likely cause: Error: `*c == d` has no effect Also multiplying (a+b) by a pointer is illegal, and c is probably

Re: Parenthesis around if/for/while condition is not necessary

2018-07-04 Thread Timon Gehr via Digitalmars-d
On 24.06.2018 13:27, Basile B. wrote: FYI this works fine, as expected it's just some small parser changes. I didn't touch to for and foreach for now. I think that SwitchStatement is a candidate too. https://github.com/BBasile/dmd/commit/5455a65c8fdee5a6d198782d1f168906b59e6d3d if (a+b)*c

Re: Parenthesis around if/for/while condition is not necessary

2018-07-04 Thread Daniel N via Digitalmars-d
On Monday, 2 July 2018 at 20:28:06 UTC, Seb wrote: On Sunday, 1 July 2018 at 12:02:03 UTC, Nick Treleaven wrote: On Sunday, 24 June 2018 at 23:40:56 UTC, Timoses wrote: The others may be rewritten to not have a leading "!" as well, e.g. if (!(t1.ty == Tarray && t2.ty == Tarray &&

Re: Parenthesis around if/for/while condition is not necessary

2018-07-04 Thread FeepingCreature via Digitalmars-d
On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote: There is this case that requires parens: if a && b c; Is there a missing && or not ? It seems obvious for a human but compiler parsers are "apparatchiks", i.e rules are rules. That being said this would work by allowing parens

Re: Parenthesis around if/for/while condition is not necessary

2018-07-02 Thread Seb via Digitalmars-d
On Sunday, 1 July 2018 at 12:02:03 UTC, Nick Treleaven wrote: On Sunday, 24 June 2018 at 23:40:56 UTC, Timoses wrote: The others may be rewritten to not have a leading "!" as well, e.g. if (!(t1.ty == Tarray && t2.ty == Tarray && needsDirectEq(t1, t2)) if (t1.ty != Tarray || t2.ty !=

Re: Parenthesis around if/for/while condition is not necessary

2018-07-02 Thread Basile B. via Digitalmars-d
On Monday, 25 June 2018 at 12:19:15 UTC, aliak wrote: On Monday, 25 June 2018 at 10:38:49 UTC, Basile B. wrote: On Monday, 25 June 2018 at 10:36:46 UTC, Basile B. wrote: On Sunday, 24 June 2018 at 23:08:15 UTC, aliak wrote: Wow nice, that was quick, would it be much more to make it so that

Re: Parenthesis around if/for/while condition is not necessary

2018-07-01 Thread Nick Treleaven via Digitalmars-d
On Sunday, 24 June 2018 at 23:40:56 UTC, Timoses wrote: The others may be rewritten to not have a leading "!" as well, e.g. if (!(t1.ty == Tarray && t2.ty == Tarray && needsDirectEq(t1, t2)) if (t1.ty != Tarray || t2.ty != Tarray || ...) Yes, but you might make a mistake, and sometimes it

Re: Parenthesis around if/for/while condition is not necessary

2018-06-25 Thread aliak via Digitalmars-d
On Monday, 25 June 2018 at 10:38:49 UTC, Basile B. wrote: On Monday, 25 June 2018 at 10:36:46 UTC, Basile B. wrote: On Sunday, 24 June 2018 at 23:08:15 UTC, aliak wrote: Wow nice, that was quick, would it be much more to make it so that braces are required with if statements that do not

Re: Parenthesis around if/for/while condition is not necessary

2018-06-25 Thread Basile B. via Digitalmars-d
On Sunday, 24 June 2018 at 23:08:15 UTC, aliak wrote: On Sunday, 24 June 2018 at 11:27:12 UTC, Basile B. wrote: On Saturday, 23 June 2018 at 06:24:29 UTC, Basile B. wrote: On Saturday, 23 June 2018 at 06:18:53 UTC, user1234 wrote: On Saturday, 23 June 2018 at 05:09:13 UTC, aedt wrote: On

Re: Parenthesis around if/for/while condition is not necessary

2018-06-25 Thread Basile B. via Digitalmars-d
On Monday, 25 June 2018 at 10:36:46 UTC, Basile B. wrote: On Sunday, 24 June 2018 at 23:08:15 UTC, aliak wrote: On Sunday, 24 June 2018 at 11:27:12 UTC, Basile B. wrote: On Saturday, 23 June 2018 at 06:24:29 UTC, Basile B. wrote: On Saturday, 23 June 2018 at 06:18:53 UTC, user1234 wrote: On

Re: Parenthesis around if/for/while condition is not necessary

2018-06-24 Thread Timoses via Digitalmars-d
On Sunday, 24 June 2018 at 22:03:13 UTC, Dennis wrote: if (!("key" in dict)) {...} if ("key" !in dict) {...} At least that one has a shorter form. The others may be rewritten to not have a leading "!" as well, e.g. if (!(t1.ty == Tarray && t2.ty == Tarray && needsDirectEq(t1, t2)) if

Re: Parenthesis around if/for/while condition is not necessary

2018-06-24 Thread aliak via Digitalmars-d
On Sunday, 24 June 2018 at 22:25:43 UTC, Jonathan M Davis wrote: On Sunday, June 24, 2018 22:03:13 Dennis via Digitalmars-d wrote: On Saturday, 23 June 2018 at 02:14:04 UTC, Jonathan M Davis wrote: > [...] I don't see why allowing one to omit the parens makes porting C code harder. It

Re: Parenthesis around if/for/while condition is not necessary

2018-06-24 Thread aliak via Digitalmars-d
On Sunday, 24 June 2018 at 11:27:12 UTC, Basile B. wrote: On Saturday, 23 June 2018 at 06:24:29 UTC, Basile B. wrote: On Saturday, 23 June 2018 at 06:18:53 UTC, user1234 wrote: On Saturday, 23 June 2018 at 05:09:13 UTC, aedt wrote: On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote:

Re: Parenthesis around if/for/while condition is not necessary

2018-06-24 Thread Jonathan M Davis via Digitalmars-d
On Sunday, June 24, 2018 22:03:13 Dennis via Digitalmars-d wrote: > On Saturday, 23 June 2018 at 02:14:04 UTC, Jonathan M Davis wrote: > > In general, C code is supposed to be either valid D code or not > > compile in order to making porting it easier. Getting rid of > > the parens wouldn't break

Re: Parenthesis around if/for/while condition is not necessary

2018-06-24 Thread Dennis via Digitalmars-d
On Saturday, 23 June 2018 at 02:14:04 UTC, Jonathan M Davis wrote: In general, C code is supposed to be either valid D code or not compile in order to making porting it easier. Getting rid of the parens wouldn't break that, but it _would_ make it so that it's more work to port C code to D when

Re: Parenthesis around if/for/while condition is not necessary

2018-06-24 Thread Basile B. via Digitalmars-d
On Saturday, 23 June 2018 at 06:24:29 UTC, Basile B. wrote: On Saturday, 23 June 2018 at 06:18:53 UTC, user1234 wrote: On Saturday, 23 June 2018 at 05:09:13 UTC, aedt wrote: On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote: On Saturday, 23 June 2018 at 01:27:30 UTC, aedt wrote: for

Re: Parenthesis around if/for/while condition is not necessary

2018-06-24 Thread Basile B. via Digitalmars-d
On Sunday, 24 June 2018 at 08:30:28 UTC, Jacob Carlborg wrote: On 2018-06-23 14:34, Tobias Müller wrote: AFAIK the if and else branches in Rust always have to be enclosed in curly braces because of this. I don't remember the exact ambiguity though. There's an ambiguity between the condition

Re: Parenthesis around if/for/while condition is not necessary

2018-06-24 Thread Jacob Carlborg via Digitalmars-d
On 2018-06-23 14:34, Tobias Müller wrote: AFAIK the if and else branches in Rust always have to be enclosed in curly braces because of this. I don't remember the exact ambiguity though. There's an ambiguity between the condition and the body. There needs to be some kind of symbol to separate

Re: Parenthesis around if/for/while condition is not necessary

2018-06-23 Thread crimaniak via Digitalmars-d
On Saturday, 23 June 2018 at 09:19:45 UTC, user1234 wrote: ...Forcing Curly braces is nice, logic and natural imo. The operator brackets themselves are a separate construction. In addition, the more structured the code, the less they are needed. In my code, most of the loops and branches

Re: Parenthesis around if/for/while condition is not necessary

2018-06-23 Thread Tobias Müller via Digitalmars-d
aedt wrote: > Modern languages have already > dropped this requirement (i.e. Rust, Nim) and I don't see any > reason not to do so. AFAIK the if and else branches in Rust always have to be enclosed in curly braces because of this. I don't remember the exact ambiguity though.

Re: Parenthesis around if/for/while condition is not necessary

2018-06-23 Thread user1234 via Digitalmars-d
On Saturday, 23 June 2018 at 09:19:45 UTC, user1234 wrote: On Saturday, 23 June 2018 at 08:07:23 UTC, Jacob Carlborg wrote: On 2018-06-23 03:27, aedt wrote: for line in stdin.lines() {} if condition {} while condition {} for init; condition; op {} What's the rationale of keeping the

Re: Parenthesis around if/for/while condition is not necessary

2018-06-23 Thread user1234 via Digitalmars-d
On Saturday, 23 June 2018 at 08:07:23 UTC, Jacob Carlborg wrote: On 2018-06-23 03:27, aedt wrote: for line in stdin.lines() {} if condition {} while condition {} for init; condition; op {} What's the rationale of keeping the requirement that the condition of if/for/while must be wrapped

Re: Parenthesis around if/for/while condition is not necessary

2018-06-23 Thread Jacob Carlborg via Digitalmars-d
On 2018-06-23 03:27, aedt wrote: for line in stdin.lines() {} if condition {} while condition {} for init; condition; op {} What's the rationale of keeping the requirement that the condition of if/for/while must be wrapped with a parenthesis (other than keeping parser simple)? Modern

Re: Parenthesis around if/for/while condition is not necessary

2018-06-23 Thread Basile B. via Digitalmars-d
On Saturday, 23 June 2018 at 06:18:53 UTC, user1234 wrote: On Saturday, 23 June 2018 at 05:09:13 UTC, aedt wrote: On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote: On Saturday, 23 June 2018 at 01:27:30 UTC, aedt wrote: for line in stdin.lines() {} if condition {} while condition {}

Re: Parenthesis around if/for/while condition is not necessary

2018-06-23 Thread user1234 via Digitalmars-d
On Saturday, 23 June 2018 at 05:09:13 UTC, aedt wrote: On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote: On Saturday, 23 June 2018 at 01:27:30 UTC, aedt wrote: for line in stdin.lines() {} if condition {} while condition {} for init; condition; op {} What's the rationale of

Re: Parenthesis around if/for/while condition is not necessary

2018-06-22 Thread Nick Sabalausky (Abscissa) via Digitalmars-d
On 06/22/2018 09:27 PM, aedt wrote: for line in stdin.lines() {} if condition {} while condition {} for init; condition; op {} What's the rationale of keeping the requirement that the condition of if/for/while must be wrapped with a parenthesis (other than keeping parser simple)? Modern

Re: Parenthesis around if/for/while condition is not necessary

2018-06-22 Thread aedt via Digitalmars-d
On Saturday, 23 June 2018 at 04:45:07 UTC, user1234 wrote: On Saturday, 23 June 2018 at 01:27:30 UTC, aedt wrote: for line in stdin.lines() {} if condition {} while condition {} for init; condition; op {} What's the rationale of keeping the requirement that the condition of if/for/while

Re: Parenthesis around if/for/while condition is not necessary

2018-06-22 Thread user1234 via Digitalmars-d
On Saturday, 23 June 2018 at 01:27:30 UTC, aedt wrote: for line in stdin.lines() {} if condition {} while condition {} for init; condition; op {} What's the rationale of keeping the requirement that the condition of if/for/while must be wrapped with a parenthesis (other than keeping

Re: Parenthesis around if/for/while condition is not necessary

2018-06-22 Thread Jonathan M Davis via Digitalmars-d
On Saturday, June 23, 2018 01:27:30 aedt via Digitalmars-d wrote: > for line in stdin.lines() {} > > if condition {} > > while condition {} > > for init; condition; op {} > > > What's the rationale of keeping the requirement that the > condition of if/for/while must be wrapped with a parenthesis >

Parenthesis around if/for/while condition is not necessary

2018-06-22 Thread aedt via Digitalmars-d
for line in stdin.lines() {} if condition {} while condition {} for init; condition; op {} What's the rationale of keeping the requirement that the condition of if/for/while must be wrapped with a parenthesis (other than keeping parser simple)? Modern languages have already dropped this