Operators

Standard Leibniz operators are defined by a name that consists of any sequence of characters satisfying the predicate Character>>#isLzIdentifierCharacter

isLzIdentifierCharacter
	^ self isLetter "Unicode categories Ll Lm Lo Lt Lu"
		or: [ ('-*/☰' includes: self)
		or: [ self isMathSymbol "Unicode category Sm"
		or: [ self isCurrencySymbol "Unicode category Sc"
		or: [ (self isModifierSymbol "Unicode category Sk"
					and: [ ('^' includes: self) not ])
		or: [ self isOtherSymbol "Unicode category So" ] ] ] ] ]
.

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 example s, we can define

a no-argument operator example noArg : s

a prefix operator example prefix(s, s) : s (any number of arguments)

an infix operator example s infix s : s (exactly two arguments)

the bracket operators
example s[s] : s
example s[s, s] : s
etc. (any number of arguments between the brackets)

the superscript operators
example ss : s
example ss, s : s
etc. (any number of superscript arguments)

the subscript operators
example ss : s
example ss, s : s
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