Implies operator

Hasan Aljudy hasan.aljudy at gmail.com
Tue Nov 14 13:46:11 PST 2006


Mariano wrote:
> Wouldn't it be nice to have an ''implies'' operator?
> 
>   if(A -> B)
> 
> I know this can be written as
> 
>   if(!A || B)

I don't recall ever being in a situation like that ..
I'm not saying I've never had a conditional of the form if(!a || b) but 
I never thought about it as a logical implication ...
Plus, "logical implication" only makes sense for rules and theorems, not 
variables.

> 
> 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);

What does that mean? what's 'a' and what's 'check_boundaries'?

> 
> or
> 
>   if( ! (check_boundaries && a.length > max_int ) )
>       process(a);
> 
> besides, I don't think the '->' notation should be a big problem for
> the parser, and the front end can easily convert this structure to
> the corresponding not + or/and.

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.

> 
> There is, of course, still the issue of precedence, but I think it
> should match that of || and &&.
> 
> And since Walter likes Wikipedia links: http://en.wikipedia.org/wiki/
> Logical_implication
> 
> Mariano



More information about the Digitalmars-d mailing list