Emulation macros and pattern matching on D

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 5 13:14:52 PDT 2015


On 6/5/15 4:03 PM, Dennis Ritchie wrote:
> On Friday, 5 June 2015 at 19:08:19 UTC, Steven Schveighoffer wrote:
>> It's just so I didn't have to escape the quotes :D
>>
>> Otherwise it looks like this:
>>
>> return "writefln(\"mode " ~ mode ~ ": %s\", " ~ value ~ ");"
>
> But such an option is possible to do work? : D
>
> return `writefln(q"["mode]" ` ~ mode ~ `q"[: %s"]", ` ~ value ~ `);`;

This looks horrid :)

>
>> I think we can probably do a compile-time substitution processor like
>> rust (and other languages, including php and ruby) which just uses the
>> variable name inside a string with some escape around it. `~var~` is
>> not very succinct, I like $var better.
>
> It would be very good, because many have long been trying to implement
> this functionality handmade :)
>
> http://www.prowiki.org/wiki4d/wiki.cgi?DanielKeep/shfmt

Yes, unfortunately that version is BSD licensed, won't make it into phobos.

-Steve


More information about the Digitalmars-d-learn mailing list