digitalmars.D - Help with mixins
- Derek Parnell (36/36) Feb 17 2005 I guess I don't really understand the mixin concept after all. Here is t...
- Regan Heath (20/54) Feb 17 2005 I'm not sure how much this helps, but it works if you do this...
- Derek Parnell (16/89) Feb 17 2005 Thanks for the hint. Now I read the docs with this fresh perspective, I
- Russ Lewis (3/6) Feb 18 2005 It occurs to me that maybe you should make a mixin which includes both
- Derek Parnell (8/82) Feb 17 2005 BTW, it would be nice if we could do ...
- Ben Hinkle (3/6) Feb 18 2005 This worked for me:
- Derek (5/14) Feb 18 2005 Thanks. I was so fixated on 'mixin' that I forgot using it a template ;-...
- Ben Hinkle (6/17) Feb 18 2005 I was actually surprised the mixin-less version worked. I don't think Se...
I guess I don't really understand the mixin concept after all. Here is the code example (after cutting it down from a very large source file) that is giving me grief... module test; class Foo { template SetStool(T) { void Setter(T A) { BarStool = A;} } real BarStool; this (float A) { this.Setter( A ); } this (real A) { this.Setter( A ); } } The messages I get are ... test.d(6): function test.Foo.SetStool!(real).Setter conflicts with test.Foo.SetStool!(float).Setter at test.d(6) test.d(6): function test.Foo.SetStool!(real).Setter conflicts with test.Foo.SetStool!(float).Setter at test.d(6) it compiles fine. in the text of the template with the appropriate substitutions. To make matter more confusing, if I just comment out either *one* of the mixins, it also compiles okay, making it seem as if I'd typed in the Setter function in full instead of the mixin. Can somebody explain to me where my understanding is off track? -- Derek Melbourne, Australia 18/02/2005 2:30:28 PM
Feb 17 2005
On Fri, 18 Feb 2005 14:30:32 +1100, Derek Parnell <derek psych.ward> wrote:I guess I don't really understand the mixin concept after all. Here is the code example (after cutting it down from a very large source file) that is giving me grief... module test; class Foo { template SetStool(T) { void Setter(T A) { BarStool = A;} } real BarStool; this (float A) { this.Setter( A ); } this (real A) { this.Setter( A ); } } The messages I get are ... test.d(6): function test.Foo.SetStool!(real).Setter conflicts with test.Foo.SetStool!(float).Setter at test.d(6) test.d(6): function test.Foo.SetStool!(real).Setter conflicts with test.Foo.SetStool!(float).Setter at test.d(6) it compiles fine. typed in the text of the template with the appropriate substitutions. To make matter more confusing, if I just comment out either *one* of the mixins, it also compiles okay, making it seem as if I'd typed in the Setter function in full instead of the mixin. Can somebody explain to me where my understanding is off track?I'm not sure how much this helps, but it works if you do this... class Foo { template SetStool(T) { void Setter(T A) { BarStool = A;} } real BarStool; alias mr.Setter Setter; alias mf.Setter Setter; this (float A) { this.Setter( A ); } this (real A) { this.Setter( A ); } } void main() { } It might have something to do with the fact that "A mixin has its own scope"? Regan
Feb 17 2005
On Fri, 18 Feb 2005 17:17:53 +1300, Regan Heath wrote:On Fri, 18 Feb 2005 14:30:32 +1100, Derek Parnell <derek psych.ward> wrote:Thanks for the hint. Now I read the docs with this fresh perspective, I suspect its the rule ... "If two different mixins are put in the same scope, and each define a declaration with the same name, there is an ambiguity error when the declaration is referenced" coming in to play. Up until now, I read this as "two different mixin _templates_" but it seems that it literally means two "mixin" statements regardless of the template name they are mixing in. Well, I was hoping to reduce the amount of typing I had to do but as the mixin solution involves more typing than copy-paste solution, I guess I leave mixins for another day. -- Derek Melbourne, Australia 18/02/2005 3:37:01 PMI guess I don't really understand the mixin concept after all. Here is the code example (after cutting it down from a very large source file) that is giving me grief... module test; class Foo { template SetStool(T) { void Setter(T A) { BarStool = A;} } real BarStool; this (float A) { this.Setter( A ); } this (real A) { this.Setter( A ); } } The messages I get are ... test.d(6): function test.Foo.SetStool!(real).Setter conflicts with test.Foo.SetStool!(float).Setter at test.d(6) test.d(6): function test.Foo.SetStool!(real).Setter conflicts with test.Foo.SetStool!(float).Setter at test.d(6) it compiles fine. typed in the text of the template with the appropriate substitutions. To make matter more confusing, if I just comment out either *one* of the mixins, it also compiles okay, making it seem as if I'd typed in the Setter function in full instead of the mixin. Can somebody explain to me where my understanding is off track?I'm not sure how much this helps, but it works if you do this... class Foo { template SetStool(T) { void Setter(T A) { BarStool = A;} } real BarStool; alias mr.Setter Setter; alias mf.Setter Setter; this (float A) { this.Setter( A ); } this (real A) { this.Setter( A ); } } void main() { } It might have something to do with the fact that "A mixin has its own scope"?
Feb 17 2005
Well, I was hoping to reduce the amount of typing I had to do but as the mixin solution involves more typing than copy-paste solution, I guess I leave mixins for another day.It occurs to me that maybe you should make a mixin which includes both of the overloaded functions. Then you only have to use one mixin statement, and the alias is not required.
Feb 18 2005
On Fri, 18 Feb 2005 17:17:53 +1300, Regan Heath wrote:On Fri, 18 Feb 2005 14:30:32 +1100, Derek Parnell <derek psych.ward> wrote:BTW, it would be nice if we could do ... alias mixin SetStool!(real).Setter Setter; instead of having to invent a symbol name just for this purpose. -- Derek Melbourne, Australia 18/02/2005 3:50:44 PMI guess I don't really understand the mixin concept after all. Here is the code example (after cutting it down from a very large source file) that is giving me grief... module test; class Foo { template SetStool(T) { void Setter(T A) { BarStool = A;} } real BarStool; this (float A) { this.Setter( A ); } this (real A) { this.Setter( A ); } } The messages I get are ... test.d(6): function test.Foo.SetStool!(real).Setter conflicts with test.Foo.SetStool!(float).Setter at test.d(6) test.d(6): function test.Foo.SetStool!(real).Setter conflicts with test.Foo.SetStool!(float).Setter at test.d(6) it compiles fine. typed in the text of the template with the appropriate substitutions. To make matter more confusing, if I just comment out either *one* of the mixins, it also compiles okay, making it seem as if I'd typed in the Setter function in full instead of the mixin. Can somebody explain to me where my understanding is off track?I'm not sure how much this helps, but it works if you do this... class Foo { template SetStool(T) { void Setter(T A) { BarStool = A;} } real BarStool; alias mr.Setter Setter; alias mf.Setter Setter; this (float A) { this.Setter( A ); } this (real A) { this.Setter( A ); } } void main() { } It might have something to do with the fact that "A mixin has its own scope"? Regan
Feb 17 2005
BTW, it would be nice if we could do ... alias mixin SetStool!(real).Setter Setter; instead of having to invent a symbol name just for this purpose.This worked for me: alias SetStool!(float).Setter Setter; alias SetStool!(real).Setter Setter;
Feb 18 2005
On Fri, 18 Feb 2005 13:18:12 +0000 (UTC), Ben Hinkle wrote:Thanks. I was so fixated on 'mixin' that I forgot using it a template ;-) -- Derek Melbourne, AustraliaBTW, it would be nice if we could do ... alias mixin SetStool!(real).Setter Setter; instead of having to invent a symbol name just for this purpose.This worked for me: alias SetStool!(float).Setter Setter; alias SetStool!(real).Setter Setter;
Feb 18 2005
"Derek" <derek psych.ward> wrote in message news:1hqc25fq33yw9.yjfpno4bcjj9.dlg 40tude.net...On Fri, 18 Feb 2005 13:18:12 +0000 (UTC), Ben Hinkle wrote:I was actually surprised the mixin-less version worked. I don't think Setter becomes a member function without using a mixin so I'm not exactly sure what state Setter is in. Some experiments with subclassing should flush out any bugs if there are compiler bugs in there.Thanks. I was so fixated on 'mixin' that I forgot using it a template ;-)BTW, it would be nice if we could do ... alias mixin SetStool!(real).Setter Setter; instead of having to invent a symbol name just for this purpose.This worked for me: alias SetStool!(float).Setter Setter; alias SetStool!(real).Setter Setter;
Feb 18 2005