digitalmars.D.learn - Calling functions using mixins
- Dennis Ritchie (13/13) May 01 2015 hi,
- anonymous (5/18) May 01 2015 writeln(mixin(`mixin(strArr[0])`));
- Dennis Ritchie (16/39) May 01 2015 Thanks.
- anonymous (2/16) May 01 2015 What's that supposed to do?
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (9/11) May 01 2015 If you are trying to call those functions, remove the double quotes by
- Dennis Ritchie (6/20) May 01 2015 Excuse me, what is not said. I thought that my wish will be
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")`)); writeln(mixin(`mixin("strArr[0]")`)); }
May 01 2015
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]));}
May 01 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: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)`));; }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]));}
May 01 2015
On Friday, 1 May 2015 at 21:41:10 UTC, Dennis Ritchie wrote: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)`));; }What's that supposed to do?
May 01 2015
On 05/01/2015 02:41 PM, Dennis Ritchie wrote:immutable string[] s = [ "foo", "bar" ]; writeln(mixin(`format("%(%s, %)", s)`));;If you are trying to call those functions, remove the double quotes by %-(, and use %| to specify what is a delimiter. To call, each needs a semicolon: mixin(format("%-(%s();%| %)", s)); If you wanted to print the results of calling those functions, then, yes, use a comma. Also, I think you need to put "writeln" inside as well: mixin(format("writeln(%-(%s(), %));", s)); Ali
May 01 2015
On Friday, 1 May 2015 at 21:50:51 UTC, anonymous wrote:What's that supposed to do?Excuse me, what is not said. I thought that my wish will be obvious. On Friday, 1 May 2015 at 21:59:31 UTC, Ali Çehreli wrote:On 05/01/2015 02:41 PM, Dennis Ritchie wrote:Thanks. Yes, I wanted to print the results of calling these functions.immutable string[] s = [ "foo", "bar" ]; writeln(mixin(`format("%(%s, %)", s)`));;If you are trying to call those functions, remove the double quotes by %-(, and use %| to specify what is a delimiter. To call, each needs a semicolon: mixin(format("%-(%s();%| %)", s)); If you wanted to print the results of calling those functions, then, yes, use a comma. Also, I think you need to put "writeln" inside as well: mixin(format("writeln(%-(%s(), %));", s)); Ali
May 01 2015