On Tuesday, 17 April 2012 at 18:39:16 UTC, Xan wrote:
On Tuesday, 17 April 2012 at 18:25:21 UTC, Ali Çehreli wrote:
On 04/17/2012 11:13 AM, Xan wrote:
> The idea is behind this https://gist.github.com/2407923
> But I receive:
>
> $ gdmd-4.6 algorisme_code.d
> algorisme_code.d:22: Error: variable codi cannot be read at
compile time
> algorisme_code.d:22: Error: argument to mixin must be a
string, not (codi)
mixin is about code generation. For that reason the string
that is given to it must be available at compile time. Upon
analyzing the code, that is the case in your example, but
because mixin() appears inside the constructor, it cannot use
a string parameter.
That's why I had used a template parameter for the function
string. There may be a number of solutions but only you can
decide on what to do. One solution is to mixin the delegate
outside of the constructor and pass as an argument along with
its string representation:
// Untested code
this(... Funcio funcio, string funcioText) {
...
}
In main:
enum funcioText = "...";
auto funcio = mixin(funcioText);
... new Algorisme(..., funcio, funcioText);
Ali
What is change is this code? Is it the same as this
https://gist.github.com/2407923 (I revise the code)?
With my (v. 2) code I receive the errors:
$ gdmd-4.6 algorisme_code.d
algorisme_code.d:44: Error: variable codi cannot be read at
compile time
algorisme_code.d:44: Error: argument to mixin must be a string,
not (codi)
algorisme_code.d:45: Error: constructor
algorisme_code.Algorisme!(int,int).Algorisme.this (string nom,
uint versio, int function(int) funcio, string codi) is not
callable using argument types (string,int,_error_,string)
Why the string is not given at compile code? I don't understand
it!
Xan.
It works with enum instead of string:
https://gist.github.com/2407923
Thanks all of you,
Xan.