"Philippe Sigaud" <[email protected]> wrote in message news:[email protected]... > On Wed, Sep 15, 2010 at 22:19, Nick Sabalausky <[email protected]> wrote: > >> One thing that could be used for that is the eval() function I've >> recently >> added to my SemiTwist D Tools library: >> >> >> http://www.dsource.org/projects/semitwist/browser/trunk/src/semitwist/util/process.d >> >> Example: >> ----------------------------- >> import semitwist.util.all; >> void main() >> { >> auto x = eval!int(q{ return 21 * 2; }); // String can be >> runtime-generated >> assert(x == 42); >> >> eval!void( q{ writeln("Hello World"); }, q{ import std.stdio; } ); >> } >> > > Oh, interesting! > I had a look at your code. I like this part: > > code = boilerplate.format(imports, TRet.stringof, code); >
Yea, I love format :). It has all sorts of nifty applications. Although, what I'd really like is a utility more like this: "Hello $(name), the answer is $(answer)".populate(["name":"Mr. Prefect", "answer":"42"]) Which really wouldn't be hard to do. And maybe beef it up by having it take a Variant[string] instead of string[string]. And maybe make the template string optionally a template parameter so it can pre-parse it at compile-time. But format's a very nice next-best-thing. > Inside boilerplate, I wonder if it's possible to test for auto ret = > _main() > inside a static if(is(typeof( )))? That way, if _main() 'returns' a void, > the static if won't check and you know you have a void return value. > Not sure I get what you mean or what benefit you're going for here...?
