Ref local variables?

Robert Jacques sandford at jhu.edu
Wed Jan 11 16:44:55 PST 2012


On Wed, 11 Jan 2012 16:49:35 -0600, Nick Sabalausky <a at a.a> wrote:

> "Ben Davis" <entheh at cantab.net> wrote in message
> news:jejkdm$16un$1 at digitalmars.com...
>>
>> Note that this is already supported (apologies if I've got the syntax
>> slightly wrong):
>>
>> foreach (i, ref tile; map) { ... }
>>
>> That's a local variable too. It could have instead been defined such that
>> "tile" is an alias for "map[i]", but that would be a little strange.
>>
>
> That's a very good point.
>
> Technically, foreach is implemented such that its body is a function and the
> "i, ref tile" is the parameter list. But I think that's beside the point.

Given that enabling foreach's syntax for general D functions, i.e.

myLoop(i, ref tile; map) { ... }

has been discussed several times in this newsgroup, the fact that "i, ref tile" is the parameter list of a delegate is not beside the point.


More information about the Digitalmars-d mailing list