is evaluation order defined, and evaluation of conditionals

Jerry Jensen jhj at jhj.com
Mon Jun 25 23:27:52 EDT 2012


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






More information about the Use-livecode mailing list