imports and a data structure (any critique welcome)

bearophile bearophileHUGS at lycos.com
Fri Dec 27 05:45:10 PST 2013


Timon Gehr:

> mixin ADT!q{ Term: Var char | Op char Term[] };
>
> void main(){
>     const expr = Op('f', [Op('g',[Var('x'), Var('y')]), 
> Op('a',[]), Var('x')]);
> }

Where is ADT defined? (And why isn't it a Phobos patch on GitHub?)


> convertNum could be written more compactly as:
> char convertNum(int x){
>     return "exyzfgh"[x<$?x:0];

That's too much compact :-) Humans put a space around operators, 
and sometimes some parentheses don't hurt:

char convertNum(in int x) pure nothrow
in {
     assert(x >= 0);
} body {
     return "exyzfgh"[(x < $) ? x : 0];
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list