Re: static code generation

2012-12-21 Thread r_m_r
On 12/21/2012 10:30 AM, r_m_r wrote: http://wiki.dlang.org/Combining_Structs) the link should be: http://wiki.dlang.org/Combining_structs regards, r_m_r

Re: static code generation

2012-12-20 Thread js.mdnq
On Thursday, 20 December 2012 at 04:17:48 UTC, r_m_r wrote: On 12/18/2012 04:42 AM, js.mdnq wrote: It looks like the approach 2 does what I'm looking for pretty nicely except that, If I'm not mistaken the user struct will error out when trying to access members from the master. Another

Re: static code generation

2012-12-20 Thread r_m_r
On 12/21/2012 07:18 AM, js.mdnq wrote: struct S_A { int x; int y; void func(); void funcA(); } struct S_B { int x; int z; void func(); void funcB(); } then GenUnion(S_A, S_B) will produce a struct like S_AB { int x; int y; int z; //did u miss this? ;) void func(); void

Re: static code generation

2012-12-19 Thread r_m_r
On 12/18/2012 04:42 AM, js.mdnq wrote: It looks like the approach 2 does what I'm looking for pretty nicely except that, If I'm not mistaken the user struct will error out when trying to access members from the master. Another approach that works: http://dpaste.dzfl.pl/966d9f3a (could have

Re: static code generation

2012-12-17 Thread r_m_r
On 12/17/2012 04:33 AM, js.mdnq wrote: Well, it a slightly another way and close. Let me see if I can come up with something that expresses better what I'm after. It will be a week or two though till I get around to it probably. OK. I'll just leave this here for future reference:

Re: static code generation

2012-12-17 Thread js.mdnq
On Monday, 17 December 2012 at 22:24:58 UTC, r_m_r wrote: On 12/17/2012 04:33 AM, js.mdnq wrote: Well, it a slightly another way and close. Let me see if I can come up with something that expresses better what I'm after. It will be a week or two though till I get around to it probably. OK.

Re: static code generation

2012-12-17 Thread r_m_r
On 12/18/2012 04:42 AM, js.mdnq wrote: In any case, it seems your method does not work with methods? if I add the `check()` to your approach-2 it fails with several strange errors. Any ideas? approach-2 can only combine struct fields (i.e., no method support - for that you have to use

Re: static code generation

2012-12-16 Thread js.mdnq
On Sunday, 16 December 2012 at 01:32:44 UTC, r_m_r wrote: On 12/16/2012 06:36 AM, r_m_r wrote: this is the closest I can get: http://dpaste.dzfl.pl/9d11d060 Cleaned up a bit: http://dpaste.dzfl.pl/d9f001db regards, r_m_r That looks like it might be pretty close. I was also thinking that

Re: static code generation

2012-12-16 Thread js.mdnq
On Sunday, 16 December 2012 at 06:38:13 UTC, anonymous wrote: On Saturday, 15 December 2012 at 16:32:27 UTC, r_m_r wrote: On 12/15/2012 08:57 PM, anonymous wrote: Note that here s1alpha and s2alpha are distinct types. what about this: http://dpaste.dzfl.pl/95f7a74d Consider struct Foo

Re: static code generation

2012-12-16 Thread anonymous
On Sunday, 16 December 2012 at 08:49:10 UTC, js.mdnq wrote: On Sunday, 16 December 2012 at 06:38:13 UTC, anonymous wrote: On Saturday, 15 December 2012 at 16:32:27 UTC, r_m_r wrote: On 12/15/2012 08:57 PM, anonymous wrote: Note that here s1alpha and s2alpha are distinct types. what about

Re: static code generation

2012-12-16 Thread Philippe Sigaud
it would be real nice if I there was a compile time construct for this. like me or something that would return type info inside the current scope. class A(T) { this() { writeln(me.typeinfo.name); } would print A(T). (of course me is probably a bad name but just an example :) You could

Re: static code generation

2012-12-16 Thread r_m_r
On 12/16/2012 02:03 PM, js.mdnq wrote: That looks like it might be pretty close. I was also thinking that one could just use mixin templates of trying to do it with structs directly. i dunno if this is what u want, but have a look: http://dpaste.dzfl.pl/f5616d77 cheers, r_m_r

Re: static code generation

2012-12-16 Thread js.mdnq
On Sunday, 16 December 2012 at 15:34:34 UTC, Philippe Sigaud wrote: One could also think of it as an algebra of structs. It would be nice to be able to do stuff like A + B, A - B(possibly useless), A*B(possibly useless), etc... A + B would just combine the members, A - B could remove the

Re: static code generation

2012-12-16 Thread js.mdnq
On Sunday, 16 December 2012 at 20:29:19 UTC, r_m_r wrote: On 12/16/2012 02:03 PM, js.mdnq wrote: That looks like it might be pretty close. I was also thinking that one could just use mixin templates of trying to do it with structs directly. i dunno if this is what u want, but have a look:

Re: static code generation

2012-12-15 Thread r_m_r
On 12/10/2012 01:43 AM, anonymous wrote: Maybe it helps if you see it in action: http://dpaste.dzfl.pl/5d4cb742 Here's a slightly modified version: http://dpaste.dzfl.pl/f2bd1428 regards, r_m_r

Re: static code generation

2012-12-15 Thread anonymous
On Saturday, 15 December 2012 at 15:15:21 UTC, r_m_r wrote: On 12/10/2012 01:43 AM, anonymous wrote: Maybe it helps if you see it in action: http://dpaste.dzfl.pl/5d4cb742 Note that here s1alpha and s2alpha are distinct types. Here's a slightly modified version:

Re: static code generation

2012-12-15 Thread r_m_r
On 12/15/2012 08:57 PM, anonymous wrote: Note that here s1alpha and s2alpha are distinct types. what about this: http://dpaste.dzfl.pl/95f7a74d regards, r_m_r

Re: static code generation

2012-12-15 Thread r_m_r
On 12/10/2012 01:24 AM, js.mdnq wrote: which will fail or not be what I want, since I want to generate the structs s1 and s1. how about this: http://dpaste.dzfl.pl/c0325def regards, r_m_r

Re: static code generation

2012-12-15 Thread js.mdnq
On Saturday, 15 December 2012 at 19:09:25 UTC, r_m_r wrote: On 12/10/2012 01:24 AM, js.mdnq wrote: which will fail or not be what I want, since I want to generate the structs s1 and s1. how about this: http://dpaste.dzfl.pl/c0325def regards, r_m_r Cool, That looks like a step in the

Re: static code generation

2012-12-15 Thread r_m_r
On 12/16/2012 04:00 AM, js.mdnq wrote: Now, the next step is to be able to insert code into the struct! ;) how about this: http://dpaste.dzfl.pl/8161d00a regards, r_m_r

Re: static code generation

2012-12-15 Thread js.mdnq
On Saturday, 15 December 2012 at 23:04:37 UTC, r_m_r wrote: On 12/16/2012 04:00 AM, js.mdnq wrote: Now, the next step is to be able to insert code into the struct! ;) how about this: http://dpaste.dzfl.pl/8161d00a regards, r_m_r No, it's backwards! ;) Or, sort of what one wants to do is:

Re: static code generation

2012-12-15 Thread r_m_r
On 12/16/2012 05:30 AM, js.mdnq wrote: and mixin the UserStruct.S with the MasterStruct_A this is the closest I can get: http://dpaste.dzfl.pl/9d11d060 regards, r_m_r

Re: static code generation

2012-12-15 Thread r_m_r
On 12/16/2012 06:36 AM, r_m_r wrote: this is the closest I can get: http://dpaste.dzfl.pl/9d11d060 Cleaned up a bit: http://dpaste.dzfl.pl/d9f001db regards, r_m_r

Re: static code generation

2012-12-15 Thread anonymous
On Saturday, 15 December 2012 at 16:32:27 UTC, r_m_r wrote: On 12/15/2012 08:57 PM, anonymous wrote: Note that here s1alpha and s2alpha are distinct types. what about this: http://dpaste.dzfl.pl/95f7a74d Consider struct Foo {mixin (genStruct!(s1));} struct Bar {mixin (genStruct!(s1));}

Re: static code generation

2012-12-15 Thread r_m_r
On 12/16/2012 12:08 PM, anonymous wrote: Foo.s1alpha and Bar.s1alpha are the same type. In my version they are not. OK. Fair Enough :-)

