digitalmars.D.learn - Why not mixin "int a;" ??
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= <tomeksowi gmail.com> Aug 24 2008
- "Jarrett Billingsley" <kb3ctd2 yahoo.com> Aug 24 2008
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= <tomeksowi gmail.com> Aug 24 2008
- BCS <ao pathlink.com> Aug 24 2008
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= <tomeksowi gmail.com> Aug 24 2008
- BCS <ao pathlink.com> Aug 24 2008
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= <tomeksowi gmail.com> Aug 24 2008
- BCS <ao pathlink.com> Aug 24 2008
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= <tomeksowi gmail.com> Aug 25 2008
- BCS <ao pathlink.com> Aug 25 2008
- Max Samukha <samukha voliacable.com.removethis> Aug 24 2008
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... Tomek
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..
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: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..
string? I still don't see why this distinction is necessary. Tomek
template Foo() { static const char[] Foo = "int a;" } mixin Foo; did that add a var named a or a const named Foo?
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. Tomek
using 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:using 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.
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...
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, sorry
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, sorry
never 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: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, sorry
trying to fix it. Thanks
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.
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









=?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= <tomeksowi gmail.com> 