DMD 0.148 - regular expressions

Walter Bright newshound at digitalmars.com
Wed Mar 8 23:10:27 PST 2006


"Brad Roberts" <braddr at puremagic.com> wrote in message 
news:Pine.LNX.4.64.0603061143490.30259 at bellevue.puremagic.com...
> Easy enough to define the behavior.

I know. But if there isn't an obvious and intuitive behavior to define, then 
one is picking something arbitrary. For example, the classic conundrum is:

    "12" + 6

Does that evaluate to "126" or 18? One can easilly define the behavior, but 
which one, and what will programmers expect it to be? With that expression, 
there really are only wrong answers, and so the only solution is to make it 
illegal.

For:

if (auto a = foo() || auto b = bar())
{
            a + b;        // is b declared or not?
 }

one could as sensibly define that b is only valid in the conditional 
subexpression in which it appears, as in:

if (auto a = foo() || (auto b = bar(), b + 1))    // ok, b valid in the b+1 
expression
{
        a + b;  // error, b undefined here
}

Faced with two equally valid but incompatible definitions, I think the best 
course of action is to make it illegal, especially since there doesn't seem 
to be much utility in such a feature anyway. 





More information about the Digitalmars-d mailing list