imports and a data structure (any critique welcome)
Marco Leise
Marco.Leise at gmx.de
Fri Dec 27 07:45:16 PST 2013
Am Fri, 27 Dec 2013 13:45:10 +0000
schrieb "bearophile" <bearophileHUGS at lycos.com>:
> 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
Before you go _that_ far, just write:
char convertNum(in size_t x) pure nothrow
{
return "exyzfgh"[(x < $) ? x : 0];
}
:-)
--
Marco
More information about the Digitalmars-d-learn
mailing list