Previous Page Next Page Contents

operator -- define a new operator symbol

Introduction

operator(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.

Call(s)

operator(symb, f <, T, prio>)
operator(symb, Delete)

Parameters

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.

Options

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

Returns

the void object of type DOM_NULL.

Side Effects

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.

Details

Option: Prefix

Option: Postfix

Option: Binary

Option: Nary

Example 1

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):

Example 2

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):

Example 3

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):

Background

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000