Re: static code generation

2012-12-13 Thread js.mdnq
On Thursday, 13 December 2012 at 06:26:15 UTC, dennis luehring wrote: Am 13.12.2012 04:32, schrieb js.mdnq: I think the issue I have with all this is that when you put code inside a string you lose a lot of compile time features AFAICT. your right - but...try to come up with an similar (easy

Re: static code generation

2012-12-13 Thread Jacob Carlborg
On 2012-12-09 11:42, js.mdnq wrote: How can I create mixes of stringified code and code itself? http://dlang.org/mixin.html explains how to create structs using strings. But what if I do not want to have to encode the whole struct as a string but only parts of it? mixin template

Re: static code generation p2

2012-12-12 Thread js.mdnq
On Thursday, 13 December 2012 at 01:09:28 UTC, js.mdnq wrote: Take the example here: http://forum.dlang.org/thread/vrupqijwqmccdpabm...@forum.dlang.org note how he provides the body of the method in the mixin. I would like to something similar to what he has done but provide the body of the

Re: static code generation

2012-12-12 Thread js.mdnq
On Monday, 10 December 2012 at 22:01:37 UTC, Ali Çehreli wrote: On 12/10/2012 01:52 PM, js.mdnq wrote: I want to avoid having to wrap the code with as it disables highlighting and possibly other features(intellisense, etc...)) The q{} syntax is supposed to help with that issue. Emacs

