Odd if statement
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Odd if statement
Saw this incidentally in another thread.
This statement throws no error;
if x,y,z = 0 then...
I found it odd that the LC compiler lets this pass. When LC resolves the string, it has to come back as "x,y,z", Does LC mean to say that such a string is, simply, not 0?
I would have bet two dollars this would have been rejected on general principles and righteousness.
Craig Newman
This statement throws no error;
if x,y,z = 0 then...
I found it odd that the LC compiler lets this pass. When LC resolves the string, it has to come back as "x,y,z", Does LC mean to say that such a string is, simply, not 0?
I would have bet two dollars this would have been rejected on general principles and righteousness.
Craig Newman
Re: Odd if statement
Hi Craig,
This is just a special case of how xTalk languages parse strings. The given string is a comma-delimited list. LiveCode first parses each item in the list, continues to parse the list as a whole and eventually considers the list to be a string when it parses the remainder of the syntax on the line. Try this in the message box:
If you want to parse the equation as a separate item of the list, you have to write
Kind regards,
Mark
This is just a special case of how xTalk languages parse strings. The given string is a comma-delimited list. LiveCode first parses each item in the list, continues to parse the list as a whole and eventually considers the list to be a string when it parses the remainder of the syntax on the line. Try this in the message box:
Code: Select all
put 2*2,3*3,0=0
Code: Select all
put 2*2,3*3,(0=0)
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Odd if statement
Mark.
Guess I am getting old. HC throws an error with any such construction. But LC does indeed give answers to such a string. I intend to ignore this feature.
Craig
Guess I am getting old. HC throws an error with any such construction. But LC does indeed give answers to such a string. I intend to ignore this feature.
Craig
Re: Odd if statement
Hi Craig,
I checked SuperCard and SC throws an error too, just like HyperCard. One might argue that this is wrong, but one might also consider it a relatively new development in xTalk language. Pick you choice
Mark
I checked SuperCard and SC throws an error too, just like HyperCard. One might argue that this is wrong, but one might also consider it a relatively new development in xTalk language. Pick you choice
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Odd if statement
I could be wrong, but I believe the parser's interpretation of
isif x,y,z = 0 then...
Code: Select all
if "x,y,z" = "0" then...
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: Odd if statement
Mark,
That's what I said.
Mark
That's what I said.
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Odd if statement
Yes, you just didn't explain it well enough to make it readily understandable.
is parsed as
Code: Select all
put 2*2,3*3,0=0
Code: Select all
put "2*2,3*3,0"=0
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: Odd if statement
Mark,
Now you're wrong.
Best,
Mark
Now you're wrong.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Odd if statement
Really? You get something other than "false"?
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: Odd if statement
Mark,
No, but you forget that the items in the list are parsed before the list as a whole. Try this:
This implies that 2*2,3*3,0=0 isn't parsed as "2*2,3*3,0"=0 but as "4,9,0"=0.
Best,
Mark
No, but you forget that the items in the list are parsed before the list as a whole. Try this:
Code: Select all
put 2*2,3*3,(0=0) --> 4,9,true
put 2*2,3*3,0=0 --> false
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Odd if statement
Ah, OK - I see what you're saying now. But it's irrelevant.
The important thing is that there's an rValue and an lValue in the equation, and no matter how the the string in the lValue is evaluated it's never going to satisfy the equality statement unless it really evaluates to zero. And no string with embedded commas is going to do that.
The important thing is that there's an rValue and an lValue in the equation, and no matter how the the string in the lValue is evaluated it's never going to satisfy the equality statement unless it really evaluates to zero. And no string with embedded commas is going to do that.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: Odd if statement
Hi,
It is true that a comma delimited list with more than 1 item will never evaluate to 0 and therefore the equation in the example will never return true, but what about
put 2*2,3*3=4,9
Now, it is suddenly very relevant. Another very interesting feature is the possibility to use functions in the lists on both sides of the equal sign, which allows for testing complex conditions.
Kind regards,
Mark
It is true that a comma delimited list with more than 1 item will never evaluate to 0 and therefore the equation in the example will never return true, but what about
put 2*2,3*3=4,9
Now, it is suddenly very relevant. Another very interesting feature is the possibility to use functions in the lists on both sides of the equal sign, which allows for testing complex conditions.
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Odd if statement
Hmm. Your example evaluates to true, changing the first 2*2 to something else makes it false, my question is.. WHY? This one has me royally stumped, would appreciate an explanation of whats going on behind the scenes so I can get my noggin around this one.
Mark wrote:Hi,
It is true that a comma delimited list with more than 1 item will never evaluate to 0 and therefore the equation in the example will never return true, but what about
put 2*2,3*3=4,9
Now, it is suddenly very relevant. Another very interesting feature is the possibility to use functions in the lists on both sides of the equal sign, which allows for testing complex conditions.
Kind regards,
Mark
Re: Odd if statement
Hi,
LiveCode first parses the items in the list on the left side of the equal sign. The second step is to parse the items in the list on the right side. Third, the list on the left side is parsed as a string and the fourth step is to parse the list on the right side as a string, after which the two strings are compared.
Best regards,
Mark
LiveCode first parses the items in the list on the left side of the equal sign. The second step is to parse the items in the list on the right side. Third, the list on the left side is parsed as a string and the fourth step is to parse the list on the right side as a string, after which the two strings are compared.
Best regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Odd if statement
Ah k, I see it now. left side of the = turns into 4,9, right side is already 4,9. Dunno why I was making it so complicated. Thanks!
2*2,3*3=4,9
2*2,3*3=4,9