Re: D Logic bug

2018-10-15 Thread Nick Treleaven via Digitalmars-d
On Thursday, 11 October 2018 at 23:17:15 UTC, Jonathan Marler wrote: For example, the "Conditional operator" in D actually has a higher priority than an assignment, but in C++ it's the same and is evaluated right-to-left. So this expression would be different in C++ and D: a ? b : c = d In

Re: D Logic bug

2018-10-12 Thread Patrick Schluter via Digitalmars-d
On Friday, 12 October 2018 at 13:15:22 UTC, Steven Schveighoffer wrote: On 10/12/18 6:06 AM, Kagamin wrote: On Thursday, 11 October 2018 at 23:17:15 UTC, Jonathan Marler wrote: [...] That's https://issues.dlang.org/show_bug.cgi?id=14186 Wow, interesting that C precedence is different from

Re: D Logic bug

2018-10-12 Thread Patrick Schluter via Digitalmars-d
On Thursday, 11 October 2018 at 23:17:57 UTC, Jonathan M Davis wrote: On Thursday, October 11, 2018 8:35:34 AM MDT James Japherson via Digitalmars-d wrote: Certainly, major languages like C, C++, Java, and C# all do it the way that D does, and they all have the same kind of precedence for

Re: D Logic bug

2018-10-12 Thread Patrick Schluter via Digitalmars-d
On Thursday, 11 October 2018 at 23:17:15 UTC, Jonathan Marler wrote: On Thursday, 11 October 2018 at 21:57:00 UTC, Jonathan M Davis wrote: On Thursday, October 11, 2018 1:09:14 PM MDT Jonathan Marler via Digitalmars-d wrote: On Thursday, 11 October 2018 at 14:35:34 UTC, James Japherson wrote:

Re: D Logic bug

2018-10-12 Thread Steven Schveighoffer via Digitalmars-d
On 10/12/18 6:06 AM, Kagamin wrote: On Thursday, 11 October 2018 at 23:17:15 UTC, Jonathan Marler wrote: I had a look at the table again, looks like the ternary operator is on there, just called the "conditional operator". And to clarify, D's operator precedence is close to C/C++ but doesn't

Re: D Logic bug

2018-10-12 Thread Kagamin via Digitalmars-d
On Thursday, 11 October 2018 at 23:17:15 UTC, Jonathan Marler wrote: I had a look at the table again, looks like the ternary operator is on there, just called the "conditional operator". And to clarify, D's operator precedence is close to C/C++ but doesn't match exactly. This is likely a

Re: D Logic bug

2018-10-11 Thread Steven Schveighoffer via Digitalmars-d
On 10/11/18 9:16 PM, Jonathan Marler wrote: On Thursday, 11 October 2018 at 23:29:05 UTC, Steven Schveighoffer wrote: On 10/11/18 7:17 PM, Jonathan Marler wrote: I had a look at the table again, looks like the ternary operator is on there, just called the "conditional operator". And to

Re: D Logic bug

2018-10-11 Thread Jonathan Marler via Digitalmars-d
On Thursday, 11 October 2018 at 23:29:05 UTC, Steven Schveighoffer wrote: On 10/11/18 7:17 PM, Jonathan Marler wrote: I had a look at the table again, looks like the ternary operator is on there, just called the "conditional operator".  And to clarify, D's operator precedence is close to

Re: D Logic bug

2018-10-11 Thread Trass3r via Digitalmars-d
On Thursday, 11 October 2018 at 14:35:34 UTC, James Japherson wrote: Took me about an hour to track this one down! A + (B == 0) ? 0 : C; D is evaluating it as (A + (B == 0)) ? 0 : C; That's why shouldn't compose it like that. It's been a constant source of bugs in C/C++ code:

Re: D Logic bug

2018-10-11 Thread Steven Schveighoffer via Digitalmars-d
On 10/11/18 7:17 PM, Jonathan Marler wrote: I had a look at the table again, looks like the ternary operator is on there, just called the "conditional operator".  And to clarify, D's operator precedence is close to C/C++ but doesn't match exactly.  This is likely a result of the grammar

Re: D Logic bug

