Calling functions using mixins

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 1 14:41:08 PDT 2015


On Friday, 1 May 2015 at 21:26:20 UTC, anonymous wrote:
> On Friday, 1 May 2015 at 21:04:10 UTC, Dennis Ritchie wrote:
>> hi,
>> Is it possible to call functions using mixins in this way?
>>
>> -----
>> import std.stdio;
>>
>> int fooTestMixin() {
>> 	return 5;
>> }
>>
>> void main() {
>>
>> 	enum t { fooTestMixin };
>> 	immutable string[] strArr = [ "fooTestMixin" ];
>>
>> 	writeln(mixin(`mixin("t.fooTestMixin")`));
>
> Don't know what you're trying to do here.
>
>> 	writeln(mixin(`mixin("strArr[0]")`));
>
> writeln(mixin(`mixin(strArr[0])`));
>
> or without the pointless outer mixin:
>
> writeln(mixin(strArr[0]));
>
>> }

Thanks.
My final goal is to do something like this:

-----
import std.stdio, std.string;

int foo() {
	return 5;
}

int bar() {
	return 10;
}

void main()
{
	immutable string[] s = [ "foo", "bar" ];

	writeln(mixin(`format("%(%s, %)", s)`));;
}


More information about the Digitalmars-d-learn mailing list