operator
-- define a new
operator symboloperator
(symb, f, T, prio)
defines a new
operator symbol symb
of type T
with priority
prio
. The function f
evaluates expressions
using the new operator.
operator
(symb, Delete)
removes the definition of the operator
symbol symb
.
operator(symb, f <, T, prio>)
operator(symb, Delete)
symb |
- | the operator symbol: a character string. |
f |
- | the function evaluating expressions using the operator. |
T |
- | the type of the operator: one of the options Prefix, Postfix, Binary or Nary. The default is Nary. |
prio |
- | the priority of the operator: an integer between 1 and 1999. The default is 1300. |
Prefix |
- | the operator is a unary operator with prefix notation |
Postfix |
- | the operator is a unary operator with postfix notation |
Binary |
- | the operator is a non-associative binary operator with infix notation |
Nary |
- | the operator is an associative binary operator with infix notation |
Delete |
- | the operator with symbol symb is
deleted |
the void object of type DOM_NULL
.
The new operator symbol symb
is known by the parser and
may be used to enter expressions. The new operator symbol will
not be used when reading files using the function read
with the option Plain.
operator
is used to define new user-defined operator
symbols or to delete them."++"
, say, with evaluating
function f
, the following expressions are built by the
parser, depending on the type of the operator:
++x
results in f(x)
.x++
results in f(x)
.x ++ y ++ z
results in f(f(x, y),
z)
.x ++ y ++ z
results in f(x, y,
z))
.++
and a binary ++
at the same time.symb
:
\
(backslash) character." @"
and "\\/"
are not
allowed. Please note that currently operator
does not
check these restrictions.read
using the option Plain, the new operator is not taken into account. (This
option is used if MuPAD library files are read, because
otherwise user-defined operators could change the meaning of the source
code in an uncontrolled way.)builtin
to
define the text output of expressions. This, however, is not
recommended.)"++"
and the evaluation function
f
, the input ++x
is parsed as the expression
f(x)
."++"
and the evaluation function
f
, the input x++
is parsed as the expression
f(x)
."++"
and the
evaluation function f
, the input x ++ y ++ z
is parsed as the expression f(f(x, y), z)
, i.e. the
operator binds left-to-right."++"
and the
evaluation function f
, the input x ++ y ++ z
is parsed as the expression f(x, y, z)
.This example shows how to define an operator symbol for the logical equivalence:
>> equiv := (a, b) -> (a and b) or (not a and not b): operator("<=>", equiv, Binary, 50):
After this call, the symbol <=>
can
be used to enter expressions:
>> a <=> FALSE, bool(1 < 0 <=> 1 > 0)
not a, FALSE
>> operator("<=>", Delete):
Identifiers may be used as operator symbols:
>> operator("x", _vector_product, Binary, 1000):
>> a x b x c
_vector_product(_vector_product(a, b), c)
>> operator("x", Delete):
This example shows that the scanner tries to match the longest operator symbol:
>> operator("~", F, Prefix, 1000): operator("~>", F1, Prefix, 1000): operator("~~>", F2, Prefix, 1000):
>> ~~ x, ~~> x, ~ ~> x, ~~~> x
F(F(x)), F2(x), F(F1(x)), F(F2(x))
>> operator("~", Delete): operator("~>", Delete): operator("~~>", Delete):