dmd 1.046 and 2.031 releases
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Jul 6 23:15:06 PDT 2009
Derek Parnell wrote:
> Because
>
> 1. case X..Y:
>
> looks like
>
> 2. foreach(e; X..Y)
> 3. array[X..Y]
> 4. case X:..caseY:
>
>
> yet the X..Y has a VERY DIFFERENT meaning. (1) is inclusive of Y, and
> (2) and (3) are exclusive of Y, and (4) is inclusive of Y ... oh, hang
> on...
>
> Sorry, but I'm just not getting the "VERY DIFFERENT" part yet. Right now, D
> has ".." meaning exclude-end value (2. and 3.) AND it also has ".." meaning
> include-end value (4.), depending on context.
I think here's the point where our thinking diverges. You say ".." has a
meaning. No. It does not have any meaning. It's punctuation. Same way,
"*", "&", ":", ",", etc. have no meaning in D all alone. They are
tokens. They acquire a meaning by partaking in grammatical constructs.
What does have arguably a meaning is "expression1 .. expression2". (Even
that could be debatable because it's not a standalone expression). But
anyway, the meaning that "expression1 .. expression2" acquires in array
slices and foreach statements is uniform.
Now we have the different construct "case expression1: .. case
expression2:" That is evidently not "expression1 .. expression2", does
not include it as a part, and shares essentially nothing except the ".."
with it. That's my point.
> Ok, I admit that there is one subtle difference. Examples 2 and 3 are of
> the form
>
> IntExpression .. IntExpression
>
> and example 4 is
>
> CaseLabelInt .. CaseLabelInt
>
> but seriously, people are not going to notice that. We see double-dot and
> think "range".
You should see "expression1 .. expression2" and think "range". There's
very few tokens that make one think of only one thing when seeing them.
One of them is "%" - makes one think of modulus, another is "^" meaning
xor, another is "$" - array size... but that's about it.
> I know that this is not ever going to be changed so I'm not arguing that it
> should.
>
> (One of the most frequent bugs I have in my D programs is that I forget
> that X..Y excludes Y because it's not natural to me to see text that looks
> like "the range X to Y" but means "the range X to Y-1".)
>
> It seems that D would benefit from having a standard syntax format for
> expressing various range sets;
> a. Include begin Include end, i.e. []
> b. Include begin Exclude end, i.e. [)
> c. Exclude begin Include end, i.e. (]
> d. Exclude begin Exclude end, i.e. ()
I'm afraid this would majorly mess with pairing of parens.
Andrei
More information about the Digitalmars-d-announce
mailing list