digitalmars.D - No parenthesis for assert?
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (11/11) Jan 12 2012 Hi,
- Manfred Nowak (6/8) Jan 12 2012 Maybe, but only when no `assert'-expression(!) is evaluated ever ...
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (4/12) Jan 12 2012 Right, it would only make sense when it's used as a statement
- Peter Alexander (7/21) Jan 12 2012 assert can also have a message:
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (4/27) Jan 12 2012 I did point out that it would only really make sense for asserts without...
- Stewart Gordon (20/25) Jan 14 2012 Therein lies the point. If we changed the AssertExpression grammar to
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (7/35) Jan 14 2012 Point taken; I now see what you're getting at. I tend to forget the
- Stewart Gordon (4/7) Jan 15 2012 Correction: because of the way the grammar works, it would be a case of ...
Hi, Is there any reason parentheses are required on asserts? It would be much neater to be able to write: assert x != 0; than: assert(x != 0); By making parentheses optional, it would also feel more like a language feature than some sort of function. I realize optional parentheses wouldn't be useful if you're passing a message to assert, but I think for all other use cases, it would be a nice thing to have. - Alex
Jan 12 2012
Alex Rønne Petersen wrote:Is there any reason parentheses are requiredYes.for all other use cases, it would be a nice thing to have.Maybe, but only when no `assert'-expression(!) is evaluated ever ... Because making parenthesis optional for `assert' would introduce ambiguities. -manfred
Jan 12 2012
On 12-01-2012 16:57, Manfred Nowak wrote:Alex Rønne Petersen wrote:Right, it would only make sense when it's used as a statement expression. In all other cases, it wouldn't work, of course. - AlexIs there any reason parentheses are requiredYes.for all other use cases, it would be a nice thing to have.Maybe, but only when no `assert'-expression(!) is evaluated ever ... Because making parenthesis optional for `assert' would introduce ambiguities. -manfred
Jan 12 2012
On 12/01/12 4:34 PM, Alex Rønne Petersen wrote:On 12-01-2012 16:57, Manfred Nowak wrote:assert can also have a message: assert(x == 0, "What's going on!?"); This would look odd without parentheses. assert x == 0, "What's going on!?"; Not to mention that it would be ambiguous with the comma operator: assert (a, b); // is this the comma operator, or two arguments?Alex Rønne Petersen wrote:Right, it would only make sense when it's used as a statement expression. In all other cases, it wouldn't work, of course. - AlexIs there any reason parentheses are requiredYes.for all other use cases, it would be a nice thing to have.Maybe, but only when no `assert'-expression(!) is evaluated ever ... Because making parenthesis optional for `assert' would introduce ambiguities. -manfred
Jan 12 2012
On 12-01-2012 22:35, Peter Alexander wrote:On 12/01/12 4:34 PM, Alex Rønne Petersen wrote:I did point out that it would only really make sense for asserts without messages. - AlexOn 12-01-2012 16:57, Manfred Nowak wrote:assert can also have a message: assert(x == 0, "What's going on!?"); This would look odd without parentheses. assert x == 0, "What's going on!?"; Not to mention that it would be ambiguous with the comma operator: assert (a, b); // is this the comma operator, or two arguments?Alex Rønne Petersen wrote:Right, it would only make sense when it's used as a statement expression. In all other cases, it wouldn't work, of course. - AlexIs there any reason parentheses are requiredYes.for all other use cases, it would be a nice thing to have.Maybe, but only when no `assert'-expression(!) is evaluated ever ... Because making parenthesis optional for `assert' would introduce ambiguities. -manfred
Jan 12 2012
On 12/01/2012 22:56, Alex Rønne Petersen wrote:On 12-01-2012 22:35, Peter Alexander wrote:<snip>Therein lies the point. If we changed the AssertExpression grammar to AssertExpression: assert ( AssignExpression ) assert ( AssignExpression , AssignExpression ) assert AssignExpression then the form assert ( AssignExpression , AssignExpression ) would become ambiguous, because it could be parsed as assert ( AssignExpression , CommaExpression ) assert ( CommaExpression ) assert ( Expression ) assert AssignExpression In some cases it's resolved by an "if it's parseable as X, it's X" rule, but this would create fragility because of the possibility of a CommaExpression of three or more terms. As such, it would be a case of explicitly disallowing assert ( CommaExpression ) in the grammar. Stewart.Not to mention that it would be ambiguous with the comma operator: assert (a, b); // is this the comma operator, or two arguments?I did point out that it would only really make sense for asserts without messages.
Jan 14 2012
On 14-01-2012 13:59, Stewart Gordon wrote:On 12/01/2012 22:56, Alex Rønne Petersen wrote:Point taken; I now see what you're getting at. I tend to forget the existence of the comma operator when considering these things... I wish we wouldn't have it in the language; it seems to be more trouble than it's worth (in more ways than one). -- - AlexOn 12-01-2012 22:35, Peter Alexander wrote:<snip>Therein lies the point. If we changed the AssertExpression grammar to AssertExpression: assert ( AssignExpression ) assert ( AssignExpression , AssignExpression ) assert AssignExpression then the form assert ( AssignExpression , AssignExpression ) would become ambiguous, because it could be parsed as assert ( AssignExpression , CommaExpression ) assert ( CommaExpression ) assert ( Expression ) assert AssignExpression In some cases it's resolved by an "if it's parseable as X, it's X" rule, but this would create fragility because of the possibility of a CommaExpression of three or more terms. As such, it would be a case of explicitly disallowing assert ( CommaExpression ) in the grammar. Stewart.Not to mention that it would be ambiguous with the comma operator: assert (a, b); // is this the comma operator, or two arguments?I did point out that it would only really make sense for asserts without messages.
Jan 14 2012
On 14/01/2012 15:32, Alex Rønne Petersen wrote:As such, it would be a case of explicitly disallowing assert ( CommaExpression ) in the grammar.Correction: because of the way the grammar works, it would be a case of explicitly disallowing assert ( AssignExpression , CommaExpression ) Stewart.
Jan 15 2012