digitalmars.D.learn - mixin template FAIL
- Zach the Mystic <reachzachatgooglesmailservice dot.com> Feb 21 2012
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> Feb 21 2012
- Jacob Carlborg <doob me.com> Feb 21 2012
- Ellery Newcomer <ellery-newcomer utulsa.edu> Feb 21 2012
- Zach the Mystic <reachzachatgooglesmailservice dot.com> Feb 23 2012
- Ellery Newcomer <ellery-newcomer utulsa.edu> Feb 23 2012
- "H. S. Teoh" <hsteoh quickfur.ath.cx> Feb 23 2012
- "H. S. Teoh" <hsteoh quickfur.ath.cx> Feb 24 2012
- James Miller <james aatch.net> Feb 24 2012
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 Ali
come 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 Ali
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!"); } 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
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:import std.stdio; mixin template helpMe() { writeln("Satisfying!"); }
like this: mixin template helpMe() { int durrr = (writeln("Satisfying!"), 1); }
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? Zach
Feb 24 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:According to the docs, template mixins can have only declarations but helpMe above has a statement. http://dlang.org/template-mixin.html Ali
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!");
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".
Feb 23 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 it correctly Java and C#'s generics don't even come close to C++'s 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
--0015175dd97293e77004b9bf4c63 Content-Type: text/plain; charset=UTF-8 On Feb 25, 2012 9:08 AM, "Zach the Mystic" < reachzachatgooglesmailservice dot.com> wrote:On 2/23/12 7:33 PM, Ellery Newcomer wrote: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); }
No, it doesn't. You're right. I guess I have a long way to go to learn
Thank you. Even at my primitive level, though, I can see how awesome
language come close to D in terms of generics? I don't know, I'm just asking?Zach
Lisp macros. But that's not a fair comparison, Lisp's object system was built using their macros... -- James Miller --0015175dd97293e77004b9bf4c63 Content-Type: text/html; charset=UTF-8 <p>On Feb 25, 2012 9:08 AM, "Zach the Mystic" <<a href="mailto:reachzachatgooglesmailservice dot.com">reachzachatgooglesmailser ice dot.com</a>> wrote:<br> ><br> > On 2/23/12 7:33 PM, Ellery Newcomer wrote:<br> >>><br> >>> import std.stdio;<br> >>><br> >>> mixin template helpMe()<br> >>> {<br> >>> writeln("Satisfying!");<br> >>> }<br> >><br> >> does it do that if you replace the statement with a declaration?<br> >><br> >> like this:<br> >><br> >> mixin template helpMe()<br> >> {<br> >> int durrr = (writeln("Satisfying!"), 1);<br> >> }<br> ><br> ><br> > No, it doesn't. You're right. I guess I have a long way to go to learn these things.<br> ><br> > 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?<br> ><br> > Zach</p> <p>Lisp macros. But that's not a fair comparison, Lisp's object system was built using their macros...</p> <p>--<br> James Miller</p> --0015175dd97293e77004b9bf4c63--
Feb 24 2012









Jacob Carlborg <doob me.com> 