is it true ?

Jeanne A. E. DeVoto revolution at jaedworks.com
Wed May 18 22:40:19 EDT 2005


At 6:59 PM +0100 5/18/05, Alex Tweedly wrote:
>jbv wrote:
>>Rev would drop the evaluation as soon as a false is encountered, hence
>>speeding up
>>the execution of the script...
>>
>>Is that true, or did I dream ?
>>
>Yes, it's true - quoted from Scott Raney on the MC list; conditional 
>evaluation ceases as soon as the result can be determined.

It's also documented:

   Note: Transcript uses what is known as "short-circuit evaluation" 
for logical operators. This means that value1 is evaluated first. If 
value1 is false, the expression value1 and value2 is false regardless 
of what value2 is (because the expression evaluates to false unless 
both the values are true). In this case, Revolution does not evaluate 
value2, since doing so is not necessary to determine the value of 
value1 and value2. For example, evaluating the expression asin(2) 
normally causes an execution error (because 2 is not a legal argument 
for the arc sine function), but evaluating the expression (1 = 0) and 
(asin(2) = 1) does not cause an error:  since (1 = 1) is always 
false, the whole statement is always false and Revolution never tries 
to evaluate the asin function.

(This is under "and" and "or", and probably at least the first part 
should be included in "if" as well.)


>I don't know whether his statement covered switch condition 
>evaluation or not - I would expect it does, but would verify that by 
>testing before depending on it.

It's done any time an expression with a binary boolean operator is 
encountered, regardless of context. So it works in a switch or if or 
anywhere else, e.g.:

   put (1 = 0) and (asin(2) = 1) into foo

puts false into foo without running the faulty asin.
-- 
jeanne a. e. devoto ~ revolution at jaedworks.com
http://www.jaedworks.com


More information about the use-livecode mailing list