Jump to content
  • Advertisement
  • entries
    359
  • comments
    237
  • views
    189653

Tangent: Enums

Sign in to follow this  
Telastyn

265 views

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.
heart
club
diamond
spade

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!