Page 1 of 1
The "it" variable
Posted: Fri Aug 08, 2014 3:16 pm
by WaltBrown
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
Re: The "it" variable
Posted: Fri Aug 08, 2014 3:57 pm
by MaxV
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 ?
Re: The "it" variable
Posted: Fri Aug 08, 2014 5:30 pm
by mwieder
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.
Re: The "it" variable
Posted: Sat Aug 09, 2014 1:44 am
by WaltBrown
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...
Re: The "it" variable
Posted: Sat Aug 09, 2014 2:33 am
by mwieder
Walt- if you create a function and return something:
Code: Select all
function basura pValue
return 2 * pValue
end basura
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
Code: Select all
command basura pValue
return 2 * pValue
end basura
you'll get the same thing in the "it" variable but the compiler will reject
unless you disable strictCompilation mode (at least temporarily).
Re: The "it" variable
Posted: Sat Aug 09, 2014 5:05 am
by jacque
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.
Re: The "it" variable
Posted: Sun Aug 10, 2014 2:59 am
by mwieder
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.
Re: The "it" variable
Posted: Sun Aug 10, 2014 3:09 am
by FourthWorld
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?

Re: The "it" variable
Posted: Sun Aug 10, 2014 3:58 am
by mwieder
It's even worse with the dispatch statement:
Code: Select all
dispatch function "getValue" to button 2 with tParam
put the result into tValueReturnedFromFunction
put it into tHandledStatus
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.