Can you do this in D?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Jul 26 07:53:55 PDT 2012


On 7/26/12 7:44 AM, bearophile wrote:
> Wes:
>
>> Can you do this in D? If not then what other language?
>
> Maybe CommonLisp and Scheme (and maybe Clojure) are able to do what you
> ask for (but normally they don't have the stringification with $).
>
>
>> 1. Can you get a list of all classes and variables in the current
>> scope e.g. __traits()?
>
> I think it's a missing feature. But what are the use cases? In Python
> it's easy to do, but it's not a common need.

What happened to __traits(allMembers, module_name)? It doesn't list the 
contents of the current scope, but instead that of a module (including 
the current one).

>> 2. Can you statically iterate over every field of a class?
>> It seems like the only returns are string lists from __traits().
>> I basically am interested in being able to generate a
>> PrettyPrint/Serializable/Hash template without passing in every
>> single field.
>
> With their names and mixin() then maybe you able to do what you look for.
>
>
>> 3. Is there any way of executing code or programs during compile
>> time?
>
> Only CTFE.

The OP is likely new to the community, so throwing acronyms around may 
not be helpful.

CTFE stands for Compile-Time Function Evaluation. In short you get to 
evaluate a subset of D during compilation if you force a function call 
in a static evaluation context, such as initializing an enum or a static.


Andrei


More information about the Digitalmars-d mailing list