digitalmars.D.learn - Recursive mixins problem
- Max Samukha (25/25) Apr 07 2007 Why recursive mixins are disallowed?
- Max Samukha (7/32) Apr 09 2007 In the example above, char[] delegate() should be replaced with
- JScott (14/46) Apr 12 2007 I would assume that this is not allowed because of the way mixin templat...
- Max Samukha (4/50) Apr 16 2007 Thanks. I know about the new mixins, but the bodies of functions being
Why recursive mixins are disallowed? template Call(A...) { static if (A.length > 0) { void call(A[0] fn) { } mixin Call!(A[1..$]); } } class Caller(A...) { mixin Call!(A); } void main() { auto caller = new Caller!(int delegate(), char[] delegate()); } hello.d(15): mixin hello.Caller!(int delegate(),char[] delegate()).Caller.Call!(int delegate(),char[] delegate()).Call!(char[] delegate()).Call!() recursive mixin instantiation hello.d(26): template instance hello.Caller!(int delegate(),char[] delegate()) error instantiating
Apr 07 2007
On Sat, 07 Apr 2007 16:55:16 +0300, Max Samukha <samukha voliacable.com> wrote:Why recursive mixins are disallowed? template Call(A...) { static if (A.length > 0) { void call(A[0] fn) { } mixin Call!(A[1..$]); } } class Caller(A...) { mixin Call!(A); } void main() { auto caller = new Caller!(int delegate(), char[] delegate()); } hello.d(15): mixin hello.Caller!(int delegate(),char[] delegate()).Caller.Call!(int delegate(),char[] delegate()).Call!(char[] delegate()).Call!() recursive mixin instantiation hello.d(26): template instance hello.Caller!(int delegate(),char[] delegate()) error instantiatingIn the example above, char[] delegate() should be replaced with something like int delegate(char[]) for proper function overloading. Anyway, the problem remains. Is it a bug or temporary restriction? If not, should a note be added to the specs?
Apr 09 2007
Max Samukha Wrote:Why recursive mixins are disallowed? template Call(A...) { static if (A.length > 0) { void call(A[0] fn) { } mixin Call!(A[1..$]); } } class Caller(A...) { mixin Call!(A); } void main() { auto caller = new Caller!(int delegate(), char[] delegate()); } hello.d(15): mixin hello.Caller!(int delegate(),char[] delegate()).Caller.Call!(int delegate(),char[] delegate()).Call!(char[] delegate()).Call!() recursive mixin instantiation hello.d(26): template instance hello.Caller!(int delegate(),char[] delegate()) error instantiatingI would assume that this is not allowed because of the way mixin templates work. Everytime you instanciate a template as a mixin a new scope is created so it's possible to create a symbol with too long of a name. Now that there are mixins and compile-time execution of functions it's possible to do what you want. template Call(A...) { static if(A.length == 0) const char[] Call = ""; else static if(A.length == 1 ) const char[] Call = "void call("~(typeof(A[0])).stringof~" fn) { \n \n }"; else const char[] Call = "void call("~(typeof(A[0])).stringof~" fn) { \n \n } \n" ~ Call!(A[1..$]); } class Caller(A...) { mixin(Call!(A)); }
Apr 12 2007
On Thu, 12 Apr 2007 08:56:16 -0400, JScott <jnl417 gmail.com> wrote:Max Samukha Wrote:Thanks. I know about the new mixins, but the bodies of functions being mixed in are big in my case and the whole thing quickly turns into an unreadable mess when the new mixins are used.Why recursive mixins are disallowed? template Call(A...) { static if (A.length > 0) { void call(A[0] fn) { } mixin Call!(A[1..$]); } } class Caller(A...) { mixin Call!(A); } void main() { auto caller = new Caller!(int delegate(), char[] delegate()); } hello.d(15): mixin hello.Caller!(int delegate(),char[] delegate()).Caller.Call!(int delegate(),char[] delegate()).Call!(char[] delegate()).Call!() recursive mixin instantiation hello.d(26): template instance hello.Caller!(int delegate(),char[] delegate()) error instantiatingI would assume that this is not allowed because of the way mixin templates work. Everytime you instanciate a template as a mixin a new scope is created so it's possible to create a symbol with too long of a name. Now that there are mixins and compile-time execution of functions it's possible to do what you want. template Call(A...) { static if(A.length == 0) const char[] Call = ""; else static if(A.length == 1 ) const char[] Call = "void call("~(typeof(A[0])).stringof~" fn) { \n \n }"; else const char[] Call = "void call("~(typeof(A[0])).stringof~" fn) { \n \n } \n" ~ Call!(A[1..$]); } class Caller(A...) { mixin(Call!(A)); }
Apr 16 2007