On Tue, 02 Nov 2010 14:27:28 -0400, kenji hara <[email protected]> wrote:

enum code = text(q{ enum msg = "I call you "}, count, q{" times"} );
enum code = text(` enum msg = "I call you `, count, ` times;` );
enum code = ` enum msg = "I call you ` ~ count ~ ` times;`
enum code = q{ enum msg = "I call you "} ~ count ~ q{" times"; }

1st and 4th does not generate intended code string, but generates invalid one.
expand! generates 3rd code automatically cooperation with mixin.
(2nd is ... the code currently others want to generate for run-time
performance?)

Opps. Sorry, I tested 2 & 3, but forgot to test 1 & 2. I also seemed to have forgotten a " after times in 2 & 3.

Also, what do you mean by: (2nd is ... the code currently others want to generate for run-time performance?)

I admit ${n} is slightly better than },n,q{, but it's by no means ugly. (And
using `` instead of q{} makes it better: `,n,`)

The advantage of expand! is that escapes string quotations and
concatenates correctly while keeping readability of our meta-code
well.
(In above 3rd, you escape q{} to `` and interpolate "count" *manually*.)

Yes, manually escaping and concatenating, in all but the trivial cases, is really annoying. But my main point was that text is both CTFE-able and lets you cleanly do everything expand does naturally. Expand is more complex to use, isn't self-documenting (i.e. you have to remember to use a mixin), is mostly redundant and increases the radius of comprehension of phobos. However, it does allow you to escape a token strings inside a nested string in a nice in-lined way. So far, the examples don't seem to provide a strong argument for yet another text formater beyond text and Format. Also, if I recall correctly the plan is to get a large portion of both phobos and D CTFE compatible, which would eventually eliminate the need for the current metastrings.


_______________________________________________
phobos mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos

Reply via email to