Repost: make foreach(i, a; range) "just work"
Regan Heath
regan at netmail.co.nz
Thu Feb 20 08:02:28 PST 2014
On Thu, 20 Feb 2014 12:56:27 -0000, Marc Schütz <schuetzm at gmx.net> wrote:
> IMO, any change needs to be both backwards-compatible (i.e., it should
> not only "just work", as you phrased, but existing code should "just
> keep working"), and forward-compatible, so as not to obstruct any
> potential improvements of tuple handling.
>
> Scheme #1 fails backwards-compatibility.
Fair enough. We can always pack things manually using something like the
enumerate() method mentioned in the link.
> Scheme #2 doesn't, but I feel the matching rules if a type is specified
> are too complicated. Instead, I would suggest just to always assign the
> variables from the right, i.e. you cannot skip variables, and if you
> specify a type, it must match the type of the value in this position.
>
> If you really want to skip a tuple member (in order to avoid an
> expensive copy), a special token "_" or "$" could be introduced, as has
> also been suggested in one the tuple unpacking/pattern matching DIPs,
> IIRC.
>
> As for unpacking a tuple value (or key), an additional pair of
> parentheses can be used, so such a feature would still be possible in
> the future:
>
> foreach(i, k, (a,b,c); ...)
Cool.
> (Scheme #3 seems just too complicated for my taste. It's important to be
> intuitively understandable and predictable.)
Fair enough.
Any comments on the initial solution to my original problem?
R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list