Re: static code generation

2012-12-12 Thread dennis luehring
Am 13.12.2012 04:32, schrieb js.mdnq: I think the issue I have with all this is that when you put code inside a string you lose a lot of compile time features AFAICT. your right - but...try to come up with an similar (easy to implement) powerfull solution that is not based on strings and you

Re: static code generation

2012-12-10 Thread js.mdnq
On Monday, 10 December 2012 at 20:17:41 UTC, Philippe Sigaud wrote: If I'm not mistaken isn't the code I'm trying to generate still in a string? Well, yes, but not when you mix it in. It's a string mixin in this case, not a template mixin. My whole point is not to use strings to insert

Re: static code generation

2012-12-10 Thread Ali Çehreli
On 12/10/2012 01:52 PM, js.mdnq wrote: I want to avoid having to wrap the code with as it disables highlighting and possibly other features(intellisense, etc...)) The q{} syntax is supposed to help with that issue. Emacs manages syntax highlighting correctly for the q{} strings: import

Re: static code generation

2012-12-10 Thread js.mdnq
On Monday, 10 December 2012 at 22:01:37 UTC, Ali Çehreli wrote: On 12/10/2012 01:52 PM, js.mdnq wrote: I want to avoid having to wrap the code with as it disables highlighting and possibly other features(intellisense, etc...)) The q{} syntax is supposed to help with that issue. Emacs

Re: static code generation

2012-12-09 Thread js.mdnq
On Sunday, 9 December 2012 at 10:42:40 UTC, js.mdnq wrote: How can I create mixes of stringified code and code itself? http://dlang.org/mixin.html explains how to create structs using strings. But what if I do not want to have to encode the whole struct as a string but only parts of it?

Re: static code generation

2012-12-09 Thread js.mdnq
On Sunday, 9 December 2012 at 11:25:25 UTC, Philippe Sigaud wrote: You can use a templated string-returning function and mix it in: string codeGenerator(compileTimeArguments, Other...)(Other others) { string result = ... (...) // build your code here return result; } (...)

Re: static code generation

2012-12-09 Thread anonymous
On Sunday, 9 December 2012 at 10:42:40 UTC, js.mdnq wrote: How can I create mixes of stringified code and code itself? [...] mixin template GenStruct(stringname) { struct stringname ~ alpha { } } mixin GenStruct!(Helpme); would be equivalent to do the following

Re: static code generation

2012-12-09 Thread js.mdnq
On Sunday, 9 December 2012 at 19:09:49 UTC, anonymous wrote: On Sunday, 9 December 2012 at 10:42:40 UTC, js.mdnq wrote: How can I create mixes of stringified code and code itself? [...] mixin template GenStruct(stringname) { struct stringname ~ alpha { } } mixin

Re: static code generation

2012-12-09 Thread anonymous
On Sunday, 9 December 2012 at 19:24:24 UTC, js.mdnq wrote: In this particular case you can do this: mixin template GenStruct(string stringname) { struct S { } mixin(alias S ~ stringname ~ alpha;); } But what if I use more than one mixin? I'll have multiple

Re: static code generation

2012-12-09 Thread js.mdnq
On Sunday, 9 December 2012 at 19:34:05 UTC, anonymous wrote: On Sunday, 9 December 2012 at 19:24:24 UTC, js.mdnq wrote: In this particular case you can do this: mixin template GenStruct(string stringname) { struct S { } mixin(alias S ~ stringname ~ alpha;); } But what

Re: static code generation

2012-12-09 Thread Benjamin Thaut
If you need a small example for code generation, the following code will generate code for translating any enum value into a string: string EnumToStringGenerate(T,string templateVar = T, string pre = )(string var){ string res = final switch( ~ var ~ ){;

Re: static code generation

2012-12-09 Thread anonymous
On Sunday, 9 December 2012 at 19:54:17 UTC, js.mdnq wrote: On Sunday, 9 December 2012 at 19:34:05 UTC, anonymous wrote: On Sunday, 9 December 2012 at 19:24:24 UTC, js.mdnq wrote: In this particular case you can do this: mixin template GenStruct(string stringname) { struct S {