Re: Mixin Template: cannot mixin scope(exit)?
On Monday, 14 January 2013 at 06:26:33 UTC, 1100110 wrote: On 01/13/2013 11:35 PM, 1100110 wrote: Ok, I wish to create a standard timing system so that I can measure ~how long each function takes to execute. I wish to be able to place at the start of a function version(Time) mixin TimeExecution(funcName); mixin template TimeExecution(T) if(isSomeString!T) { import std.stdio, std.datetime, std.conv; auto sw = StopWatch(AutoStart.yes); // Error: Declaration expected, not '(' scope(exit) writeln(T, : , to!Duration(sw.peek)); } Why do I receive the Error when the scope statement is included? Is this an error, or what is the rationale behind the decision? Thank you. It appears that you cannot mixin *any* statement with scope([exit,success,etc]) in it. Mixin templates are supposed to introduce *declarations* not statements. Eg. even this shouldn't compile, should it? --- mixin template TimeExecution(T) if(isSomeString!T) { import std.stdio; writeln(T); // statement } ---
Re: Mixin Template: cannot mixin scope(exit)?
I thought template itself should compile but its statement-like instantiation should not. By the way, if all you want is to split out some generic statement block without using dirty string mixins, template functions with alias parameters may do. I.e. http://dpaste.1azy.net/68ad8133 Don't know what about inlining for it though. Mixin templates are supposed to introduce *declarations* not statements. Eg. even this shouldn't compile, should it? --- mixin template TimeExecution(T) if(isSomeString!T) { import std.stdio; writeln(T); // statement } ---
Re: Mixin Template: cannot mixin scope(exit)?
On Tuesday, 15 January 2013 at 11:19:50 UTC, mist wrote: I thought template itself should compile but its statement-like instantiation should not. The template shouldn't compile: the D grammar says that mixin templates inject declarations only. Hence the text of the error. By the way, if all you want is to split out some generic statement block without using dirty string mixins, template functions with alias parameters may do. I.e. http://dpaste.1azy.net/68ad8133 Yes, but only a string mixin can inject a scope statement.
Re: Mixin Template: cannot mixin scope(exit)?
On 01/14/2013 07:26 AM, 1100110 wrote: On 01/13/2013 11:35 PM, 1100110 wrote: Ok, I wish to create a standard timing system so that I can measure ~how long each function takes to execute. I wish to be able to place at the start of a function version(Time) mixin TimeExecution(funcName); mixin template TimeExecution(T) if(isSomeString!T) { import std.stdio, std.datetime, std.conv; auto sw = StopWatch(AutoStart.yes); // Error: Declaration expected, not '(' scope(exit) writeln(T, : , to!Duration(sw.peek)); } Why do I receive the Error when the scope statement is included? Is this an error, or what is the rationale behind the decision? Thank you. It appears that you cannot mixin *any* statement with scope([exit,success,etc]) in it. I have been rereading my copy of TDPL, and it states that mixin statements must be valid D code, and there can be multiple 'scope()' statements. Since scope(exit) writeln(); is valid D code, and refuses to compile in a mixin, I assume that this is a bug. I've been digging through the bug tracker and I cannot find a duplicate bug, so if someone can confirm that this is a bug, I'll create a report. It is not a bug. Use a string mixin.
Re: Mixin Template: cannot mixin scope(exit)?
On 01/14/2013 02:03 AM, Timon Gehr wrote: On 01/14/2013 07:26 AM, 1100110 wrote: On 01/13/2013 11:35 PM, 1100110 wrote: Ok, I wish to create a standard timing system so that I can measure ~how long each function takes to execute. I wish to be able to place at the start of a function version(Time) mixin TimeExecution(funcName); mixin template TimeExecution(T) if(isSomeString!T) { import std.stdio, std.datetime, std.conv; auto sw = StopWatch(AutoStart.yes); // Error: Declaration expected, not '(' scope(exit) writeln(T, : , to!Duration(sw.peek)); } Why do I receive the Error when the scope statement is included? Is this an error, or what is the rationale behind the decision? Thank you. It appears that you cannot mixin *any* statement with scope([exit,success,etc]) in it. I have been rereading my copy of TDPL, and it states that mixin statements must be valid D code, and there can be multiple 'scope()' statements. Since scope(exit) writeln(); is valid D code, and refuses to compile in a mixin, I assume that this is a bug. I've been digging through the bug tracker and I cannot find a duplicate bug, so if someone can confirm that this is a bug, I'll create a report. It is not a bug. Use a string mixin. Well, dangit. Thanks!
Re: Mixin Template: cannot mixin scope(exit)?
It appears that you cannot mixin *any* statement with scope([exit,success,etc]) in it. I have been rereading my copy of TDPL, and it states that mixin statements must be valid D code, and there can be multiple 'scope()' statements. Since scope(exit) writeln(); is valid D code, and refuses to compile in a mixin, I assume that this is a bug. I've been digging through the bug tracker and I cannot find a duplicate bug, so if someone can confirm that this is a bug, I'll create a report. It is not a bug. Use a string mixin. What is the rationale behind this limitation?
Re: Mixin Template: cannot mixin scope(exit)?
On 2013-01-14 11:44, mist wrote: What is the rationale behind this limitation? I'm not sure but it might have something to do with template mixins introduce a new scope or similar. -- /Jacob Carlborg
Re: Mixin Template: cannot mixin scope(exit)?
On 01/13/2013 11:35 PM, 1100110 wrote: Ok, I wish to create a standard timing system so that I can measure ~how long each function takes to execute. I wish to be able to place at the start of a function version(Time) mixin TimeExecution(funcName); mixin template TimeExecution(T) if(isSomeString!T) { import std.stdio, std.datetime, std.conv; auto sw = StopWatch(AutoStart.yes); // Error: Declaration expected, not '(' scope(exit) writeln(T, : , to!Duration(sw.peek)); } Why do I receive the Error when the scope statement is included? Is this an error, or what is the rationale behind the decision? Thank you. It appears that you cannot mixin *any* statement with scope([exit,success,etc]) in it. I have been rereading my copy of TDPL, and it states that mixin statements must be valid D code, and there can be multiple 'scope()' statements. Since scope(exit) writeln(); is valid D code, and refuses to compile in a mixin, I assume that this is a bug. I've been digging through the bug tracker and I cannot find a duplicate bug, so if someone can confirm that this is a bug, I'll create a report.