Logical Operators

M logical operators always produce a result that is TRUE (1) or FALSE (0). All logical operators force M to evaluate the expressions to which they apply as truth-valued. The logical operators are:

' unary NOT operator negates current truth-value; M accepts placement of the NOT operator next to a relational operator, for example, A'=B as meaning '(A=B).

&binary AND operator produces a true result only if both of the expressions are true.

! binary OR operator produces a true result if either of the expressions is true.

Remember that precedence is always left to right, and that logical operators have the same precedence as all other operators.

Example:

        GTM>WRITE '0
        1
        GTM>WRITE '1
        0
        GTM>WRITE '5689
        0
        GTM>WRITE '-1
        0
        GTM>WRITE '"ABC"
        1
        GTM>
        

The above example demonstrates the unary NOT operation. Note that any non-zero numeric value is true and has a false negation.

Example:

        GTM>WRITE 0&0
        0
        GTM>WRITE 1&0
        0
        GTM>WRITE 0&1
        0
        GTM>WRITE 1&1
        1
        GTM>WRITE 2&1
        1
        GTM>WRITE 0!0
        0
        GTM>WRITE 1!0
        1
        GTM>WRITE 0!1
        1
        GTM>WRITE 1!1
        1
        GTM>WRITE 2!1
        1
        GTM>
        

The above example demonstrates all cases covered by the binary logical operators.