The "it" variable

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

The "it" variable

Post by WaltBrown » Fri Aug 08, 2014 3:16 pm

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
Walt Brown
Omnis traductor traditor

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: The "it" variable

Post by MaxV » Fri Aug 08, 2014 3:57 pm

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 ?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: The "it" variable

Post by mwieder » Fri Aug 08, 2014 5:30 pm

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.

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: The "it" variable

Post by WaltBrown » Sat Aug 09, 2014 1:44 am

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...
Walt Brown
Omnis traductor traditor

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: The "it" variable

Post by mwieder » Sat Aug 09, 2014 2:33 am

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

Code: Select all

get basura(21)
put it into myVar
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

Code: Select all

basura 21
put it into myVar
unless you disable strictCompilation mode (at least temporarily).

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: The "it" variable

Post by jacque » Sat Aug 09, 2014 5:05 am

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: The "it" variable

Post by mwieder » Sun Aug 10, 2014 2:59 am

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: The "it" variable

Post by FourthWorld » Sun Aug 10, 2014 3:09 am

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? ;)
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: The "it" variable

Post by mwieder » Sun Aug 10, 2014 3:58 am

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.

Post Reply