The "it" variable
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
The "it" variable
Another dumb question - I tried searching but "it" is used in almost every message...
If I set the IDE for "Strict Compilation" LC (both 5.5.5 Commercial and 6.6.2 Community in Win7) is rejecting use of the "it" variable. Is that normal behavior? I don't remember having to declare "it" before and wonder if I have screwed the IDE up somehow.
Thanks, Walt
If I set the IDE for "Strict Compilation" LC (both 5.5.5 Commercial and 6.6.2 Community in Win7) is rejecting use of the "it" variable. Is that normal behavior? I don't remember having to declare "it" before and wonder if I have screwed the IDE up somehow.
Thanks, Walt
Walt Brown
Omnis traductor traditor
Omnis traductor traditor
Re: The "it" variable
I knew that "Strict compilation mode" force you to declare all variables before using them... 
Did you read this http://www.runrevplanet.com/index.php?o ... &Itemid=65 ?

Did you read this http://www.runrevplanet.com/index.php?o ... &Itemid=65 ?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: The "it" variable
Walt- you shouldn't have to declare "it", no matter whether Strict Compilation is enabled or not. The problem is more that the engine has a very strict set of rules as to when "it" should be valid, and these are not always correct. If you try to reference the it variable after a call to a function, then the engine expects the function to return something in "it". If you execute a command you can have something in the it variable, but the engine doesn't always know this at compile time, so it flags an error in strict compilation mode. This is a bug in the engine - there's nothing wrong with your code.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: The "it" variable
Thanks Max, I agree, I try to always have Strict Compilation turned on - I wish I had that in my Fortran days with it's implied typing. Luckily I was not programming rocket guidance... 
Thanks Mark, at least it was not indicative of my having broken something. I had previously only looked at "it" after reading the Dictionary, but when I am exploring a mystery I sometimes look at everything possible. That tells me that when this happens (and it is usually in a very short snippet) my "function under test" does nothing with "it". My assumption was that the "it" variable would always be a declared variable, it just might be empty, which is how the engine should deal with it. The Dictionary entry for "It" does list the functions that use it...

Thanks Mark, at least it was not indicative of my having broken something. I had previously only looked at "it" after reading the Dictionary, but when I am exploring a mystery I sometimes look at everything possible. That tells me that when this happens (and it is usually in a very short snippet) my "function under test" does nothing with "it". My assumption was that the "it" variable would always be a declared variable, it just might be empty, which is how the engine should deal with it. The Dictionary entry for "It" does list the functions that use it...
Walt Brown
Omnis traductor traditor
Omnis traductor traditor
Re: The "it" variable
Walt- if you create a function and return something:
the returned value will be in the "it" variable. Thus you can say
and you'll end up with 42 in myVar.
If you try that with a command instead
you'll get the same thing in the "it" variable but the compiler will reject
unless you disable strictCompilation mode (at least temporarily).
Code: Select all
function basura pValue
return 2 * pValue
end basura
Code: Select all
get basura(21)
put it into myVar
If you try that with a command instead
Code: Select all
command basura pValue
return 2 * pValue
end basura
Code: Select all
basura 21
put it into myVar
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: The "it" variable
I thought the reason "it" contains the function value is because the example you gave uses "get", which always puts things into "it". Not true? Also, it's always been the case that when calling a function from a command handler, the value is placed in "the result". I didn't know it actually went into "it".
Not being conversant in C-anything, I believe you. It's just a surprise.
Not being conversant in C-anything, I believe you. It's just a surprise.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: The "it" variable
Jacque- you are, of course, right, and I misspoke there. Wishful thinking on my part, as I'm constantly wanting to return values in "it" for consistency, and error values in the result.
Walt- sorry for misleading you there. Jacque is spot on about commands.
Walt- sorry for misleading you there. Jacque is spot on about commands.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: The "it" variable
When two such experienced experts as you two (and myself) get confused about the details of things like "it" and "the result", maybe it's time for a re-think on both.
For starters, why two?
And why is "the result" sometimes used for error info, but other times used for data?
Why not have an error() function to compliment the existing sysError(), and take error-handling away from these.
If that were done, then what do we do to provide anticipatable consistency between "it" and "the result"? Do we really need both? What is the rule that distinguishes them? Or was this just another one of those moments where the HyperCard team's proximity to Humbolt shows itself?
For starters, why two?
And why is "the result" sometimes used for error info, but other times used for data?
Why not have an error() function to compliment the existing sysError(), and take error-handling away from these.
If that were done, then what do we do to provide anticipatable consistency between "it" and "the result"? Do we really need both? What is the rule that distinguishes them? Or was this just another one of those moments where the HyperCard team's proximity to Humbolt shows itself?

Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: The "it" variable
It's even worse with the dispatch statement:
I remember venting about this being backward at the time we introduced the dispatch command, but the word from the team was that returning a value in "the result" brought the dispatch statement into conformance with other commands.
At any rate, I think we're dug too deeply into that hole to bring any sanity into the picture.
Code: Select all
dispatch function "getValue" to button 2 with tParam
put the result into tValueReturnedFromFunction
put it into tHandledStatus
At any rate, I think we're dug too deeply into that hole to bring any sanity into the picture.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev