Operators
Standard Leibniz operators are defined by a name that consists of any sequence of characters satisfying the predicate Character>>#isLzIdentifierCharacter
.
The number and sorts of the arguments of an operator is part of its definition. Two operators with the same name but a different number of arguments, or arguments of different sorts, are distinct. Note that "different sorts" really means "sorts belonging to different kinds ", see Sorts for the details.
An operator without arguments is written as just its name.
Prefix operators are written like mathematical functions, i.e. the operator name is followed by the arguments in parentheses.
Infix operators have exactly two arguments, with the name written between the arguments from which it is separated by white space. Unlike most programming languages, Leibniz has no precedence rules for infix operatos (such as "multiplication before addition"). In a chain of multiple infix operators, parentheses must be written to indicate the order of application. The one exception is that chains of multiple instances of
a single
infix operator are permitted, and interpreted as grouped from left to right. The term 2 + 3 + 4
is thus allowed and equivalent to (2 + 3) + 4
.
In addition to the standard operators there are three special operators that provide a syntax familiar from mathematical notation or from programming languages: the bracket operator, the superscript operator, and the subscript operator. See below for examples. Superscript and subscript are rendered typographically.
Each operator definition ends with a sort, which is the operator's value sort . This sort becomes the sort of each term that refers to the operator.
Example
Given the sort
a no-argument operator
a prefix operator
an infix operator
the bracket operators
etc. (any number of arguments between the brackets)
the superscript operators
etc. (any number of superscript arguments)
the subscript operators
etc. (any number of subscript arguments)
See Terms for examples of terms using these operators. You can also look at the list of operators defined on this page by running the following code snippet:
(LzGlobalCache uniqueInstance subcontext: 'example' for: 'Operators') signature operators