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

*From*: Lie Ryan <lie.1296@xxxxxxxxx>*Date*: Thu, 13 May 2010 04:43:17 +1000

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

"Lie Ryan" <lie.1296@xxxxxxxxx> wrote in message

news:4bea5a56$1@xxxxxxxxxxxxxxxxxxxx

On 05/10/10 18:12, Jussi Piitulainen wrote:

Yes, I have trouble thinking up any naturally ternary operations. AsAnything 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).

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

value;

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

.

**Follow-Ups**:**Re: Converting from 0 and 1 to -1 and 1***From:*bart.c

**Re: Converting from 0 and 1 to -1 and 1***From:*Jussi Piitulainen

**References**:**Converting from 0 and 1 to -1 and 1***From:*Ikke

**Re: Converting from 0 and 1 to -1 and 1***From:*Keith Thompson

**Re: Converting from 0 and 1 to -1 and 1***From:*Jussi Piitulainen

**Re: Converting from 0 and 1 to -1 and 1***From:*bart.c

**Re: Converting from 0 and 1 to -1 and 1***From:*Jussi Piitulainen

**Re: Converting from 0 and 1 to -1 and 1***From:*Lie Ryan

**Re: Converting from 0 and 1 to -1 and 1***From:*bart.c

- Prev by Date:
**Re: Converting from 0 and 1 to -1 and 1** - Next by Date:
**Re: Converting from 0 and 1 to -1 and 1** - Previous by thread:
**Re: Converting from 0 and 1 to -1 and 1** - Next by thread:
**Re: Converting from 0 and 1 to -1 and 1** - Index(es):