On 2/9/11 7:46 AM, Nick Sabalausky wrote:
"spir"<denis.s...@gmail.com> wrote in message
news:mailman.1422.1297254724.4748.digitalmar...@puremagic.com...
Side-question: what is actually 1..5 as of now for a thing? Or is it
conceptually "unconstructed" by rewriting to (probably) an ordinary for
loop? Anyway, the point above applies to language-side semantics, whatever
optimisation may happen.
AIUI: Syntactically, it doesn't exist at all, at least not by itself. It's
just part of one of the foreach syntaxes:
'foreach' '(' {declaration list} ';' {expression} '..' {expression} ')'
and also part of one of the slice syntaxes:
(from the docs:)
PostfixExpression [ AssignExpression .. AssignExpression ]
Although it's possible I've understood it wrong.
Don't have a clue how it's handled beyond that though.
Indeed, a..b is just punctuation in the two grammatical constructs you
mentioned.
Your proposal has indeed been made a couple of times, first probably by
bearophile - but then what did bearophile /not/ propose? (Meaning this
in good fun.) I think it would be okay to move iota into druntime and
enact the rewrite. But this would improve the language by such a small
iota...
I buy the orthogonality argument as much as you do. foreach is not
orthogonal because it is a short form of for, which is not orthogonal
because it is a short form of while, which is not orthogonal because it
is a short form of a scope with if/goto at the top.
If a..b would be rewritten into iota(a, b) that would still be
non-orthogonal because one could express one thing in two ways.
Ironically, it's more orthogonal to leave things as they are: you have
iota(a, b) as the general concept and you have a..b as punctuation in
two grammatical constructs.
But the most important question is: if the rewrite were done, to what
extent would that improve your use of the language? Integral intervals
do occur outside foreach and slices, but quite infrequently. In those
cases you'd gain by replacing iota(a, b) with a..b. Is this significant?
Andrei