Parenthesis around if/for/while condition is not necessary
Basile B.
b2.temp at gmx.com
Sat Jun 23 06:24:29 UTC 2018
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 {}
>>>>
>>>> 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 requirement (i.e. Rust, Nim) and I
>>>> don't see any reason not to do so.
>>>
>>> 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 for
>>> disambiguation.
>>
>> Same thing as the following"
>> return a && b;
>>
>> I'm not saying to drop parens completely, I'm saying why is it
>> not optional. D seems to have no problem with x.to!string or
>> std.lines
>
> I agree that this would be in adequation with certain stuff of
> the D syntax, such as parens-less single template parameter.
> Someone has to make a DIP for this
Maybe but this is a simple parser thing. For example after
reading the discussion here i have tested the idea in my toy
programming language
(https://github.com/BBasile/styx/commit/83c96d8a789aa82f9bed254ab342ffc4aed4fd88) and i believe that for D this would be as simple ( < 20 SLOC, w/o the tests).
> otherwise we're good for one of this sterile NG discussion
> leading to nothing, i.e intellectual mast... well guess the
> word.
I'm tempted to try this in DMDFE. Change is simple enough so that
if it get rejected no much time is lost.
More information about the Digitalmars-d
mailing list