M has both unary and binary operators.
&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.
GTM>WRITE '0 1 GTM>WRITE '1 0 GTM>WRITE '5689 0 GTM>WRITE '-1 0 GTM>WRITE '"ABC" 1 GTM>
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.
_binary operator causes M to concatenate the second expression with the first expresion
GTM>WRITE "B"_"A" BA GTM>WRITE "A"_1 A1 GTM>
>binary arithmetic greater than
Other numeric relations are formed using the logical NOT operator apostrophe (') as follows:
'> not greater than, that is, less than or equal to
'< not less than, that is, greater than or equal to
>= greater than or equal to, that is, not less than
<= less than or equal to, that is, not greater than
'= not equal, numeric or string operation
GTM>WRITE 1>2 0 GTM>WRITE 1<2 1 GTM>
The above example demonstrates the basic arithmetic relational operations.
GTM>WRITE 1'<2 0 GTM>WRITE 2'<1 1 GTM>
= binary operator causes M to produce a TRUE if the expressions are equal.
Other string relations are formed using the logical NOT operator apostrophe (') as follows:
'] does not follow, that is, lexically less than or equal to.
'= not equal, numeric or string operation.
GTM>WRITE "A"="B" 0 GTM>WRITE "C"="C" 1 GTM>WRITE "A"["B" 0 GTM>WRITE "ABC"["C" 1 GTM>WRITE "A"]"B" 0 GTM>WRITE "B"]"A" 1 GTM>WRITE "A"]]"B" 0 GTM>WRITE "B"]]"A" 1
These examples demonstrate the string relational operators using string literals.
GTM>WRITE 2]10 1 GTM>WRITE 2]]10 0 GTM>WRITE 0]"$" 1 GTM>WRITE 0]]"$" 0
GTM>WRITE 1=1 1 GTM>WRITE 1=2 0 GTM>WRITE 1="1" 1 GTM>WRITE 1=01 1 GTM>WRITE 1="01" 0 GTM>WRITE 1=+"01" 1 GTM>
GTM>WRITE "a"'="A" 1 GTM>WRITE "FRED"'["RED" 0 GTM>WRITE "ABC"']"" 0
These examples demonstrate combinations of the string relational operators with the NOT operator.
Patterns are made up of two elements:
A alphabetic characters upper or lower case
C control characters ASCII 0-31 and 127
L lower-case alphabetic characters, ASCII 97-122
P punctuation, ASCII 32-47, 58-64, 91-96, 123-126
U upper-case alphabetic characters, ASCII 65-90
Pattern codes may be upper or lower case and may be replaced with a string literal. GT.M allows the M pattern match definition of patcodes A, C, N, U, L, and P to be extended or changed, (A can only be modified implicitly by modifying L or U) and new patcodes added. For detailed information on enabling this functionality, see ChapterA 12: a??Internationalizationa??.
![]() | Note |
---|---|
The GT.M compiler accepts pattern codes other than those explicitly defined above. If, at run-time, the pattern codes come into use and no pattern definitions are available, GT.M issues a run-time error (PATNOTFOUND). GT.M does not currently implement a mechanism for Y and Z patterns and continues to treat those as compile-time syntax errors. GT.M defers literal optimizations involving patterns within an XECUTE as well as evaluations that encounter issues with the pattern table. |
Example:
GTM>WRITE "ABC"?3U 1 GTM>WRITE "123-45-6789"?3N1"-"2N1"-"4N 1
The first WRITE has a simple one-element pattern while the second has multiple elements including both codes and string literals. All the repetition counts are fixed.
Example:
I x?.E1C.E W !,"Must not contain a control character" Q
This example uses a pattern match to test for control characters.
Example:
I acn?1U.20A1","1U.10A D .S acn=$G((^ACX($P(acn,","),$P(acn,",",2)))
This example uses a pattern match with implicit minimums to determine that an "account number" is actually a name, and to trigger a look-up of the corresponding account number in the ^ACX cross index.
The pattern match operator accepts the alteration syntax. Alteration consists of a repeat count followed by a comma-delimited list of patatoms enclosed in parentheses "()". The semantic is that the pattern matches if any of the listed patterns matches the operand string. For example, ?1(2N1"-"7N,3N1"-"2N1"-"4N).1U might be a way to match either a social security number or a taxpayer ID. Since alternation is defined as one of the ways of constructing a patatom, alternation can nest (be used recursively).
![]() | Note |
---|---|
Complex pattern matches may not be efficient to evaluate, so every effort should be made to simplify any commonly used pattern and to determine if more efficient alternative logic would be more appropriate. |