in reply to Ternary operator (there's no Trinary operator )

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
  • Comment on Re: Ternary operator (there's no Trinary operator )

Replies are listed 'Best First'.
Re^2: Ternary operator (there's no Trinary operator )
by grinder (Bishop) on Jul 19, 2006 at 08:56 UTC

    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

      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!

Re^2: Ternary operator (there's no Trinary operator )
by davido (Cardinal) on Jul 19, 2006 at 07:19 UTC

    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)


    Dave

      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

      There can be only one

      I disagree - there can only be three. The third will encompass all, and be the ultimate truth.

      -=( Graq )=-

      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.
Re^2: Ternary operator (there's no Trinary operator )
by swampyankee (Parson) on Jul 19, 2006 at 17:47 UTC

    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.

    emc

    e(π√−1) = −1