Tangent: Enums

Published March 23, 2009
Advertisement
After doing some of my own ruminations on the subject, I made a post to the community at large to get some input/ideas for enums. Most people seem as if they'd be fine with C# enums. I don't think I'd be fine with C# enums in Tangent.

I'm not completely sold on their design yet, but the current basic implementation is fairly Java-style enums. The actual constructs themselves are sugar for some global, constant goose type instances. A individual enum value is a class instance that is a sub-type of the abstract enum class. Since they are just classes, you the programmer will be able to define methods, fields and properties on the enum class and by extension the enum values. And methods will be able to be specialized on a particular enum value, just like any other subtype.

Currently enum values have a sane ToString defined, and the enum class (as well as the global scope) has static properties that return the enum values by name. The values themselves live as static tuple members on the enum class (as you'll see below). That is likely to be hidden or abstracted later. Enumerating through the enums and specifying specializations are not done yet. Other stuff will be driven by suggestion or more likely, personal need when doing example apps.

The current testapp (yes, yes I need to get == working again...):

public enum CardSuit{    values{        club,        spade,        heart,        diamond    }    public    foo()=>void{        print "foo.\r\n";    }}public static     main()=>void{    CardSuit.tuple[0].foo();    CardSuit.diamond.foo();    if( CardSuit.tuple[0] equals CardSuit.tuple[0] ){            print "equality works.\r\n";    }    if( CardSuit.tuple[0] equals CardSuit.tuple[2] ){     }else{        print "inequality works.\r\n";    }    if( CardSuit.club equals CardSuit.club ){            print "equality works.\r\n";    }    if( CardSuit.heart equals CardSuit.diamond ){     }else{        print "inequality works.\r\n";    }    print CardSuit.heart "\r\n";    local CardSuit suit = CardSuit.club;    print suit "\r\n";    suit = CardSuit.diamond;    print suit "\r\n";        suit = spade;    print suit "\r\n";}


foo.foo.equality works.inequality works.equality works.inequality works.heartclubdiamondspade

Previous Entry Tangent: Arrow.
Next Entry Of Dice and Men
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement