Re: Ternary operator (there's no Trinary operator )
by GrandFather (Saint) on Jul 19, 2006 at 07:15 UTC
|
From The Camel (Programming Perl (Third edition): section 3.16. Conditional Operator):
As in C, ?: is the only trinary operator.
The Camel also comments in the introduction to Chapter 3:
Perl operators come in three arities: unary, binary, and trinary (or ternary, if your native tongue is Shibboleth).
Update: in light of some later replies to the OP perhaps I should note that as Perl has only one terniary/trinary operator, and given The Camel's use of 'trinary', it is reasonable in the context of Perl to refer to the conditional operator ?: as 'the trinary operator'. This may not be "correct" in a wider sense, but is certinally fitting in a Perl context. :)
DWIM is Perl's answer to Gödel
| [reply] |
|
Heh. Just because it's in the Camel book doesn't mean it's right!
I started writing C code over 20 years ago and as far as I can recall, I have never heard it called anything else than the ternary operator outside Perl. I've lost my copies of K&R, both editions 1 and 2, so I can't look it up. Stroustrup side-stepped the issue in C++ and called it a conditional statement.
My own take on the matter is that calling it trinary is never going to go anywhere; the other terminology is too well entrenched, much the same way that programmers jump up and down in anger when the mainstream media refers to black-hats as "hackers", instead of the more semantically precise term "crackers". It's a lost cause.
• another intruder with the mooring in the heart of the Perl
| [reply] |
|
Stroustrup side-stepped the issue in C++ and called it a conditional statement.
I call it the conditional operator (or the ternary conditional operator to avoid confusion). "Ternary operator" (or "trinary operator") is a description, not a name. Calling it the ternary operator is like calling me "Laurie Brine's child" in favour of using my name.
Update: Hey! perlop calls it that too!
| [reply] |
|
Lol, good job on uncovering a reliable and trusted source that manages to further the ambiguity and confusion. I should have guessed the Camel would discredit my pontification, though I'm not sure if it discredits or instead, illustrates my point. Let's get it all out on the table and arm wrestle for the rights to pick which term is going to survive. There can be only one. (Highlander)
| [reply] |
|
I see trinary somewhat as a shibboleth among Perl cognoscenti in much the same way that Perl itself is, or indeed as stumbit is among Perl Monks. It is these small things that distinguish us from users of other run of the mill boring languages and that enrich our use and immersion in our chosen language, that provides part of the solution and will prevent Perl from dying out.
DWIM is Perl's answer to Gödel
| [reply] |
|
- There can be only one
I disagree - there can only be three. The third will encompass all, and be the ultimate truth.
| [reply] |
|
This is not just a perl issue, though. ?: is most often called the ternary operator in several programming languages. I don't even see the Camel as cited as disagreeing; it just says that the operator whose name is "the ternary operator" is a member (and the only one, in perl) of the class of trinary operators.
| [reply] |
|
In my copy of the 2d edition of Programming Perl, it says this:
"Trinary ?: is the conditional operator, just as in C." (p 91).
It's also indexed under "trinary", not "ternary". At least one of the authors or editors of the book thinks "trinary" is a perfectly good word.
| [reply] |
Re: Ternary operator (there's no Trinary operator )
by Aristotle (Chancellor) on Jul 19, 2006 at 07:15 UTC
|
dict.org, when asked for definitions of “trinary”, finds nothing and helpfully suggests: did you mean “urinary”? I’ll let that fact stand as its own commentary.
Makeshifts last the longest.
| [reply] |
Re: Ternary operator (there's no Trinary operator )
by swampyankee (Parson) on Jul 19, 2006 at 10:13 UTC
|
It sounds like "trinary" is joining "irregardless" as a Word That Shouldn't Be.
I can see why trinary shows up: it looks like the logical result of (binary++). Incidentally, you will also see monoary as the logical result of (binary--) in the world of polymer chemistry.
binary++ = ternary
ternary++ = quaternary
| [reply] |
Re: Ternary operator (there's no Trinary operator )
by jdhedden (Deacon) on Jul 19, 2006 at 17:07 UTC
|
From perlop ,we have:
Conditional Operator
Ternary "?:" is the conditional operator, just as in C.
Which says that ?: is a ternary-type operator (meaning it has 3 components), and that its name is "the conditional operator".
"Trinary" is just not a word - it's a lexical error.
"Tertiary" is a description of ordinality, and means "the third position". Thus, for ?:, the tertiary argument is returned when the conditional is false.
Remember: There's always one more bug.
| [reply] [d/l] [select] |
|
Trinary certainly is a word; in this context is a synonym for ternary.
Be well,
rir
| [reply] |
Re: Ternary operator (there's no Trinary operator )
by ambrus (Abbot) on Jul 19, 2006 at 08:42 UTC
|
I think someone should look what the operator is called in the English original of K&R, and we should probably stick to that term. (If it's always referred to as something like, say, "conditional operator" then we're out of luck.)
| [reply] |
|
My copy of K&R (second edition) says 'ternary operator':
"The conditional expression, written with the ternary operator ``?:'', provides an alternate way to write this and similar constructions."
from section 2.11
| [reply] |
Re: Ternary operator (there's no Trinary operator )
by rinceWind (Monsignor) on Jul 19, 2006 at 10:20 UTC
|
I've also heard it called the "tertiary operator", which has 1.6M hits on Google.
--
Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ? (Missquoting Janis Joplin)
| [reply] |
|
| [reply] |
|
| [reply] |
Re: Ternary operator (there's no Trinary operator )
by spiritway (Vicar) on Jul 19, 2006 at 18:42 UTC
|
You've got a good point. I don't know what would be involved, nor how practical it would be, but putting something like Google's "do you mean foo?" in Super Search might be helpful. If that's impractical, then maybe a sort of Wiki-like "disambiguation page" for the more common mistakes. Ternary/Trinary would be a good one. Can't think of anything else right off, but surely there are plenty more.
OTOH, I suppose that if I did enter something about trinary operators, I'd encounter questions using that term, and see the corrections offered by the Monks - so I'm not sure that it would be worthwhile to go to the trouble of making such changes. I wonder whether this is a big enough problem to "fix" anything.
| [reply] |
Re: Ternary operator (there's no Trinary operator )
by ysth (Canon) on Jul 19, 2006 at 20:39 UTC
|
For fun, go through perlop and see how many punctuation (punctual?) operators have actual English names given. Operators are usually described like
Binary "-" returns the difference of two numbers.
The closest thing we have to a canonical list of names might be the PL_op_desc array in opcode.h in perl.git (amusingly enough, not in opnames.h in perl.git). | [reply] |
Re: Ternary operator (there's no Trinary operator )
by ww (Archbishop) on Jul 19, 2006 at 15:50 UTC
|
<grin>
So if my toddler (would that I were still of an age to have cookie-crumblers and rug-rats) calls the kitten "Dawg," does that make references to felines as "canines" correct?
I think NOT!
</grin>
Time and cultural changes encourage shifts and changes in language, but usages which obfuscate meaning (or distinctions among meanings) impoverish our ability to be precise. | [reply] |
Ternary operators
by pemungkah (Priest) on Jul 25, 2006 at 23:12 UTC
|
Just to add to the confusion:
The ternary operator, ?: has a binary value: one for true, another for false.
The binary operators <=> and cmp have ternary values: -1 (left less than right), 0 (arguments equal), and +1 (left greater than right). That's really a lovely symmetry. | [reply] |
Re: Ternary operator (there's no Trinary operator )
by jdporter (Paladin) on Jul 19, 2006 at 18:13 UTC
|
"Trinary" is Just Plain Wrong.
Are operators taking two arguments called "binary" for that fact? No.
Binary ops deal with binary values (either at the boolean or bit-wise level). A trinary operator would deal with three-state values — for example, in a logic system that allows 0, 1, and undef/null.
"Tertiary" also doesn't make sense, since it means "third". Clearly, :? isn't "the third operator".
I guess that leaves "ternary" as the best — if not ideal — choice.
Update: D'oh!
We're building the house of the future together.
| [reply] |
|
Are operators taking two arguments called "binary" for that fact? No.
Uh, yes. Yes, they are.
Just check perlop, if you don't believe me.
Or, if you don't find the Perl documentation clear enough, check Wikipedia on binary operation: "an operation whose arity is two".
(In my experience, operators dealing with binary values are commonly refered to as either boolean or bit operators.)
print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!
| [reply] [d/l] |