The new ?? and ??? operators

Stewart Gordon smjg_1998 at yahoo.com
Mon Sep 24 09:15:06 PDT 2007


"Arlen Albert Keshabyan" <arlen.albert at gmail.com> wrote in message 
news:fd7qu5$2t7e$1 at digitalmars.com...
<snip>
> If you'd read my first post carefully you'd never ask the question like 
> this.
>
>> a = b ??? c ??? d;
>> a = b ??? c;
>> a = b;
>
> the conditions must be explicit (!). Inexplicit conditions always 
> evaluates to TRUE despite types involved in conditions. So, you will got 
> the following:

I meant the symbols to denote general expressions rather than variables.  I 
must've blinked and missed the bit about the semantics of a ??? expression 
depending on the form of the operands.

But anyway, what is the definition of an "explicit" or "inexplicit" 
condition"?  Just whether the operator in the next level below the ??? 
happens to be == != is !is < <= > >= !<>= !<> <> <>= !> !>= !< !<= in?

And if you're going to do this, why _allow_ "inexplicit" conditions anywhere 
except the end?  ISTM it can only be a mistake, and one that's far too easy 
to make.

>> a = b ??? c ??? d;
> a = b; //any type, even boolean

>> a = b ??? c;
> a = b;
>
>> a = b;
> a = b; //so no ??? ternary operator. Treated just like no (?:) operator :)
<snip>

You miss the point.

Generally, when a binary operator is used n times in sequence, it denotes 
combining the n+1 operands in some fashion or another, which continues to 
hold when n == 0.  For instance, x can be thought of as a sum of one value, 
just as x + y is a sum of two values, x + y + z is a sum of three values, 
and so on.  Your ??? operator would break this principle:

n = a == x ??? b == y ??? c == z;
    takes, of the three conditions, the first condition to be true and 
assigns it to n, otherwise leaves n unchanged

n = a == x ??? b == y;
    takes, of the two conditions, the first condition to be true and assigns 
it to n, otherwise leaves n unchanged

n = a == x;
    would by extension take, of the one condition, the first condition to be 
true and assign it to n, otherwise leave n unchanged.  (In other words, 
assign the value of a == x to n only if a == x is true.)  But it doesn't....

Whether this matters, I'm not sure.  At least

    n = a == x ??? n;

would do the equivalent for a single condition.  But still....

Stewart.

-- 
My e-mail address is valid but not my primary mailbox.  Please keep replies 
on the 'group where everybody may benefit. 




More information about the Digitalmars-d mailing list