[phobos] enquote() -- a small function for std.metastrings

Don Clugston dclugston at googlemail.com
Tue Apr 20 12:35:33 PDT 2010


On 20 April 2010 19:07, Walter Bright <walter at digitalmars.com> wrote:
> Why use that instead of raw strings?

Because of cases where you have recursive mixins. Eg,

return `mixin("int" ~mixin(\"abc\") ~";)`;

You can use ` `-delimited strings, but only once.
So you end up with some ugly morass of `"` ~ or `\"` everywhere. It
gets quite disgusting.
With enquote, that example is:
return `mixin("int" ~ enquote(mixin("abc")) )`;

Then if you want to put it in another mixin, it becomes:
return `mixin(enquote(mixin("int" ~ enquote(mixin("abc")) ))`;

but without enquote, it is:
return `mixin("mixin(\"int\" ~mixin(\\"abc\\") ~\";)")`;

which is practically unreadable.




>
> Don Clugston wrote:
>>
>> I've found that the function below is invaluable for CTFE programming;
>> it gets rid of a huge fraction of the ugliness.
>>
>>
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>


More information about the phobos mailing list