forcing compile time function execution

Vladimir Panteleev vladimir at thecybershadow.net
Tue Dec 27 11:20:02 PST 2011


On Tuesday, 27 December 2011 at 19:03:07 UTC, Artur Skawina wrote:
> Umm, the point was to *avoid* the extra useless wrapper.

Sorry, I thought you were writing one wrapper per CTFE-able 
function.

> Hence the "@compile" attribute suggestion, and list selection.

Presently I don't see how your suggestion justifies an addition 
to the language itself, given that a wrapper is easy to 
implement. Furthermore, it would be yet another thing that 
requires people to inspect referenced code to keep track of 
what's going on (with @compile in the language, you can't inspect 
a function's body and know if any function call is at runtime or 
compile-time).

> (I actually tried something similar to Now(), but that only 
> obfuscates the code even more, for no gain)

If you don't like Now, let's go back to the per-function wrapper 
idea.

import std.math;
string makeNow(string name) { return `template `~name~`(X...) { 
enum `~name~` = `~name~`Impl(X); }`; }

mixin(makeNow("f"));
double fImpl(double f) { return sin(f); }

enum sin3 = f!3;



More information about the Digitalmars-d mailing list