suggested change to foreach index
Bruno Medeiros
brunodomedeirosATgmail at SPAM.com
Sat Jun 10 09:23:49 PDT 2006
Jarrett Billingsley wrote:
> "BCS" <BCS at pathlink.com> wrote in message
> news:e69lah$dmo$1 at digitaldaemon.com...
>
>> The suggested syntax
>> vvv
>> foreach([[inout] index,] value ; ...
>>
>> seems a bit odd to me. How about use "alias" instead?
>>
>> int i;
>> foreach(alias i, v; arr){}
>
> Or, more consistent, make auto foreach indices require "auto"?
>
> int i;
>
> foreach(auto i, auto j; something)
> writefln(i); // New local i which overrides outer i
>
> foreach(i, auto j; something)
> writefln(i); // Uses outer i
>
> writefln(i); // Writes the value that i last had in the loop
>
> This has the (wonderful) side-effect of making it bleedingly obvious that
> the foreach indices are using type inference; the current index inference
> form _looks_ like it's trying to use already-defined index variables.
>
>
Agreed too, this is the natural/intuitive/consistent way to go.
Those other solutions with "alias" and "inout" were awful.
--
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list