D - foreach over enum types
- Maik Zumstrull (9/9) Oct 02 2003 Hi,
- Sean L. Palmer (7/16) Oct 02 2003 Enums aren't necessarily linear, but it would be useful in the cases tha...
- Maik Zumstrull (9/13) Oct 02 2003 I think it would be useful _especially_ in case of non-linear enums,
- Walter (3/12) Oct 02 2003 It's workable.
- Helmut Leitner (9/26) Oct 03 2003 What if this were the job of a reflection module in a future standard li...
- Walter (5/28) Oct 03 2003 library?
- Helmut Leitner (19/30) Oct 03 2003 What if someone would write a
- Walter (13/22) Oct 04 2003 looks
- Juan C (6/15) Oct 04 2003 What would it do with this enum then?
- Maik Zumstrull (9/13) Oct 05 2003 That would have to be defined. I'd prefer it to do only one call per
Hi, I think there are some situations where this would be useful. It would be an easy way to write "for every possible value of this enum, do ...". As far as I can see, adding this wouldn't break the syntax (much): foreach (myEnumType e; myEnumType) { doSomething(e); } Doesn't look so bad to me. Any comments?
Oct 02 2003
Enums aren't necessarily linear, but it would be useful in the cases that the enum doesn't have gaps and goes in steady progression. I suppose it could work for nonlinear enums too, but it would have to be completely unrolled by the compiler. Sean "Maik Zumstrull" <Maik.Zumstrull gmx.de> wrote in message news:blh0jt$1qov$1 digitaldaemon.com...Hi, I think there are some situations where this would be useful. It would be an easy way to write "for every possible value of this enum, do ...". As far as I can see, adding this wouldn't break the syntax (much): foreach (myEnumType e; myEnumType) { doSomething(e); } Doesn't look so bad to me. Any comments?
Oct 02 2003
Sean L. Palmer schrieb:Enums aren't necessarily linear, but it would be useful in the cases that the enum doesn't have gaps and goes in steady progression.I think it would be useful _especially_ in case of non-linear enums, while only "nice to have" for linear enums. You could use a normal for-loop to iterate over a linear enum (although it would be a somewhat "dirty" approach IMHO - why use the enum abstraction when you treat it as int afterwards anyway).I suppose it could work for nonlinear enums too, but it would have to be completely unrolled by the compiler.Well someone has to unroll it in case of a nonlinear enum, and since unrolling is a really stupid (== simple, straightforward, yet lengthy) task, I think the compiler should do it for me.
Oct 02 2003
"Maik Zumstrull" <Maik.Zumstrull gmx.de> wrote in message news:blh0jt$1qov$1 digitaldaemon.com...Hi, I think there are some situations where this would be useful. It would be an easy way to write "for every possible value of this enum, do ...". As far as I can see, adding this wouldn't break the syntax (much): foreach (myEnumType e; myEnumType) { doSomething(e); } Doesn't look so bad to me. Any comments?It's workable.
Oct 02 2003
Walter wrote:"Maik Zumstrull" <Maik.Zumstrull gmx.de> wrote in message news:blh0jt$1qov$1 digitaldaemon.com...What if this were the job of a reflection module in a future standard library? myEnumType [] myEnumTypeReflection=ReflectModuleEnum("module.pat .name",myEnumType); foreach(myEnumType e; myEnumTypeReflection) { doSomething(e); } -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.comHi, I think there are some situations where this would be useful. It would be an easy way to write "for every possible value of this enum, do ...". As far as I can see, adding this wouldn't break the syntax (much): foreach (myEnumType e; myEnumType) { doSomething(e); } Doesn't look so bad to me. Any comments?It's workable.
Oct 03 2003
"Helmut Leitner" <helmut.leitner chello.at> wrote in message news:3F7D665C.2999F29 chello.at...Walter wrote:library?"Maik Zumstrull" <Maik.Zumstrull gmx.de> wrote in message news:blh0jt$1qov$1 digitaldaemon.com...What if this were the job of a reflection module in a future standardHi, I think there are some situations where this would be useful. It would be an easy way to write "for every possible value of this enum, do ...". As far as I can see, adding this wouldn't break the syntax (much): foreach (myEnumType e; myEnumType) { doSomething(e); } Doesn't look so bad to me. Any comments?It's workable.myEnumType []myEnumTypeReflection=ReflectModuleEnum("module.path.name",myEnumType);foreach(myEnumType e; myEnumTypeReflection) { doSomething(e); }I'm less sure how to do that <g>.
Oct 03 2003
Walter wrote:What if someone would write a "D source" => "general tree structure" parser (must be hidden in your compiler frontend)? Then it would be trivial to find the enum definition in the tree (and do a lot of other useful things). Burton's DIGC goes a long way in parsing D code to strip functions bodys, looks into module dependencies, versions ... and I think a lot of future D tools might be easier to write if there were a reusable D parser module written in D. I'm currently working on a DMI (D make from import) utility to build applications directly using the import dependencies without any need for makefiles and libraries. Just from the sources: "dmi -Ic:\d -Ic:\dmd\src\phobos main" - the same problem. Of course, it doesn't make sense for "foreach(...enum...)" alone. But if you think about how to add a kind of reflection sometime in the future? Such a library based "soft" reflection could be a cheap solution. And it wouldn't be a "Walter problem". -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.comWhat if this were the job of a reflection module in a future standardlibrary?myEnumType []myEnumTypeReflection=ReflectModuleEnum("module.path.name",myEnumType);foreach(myEnumType e; myEnumTypeReflection) { doSomething(e); }I'm less sure how to do that <g>.
Oct 03 2003
"Helmut Leitner" <leitner hls.via.at> wrote in message news:3F7DB2E0.636D1B8F hls.via.at...Burton's DIGC goes a long way in parsing D code to strip functions bodys,looksinto module dependencies, versions ... and I think a lot of future D toolsmightbe easier to write if there were a reusable D parser module written in D.There is a reusable D parser, but it's in C++ right now. Eventually, it should be rewritten in D.I'm currently working on a DMI (D make from import) utility to buildapplicationsdirectly using the import dependencies without any need for makefiles andlibraries.Just from the sources: "dmi -Ic:\d -Ic:\dmd\src\phobos main" - the sameproblem.Of course, it doesn't make sense for "foreach(...enum...)" alone. But if you think about how to add a kind of reflection sometime in thefuture?Such a library based "soft" reflection could be a cheap solution.I think supporting reflection is important. But not important enough to do it for the next version, for that I think improving the template support is much more important.
Oct 04 2003
In article <blh0jt$1qov$1 digitaldaemon.com>, Maik Zumstrull says...Hi, I think there are some situations where this would be useful. It would be an easy way to write "for every possible value of this enum, do ...". As far as I can see, adding this wouldn't break the syntax (much): foreach (myEnumType e; myEnumType) { doSomething(e); } Doesn't look so bad to me. Any comments?What would it do with this enum then? enum myEnumType { Zilch=0 , Zip=0 , Nul=0 , GooseEgg=0 , Nada=0 } ; will it call doSomething() four times with the value 0 as expected or something unexpected? Juan C
Oct 04 2003
Juan C schrieb:What would it do with this enum then? enum myEnumType { Zilch=0 , Zip=0 , Nul=0 , GooseEgg=0 , Nada=0 } ; will it call doSomething() four times with the value 0 as expected or something unexpected?That would have to be defined. I'd prefer it to do only one call per real value, not one for every alias. It could also be made to do all five calls in plain mode and optimize four of them away with enabled optimization. Would/could the optimizer be intelligent enough to optimize four calls away if it recognizes that making all five calls doesn't lead to a different result? In that case, you could write code with the assumption that all five calls are made while they aren't actually made when it's not necessary.
Oct 05 2003