On Tuesday, 17 April 2012 at 18:00:55 UTC, Xan wrote:
On Tuesday, 17 April 2012 at 15:59:25 UTC, Ali Çehreli wrote:
On 04/17/2012 08:42 AM, Xan wrote:
> How to get the "code" of a function or delegate
>
> |___string toString() {
> |___|___return format("%s (versió %s): Domini -> Recorregut,
%s(x) =
> %s", nom, versio, nom, &funcio);
>
> |___}
>
> does not produce the desired result and &funcio without
ampersand
> produces me an error.
>
> So, my doubts are:
> given a function:
>
> - how can I get the domain
> - how can I get the range
I did not understand those. :(
Domain is the set of values that we pass to the function and
Range is the set of Values which are returned by function.
V delegate (U) f;
f has Domain U and Range V
I want to "print" the type of "U" and "V".
Something like:
class Algorisme(U,V) {
string nom;
uint versio;
alias V delegate (U) Funcio;
Funcio funcio;
this(string nom, uint versio, Funcio funcio) {
this.nom = nom;
this.versio = versio;
this.funcio = funcio;
}
string toString() {
return format("%s (versió %s): %s -> %s, %s(x) = %s", nom,
versio, V, U, nom, &funcio);
}
}
but I receive
algorisme.d:24: Error: type int has no value
algorisme.d:24: Error: type int has no value
Solved with typeid:
string toString() {
|___|___return format("%s (versió %s): %s -> %s, %s(x) = %s",
nom, versio, typeid(V), typeid(U), nom, &funcio);
|___}