PHP-style (embedded variables) print statements
Bill Baxter
dnewsgroup at billbaxter.com
Thu May 31 05:20:57 PDT 2007
Don Clugston wrote:
> With CTFE and text mixins, it is now reasonably straightforward to
> implement PHP-style 'dollar' embedded variables, in a type-safe manner.
>
> For example, the attached code (rough draft) allows you to write things
> like:
>
> int i;
> const k = 8;
> char [] str;
> mixin(dprint("current=$i next=$(i+1) const=$(k*3) $str\n"));
>
...
> Downsides:
> (1) need to use "mixin()" until we get macros.
> (2) doesn't look like anything that's in D right now.
> (3) how are IDE's going to know when a string contains embedded variables?
>
> Opinions? Is something like this worth considering as an alternative to
> writefln, and to Tango's C# formatting and whisper syntax?
That's pretty cool. I would probably use that over other alternatives,
but not if it requires the mixin(...) syntax to use.
--bb
More information about the Digitalmars-d
mailing list