From: Jussi Piitulainen on
Pascal J. Bourguignon writes:
....
> Now, the real why is why would anybody try to program anything in
> BrainFuck^W a language that doesn't have "ternary operators"?
....

A related weakness in popular programming languages is that they have
only one. More should be added. Then people would learn to call the
conditional operator "the conditional operator".

Anything vaguely usable with three operands would do. Median of three
numbers. Majority vote of three booleans. I think Church also had
something he called conditional disjunction, which I even looked up
but then forgot, so I'm not sure now if its ternary.

Maybe we could have a form of Kronecker delta that evaluates to the
third argument if the first and second are equal, and otherwise
evaluates to zero. Say x!y:z == ((x == y) ? z : 0). Then yet another
solution to the present problem would be this:

x!0:-1 + x!1:1
From: Ben Bacarisse on
Jussi Piitulainen <jpiitula(a)ling.helsinki.fi> writes:

> Pascal J. Bourguignon writes:
> ...
>> Now, the real why is why would anybody try to program anything in
>> BrainFuck^W a language that doesn't have "ternary operators"?
> ...
>
> A related weakness in popular programming languages is that they have
> only one. More should be added. Then people would learn to call the
> conditional operator "the conditional operator".

In a similar vein, there is no reason why a conditional operator should
be limited to being ternary, as Pascal's language of choice (along with
several others) makes clear.

> Anything vaguely usable with three operands would do. Median of three
> numbers. Majority vote of three booleans. I think Church also had
> something he called conditional disjunction, which I even looked up
> but then forgot, so I'm not sure now if its ternary.

It is ternary, but it is essentially the same as ?: when limited to
truth-values and written in what is now thought of as an odd order:
[p,q,r] means q?p:r when p, q and r are all true/false. (Thanks for
prompting me to look this up.)

--
Ben.
From: pete on
Ben Bacarisse wrote:
>
> Jussi Piitulainen <jpiitula(a)ling.helsinki.fi> writes:
>
> > Pascal J. Bourguignon writes:
> > ...
> >> Now, the real why is why would anybody try to program anything in
> >> BrainFuck^W a language that doesn't have "ternary operators"?
> > ...
> >
> > A related weakness in popular programming
> > languages is that they have
> > only one. More should be added. Then people would learn to call the
> > conditional operator "the conditional operator".
>
> In a similar vein, there is no reason why
> a conditional operator should
> be limited to being ternary,
> as Pascal's language of choice (along with
> several others) makes clear.
>
> > Anything vaguely usable with three operands would do.
> > Median of three
> > numbers. Majority vote of three booleans. I think Church also had
> > something he called conditional disjunction, which I even looked up
> > but then forgot, so I'm not sure now if its ternary.
>
> It is ternary, but it is essentially the same as ?: when limited to
> truth-values and written in what is now thought of as an odd order:
> [p,q,r] means q?p:r when p, q and r are all true/false. (Thanks for
> prompting me to look this up.)

I think the point that Jussi Piitulainen is making,
is that operators should be named by what they do;
"the ternary operator" is a bad name.

If C were to be changed so that the only binary operator
were the assignment operator, then it should still be called
"the assignment operator" and not be called "the binary operator".

--
pete
From: bart.c on

"Jussi Piitulainen" <jpiitula(a)ling.helsinki.fi> wrote in message
news:qotzl0ahp7j.fsf(a)ruuvi.it.helsinki.fi...
> Pascal J. Bourguignon writes:
> ...
>> Now, the real why is why would anybody try to program anything in
>> BrainFuck^W a language that doesn't have "ternary operators"?
> ...
>
> A related weakness in popular programming languages is that they have
> only one. More should be added. Then people would learn to call the
> conditional operator "the conditional operator".

Maybe there should be none. The C-style a?b:c operator has a rather odd
syntax, but it just does the same thing as: if a then b else c fi (where a
language allows this as an expression), or (a|b|c).

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

Sometimes, multiple ordinary operators can be combined in a special way:
a<=b=c<d returns true or false (but I'm not sure what category you'd put
that in: is a<b<c a ternary operation?).

--
Bartc

From: Ben Bacarisse on
pete <pfiland(a)mindspring.com> writes:

> Ben Bacarisse wrote:
>>
>> Jussi Piitulainen <jpiitula(a)ling.helsinki.fi> writes:
>>
>> > Pascal J. Bourguignon writes:
>> > ...
>> >> Now, the real why is why would anybody try to program anything in
>> >> BrainFuck^W a language that doesn't have "ternary operators"?
>> > ...
>> >
>> > A related weakness in popular programming
>> > languages is that they have
>> > only one. More should be added. Then people would learn to call the
>> > conditional operator "the conditional operator".
>>
>> In a similar vein, there is no reason why
>> a conditional operator should
>> be limited to being ternary,
>> as Pascal's language of choice (along with
>> several others) makes clear.
<snip>
> I think the point that Jussi Piitulainen is making,
> is that operators should be named by what they do;
> "the ternary operator" is a bad name.

Yes, I got that. I was extending the complaint by saying that the
conditional operator need not be ternary. There are two reasons why
it's the wrong name. I was giving the other one.

[To be fail (since this has gone way over budget for such a small
matter) I don't think Pascal was using the term "ternary operator" as a
name for the conditional operator. His remark seems to say no more than
that a language without ternary operators probably has no conditional
operator.]

<snip>
--
Ben.