Re: Converting from 0 and 1 to -1 and 1

On 05/12/10 22:24, bart.c wrote:

"Lie Ryan" <lie.1296@xxxxxxxxx> wrote in message
On 05/10/10 18:12, Jussi Piitulainen wrote:
Anything vaguely usable with three operands would do. Median of
three numbers. Majority vote of three booleans.

Many of these are just special cases of N-operand operators. The
challenge is an operator syntax that allows an arbitrary number of
operands (and which doesn't look like a single operand which happens
to be a list, although that is another way of doing it).
Yes, I have trouble thinking up any naturally ternary operations. As
soon as the notation has brackets and a comma in it, it is natural to
extend the number of operands arbitrarily. We do zero, one, two, many.

Think again: function call is an N-ary operator

I think C calls "()" an operator, but that's C.

Whether C or <insert some language> considers function call an operator
or not, it doesn't matter. We're not talking about a real language which
always have syntactical limitations artificially imposed by the language
design or practicality of implementation or taste.

all the unary, binary, ternary operator can be thought a syntax sugar
for calling functions (some gotcha: laziness).

Operators and functions tend to be different, although functions might be
used to implement operators.

Conceptually, there is no difference between function and operator.
Their difference is just syntactical.

Certainly in the languages I'm involved with, operators are completely
different to functions:

Operators have a fixed number of 1 or 2 operands, and always return a
there is a fixed number of operator names/symbols, while function names are
unlimited, and can be exist in namespaces; the operator name/symbol is not
itself considered an operand (as in C's () operator), and it's not possible
to have a pointer to an operator; and operator operands fully support
overloading, as in most languages.

those are just syntactical limitations, they're irrelevant.

And there are the obvious syntax differences: operator operands don't need
parentheses, tend to use infix notation and so on.

also syntactical, irrelevant

given a language with no syntactical limitations, operator is the same
as function call and function call is the same as operator. function
call is an N-ary operator, binary operator is a function call with two
arguments, there is no way to distinguish one from the other.

things like ability to pass around function or operator as argument is
just syntactical limitations, who says you can't design a language that
allows you to write: reduce(+, [3, 4, 2])

Relevant Pages

  • Re: compare a large number of variables
    ... do you think that this confusion might be avoided by ... the "false" value and the case where both operands have that value. ... and it's hard to see how any language ... In APL and its relatives, you can apply the equality operator across ...
  • Re: Converting from 0 and 1 to -1 and 1
    ... natural to extend the number of operands arbitrarily. ... so cannot be thought of as functions in a language ... in languages that doesn't support pointer, then it can be thought as: ...
  • Re: Converting from 0 and 1 to -1 and 1
    ... extend the number of operands arbitrarily. ... in Haskell, function call is binary, which is a kind of N-ary. ... In pure language, a function that takes 1 argument is 1-ary ... In impure language, all functions just takes, as Pascal also pointed ...
  • Re: assignment to overloaded operator <<
    ... > As long as it is intuitive to the user, who cares what it does? ... One is that the language is designed to disallow operators that do not ... still be used in an assignment. ... Again, nothing requires that operators do not change any of their operands, ...