www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Suggestion (not just dreaming): Better .tupleof support for more things

DavidL inspired me to post about this..

.tupleof for classes and structs is great.  But it does have shortcomings.

One, it doesn't give names.  You can access the values and the types, but 
not the names.  This means it's still impossible to do compile-time 
reflection.

Two, it only works for fields, not methods.  This is fine for structs, but 
for classes, most of the time you'll be needing to know about the methods, 
not the fields.

Three, it only works for structs and classes.  But there are more symbols 
which have members.

Thus, I propose three things:

1) Make names available through the tuple.  Even if it were provided as a 
parallel tuple, i.e. nametupleof, that'd be great.

2) Make methods available.  Either in the .tupleof or a new property i.e. 
.methodsof.  Of course names here too would be essential.

3) Allow .tupleof on anything that can contain symbols, i.e. modules, 
interfaces (maybe it already works for them?), templates etc.  This would 
make it possible to make a compile-time binding of an entire module by doing 
something like

BindModule!(std.string);

And iterating through the .tupleof and .methodsof properties of the alias 
parameter.  :)

This would give.. amazing powers of compile-time reflection, though I can 
understand if this is too much work to implement before 1.0.  I wouldn't 
mind waiting for an experimental branch of DMD though... ;)

Ah, DavidL also mentioned a .ddoc property for symbols, which would get any 
associated documentation for the symbol.  This also sounds like a great 
idea, and doesn't sound like it'd be too difficult.  :) 
Dec 06 2006