Page 1 of 1

Ternary conditinals bug, I guess...

Posted: 18 Sep 2008 23:06
by jacky
So you know how there are 3 "expressions" involved : condition, value-if-true, and value-if-false. Both "value-if-true" and "value-if-false" should not include any concatenation, nor "secondary" ternary conditionals.

But actually, it seems to work fine if the additional ternary conditionals is on value-if-false. Here:

Code: Select all

msg confirm("first confirm") ? "ok 1" : confirm("second confirm?") ? "ok 2" : confirm("third confirm?") ? "ok 3" : "and so on...";
Works just fine. Do we call that a feature, or do you want to "remove" it?

I'd vote to keep it, since it can actually be useful, but given how it can't work for value-if-true even with appropriate parenthesis (which would be the bug I'd say), that might not be be wise...

Re: Ternary conditinals bug, I guess...

Posted: 19 Sep 2008 07:41
by admin
jacky wrote:So you know how there are 3 "expressions" involved : condition, value-if-true, and value-if-false. Both "value-if-true" and "value-if-false" should not include any concatenation, nor "secondary" ternary conditionals.

But actually, it seems to work fine if the additional ternary conditionals is on value-if-false. Here:

Code: Select all

msg confirm("first confirm") ? "ok 1" : confirm("second confirm?") ? "ok 2" : confirm("third confirm?") ? "ok 3" : "and so on...";
Works just fine. Do we call that a feature, or do you want to "remove" it?

I'd vote to keep it, since it can actually be useful, but given how it can't work for value-if-true even with appropriate parenthesis (which would be the bug I'd say), that might not be be wise...
Oh, the restriction "should not include any concatenation" is not valid anymore since I added parentheses support. Of course, even without parentheses there's always some default binding of expressions, and in your example it happens work in some cases.

Re: Ternary conditinals bug, I guess...

Posted: 19 Sep 2008 09:34
by jacky
admin wrote:Oh, the restriction "should not include any concatenation" is not valid anymore since I added parentheses support. Of course, even without parentheses there's always some default binding of expressions, and in your example it happens work in some cases.
Okay, so the way I hear you is : this works thanks to default/unwritten parentheses, and using the right parentheses, it should work all the time. How do you suggest I should do it then, to use another ternary conditionals on value-if-true ?

Code: Select all

  msg ( (1==1) ? ( (2==2) ? "yes" : "no" ) : "error" );
  //shows: 0

Re: Ternary conditinals bug, I guess...

Posted: 19 Sep 2008 19:45
by admin
jacky wrote:
admin wrote:Oh, the restriction "should not include any concatenation" is not valid anymore since I added parentheses support. Of course, even without parentheses there's always some default binding of expressions, and in your example it happens work in some cases.
Okay, so the way I hear you is : this works thanks to default/unwritten parentheses, and using the right parentheses, it should work all the time. How do you suggest I should do it then, to use another ternary conditionals on value-if-true ?

Code: Select all

  msg ( (1==1) ? ( (2==2) ? "yes" : "no" ) : "error" );
  //shows: 0
Whoops, yes, a bug! Let's see if I can fix it...