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

Max Samukha spambox at d-coding.com
Mon Nov 2 09:37:07 PST 2009


On Mon, 02 Nov 2009 17:47:53 +0100, Don <nospam at nospam.com> 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>). This would give us:
>
>meta.compiles(XXX)
>meta.isArithmetic; // note, property syntax OK if no arguments
>meta.isArithmetic(int*);
>

I like the proposed syntax and I like the "meta" keyword. Though I'm
using "meta" name for a templated function returning runtime
meta-objects, I can change it to something else.

However, I think semantic limitations of __traits are more important
(introspecting function overloads, telling apart static and instance
functions, etc.)

Also, IMO, "meta" should provide only minimal functionalily, on which
complete introspection can be build in a library. Currently, we have
the opposite situation. isArithmetic, isIntegral, isStaticArray and
the likes definitely belong to the library.



More information about the Digitalmars-d mailing list