Clearing local variables

Mark Waddingham mark at livecode.com
Thu Apr 28 11:47:15 EDT 2016


On 2016-04-28 03:31, Kay C Lan wrote:
> If you do not understand what isn't 'variable' and what really gets 
> checked
> at each iteration for each style of repeat then you are likely to see 
> some
> unexpected results. On the other hand, if do understand what is really
> going on, then you can modify x to your advantage in either case. As 
> for
> tVar in the 'repeat for each' case, I believe Mark Waddingham has 
> cautioned
> that although your scripts might currently work if you modify tVar mid
> repeat, LC is NOT guaranteed to behave the same way in the future.

Prior to 7.0 modifying the target variable inside a repeat for each 
would cause undefined behavior. i.e.

   repeat for each item tItem in tList
     delete any char of tList
   end repeat

Was always a really bad idea.

 From 7.0 onwards, this causes no problem as the engine takes a 'copy' of 
the target variable at the start of the loop. (Note you only pay for 
that copy when you mutate tList subsequently, and that mutation has no 
effect on the repeat for each loop being performed).

Warmest Regards,

Mark.

-- 
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps




More information about the Use-livecode mailing list