Evaluation of complex conditions
pete at mollysrevenge.com
Thu Oct 6 17:13:12 EDT 2011
Thanks Graham. Yes, someone else provided an example of the function you
mentioned to illustrate how things work. But I cannot reproduce the
behavior mentioned when conditions are enclosed in parens - the order of
evaluation doesn't seem to be affected.
I wrote a couple of functions (condition1 and condition2), each of which
puts its identity after a script variable named myResult then returns true.
I then wrote the following:
put empty into myResult
if condition1() is true and condition2() is true then put myResult
As expected, this displayed 12 in the message box.
Then I changed the if statement to :
if condition1() is true and (condition2() is true) then put myResult
The message box still ended up with 12 in it, not 21 as you would expect if
the parens had any effect. Maybe I'm misunderstanding something but it
doesn't seem like parens have any effect on the order of evaluation.
Molly's Revenge <http://www.mollysrevenge.com>
On Thu, Oct 6, 2011 at 1:01 PM, Graham Samuel <livfoss at mac.com> wrote:
> Yes, in any 'and' where the first condition is false, then the second
> condition is not evaluated; similarly in any 'or', if the first condition is
> true, the second isn't evaluated. Parentheses alter the order of evaluation
> as others have said.
> It's easy to prove this by writing a script where the thing generating your
> condition ('a' in your example) is a function - you can then make the
> function have a side effect. As sample function might be
> function ReturnsTrue
> put "condition returning true has been invoked;" after whatHappened
> return true
> end ReturnsTrue
> you then write an 'if' statement which at some point in the logic calls
> ReturnsTrue(), and when you look at the global 'whatHappened' you will see
> whether the evaluation reached that point or not...
> On 5 October 2011 16:25, Pete <pete at mollysrevenge.com> wrote:
> > No, I mean:
> > If a is true then
> > if (b is true or c is true) then
> > do whatever
> > end if
> > end if
> > I'm pretty sure if a was false, the second condition wouldn't be
> > But you raise an interesting point - in your example, does the condition
> > inside the parens truly get evaluated first?
> > Pete
> > Molly's Revenge <http://www.mollysrevenge.com>
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
More information about the Use-livecode