### Boolean Operation Evaluation

Posted:

**2019-12-27 17:15:27**Boolean Operation Evaluation

Good People --

I seem to be the only person asking questions these days. Apologies twice for taking so much of your time, because I'm going to start with a lecture.

NisusWriter macros allow two binary Boolean operators, AND (&&) and OR (||). AND is true if both statements it operates on are true; OR is true if either one is true.

If we have two statements, A and B, each of which evaluates as either true or false, it follows that

If A is false, then A && B is false, no matter what the value of B

If A is true, then A || B is true, no matter what the value of B

Here is the reason I bring this up. Different programming languages have different ways of evaluating A && B and A || B. Some programming languages first evaluate both, and only then evaluate the result. Others test A and evaluate from there -- that is, if the statement is A && B, they test A, and if A is false, they return false and don't evaluate B (because they know the result will be false). If the statement is A || B, and A is true, they return true and don't evaluate B.

So my question is, Which one is the NisusWriter macro language? The macro reference does not appear to say. But this

Observe that, if $MyVariable is empty, meaning that $MyVariable.length is equal to zero, the If statement works (goes to the ELSE clause) if the expression $MyVariable.length > 0 is evaluated first, and the AND statement is found to be false, before the expression $MyVariable.characterAtIndex(1) == 'x' is evaluated. But if the two expressions are evaluated simultaneously, before the AND, then the macro bombs out, because $MyVariable.characterAtIndex(1) is undefined.

So does anyone know which evaluation method the macro language uses?

Thanks for any insight. I can write around either version, but I'd like to do things the easier way... whatever it is.

Good People --

I seem to be the only person asking questions these days. Apologies twice for taking so much of your time, because I'm going to start with a lecture.

NisusWriter macros allow two binary Boolean operators, AND (&&) and OR (||). AND is true if both statements it operates on are true; OR is true if either one is true.

If we have two statements, A and B, each of which evaluates as either true or false, it follows that

If A is false, then A && B is false, no matter what the value of B

If A is true, then A || B is true, no matter what the value of B

Here is the reason I bring this up. Different programming languages have different ways of evaluating A && B and A || B. Some programming languages first evaluate both, and only then evaluate the result. Others test A and evaluate from there -- that is, if the statement is A && B, they test A, and if A is false, they return false and don't evaluate B (because they know the result will be false). If the statement is A || B, and A is true, they return true and don't evaluate B.

So my question is, Which one is the NisusWriter macro language? The macro reference does not appear to say. But this

**matters**. Here's a real world example (a simplified version of what I'm working on)Code: Select all

```
If ( $MyVariable.length > 0 ) && ( $MyVariable.characterAtIndex(1) == 'x' )
Prompt "You xxed it!"
Else
Prompt "You must supply an answer"
End If
```

So does anyone know which evaluation method the macro language uses?

Thanks for any insight. I can write around either version, but I'd like to do things the easier way... whatever it is.