Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #122 Declare enumeration

Create an enumerated type Suit with 4 possible values SPADES, HEARTS, DIAMONDS, CLUBS.

default clojure none required
(def Suit #{"Spades" "Hearts"  "Diamonds" "Clubs"})
(def suit #{:SPADES :HEARTS :DIAMONDS :CLUBS})
type Suit is (Spades, Hearts, Diamonds, Clubs);
enum Suit {
    SPADES,
    HEARTS,
    DIAMONDS,
    CLUBS
};
type suit = Spades | Hearts | Diamonds | Clubs
enum class Suit {
    SPADES, HEARTS, DIAMONDS, CLUBS
};
enum class Color : char{
	Red, Black, Green
};
enum Suit
{
	Spades,
	Hearts,
	Diamonds,
	Clubs
}
enum Suit{
  SPADES,
  HEARTS,
  DIAMONDS,
  CLUBS
}
enum Suit {
    SPADES,
    HEARTS,
    DIAMONDS,
    CLUBS,
}
enum, bind(c)
  enumerator :: spades, hearts, diamonds, clubs
end enum
type Suit int

const (
  Spades Suit = iota
  Hearts
  Diamonds
  Clubs
)
data Suit = SPADES | HEARTS | DIAMONDS | CLUBS deriving (Enum)
const spades = 0
const hearts = 1
const diamonds = 2
const clubs = 3
enum Suit{
  SPADES,
  HEARTS,
  DIAMONDS,
  CLUBS;
}
local enum = {
    SPADES=1,
    HEARTS=2,
    DIAMONDS=3,
    CLUBS=4
}
abstract class Suit
{
  const SPADES	 = 0;
  const HEARTS	 = 1;
  const DIAMONDS = 2;
  const CLUBS	 = 3;
}
Type
  Suit = (Spades, Hearts, Diamonds, Clubs);
my %suit = (
    SPADES   => 1,
    HEARTS   => 2,
    DIAMONDS => 3,
    CLUBS    => 4,
);
from enum import Enum
class Suit(Enum):
	SPADES = 1
	HEARTS = 2
	DIAMONDS = 3
	CLUBS = 4
class Suit:
	SPADES, HEARTS, DIAMONDS, CLUBS = range(4)
require 'ruby-enum'
class Colors
  include Ruby::Enum

  define :SPADES, "spades"
  define :HEARTS, "hearts"
  define :DIAMONDS, "diamonds"
  define :CLUBS, "clubs"
end
enum Suit {
    Spades, Hearts, Diamonds, Clubs
}

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org