seeding the pot for 2.0 features
Reiner Pope
xxxx at xxx.xxx
Sun Jan 28 18:19:24 PST 2007
I think something like a 'super static' function could also be good
(just to avoid using new keywords ;-) ). The idea would be that plain D
code could be called by template functions, and the compiler would
evaluate them at compile-time.
As I see it, there are only a few requirements for this (which are
recursive across all functions called):
1. the source code is available
2. there's no assembly or C (or any external library) called
3. the functions are pure (ie no static variables are read or
changed, and the passed parameters are unchanged)
This would mean, for instance, that practically all of std.string would
be accessible via templates, avoiding the much of the need for separate
meta-programming libraries. You could then just call such functions
straight from your template code:
import std.string;
template foo(char[] bar)
{
static if (bar.splitlines()[0] == "cheese")
pragma(msg, "You like cheese");
}
The compiler can check whether a function can be evaluated at
compile-time, and you may wish to ensure that yours is, since you are
writing it for template code. In that case, you annotate your function
'super static' and the compiler will give you an error if it fails any
of the three criteria.
Cheers,
Reiner
More information about the Digitalmars-d
mailing list