Proposal: user defined attributes

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Mar 21 08:11:45 PDT 2012


On 3/21/12 9:57 AM, Jacob Carlborg wrote:
> On 2012-03-21 14:54, Steven Schveighoffer wrote:
>> On Tue, 20 Mar 2012 12:16:41 -0400, Andrei Alexandrescu
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>
>>> Maybe there's a better approach than flectioned. Consider the language
>>> is frozen solid. How would you solve problems with it?
>>
>> I think the closest anyone has come is Jacob, with his orange library.
>> Maybe he can respond to this point.
>>
>> -Steve
>
> With Orange I'm doing everything with compile time reflection.
> Flectioned was all about runtime reflection. It's possible to replace
> methods with flectioned at runtime and do a lot of crazy things.
>
> In Orange I'm using mixins, tupleof and stringof to accomplish most of
> the compile time reflection. Example:
>
> class Foo
> {
> int a;
> int b;
>
> mixin NonSerialized!(b);
> }

I think the liability here is that b needs to appear in two places, once 
in the declaration proper and then in the NonSerialized part. (A 
possible advantage is that sometimes it may be advantageous to keep all 
symbols with a specific attribute in one place.) A possibility would be 
to make the mixin expand to the field and the metadata at once.

> serialize(new Foo);
>
> "mixin NonSerialized!(b);" is expanded to:
>
> static const __nonSerialized = ["a"];
>
> The fields are enumerated and serialized using tupleof. It also checks
> all structs and classes if they have "__nonSerialized" defined.

Did you mean

static const __nonSerialized = ["b"];

?

In case there are several non-serialized variables, how do you avoid 
clashes between different definitions of __nonSerialized?


Thanks,

Andrei


More information about the Digitalmars-d mailing list