TSa wrote:
Mark J. Reed wrote:
Anyway, "function" vs "operator" is mostly a difference in terminology

I'm not sure what the defined difference between function and operator
is in Perl 6 but I make a very clear distinction. An operator is acting
an *one* type, that is &op:(::T,T-->T) while a function is a mapping of
different types &f:(::S,::T-->::R). IOW, Operator does Function but not
the converse. So overloading an operator with inhomogenous types should
not change the abstract properties of the operator but be a convenient
form to upgrade the operants.

I consider an operator to be any pure routine whose invocation does not carry any side-effects besides possibly updating the values of some of its arguments; any values that its invocation results in or that any of its arguments are set to is dependent only on the values of its arguments.

There is no restriction on what the types of its parameters or results are; they can be of the same types or different types; eg a pure function to cast a number as a string is an operator.

Whether or not something is an operator has nothing to do with syntax, just semantics. Either a function (which results in a value) or a procedure (which does not) can be an operator. Infix|prefix|postfix|.meth|func() etc does not matter, that is all just syntax. As a trivial case, a procedure with zero parameters either isn't an operator or is a no-op.

Any routine which looks at or manipulates the environment is not an operator.

Most language built-ins would qualify as operators, including all pure functions and ordinary assignment operators.

Built-ins that would not be operators include: print, curr_time, <$*STDIN> etc.

-- Darren Duncan

Reply via email to