digitalmars.D.learn - mixin template FAIL
- Zach the Mystic (20/20) Feb 21 2012 I decided to try using template mixin, but even the simplest program
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/25) Feb 21 2012 According to the docs, template mixins can have only declarations but
- Jacob Carlborg (7/37) Feb 21 2012 And the correct syntax for mixing in the template would be:
- Ellery Newcomer (3/7) Feb 21 2012 come to think of it, I've occasionally wished for statement mixins. This...
- Zach the Mystic (22/26) Feb 23 2012 Thanks for your reply. You're right about the statement. But I still
- H. S. Teoh (9/27) Feb 23 2012 The writeln call is a statement.
- Ellery Newcomer (6/14) Feb 23 2012 does it do that if you replace the statement with a declaration?
- Zach the Mystic (8/20) Feb 24 2012 No, it doesn't. You're right. I guess I have a long way to go to learn
- H. S. Teoh (10/12) Feb 24 2012 [...]
- James Miller (10/30) Feb 24 2012 these things.
I decided to try using template mixin, but even the simplest program 
fails. What's wrong with this code? Error list follows.
DMD64 D Compiler v2.057  OSX 10.6
import std.stdio;
mixin template helpMe()
{
    writeln("Satisfying!");
}
void main()
{
    mixin helpMe();
}
test.d(5): unexpected ( in declarator
test.d(5): basic type expected, not "Satisfying!"
test.d(5): found '"Satisfying!"' when expecting ')'
test.d(5): no identifier for declarator writeln(int)
test.d(5): semicolon expected following function declaration
test.d(5): Declaration expected, not ')'
test.d(10): ';' expected after mixin
test.d(10): found ')' instead of statement
 Feb 21 2012
On 02/21/2012 10:47 AM, Zach the Mystic wrote:
 I decided to try using template mixin, but even the simplest program
 fails. What's wrong with this code? Error list follows.
 DMD64 D Compiler v2.057 OSX 10.6
 import std.stdio;
 mixin template helpMe()
 {
 writeln("Satisfying!");
 }
 void main()
 {
 mixin helpMe();
 }
 test.d(5): unexpected ( in declarator
 test.d(5): basic type expected, not "Satisfying!"
 test.d(5): found '"Satisfying!"' when expecting ')'
 test.d(5): no identifier for declarator writeln(int)
 test.d(5): semicolon expected following function declaration
 test.d(5): Declaration expected, not ')'
 test.d(10): ';' expected after mixin
 test.d(10): found ')' instead of statement
According to the docs, template mixins can have only declarations but 
helpMe above has a statement.
   http://dlang.org/template-mixin.html
Ali
 Feb 21 2012
On 2012-02-21 20:53, Ali Çehreli wrote:
 On 02/21/2012 10:47 AM, Zach the Mystic wrote:
  > I decided to try using template mixin, but even the simplest program
  > fails. What's wrong with this code? Error list follows.
  > DMD64 D Compiler v2.057 OSX 10.6
  >
  > import std.stdio;
  >
  > mixin template helpMe()
  > {
  > writeln("Satisfying!");
  > }
  >
  > void main()
  > {
  > mixin helpMe();
  > }
  >
  > test.d(5): unexpected ( in declarator
  > test.d(5): basic type expected, not "Satisfying!"
  > test.d(5): found '"Satisfying!"' when expecting ')'
  > test.d(5): no identifier for declarator writeln(int)
  > test.d(5): semicolon expected following function declaration
  > test.d(5): Declaration expected, not ')'
  > test.d(10): ';' expected after mixin
  > test.d(10): found ')' instead of statement
  >
 According to the docs, template mixins can have only declarations but
 helpMe above has a statement.
 http://dlang.org/template-mixin.html
 Ali
And the correct syntax for mixing in the template would be:
mixin helpMe!();
Or
mixin helpMe; // works if the template doesn't take any arguments
-- 
/Jacob Carlborg
 Feb 21 2012
On 02/21/2012 01:53 PM, Ali Çehreli wrote:According to the docs, template mixins can have only declarations but helpMe above has a statement. http://dlang.org/template-mixin.html Alicome to think of it, I've occasionally wished for statement mixins. This would make a good enhancement request.
 Feb 21 2012
On 2/21/12 2:53 PM, Ali Çehreli wrote:According to the docs, template mixins can have only declarations but helpMe above has a statement. http://dlang.org/template-mixin.html AliThanks for your reply. You're right about the statement. But I still think something's wrong. For example, even this program produces the errors: import std.stdio; mixin template helpMe() { writeln("Satisfying!"); } void main(){} test.d(5): unexpected ( in declarator test.d(5): basic type expected, not "Satisfying!" test.d(5): found '"Satisfying!"' when expecting ')' test.d(5): no identifier for declarator writeln(int) test.d(5): semicolon expected following function declaration test.d(5): Declaration expected, not ')' The parser just isn't recognizing the presence of the template mixin format. The errors happen instantly, which generally happens only when you have parser errors. I don't know, but I think there might be some stupid typo in the source code for the current dmd I'm using (2.057 Mac OSX 10.6). I'd have to download another version, but I was distracted by other things. Zach
 Feb 23 2012
On Thu, Feb 23, 2012 at 05:27:03PM -0500, Zach the Mystic wrote:On 2/21/12 2:53 PM, Ali Çehreli wrote:The writeln call is a statement. I think what you want is this: template helpMe() { mixin(`writeln("Satisfying!");`); } T -- Real Programmers use "cat > a.out".According to the docs, template mixins can have only declarations but helpMe above has a statement. http://dlang.org/template-mixin.html AliThanks for your reply. You're right about the statement. But I still think something's wrong. For example, even this program produces the errors: import std.stdio; mixin template helpMe() { writeln("Satisfying!");
 Feb 23 2012
 Thanks for your reply. You're right about the statement. But I still
 think something's wrong. For example, even this program produces the
 errors:
 import std.stdio;
 mixin template helpMe()
 {
 writeln("Satisfying!");
 }
does it do that if you replace the statement with a declaration?
like this:
mixin template helpMe()
{
   int durrr = (writeln("Satisfying!"), 1);
}
 Feb 23 2012
On 2/23/12 7:33 PM, Ellery Newcomer wrote:No, it doesn't. You're right. I guess I have a long way to go to learn these things. Thank you. Even at my primitive level, though, I can see how awesome these things could be once you know how to program them. Does any other language come close to D in terms of generics? I don't know, I'm just asking? Zachimport std.stdio; mixin template helpMe() { writeln("Satisfying!"); }does it do that if you replace the statement with a declaration? like this: mixin template helpMe() { int durrr = (writeln("Satisfying!"), 1); }
 Feb 24 2012
On Fri, Feb 24, 2012 at 03:08:18PM -0500, Zach the Mystic wrote: [...]Does any other language come close to D in terms of generics? I don't know, I'm just asking?[...] AFAIK, no. But then I only have C++ to compare with, and if I understand templates (in terms of expressive power, though they are certainly a lot cleaner than the mess that is C++ template syntax). T -- Some ideas are so stupid that only intellectuals could believe them. -- George Orwell
 Feb 24 2012
On Feb 25, 2012 9:08 AM, "Zach the Mystic" < reachzachatgooglesmailservice dot.com> wrote:On 2/23/12 7:33 PM, Ellery Newcomer wrote:these things.No, it doesn't. You're right. I guess I have a long way to go to learnimport std.stdio; mixin template helpMe() { writeln("Satisfying!"); }does it do that if you replace the statement with a declaration? like this: mixin template helpMe() { int durrr = (writeln("Satisfying!"), 1); }Thank you. Even at my primitive level, though, I can see how awesomethese things could be once you know how to program them. Does any other language come close to D in terms of generics? I don't know, I'm just asking?ZachLisp macros. But that's not a fair comparison, Lisp's object system was built using their macros... -- James Miller
 Feb 24 2012








 
  
  
 
 Jacob Carlborg <doob me.com>
 Jacob Carlborg <doob me.com> 