Proposal: Replace __traits and is(typeof(XXX)) with a 'magic namespace'.

Lutger lutger.blijdestijn at gmail.com
Mon Nov 2 09:49:40 PST 2009


Andrei Alexandrescu wrote:

> Don wrote:
>> [I'm moving this from deep inside a TDPL thread, since I think it's
>> important]
>> 
>> is(typeof(XXX)) is infamously ugly and unintuitive
>> __traits(compiles, XXX) is more comprehensible, but just as ugly.
>> 
>> They are giving metaprogramming in D a bad name. I think we need to get
>> rid of both of them.
>> 
>> A very easy way of doing this is to replace them with a 'magic
>> namespace' -- so that they _look_ as though they're functions in a
>> normal module.
>> Names which have been suggested include 'meta', 'traits', 'scope',
>> 'compiler'. Personally I think 'meta' is the nicest (and I suggested two
>> of the others <g>).
> 
> Another keyword, sigh...

Which can get rid of at least three keywords ...

> And I'll be darned if "static" isn't the perfect fit :o).
> 
>> This would give us:
>> 
>> meta.compiles(XXX)
>> meta.isArithmetic; // note, property syntax OK if no arguments
>> meta.isArithmetic(int*);
> 
> isArithmetic is library-implementable. How would the library inject
> stuff in the meta namespace? Also my alarm goes off when seeing
> meta.isArithmetic(int*) instead of meta.isArithmetic!(int*), which is
> what the unwashed masses would have to do if they wanted to implement a
> similar facility. With time I've acquired a dim view of certain stuff in
> the language benefiting of untouchable advantages.
> 
> 
> Andrei

It's not about isArithmetic, it's about __traits(foo) and is(foo).




More information about the Digitalmars-d mailing list