Re: Foreach problem

2009-01-12 Thread Bill Baxter
On Tue, Jan 13, 2009 at 6:25 AM, Steven Schveighoffer wrote: > because that's basically what a foreach does when using opApply: create an > inner function and then pass a delegate pointing to that function to > opApply. > > I think the difference between the two is that the compiler handles forea

Re: Foreach problem

2009-01-12 Thread Steven Schveighoffer
"Denis Koroskin" wrote > On Sun, 11 Jan 2009 06:04:01 +0300, Tim M wrote: > >> On Sun, 11 Jan 2009 15:59:26 +1300, Tim M wrote: >> >>> On Sun, 11 Jan 2009 15:50:54 +1300, Daniel Keep >>> wrote: >>> Tim M wrote: > Why is this an error. Dmd wants to make sure that I declare a

Re: Foreach problem

2009-01-11 Thread Tim M
On Sun, 11 Jan 2009 21:39:55 +1300, Denis Koroskin <2kor...@gmail.com> wrote: On Sun, 11 Jan 2009 11:04:38 +0300, Tim M wrote: On Sun, 11 Jan 2009 20:31:51 +1300, Denis Koroskin <2kor...@gmail.com> wrote: Yep that probibly is a slight bug. What I would like to know is why cant I do fo

Re: Foreach problem

2009-01-11 Thread Denis Koroskin
On Sun, 11 Jan 2009 11:04:38 +0300, Tim M wrote: On Sun, 11 Jan 2009 20:31:51 +1300, Denis Koroskin <2kor...@gmail.com> wrote: Yep that probibly is a slight bug. What I would like to know is why cant I do foreach with primitive types like I can with objects. You can use foreach to itera

Re: Foreach problem

2009-01-11 Thread Tim M
On Sun, 11 Jan 2009 20:31:51 +1300, Denis Koroskin <2kor...@gmail.com> wrote: Yep that probibly is a slight bug. What I would like to know is why cant I do foreach with primitive types like I can with objects. You can use foreach to iterate over arrays and tuples, if that's what you mean

Re: Foreach problem

2009-01-10 Thread Denis Koroskin
On Sun, 11 Jan 2009 10:08:47 +0300, Tim M wrote: On Sun, 11 Jan 2009 19:56:55 +1300, Denis Koroskin <2kor...@gmail.com> wrote: On Sun, 11 Jan 2009 06:04:01 +0300, Tim M wrote: On Sun, 11 Jan 2009 15:59:26 +1300, Tim M wrote: On Sun, 11 Jan 2009 15:50:54 +1300, Daniel Keep wrote:

Re: Foreach problem

2009-01-10 Thread Tim M
On Sun, 11 Jan 2009 19:56:55 +1300, Denis Koroskin <2kor...@gmail.com> wrote: On Sun, 11 Jan 2009 06:04:01 +0300, Tim M wrote: On Sun, 11 Jan 2009 15:59:26 +1300, Tim M wrote: On Sun, 11 Jan 2009 15:50:54 +1300, Daniel Keep wrote: Tim M wrote: Why is this an error. Dmd wants to m

Re: Foreach problem

2009-01-10 Thread Denis Koroskin
On Sun, 11 Jan 2009 06:04:01 +0300, Tim M wrote: On Sun, 11 Jan 2009 15:59:26 +1300, Tim M wrote: On Sun, 11 Jan 2009 15:50:54 +1300, Daniel Keep wrote: Tim M wrote: Why is this an error. Dmd wants to make sure that I declare a new variable in the foreach statement and not use an e

Re: Foreach problem

2009-01-10 Thread Bill Baxter
On Sun, Jan 11, 2009 at 12:15 PM, Tim M wrote: > On Sun, 11 Jan 2009 16:10:39 +1300, Bill Baxter wrote: > >> On Sun, Jan 11, 2009 at 12:04 PM, Tim M wrote: >>> >>> On Sun, 11 Jan 2009 15:59:26 +1300, Tim M wrote: Why does it still work for some objects? >>> >>> >>> This works: >>> >>>

Re: Foreach problem

2009-01-10 Thread Tim M
On Sun, 11 Jan 2009 16:10:39 +1300, Bill Baxter wrote: On Sun, Jan 11, 2009 at 12:04 PM, Tim M wrote: On Sun, 11 Jan 2009 15:59:26 +1300, Tim M wrote: Why does it still work for some objects? This works: module test; class A { this() { // } } class

Re: Foreach problem

2009-01-10 Thread Bill Baxter
On Sun, Jan 11, 2009 at 12:04 PM, Tim M wrote: > On Sun, 11 Jan 2009 15:59:26 +1300, Tim M wrote: >> Why does it still work for some objects? > > > This works: > > > module test; > > class A > { >this() >{ >// >} > } > > class B > { >this() >

Re: Foreach problem

2009-01-10 Thread Bill Baxter
On Sun, Jan 11, 2009 at 11:33 AM, Tim M wrote: > > Why is this an error. Dmd wants to make sure that I declare a new variable > in the foreach statement and not use an existing one? > > module test; > > void main() > { >int i; >int[] nums; >foreach(i; nums) >{ >

Re: Foreach problem

2009-01-10 Thread Tim M
On Sun, 11 Jan 2009 15:59:26 +1300, Tim M wrote: On Sun, 11 Jan 2009 15:50:54 +1300, Daniel Keep wrote: Tim M wrote: Why is this an error. Dmd wants to make sure that I declare a new variable in the foreach statement and not use an existing one? module test; void main() { int i

Re: Foreach problem

2009-01-10 Thread Tim M
On Sun, 11 Jan 2009 15:50:54 +1300, Daniel Keep wrote: Tim M wrote: Why is this an error. Dmd wants to make sure that I declare a new variable in the foreach statement and not use an existing one? module test; void main() { int i; int[] nums; foreach(i; nums) {

Re: Foreach problem

2009-01-10 Thread Jarrett Billingsley
On Sat, Jan 10, 2009 at 9:33 PM, Tim M wrote: > > Why is this an error. Dmd wants to make sure that I declare a new variable > in the foreach statement and not use an existing one? You can't reuse existing variables as foreach loop indices, long story short.

Re: Foreach problem

2009-01-10 Thread Daniel Keep
Tim M wrote: Why is this an error. Dmd wants to make sure that I declare a new variable in the foreach statement and not use an existing one? module test; void main() { int i; int[] nums; foreach(i; nums) { // } } dmd test.d test.d(7): Error: shadowing declar