There are two types of operators defined in the SNOBOL4 language. These are prefix, unary operators and infix, binary operators. Unary operators are higher in precedence than any binary operator. Binary operators have the associativity and precedence indicated in the following figure:
|OP||Definition as unary operator||Definition as binary operator||Binary association||Binary precedence|
|$||indirect reference||immediate assignment||left||11|
|%||not defined||not defined||left||9|
|#||not defined||not defined||left||6|
|@||cursor position||not defined||left||4|
concatenation (blank) binary operator concatenates the string on the left with the one on the right and returns the resulting string. Concatenation is indicated with no intervening operator except for a blank. See the SNOBOL4 syntax summary for statement syntax, because a blank does not always mean concatenation.
conditional assignment . binary operator assigns the portion of the subject string successfully matched by the pattern left of the operator, to the variable on the right, only if the entire pattern match succeeds. For example, the following replaces the first integer in string Q by 3 times its value:
cursor position @ unary operator stores the current pattern matching cursor position into the argument variable when encountered during pattern matching. Cursor position zero is just before the leftmost character of the subject string.
exponentiation (^ or ! or **) binary operator is used to perform ordinary exponentiation. Note that this operator is right associative which means that the value of 2 ** 3 ** 3 will be 134217728 and not 512.
immediate assignment $ binary operator assigns the portion of the subject string successfully matched by the pattern left of the operator, to the variable on the right, each time the operator is encountered. For example, the following statement will print all initial substrings of the string Q:
Note that if &FULLSCAN is set to 1, the above will print all substrings of Q.
indirect reference $ unary operator takes a string or name data type as an argument and returns a variable with the name specified by the argument. Indirect reference is the inverse of the name operator.
interrogation ? unary operator is used to test whether an expression evaluation succeeds or not. If the expression succeeds, then the ? prefix will succeed and return the null string. If the expression fails, the ? prefix will fail. The interrogation operator is the inverse of the negation operator ~.
keyword & unary operator is used in front of a variable name to indicate a reference to the keyword and not the natural variable. See the keywords section for a description of all of the SNOBOL4 keywords.
name . unary operator returns the name of a variable. In the case of a natural variable it returns a string which is the name of the variable. In the case of a created variable, it returns the NAME data type which refers to that variable. The name operator is the inverse of the indirect reference operator $. See the indirect reference unary operator, NRETURN token and the NAME data type descriptions for more information.
negation ~ unary operator is used to test whether an expression evaluation fails or not. If the expression fails, then the ~ prefix will succeed and return the null string. If the expression succeeds, the ~ prefix will fail. The negation operator can be used to complement predicate functions. For example there is a lexically greater than function but not the inverse. "LLE(a,b)" can be obtained with ~LGT(a,b). Note that the original SNOBOL4 language manual uses the character '¬' instead of '~' for the negation operator.
negative - unary operator is used to obtain the additive inverse of a numeric value (integer or real). Note that strings which contain numeric values are automatically converted to numeric type first.
positive + unary operator is the inverse of the negative unary operator. It simply passes on the numeric value of the argument without change. Note that strings which contain numeric values are automatically converted to numeric type first.
unevaluated expression * unary operator indicates that the argument expression is not to be evaluated until it is encountered in pattern matching or evaluated by the EVAL() function. See the EXPRESSION data type for more information.
Prior Page, Next Page, First Page of the Minnesota SNOBOL4 Reference