is evaluation order defined, and evaluation of conditionals

Peter M. Brigham pmbrig at gmail.com
Tue Jun 26 10:17:57 EDT 2012


It's also useful if you have a general handler that needs to screen out certain types of objects, eg:

on mousemove
   if word 1 of the target = "field" and the locktext of the target then
      set the defaultcursor to hand
   else
      set the defaultcursor to empty
   end if
end mouseup

If the second condition were not skipped after the first one is found false, then you'd get an error message when moving over a button.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig


On Jun 26, 2012, at 12:25 AM, Mike Bonner wrote:

> Its useful if you have a processor intensive function (say intersect()).
> You can do several bounds checks prior to the intersect, if any of them
> fail the intersect is never done. This was mentioned in the game academy.
> 
> On Mon, Jun 25, 2012 at 10:18 PM, <dunbarx at aol.com> wrote:
> 
>> Jerry.
>> 
>> 
>> Fsscinating example. It seems there is in fact an order to the
>> conditionals, at least as constructed your way. The "false" rendered in the
>> left side seems to (un)satisfy the "and", played out in order. Stepping
>> through shows this clearly.
>> 
>> 
>> Cool. Is this useful?
>> 
>> 
>> Crig Newman
>> 
>> 
>> 
>> -----Original Message-----
>> From: Jerry Jensen <jhj at jhj.com>
>> To: How to use LiveCode <use-livecode at lists.runrev.com>
>> Sent: Mon, Jun 25, 2012 11:29 pm
>> Subject: Re: is evaluation order defined, and evaluation of conditionals
>> 
>> 
>> I'm not Richard, but I'm curious too. Here's an example that may point out
>> his
>> issue:
>> 
>> In a button script, or somewhere . . .
>> 
>> on mouseUp
>>  local tFoo
>>  put func1() and func2() into tFoo
>> end mouseUp
>> 
>> function func1
>> return "false"
>> end func1
>> 
>> function func2
>>    put "func2 was called"
>>    return "true"
>> end func2
>> 
>> In this example, func2() IS NOT called.
>> If func1 returns "true" instead, func2() IS called.
>> 
>> This behavior is guaranteed in the C language, but I don't know about
>> guarantees
>> in LiveCode. In C, similarly if "or" is used instead of "and", if the
>> first part
>> evaluates to "true", the second is NOT called. Again, I dunno about
>> LiveCode.
>> Exercise left to the reader (or somebody who knows!)
>> 
>> .Jerry
>> 
>> On Jun 25, 2012, at 7:47 PM, dunbarx at aol.com wrote:
>> 
>>> Richard.
>>> 
>>> 
>>> The case specifies a boolean "and". The order is unimportant in this
>> example.
>> If either argument is false, the case is ignored. It would not matter
>> which was
>> written first. The same would be true for a boolean "or, in that the order
>> is
>> not pertinent.
>>> 
>>> 
>>> 
>>> In that sense (though it is trivial) if the first condition fails, the
>> second
>> is ignored. I am not sure that this actually takes place internally, as I
>> do not
>> know how the tokens are parsed.
>>> 
>>> 
>>> The ability to specify multiple conditionals, including mixed "and",
>> "or" and
>> "not" types, allows for compact and readable code. But these still stand
>> alone,
>> based entirely on their own logic. Though the order of evaluation is still
>> not
>> important, the construction of mixed conditionals, especially "and" mixed
>> with
>> "or" is critical, and must be written with care. Usually lots of
>> parentheses are
>> required.
>>> 
>>> 
>>> Order of evaluation is intrinsically important in arithmetic
>> expressions, of
>> course.
>>> 
>>> 
>>> 
>>> Can you restate your problem? Or are you just exploring the language?
>>> 
>>> 
>>> Craig Newman
>>> 
>>> 
>>> 
>>> -----Original Message-----
>>> From: Jerry Jensen <jhj at jhj.com>
>>> To: How to use LiveCode <use-livecode at lists.runrev.com>
>>> Sent: Mon, Jun 25, 2012 8:14 pm
>>> Subject: Re: is evaluation order defined, and evaluation of conditionals
>>> 
>>> 
>>> Note that exists() is only sensible for objects. From the dictionary:
>>> "You can also specify a chunk of a container, but in this case the exists
>>> function always returns true."
>>> 
>>> .Jerry
>>> 
>>> On Jun 25, 2012, at 4:17 PM, Dr. Hawkins wrote:
>>> 
>>>> Is the order in which expressions will be evaluated defined int LiveCode
>>>> 
>>>> For example, if I have fields such as live_cats live_dogs and such,
>>>> some but not others of which have corresponding fields dead_cat,
>>>> dead_mouse, etc, can if have a construct that comes to
>>>> 
>>>> switch
>>>> case exists(dead_cat) and  ("bad_smell" is among the words of dead_cat)
>>>> 
>>>> If it is defined that the leftmost expression is evaluated first, and
>>>> the right-hand only if needed to resolve the "and," I would expect
>>>> this to work.
>>>> 
>>>> If it doesn't, though, things get more difficult:  using the exists()
>>>> within the switch throws me down that path, and only down it can I
>>>> check bad_smell.
>>>> 
>>>> --
>>>> The Hawkins Law Firm
>>>> Richard E. Hawkins, Esq.
>>>> (702) 508-8462
>>>> HawkinsLawFirm at gmail.com
>>>> 3025 S. Maryland Parkway
>>>> Suite A
>>>> Las Vegas, NV  89109
>> 
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list