[phobos] expand for std.metastrings

Robert Jacques sandford at jhu.edu
Fri Nov 5 10:57:34 PDT 2010


On Thu, 04 Nov 2010 02:06:37 -0400, kenji hara <k.hara.pg at gmail.com> wrote:

>> Personally, I consider comma separated formatting to be inlined, or at  
>> least inline style
> OK, I call the kind of expand "Embedded Formatting" in this
> discussion, to avoid confusion.
>
> I again want to emphasize with the Need of Embedded Formatting, with  
> some code.
> If you only use built-in string literals, you can't avoid escaping of
> code string.
> ----
> enum op = "+";
> enum code = "a "~op~" b";
> // use "" and manual escaping. It is same with r"" and ``.
> enum code = mixin(expand!"a $op b");
> // automatically escaping
>
> // quoted string has problem with embedding...
> enum code = q{
>   struct A{
>     enum str = "hello!";
>     enum val = a }~op~{ b;  // invalid! can't embed correctly.
>   }
> };
> enum code = "
>   struct A{
>     enum str = \"hello!\";  // manual escaping!
>     enum val = a " ~ op ~ " b;
>   }
> ";
> enum code = mixin(expand!q{
>   struct A{
>     enum str = "hello!";    // automatically escaping
>     enum val = a $op b;     // automatically embedding
>   }
> });  // and editor highlighting will mostly succeed.
> ----
> I DO NOT want to think about escaping of code string!
> In this regard, expand is very usuful.
>
> Kenji

I just wanted to point out that D has 6 different types of Wysiwyg Strings  
in addition to standard escape based "" strings and the q{} token strings.  
i.e.

enum code = `
    struct A{
      enum str = "hello!";
      enum val = a `~op~` b;
   `;

Anyways, for me, $Type definitely makes expand a worthwhile addition to  
Phobos.


More information about the phobos mailing list