People, and their irrational fear of string mixins

retard re at tard.com.invalid
Mon Dec 7 11:46:05 PST 2009


Mon, 07 Dec 2009 16:55:43 +0100, downs wrote:

> Nick Sabalausky wrote:
>> I just noticed in D1 that the values for the cases in a switch must be
>> known at compile-time (btw, the docs don't seem somewhat vague on
>> that). Is this also true in D2? If so, I don't suppose we could get
>> that changed before the book? It's a real PITA for dynamic code.
>> 
>> 
>> 
> I wish they'd get over it.
> 
> import tools.base;
> 
> ...
> 
> mixin(
>   ReplaceConcat!(2, "if (x == #) { ! } else",
>     "#", "!",
>     "A", "handleTheACase; ",
>     "B", "handleTheBCase; ",
>     "C", "handleTheCCase; "
>   )
>   ~ " assert(false); "
> );

That reminded me.. I should write a case-of mixin some day:

auto result = mixin case_of(foo, `
  Tree(l,r) => "We have children "~l.toString()~" and "~r.toString()
  Nil => "It's a leaf"
`);



More information about the Digitalmars-d mailing list