Thread overview
Template mixin problem
Dec 15, 2008
Olli Aalto
Dec 15, 2008
Olli Aalto
Dec 15, 2008
Bill Baxter
Dec 15, 2008
Olli Aalto
Dec 15, 2008
Bill Baxter
Dec 15, 2008
Olli Aalto
December 15, 2008
I already posed this question on the #D channel, but here's for the rest of you.

http://tango.pastebin.com/m59b8715f

Here's the error:

oaalto-desktop Projects/workspace/MixinTest> dsss build
mixins/main.d => mixin_test
mixins/HelloWorld.d(7): mixin is not defined
mixins/HelloWorld.d(8): mixin mixins.HelloWorld.HelloWorld.HelloSpeaker!() error instantiating
mixins/HelloWorld.d(7): mixin is not defined
mixins/HelloWorld.d(8): mixin mixins.HelloWorld.HelloWorld.HelloSpeaker!() error instantiating
Command /home/oaalto/D/dsss/bin/rebuild returned with code 256, aborting.
Error: Command failed, aborting.

Any ideas what's going wrong?

DMD 1.033
DSSS 0.78

O.
December 15, 2008
Ok, downs figured it out on #D. You can't have mixins in templates, which is a big disappointment.

Removing the HelloData mixin from HelloSpeaker and all references to helloStr it "works".

O.
December 15, 2008
On Mon, Dec 15, 2008 at 5:48 PM, Olli Aalto <oaalto@gmail.com> wrote:
> Ok, downs figured it out on #D. You can't have mixins in templates, which is a big disappointment.
>
> Removing the HelloData mixin from HelloSpeaker and all references to helloStr it "works".

Hmm, didn't know that.  But also if you import a module that uses a mixin, the module that uses the mixin also needs to import the mixin module.  I'm sure that didn't make any sense.

I.e. you may need to import mixins.HelloData in mixins.HelloWorld. And maybe import all the mixin modules in in main.

--bb
December 15, 2008
Bill Baxter wrote:
> On Mon, Dec 15, 2008 at 5:48 PM, Olli Aalto <oaalto@gmail.com> wrote:
>> Ok, downs figured it out on #D. You can't have mixins in templates, which is
>> a big disappointment.
>>
>> Removing the HelloData mixin from HelloSpeaker and all references to
>> helloStr it "works".
> 
> Hmm, didn't know that.  But also if you import a module that uses a
> mixin, the module that uses the mixin also needs to import the mixin
> module.  I'm sure that didn't make any sense.
> 
> I.e. you may need to import mixins.HelloData in mixins.HelloWorld.
> And maybe import all the mixin modules in in main.
> 

Yeah, just tried that and it worked. :) I think all this makes some kind of sense, but having to import the module for HelloData in HelloWorld shouldn't be needed. It's already been mixed-in in HelloSpeaker so from the HelloWorld's standpoint there is no HelloData. But any way glad to have it working.

O.
December 15, 2008
On Mon, Dec 15, 2008 at 5:58 PM, Olli Aalto <oaalto@gmail.com> wrote:
> Bill Baxter wrote:
>>
>> On Mon, Dec 15, 2008 at 5:48 PM, Olli Aalto <oaalto@gmail.com> wrote:
>>>
>>> Ok, downs figured it out on #D. You can't have mixins in templates, which
>>> is
>>> a big disappointment.
>>>
>>> Removing the HelloData mixin from HelloSpeaker and all references to helloStr it "works".
>>
>> Hmm, didn't know that.  But also if you import a module that uses a mixin, the module that uses the mixin also needs to import the mixin module.  I'm sure that didn't make any sense.
>>
>> I.e. you may need to import mixins.HelloData in mixins.HelloWorld. And maybe import all the mixin modules in in main.
>>
>
> Yeah, just tried that and it worked. :) I think all this makes some kind of sense, but having to import the module for HelloData in HelloWorld shouldn't be needed. It's already been mixed-in in HelloSpeaker so from the HelloWorld's standpoint there is no HelloData. But any way glad to have it working.

But modules are inherited privately by default.
If you use "public import blahblah" for the modules the mixins require
then you can get around the problem.

Also there is a trick that I think h3r3tic first noticed -- you can actually put an import statement inside the template, and at least if it gets mixed into a class, it will work.  May work in other cases too, but not so sure about that.

--bb
December 15, 2008
Bill Baxter wrote:
> On Mon, Dec 15, 2008 at 5:58 PM, Olli Aalto <oaalto@gmail.com> wrote:
>> Bill Baxter wrote:
>>> On Mon, Dec 15, 2008 at 5:48 PM, Olli Aalto <oaalto@gmail.com> wrote:
>>>> Ok, downs figured it out on #D. You can't have mixins in templates, which
>>>> is
>>>> a big disappointment.
>>>>
>>>> Removing the HelloData mixin from HelloSpeaker and all references to
>>>> helloStr it "works".
>>> Hmm, didn't know that.  But also if you import a module that uses a
>>> mixin, the module that uses the mixin also needs to import the mixin
>>> module.  I'm sure that didn't make any sense.
>>>
>>> I.e. you may need to import mixins.HelloData in mixins.HelloWorld.
>>> And maybe import all the mixin modules in in main.
>>>
>> Yeah, just tried that and it worked. :) I think all this makes some kind of
>> sense, but having to import the module for HelloData in HelloWorld shouldn't
>> be needed. It's already been mixed-in in HelloSpeaker so from the
>> HelloWorld's standpoint there is no HelloData. But any way glad to have it
>> working.
> 
> But modules are inherited privately by default.
> If you use "public import blahblah" for the modules the mixins require
> then you can get around the problem.
> 
> Also there is a trick that I think h3r3tic first noticed -- you can
> actually put an import statement inside the template, and at least if
> it gets mixed into a class, it will work.  May work in other cases
> too, but not so sure about that.
> 

Yes, I know that they are private by default and that's great. My point here is this: (copy pasted from #D)
< Odeamus> the way I see this is that when the HelloWorld sees the mixin
for HelloSpeaker the HelloSpeaker template should already  contain the line "private char[] helloStr" and not the mixin

But any way I wrote couple words about what I was after here:
http://odefu.blogspot.com/2008/12/composite-oriented-programming.html

O.