Implies operator
antonio
antonio at abrevia.net
Thu Nov 16 13:59:21 PST 2006
Kristian Kilpi wrote:
> On Thu, 16 Nov 2006 13:46:08 +0200, Mariano <rotoshi at yahoo.com> wrote:
>
>> == Quote from Stewart Gordon (smjg_1998 at yahoo.com)'s article
>>> Hasan Aljudy wrote:
>>> > Mariano wrote:
>>> <snip>
>>> >> but the implication makes it far more clear for common day speach
>>> >>
>>> >> if( check_boundaries -> a.length <= max_int )
>>> >> process(a);
>>> >>
>>> >> makes more sence than
>>> >>
>>> >> if( !check_boundaries || a.length <= max_int )
>>> >> process(a);
>>> </snip>
>>> What this notation is saying is: If check_boundaries is true, then we
>>> need to check whether a.length <= max_int - otherwise we needn't bother.
>>> But still, it isn't exactly the clearest notation.
>> Yes, it was just an example out of the blue. I think it is clearer,
>> and I can't think of a better way.
>>
>>> <snip>
>>> > Yea, it's easy, sure .. but -> has another totally different
>>> meaning in
>>> > C++. Not that I care about C++ anymore, but D, being a C-family
>>> > language, IMHO, shouldn't do this.
>>> <snip>
>>
>> The notation was just a suggestion. I would prefer =>, but it might be
>> confused with >=. Other options are
>> ==>, -->, and since we have UTF-8 support, why not → or ⇒!
>>
>> I understand most people don't have the notion of 'implicance' so
>> fresh in their heads as with other logical
>> operators, but I believe this is a consecuence of the imposed
>> operators by languages. Having an extra logical
>> operator would give an edge for the programmer used to it, and won't
>> hurt the one who doesn't whant to use it.
>>
>> What's more, this operator is far more coherent with the behaviour of
>> not revising the second condition if not
>> needed.
>>
>> Who knows, if implemented, it might even become widely used one day.
>>
>> Mariano.
>
> I haven't used implication anywhere; I'm not 'able' to think x implies
> y.. But that's probably because there is no implication operator.
>
> Now when I think about it, I have to say that 'x implies y' is a lot
> easier to understand than '!x || y'.
>
> I cannot say how much I would use it, if there was one. (I'm still not
> used to such an operator.)
The most common example is the null check...
if( a!=null && a[5]==2 ) {
}
we assume "&&" operator is optimized and evaluates left to right... but
it's really "dirty" because we use a compiler optimization as a logic
functionality.
for this example, I really will prefer to write
if( a!=null -> a[5]==2 ) {
}
that uses left to right optimized evaluation, but it's more "clean"
following this, why not
if( a[5]==2 <- a!=null ) {
}
( "<-" optimized evaluation is right to left )
One question about && and || optimization:
Is there some way to specify that I need to evaluate the 2 sides of the
comparer?
(something like &&& or ||| )
note: "if( And( left() , right() ) )" or similar is not a solution :-)
Thanks
More information about the Digitalmars-d
mailing list