digitalmars.D.learn - Why not mixin "int a;" ??
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= (9/9) Aug 24 2008 I can mixin templates without parens, like this:
- Jarrett Billingsley (6/15) Aug 24 2008 mixin foo;
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= (4/10) Aug 24 2008 Is there a difference in what happens when you mixin a template and a st...
- BCS (7/20) Aug 24 2008 template Foo()
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= (7/15) Aug 24 2008 a const named Foo
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= (16/16) Aug 24 2008 I got a code generating function:
- BCS (5/28) Aug 24 2008 using CTFE (compile time function evaluation) with arrays is "finicky"
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= (9/15) Aug 24 2008 It says intGen("aa", "bb", "cc") can't be evaluated at compile time... ...
- BCS (4/21) Aug 24 2008 The CTFE engine is insanely limited and I can't seem to find the docs. Y...
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= (2/7) Aug 25 2008 never mind, knowing that it's a bug helps, because I won't waste time tr...
- BCS (3/13) Aug 25 2008 I'm not saying it's a bug (or that it is not), closed bug's would contai...
- Max Samukha (19/20) Aug 24 2008 I think you tried to pass separate strings to the non-variadic
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= (2/6) Aug 25 2008 works! thank you
I can mixin templates without parens, like this: mixin foo!(int); So why can't I do this: mixin "int a;"; instead of this: mixin("int a;"); ? Seems a bit inconsistent to me, but maybe I don't see the reason... Tomek
Aug 24 2008
"Tomasz Sowiński" <tomeksowi gmail.com> wrote in message news:g8rnkc$1fj5$1 digitalmars.com...I can mixin templates without parens, like this: mixin foo!(int); So why can't I do this: mixin "int a;"; instead of this: mixin("int a;"); ? Seems a bit inconsistent to me, but maybe I don't see the reason... Tomekmixin foo; This is now grammatically ambiguous. If foo is a const char[], then it's a string mixin. If foo is a template, then it's the same as "mixin foo!();". This could be disambiguated later, but..
Aug 24 2008
Jarrett Billingsley Wrote:mixin foo; This is now grammatically ambiguous. If foo is a const char[], then it's a string mixin. If foo is a template, then it's the same as "mixin foo!();". This could be disambiguated later, but..Is there a difference in what happens when you mixin a template and a string? I still don't see why this distinction is necessary. Tomek
Aug 24 2008
Reply to Tomasz,Jarrett Billingsley Wrote:template Foo() { static const char[] Foo = "int a;" } mixin Foo; did that add a var named a or a const named Foo?mixin foo; This is now grammatically ambiguous. If foo is a const char[], then it's a string mixin. If foo is a template, then it's the same as "mixin foo!();". This could be disambiguated later, but..Is there a difference in what happens when you mixin a template and a string? I still don't see why this distinction is necessary. Tomek
Aug 24 2008
BCS Wrote:template Foo() { static const char[] Foo = "int a;" } mixin Foo; did that add a var named a or a const named Foo?a const named Foo something like "mixin Foo!().Foo;" should add a var named a, no? btw, I tried "mixin(Foo);" and it doesn't compile: Error: argument to mixin must be a string, not (Foo()) so there wouldn't be any ambiguity anyway Tomek
Aug 24 2008
I got a code generating function: string intGen(string[] names...) { string result; foreach (name; names) result ~= "int " ~ name ~ "; "; return result; } void main() { writeln(intGen("aa", "bb", "cc")); // ok, writes "int aa; int bb; int cc; " } struct tag { mixin(intGen("aa", "bb", "cc")); // doesn't compile, but why? } I tried using a string[] as an argument instead of a variadic argument, but still it doesn't work. I know the compiler must be able to evaluate mixins at compile time and I think it's able to do so in the example. Tomek
Aug 24 2008
Reply to Tomasz,I got a code generating function: string intGen(string[] names...) { string result; foreach (name; names) result ~= "int " ~ name ~ "; "; return result; } void main() { writeln(intGen("aa", "bb", "cc")); // ok, writes "int aa; int bb; int cc; " } struct tag { mixin(intGen("aa", "bb", "cc")); // doesn't compile, but why? } I tried using a string[] as an argument instead of a variadic argument, but still it doesn't work. I know the compiler must be able to evaluate mixins at compile time and I think it's able to do so in the example. Tomekusing CTFE (compile time function evaluation) with arrays is "finicky" To limit the problem to the CTFE issues switch to this: pragma(msg, intGen("aa", "bb", "cc")); Post the error messages from that if you can't figure them out.
Aug 24 2008
BCS Wrote:using CTFE (compile time function evaluation) with arrays is "finicky"so I noticed:)To limit the problem to the CTFE issues switch to this: pragma(msg, intGen("aa", "bb", "cc")); Post the error messages from that if you can't figure them out.It says intGen("aa", "bb", "cc") can't be evaluated at compile time... I don't see why, all of its arguments are known at compile time and the function doesn't refer to anything outside its body... test.d(13): Error: cannot evaluate intGen(cast(invariant(char)[][])((invariant(char)[][3u] __arrayArg286 = void; ) , (__arrayArg286[0u]) = "aa" , (__arrayArg286[1u]) = "bb" , (__arrayArg286[2u]) = "cc" , __arrayArg286)) at compile time test.d(13): Error: string expected for message, not 'intGen(cast(invariant(char)[][])((invariant(char)[][3u] __arrayArg286 = void; ) , (__arrayArg286[0u]) = "aa" , (__arrayArg286[1u]) = "bb" , (__arrayArg286[2u]) = "cc" , __arrayArg286))' line 13 contains the pragma, of course. Tomek
Aug 24 2008
Reply to Tomasz,BCS Wrote:The CTFE engine is insanely limited and I can't seem to find the docs. You might search in the buzilla for closed bugs with CTFE. Looking at that error I'm not shure what was happening, sorryusing CTFE (compile time function evaluation) with arrays is "finicky"so I noticed:)To limit the problem to the CTFE issues switch to this: pragma(msg, intGen("aa", "bb", "cc")); Post the error messages from that if you can't figure them out.It says intGen("aa", "bb", "cc") can't be evaluated at compile time... I don't see why, all of its arguments are known at compile time and the function doesn't refer to anything outside its body...
Aug 24 2008
BCS Wrote:The CTFE engine is insanely limited and I can't seem to find the docs. You might search in the buzilla for closed bugs with CTFE. Looking at that error I'm not shure what was happening, sorrynever mind, knowing that it's a bug helps, because I won't waste time trying to fix it. Thanks
Aug 25 2008
Reply to Tomasz,BCS Wrote:I'm not saying it's a bug (or that it is not), closed bug's would contain examples of things that DMD can now do.The CTFE engine is insanely limited and I can't seem to find the docs. You might search in the buzilla for closed bugs with CTFE. Looking at that error I'm not shure what was happening, sorrynever mind, knowing that it's a bug helps, because I won't waste time trying to fix it. Thanks
Aug 25 2008
On Sun, 24 Aug 2008 19:21:54 -0400, Tomasz Sowi?ski <tomeksowi gmail.com> wrote:I tried using a string[] as an argument instead of a variadic argument, but still it doesn't work.I think you tried to pass separate strings to the non-variadic version. The following works: string intGen(string[] names) { string result; foreach (name; names) result ~= "int " ~ name ~ "; "; return result; } struct tag { mixin(intGen(["aa", "bb", "cc"])); } void main() { writefln(tag.tupleof.stringof); // tuple((tag).aa,(tag).bb,(tag).cc) }
Aug 24 2008
Max Samukha Wrote:I think you tried to pass separate strings to the non-variadic version. The following works:works! thank you
Aug 25 2008