Jump to page: 1 2
Thread overview
Mixin declarations not showing up in ModuleInfo
Nov 30, 2014
bitwise
Nov 30, 2014
Daniel Kozak
Nov 30, 2014
bitwise
Nov 30, 2014
bitwise
Nov 30, 2014
Daniel Kozak
Dec 01, 2014
bitwise
Dec 01, 2014
Daniel Kozák
Dec 02, 2014
bitwise
Dec 02, 2014
Daniel Kozák
Dec 02, 2014
Adam D. Ruppe
Dec 02, 2014
Daniel Kozak
November 30, 2014
In the following program, the output does not contain "SomeClass". Is this a bug?


module main;
import std.stdio;

mixin template Test()
{
	class SomeClass {
		int n = 123;
	}
}

mixin Test;

void main() {

	auto sc = new SomeClass;
	writeln(sc.n);

	foreach(m; ModuleInfo)
	{
		foreach(c; m.localClasses())
		{
			writeln(c.name);
		}
	}
}
November 30, 2014
On Sunday, 30 November 2014 at 02:10:13 UTC, bitwise wrote:
> In the following program, the output does not contain "SomeClass". Is this a bug?

Maybe yes, as a workaround this works:

module main;
import std.stdio;

template Test()
{
    enum Test = q{
        class SomeClass {
            int n = 123;
        }
    };
}

mixin(Test!());

void main() {

    auto sc = new SomeClass;
    writeln(sc.n);

    foreach(m; ModuleInfo)
    {
        foreach(c; m.localClasses())
        {
            writeln(c.name);
        }
    }
}

Btw. you can use just template, IIRC there is no difference between template and mixin template
November 30, 2014
On Sunday, 30 November 2014 at 08:00:20 UTC, Daniel Kozak wrote:
> On Sunday, 30 November 2014 at 02:10:13 UTC, bitwise wrote:
>> In the following program, the output does not contain "SomeClass". Is this a bug?
>
> Maybe yes, as a workaround this works:
>
> module main;
> import std.stdio;
>
> template Test()
> {
>     enum Test = q{
>         class SomeClass {
>             int n = 123;
>         }
>     };
> }
>
> mixin(Test!());
>
> void main() {
>
>     auto sc = new SomeClass;
>     writeln(sc.n);
>
>     foreach(m; ModuleInfo)
>     {
>         foreach(c; m.localClasses())
>         {
>             writeln(c.name);
>         }
>     }
> }
>
> Btw. you can use just template, IIRC there is no difference between template and mixin template

Hey, thanks for the q{} trick. I knew I had seen it somewhere... but couldn't find it.

That trick only really helps when there is minimal concatenation going on though. When you have to splice a bunch of stuff together, a TokenString doesn't provide much relief.

Docs for template mixins explicitly support the behaviour that I'm after, so I'm gonna file a bug.

" TemplateMixin takes an arbitrary set of declarations from the body of a TemplateDeclaration and inserts them into the current context."



November 30, 2014
https://issues.dlang.org/show_bug.cgi?id=13800
November 30, 2014
Dne Sun, 30 Nov 2014 19:34:52 +0100 bitwise via Digitalmars-d <digitalmars-d@puremagic.com> napsal(a):

> On Sunday, 30 November 2014 at 08:00:20 UTC, Daniel Kozak wrote:
>> On Sunday, 30 November 2014 at 02:10:13 UTC, bitwise wrote:
>>> In the following program, the output does not contain "SomeClass". Is this a bug?
>>
>> Maybe yes, as a workaround this works:
>>
>> module main;
>> import std.stdio;
>>
>> template Test()
>> {
>>     enum Test = q{
>>         class SomeClass {
>>             int n = 123;
>>         }
>>     };
>> }
>>
>> mixin(Test!());
>>
>> void main() {
>>
>>     auto sc = new SomeClass;
>>     writeln(sc.n);
>>
>>     foreach(m; ModuleInfo)
>>     {
>>         foreach(c; m.localClasses())
>>         {
>>             writeln(c.name);
>>         }
>>     }
>> }
>>
>> Btw. you can use just template, IIRC there is no difference between template and mixin template
>
> Hey, thanks for the q{} trick. I knew I had seen it somewhere... but couldn't find it.
>
> That trick only really helps when there is minimal concatenation going on though. When you have to splice a bunch of stuff together, a TokenString doesn't provide much relief.
>
> Docs for template mixins explicitly support the behaviour that I'm after, so I'm gonna file a bug.
>
> " TemplateMixin takes an arbitrary set of declarations from the body of a TemplateDeclaration and inserts them into the current context."
>

