seeding the pot for 2.0 features
Reiner Pope
xxxx at xxx.xxx
Sun Jan 28 21:54:09 PST 2007
Reiner Pope wrote:
> 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
Alternatively, if this is too hard to implement (since I think it
effectively means writing a D interpreter within the compiler -- for the
references only, since almost anything with value semantics already
needs to be const-foldable for templates) another option could be the
(slightly less cool) approach that Nemerle takes: precompile the library
to a .dll file, and direct the compiler to that when it runs.
More information about the Digitalmars-d
mailing list