digitalmars.D - Static Foreach
- Shammah Chancellor (26/26) Nov 24 2013 It seems that DMD already interprets some foreach's at compiletime if
- Philippe Sigaud (6/19) Nov 24 2013 The consensus might well be 'use recursion' :) That's what I'd do in
- John Colvin (8/32) Nov 24 2013 However, the current set of tools is a bit lacking in that
- Philippe Sigaud (8/13) Nov 24 2013 You can have a look there:
- John Colvin (6/23) Nov 24 2013 I've been looking at that stuff recently :-) It's pretty cool,
- Philippe Sigaud (7/21) Nov 24 2013 That's why I never tried to get it into Phobos :)
- John Colvin (6/32) Nov 24 2013 Yeah I'm mostly working around porting std.range and
- Shammah Chancellor (4/10) Nov 24 2013 Yes. That's what I'm doing, and it's ugggglyyyy.
- Philippe Sigaud (7/17) Nov 24 2013 learn to stop worrying and love the String
- Jesse Phillips (3/4) Nov 24 2013 https://d.puremagic.com/issues/show_bug.cgi?id=1642
It seems that DMD already interprets some foreach's at compiletime if the argument is known at compile time: eg: string FooString() { string stuff = ""; foreach(member, __traits( allMembers, moduleName) { stuff ~= member; } return stuff; } mixin(FooString()); However, for non-string templates. They have to be written in a recursive form, which can be particularly difficult in some cases. template FooTemplate() //This code is totally made up and not meant to do anything useful, or necessarily be valid. { auto FooTemplate = TypeTuple!() static foreach(member, __traits( allMembers, someClass) { FooTemplate = TypeTuple!(FooTemplate, __traits(getMember, someClass, member)); } } What's the consensis on something like this?
Nov 24 2013
On Sun, Nov 24, 2013 at 6:40 PM, Shammah Chancellor <anonymous coward.com> wrote:However, for non-string templates. They have to be written in a recursive form, which can be particularly difficult in some cases. template FooTemplate() //This code is totally made up and not meant to do anything useful, or necessarily be valid. { auto FooTemplate = TypeTuple!() static foreach(member, __traits( allMembers, someClass) { FooTemplate = TypeTuple!(FooTemplate, __traits(getMember, someClass, member)); } } What's the consensis on something like this?The consensus might well be 'use recursion' :) That's what I'd do in your case. CT computation on types is a lot like functional programming: recursion and immutability. Another solution would be to construct you type as a string, and then mix it in.
Nov 24 2013
On Sunday, 24 November 2013 at 19:42:21 UTC, Philippe Sigaud wrote:On Sun, Nov 24, 2013 at 6:40 PM, Shammah Chancellor <anonymous coward.com> wrote:However, the current set of tools is a bit lacking in that department. Hopefully I'll be able to rectify this with my attempt at a proper std.meta package :) Unfortunately, it's proving to a bit of a stress-test on some dustier parts of the compiler (not to mention my brain), so progress is a bit slower than I would have hoped.However, for non-string templates. They have to be written in a recursive form, which can be particularly difficult in some cases. template FooTemplate() //This code is totally made up and not meant to do anything useful, or necessarily be valid. { auto FooTemplate = TypeTuple!() static foreach(member, __traits( allMembers, someClass) { FooTemplate = TypeTuple!(FooTemplate, __traits(getMember, someClass, member)); } } What's the consensis on something like this?The consensus might well be 'use recursion' :) That's what I'd do in your case. CT computation on types is a lot like functional programming: recursion and immutability.
Nov 24 2013
On Sun, Nov 24, 2013 at 8:46 PM, John Colvin <john.loughran.colvin gmail.com> wrote:However, the current set of tools is a bit lacking in that department. Hopefully I'll be able to rectify this with my attempt at a proper std.meta package :) Unfortunately, it's proving to a bit of a stress-test on some dustier parts of the compiler (not to mention my brain), so progress is a bit slower than I would have hoped.You can have a look there: https://github.com/PhilippeSigaud/dranges/blob/master/tuple.d and https://github.com/PhilippeSigaud/dranges/blob/master/typetuple.d (this one was fun: regex on type tuples!) https://github.com/PhilippeSigaud/dranges/blob/master/typepattern.d
Nov 24 2013
On Sunday, 24 November 2013 at 19:57:06 UTC, Philippe Sigaud wrote:On Sun, Nov 24, 2013 at 8:46 PM, John Colvin <john.loughran.colvin gmail.com> wrote:I've been looking at that stuff recently :-) It's pretty cool, in particular the regex stuff. I'm wary of going overboard though, it's very tempting to keep adding functionality that is too obscure for a standard library.However, the current set of tools is a bit lacking in that department. Hopefully I'll be able to rectify this with my attempt at a proper std.meta package :) Unfortunately, it's proving to a bit of a stress-test on some dustier parts of the compiler (not to mention my brain), so progress is a bit slower than I would have hoped.You can have a look there: https://github.com/PhilippeSigaud/dranges/blob/master/tuple.d and https://github.com/PhilippeSigaud/dranges/blob/master/typetuple.d (this one was fun: regex on type tuples!) https://github.com/PhilippeSigaud/dranges/blob/master/typepattern.d
Nov 24 2013
On Sun, Nov 24, 2013 at 9:06 PM, John Colvin <john.loughran.colvin gmail.com> wrote:That's why I never tried to get it into Phobos :) And, truth is, I used almost none of it, even when most of this code is 4 years old. Mapping/filtering/reducing tuples is the most useful part. The regex-on-types stuff was purely for fun.You can have a look there: https://github.com/PhilippeSigaud/dranges/blob/master/tuple.d and https://github.com/PhilippeSigaud/dranges/blob/master/typetuple.d (this one was fun: regex on type tuples!) https://github.com/PhilippeSigaud/dranges/blob/master/typepattern.dI've been looking at that stuff recently :-) It's pretty cool, in particular the regex stuff. I'm wary of going overboard though, it's very tempting to keep adding functionality that is too obscure for a standard library.
Nov 24 2013
On Sunday, 24 November 2013 at 20:22:05 UTC, Philippe Sigaud wrote:On Sun, Nov 24, 2013 at 9:06 PM, John Colvin <john.loughran.colvin gmail.com> wrote:Yeah I'm mostly working around porting std.range and std.algorithm. They're a pretty good subset of "useful things to do with sequences of things". Even so, I suspect come review people will want it pruned a little.That's why I never tried to get it into Phobos :) And, truth is, I used almost none of it, even when most of this code is 4 years old. Mapping/filtering/reducing tuples is the most useful part.You can have a look there: https://github.com/PhilippeSigaud/dranges/blob/master/tuple.d and https://github.com/PhilippeSigaud/dranges/blob/master/typetuple.d (this one was fun: regex on type tuples!) https://github.com/PhilippeSigaud/dranges/blob/master/typepattern.dI've been looking at that stuff recently :-) It's pretty cool, in particular the regex stuff. I'm wary of going overboard though, it's very tempting to keep adding functionality that is too obscure for a standard library.
Nov 24 2013
On 2013-11-24 19:42:11 +0000, Philippe Sigaud said:The consensus might well be 'use recursion' :) That's what I'd do in your case. CT computation on types is a lot like functional programming: recursion and immutability. Another solution would be to construct you type as a string, and then mix it in.Yes. That's what I'm doing, and it's ugggglyyyy. This seems excessive: https://github.com/schancel/gameserver/blob/master/source/messages/core.d#L176
Nov 24 2013
On Sun, Nov 24, 2013 at 9:54 PM, Shammah Chancellor <anonymous coward.com> wrote:On 2013-11-24 19:42:11 +0000, Philippe Sigaud said:learn to stop worrying and love the String (http://en.wikipedia.org/wiki/Dr._Strangelove) :-)The consensus might well be 'use recursion' :) That's what I'd do in your case. CT computation on types is a lot like functional programming: recursion and immutability. Another solution would be to construct you type as a string, and then mix it in.Yes. That's what I'm doing, and it's ugggglyyyy.This seems excessive: https://github.com/schancel/gameserver/blob/master/source/messages/core.d#L176Indeed :) (btw, you're using EvaulateMessageModules, when I think you want Eval*u*ateMessageModules)
Nov 24 2013
On Sunday, 24 November 2013 at 17:40:14 UTC, Shammah Chancellor wrote:What's the consensis on something like this?https://d.puremagic.com/issues/show_bug.cgi?id=1642
Nov 24 2013