Yes, thats true. It is a bug. But I just try to say you can omit mixin word in template declaration. Because it doesn't have any effect.
December 01, 2014
> But I just try to say you can omit mixin word in template declaration. Because it doesn't have any effect.

mixin != mixin template != template
December 01, 2014
V Mon, 01 Dec 2014 00:07:10 +0000
bitwise via Digitalmars-d <digitalmars-d@puremagic.com> napsáno:

> > But I just try to say you can omit mixin word in template declaration. Because it doesn't have any effect.
> 
> mixin != mixin template != template
Yes and no :)

import std.stdio;

mixin template t1() {
    int x = 5;
}

void main(string[] args)
{
    mixin t1;
    writeln(x);
}

is same as:

import std.stdio;

template t1() {
    int x = 5;
}

void main(string[] args)
{
    mixin t1;
    writeln(x);
}

December 02, 2014
On Monday, 1 December 2014 at 07:28:28 UTC, Daniel Kozák via Digitalmars-d wrote:
> V Mon, 01 Dec 2014 00:07:10 +0000
> bitwise via Digitalmars-d <digitalmars-d@puremagic.com> napsáno:
>
>> > But I just try to say you can omit mixin word in template declaration. Because it doesn't have any effect.
>> 
>> mixin != mixin template != template
> Yes and no :)
>
> import std.stdio;
>
> mixin template t1() {
>     int x = 5;
> }
>
> void main(string[] args)
> {
>     mixin t1;
>     writeln(x);
> }
>
> is same as:
>
> import std.stdio;
>
> template t1() {
>     int x = 5;
> }
>
> void main(string[] args)
> {
>     mixin t1;
>     writeln(x);
> }

Heh... Guess you got me there ;)

That is strange though... I don't see in the docs that mixin templates have been deprecated, and can't seem to find anything that doesn't work in both templates and mixin templates. The "mixin name" usage is also not present in the docs for regular templates.
December 02, 2014
On Monday, 1 December 2014 at 07:28:28 UTC, Daniel Kozák via Digitalmars-d
> Yes and no :)

huh, it isn't supposed to be and I'm pretty sure it was made an error at some point...
December 02, 2014
V Tue, 02 Dec 2014 04:05:16 +0000
bitwise via Digitalmars-d <digitalmars-d@puremagic.com> napsáno:

> On Monday, 1 December 2014 at 07:28:28 UTC, Daniel Kozák via Digitalmars-d wrote:
> > V Mon, 01 Dec 2014 00:07:10 +0000
> > bitwise via Digitalmars-d <digitalmars-d@puremagic.com> napsáno:
> >
> >> > But I just try to say you can omit mixin word in template declaration. Because it doesn't have any effect.
> >> 
> >> mixin != mixin template != template
> > Yes and no :)
> >
> > import std.stdio;
> >
> > mixin template t1() {
> >     int x = 5;
> > }
> >
> > void main(string[] args)
> > {
> >     mixin t1;
> >     writeln(x);
> > }
> >
> > is same as:
> >
> > import std.stdio;
> >
> > template t1() {
> >     int x = 5;
> > }
> >
> > void main(string[] args)
> > {
> >     mixin t1;
> >     writeln(x);
> > }
> 
> Heh... Guess you got me there ;)
> 
> That is strange though... I don't see in the docs that mixin templates have been deprecated, and can't seem to find anything that doesn't work in both templates and mixin templates. The "mixin name" usage is also not present in the docs for regular templates.

There is one limitation of mixin template. You can not do this
(instantied mixin template):
import std.stdio;

mixin template t1() {
    int x = 5;
}

void main(string[] args)
{
    alias t1!() T;
    writeln(T.x);
}


But this is valid:

import std.stdio;

template t1() {
    int x = 5;
}

void main(string[] args)
{
    alias t1!() T;
    writeln(T.x);
}



« First   ‹ Prev
1 2