digitalmars.D.bugs - [Issue 9009] New: allow foreach without identifier
- d-bugmail puremagic.com (29/29) Nov 12 2012 http://d.puremagic.com/issues/show_bug.cgi?id=9009
- d-bugmail puremagic.com (20/20) Jan 11 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9009
- d-bugmail puremagic.com (15/29) Jan 13 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9009
- d-bugmail puremagic.com (12/12) Mar 06 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9009
- d-bugmail puremagic.com (8/12) Mar 07 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9009
- d-bugmail puremagic.com (12/12) Aug 25 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9009
- d-bugmail puremagic.com (12/16) Aug 25 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9009
http://d.puremagic.com/issues/show_bug.cgi?id=9009
Summary: allow foreach without identifier
Product: D
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: monarchdodra gmail.com
Minor enhancement request, but the language should allow using "foreach"
without specifying an iteration name. THis can be useful when you want to
iterate a fixed amount, without caring about the index. For example, when you
want to "popFrontN exactly" (popFrontN is safe, so slightly slower), you'd want
to write:
foreach( ; 0 .. n ) r.popFront();
Right now, if you do this, you get:
main.d(5): Error: basic type expected, not ;
main.d(5): Error: no identifier for declarator int
for can do without declarators, I don't see why foreach can't have the above
syntax.
Just a minor ER, but I think it would make foreach that little extra user
friendly.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 12 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9009
Andrej Mitrovic <andrej.mitrovich gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andrej.mitrovich gmail.com
17:50:06 PST ---
I think this is a worthy request, although you can use "_" as an unused
iteration variable you may end up having to invent unique names with 2 or more
nested foreach loops:
foreach(_; 0 .. n ) {
foreach(__; 0 .. m) {
// statements
}
}
Since foreach lowers to a for statement I think it should be possible to
implement the request.
Can we get a pre-approval from Walter/Andrei?
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 11 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9009
I think this is a worthy request, although you can use "_" as an unused
iteration variable you may end up having to invent unique names with 2 or more
nested foreach loops:
foreach(_; 0 .. n ) {
foreach(__; 0 .. m) {
// statements
}
}
Since foreach lowers to a for statement I think it should be possible to
implement the request.
Can we get a pre-approval from Walter/Andrei?
BTW, given the compiler error that is spit out by DMD upon writing
//----
foreach ( ; 0 .. n )
//----
Error: basic type expected, not ;
Error: no identifier for declarator int
//----
I'd say it is either a bug that this isn't already supported anyway, or the
compiler error should be re-written.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 13 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9009
bearophile_hugs eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bearophile_hugs eml.cc
I think this is a simple nice idea. There is no point in requiring to name a
variable that will not used. It's like in function signatures:
void foo(int, int y) {}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 06 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9009
07:08:24 PST ---
I think this is a simple nice idea. There is no point in requiring to name a
variable that will not used. It's like in function signatures:
void foo(int, int y) { }
He meant:
void foo(int, int) { }
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 07 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9009
Piotr Szturmaj <pszturmaj tlen.pl> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pszturmaj tlen.pl
---
I'd vote for version without a semicolon:
1. foreach (0 .. n)
2. foreach (range)
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 25 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9009
Lionello Lunesu <lio+bugzilla lunesu.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lio+bugzilla lunesu.com
19:10:53 PDT ---
I'd vote for version without a semicolon:
1. foreach (0 .. n)
2. foreach (range)
Yes, I'd prefer that too. It's what newbies would write. foreach(; ...) is just
too hard to explain to newcomers.t
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 25 2013









d-bugmail puremagic.com 