From: Jussi Piitulainen on 10 May 2010 04:12 bart.c writes: > "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). Yes, I agree about the syntax. Incidentally, Kernighan and Richie index has an entry for "conditional expression" and nothing for "ternary" anything. I think Java Language Specification also calls it "conditional". So I'd be happier if people just followed authorities in this matter, but they don't. > > 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. > 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?). Those cannot be introduced into languages like C or Java where these expressions already have a different meaning, useless but established. They would not be naturally ternary either. I'd say syntactically it is something like a chain of binary operators. Python has these but I don't remember what terminology is used. Not "ternary" anyway.
From: Jussi Piitulainen on 10 May 2010 04:34 Ben Bacarisse writes: > pete writes: .... > > 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. I think McCarthy used (c0 -> e0 ; c1 -> e1 ; ... ; T -> d). That could be seen as a chain of ternary (c -> e ; f) expressions instead of a single multibranching conditional expression, but the multibranching view is natural and perhaps historically more original. Lisps have both now. > [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.] He used quotes around the term, and I took these to be the so called scare quotes. I just went off on a tangent.
From: Lie Ryan on 12 May 2010 03:34 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 all the unary, binary, ternary operator can be thought a syntax sugar for calling functions (some gotcha: laziness). btw, is there any language that have zero-ary operator? otherise we should go one, two, many not zero, one, two, many...
From: Pascal J. Bourguignon on 12 May 2010 03:47 Lie Ryan <lie.1296(a)gmail.com> writes: > 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 > > all the unary, binary, ternary operator can be thought a syntax sugar > for calling functions (some gotcha: laziness). > > > btw, is there any language that have zero-ary operator? otherise we > should go one, two, many not zero, one, two, many... Sure. Constants are zero-ary operators. Well actually if you want to include variables in the equation, you need to involve time as a hidden parameter, so constants are 0-ary, variables 1-ary, and you need to add 1 arity to each function and method that are not purely functional. -- __Pascal Bourguignon__
From: Jussi Piitulainen on 12 May 2010 04:23
Lie Ryan writes: > 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 Not in the minds of the people who succesfully speak of ?: as "the ternary operator". Not in my mind either, but that doesn't matter. > all the unary, binary, ternary operator can be thought a syntax > sugar for calling functions (some gotcha: laziness). That is a good way to think about many of them. Others do not evaluate all their operands, so cannot be thought of as functions in a language where function calls do that. Assignment operators are another special kind. |