2018-10-11 Thread Jonathan Marler via Digitalmars-d
On Thursday, 11 October 2018 at 21:57:00 UTC, Jonathan M Davis wrote: On Thursday, October 11, 2018 1:09:14 PM MDT Jonathan Marler via Digitalmars-d wrote: On Thursday, 11 October 2018 at 14:35:34 UTC, James Japherson wrote: > Took me about an hour to track this one down! > > A + (B == 0) ? 0

Re: D Logic bug

2018-10-11 Thread Jonathan M Davis via Digitalmars-d
On Thursday, October 11, 2018 8:35:34 AM MDT James Japherson via Digitalmars-d wrote: > Took me about an hour to track this one down! > > A + (B == 0) ? 0 : C; > > D is evaluating it as > > (A + (B == 0)) ? 0 : C; > > > The whole point of the parenthesis was to associate. > > I usually explicitly

Re: D Logic bug

2018-10-11 Thread Jonathan M Davis via Digitalmars-d
On Thursday, October 11, 2018 1:09:14 PM MDT Jonathan Marler via Digitalmars-d wrote: > On Thursday, 11 October 2018 at 14:35:34 UTC, James Japherson > > wrote: > > Took me about an hour to track this one down! > > > > A + (B == 0) ? 0 : C; > > > > D is evaluating it as > > > > (A + (B == 0)) ? 0

Re: D Logic bug

2018-10-11 Thread Neia Neutuladh via Digitalmars-d
On 10/11/2018 07:35 AM, James Japherson wrote: Took me about an hour to track this one down! A + (B == 0) ? 0 : C; D is evaluating it as (A + (B == 0)) ? 0 : C; Friends don't let friends use the ternary operator except in trivial cases. This would be a good thing for a linter to check.

Re: D Logic bug

2018-10-11 Thread Jonathan Marler via Digitalmars-d
On Thursday, 11 October 2018 at 14:35:34 UTC, James Japherson wrote: Took me about an hour to track this one down! A + (B == 0) ? 0 : C; D is evaluating it as (A + (B == 0)) ? 0 : C; The whole point of the parenthesis was to associate. I usually explicitly associate precisely because of

Re: D Logic bug

2018-10-11 Thread Shachar Shemesh via Digitalmars-d
On 11/10/18 20:16, Kagamin wrote: On Thursday, 11 October 2018 at 14:35:34 UTC, James Japherson wrote: In the ternary operator it should treat parenthesis directly to the left as the argument. I don't think parentheses are ever treated like that. They are self-contained and don't affect

Re: D Logic bug

2018-10-11 Thread Patrick Schluter via Digitalmars-d
On Thursday, 11 October 2018 at 14:35:34 UTC, James Japherson wrote: Took me about an hour to track this one down! A + (B == 0) ? 0 : C; D is evaluating it as (A + (B == 0)) ? 0 : C; As it should. The whole point of the parenthesis was to associate. I usually explicitly associate

Re: D Logic bug

2018-10-11 Thread Kagamin via Digitalmars-d
On Thursday, 11 October 2018 at 14:35:34 UTC, James Japherson wrote: In the ternary operator it should treat parenthesis directly to the left as the argument. I don't think parentheses are ever treated like that. They are self-contained and don't affect operators outside them.

Re: D Logic bug

2018-10-11 Thread krzaq via Digitalmars-d
On Thursday, 11 October 2018 at 14:35:34 UTC, James Japherson wrote: Took me about an hour to track this one down! A + (B == 0) ? 0 : C; D is evaluating it as (A + (B == 0)) ? 0 : C; The whole point of the parenthesis was to associate. I usually explicitly associate precisely because of

Re: D Logic bug

2018-10-11 Thread rikki cattermole via Digitalmars-d
On 12/10/2018 3:35 AM, James Japherson wrote: Took me about an hour to track this one down! A + (B == 0) ? 0 : C; D is evaluating it as (A + (B == 0)) ? 0 : C; The whole point of the parenthesis was to associate. I usually explicitly associate precisely because of this! A + ((B == 0) ? 0

D Logic bug

2018-10-11 Thread James Japherson via Digitalmars-d
Took me about an hour to track this one down! A + (B == 0) ? 0 : C; D is evaluating it as (A + (B == 0)) ? 0 : C; The whole point of the parenthesis was to associate. I usually explicitly associate precisely because of this! A + ((B == 0) ? 0 : C); In the ternary operator it should treat