Logo

Programming-Idioms

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

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
type Suit is (Spades, Hearts, Diamonds, Clubs);
enum Suit {
    SPADES,
    HEARTS,
    DIAMONDS,
    CLUBS
};
type suit = Spades | Hearts | Diamonds | Clubs
default clojure none required
(def Suit #{"Spades" "Hearts"  "Diamonds" "Clubs"})
(def suit #{:SPADES :HEARTS :DIAMONDS :CLUBS})
enum class Color : char{
	Red, Black, Green
};
enum class Suit {
    SPADES, HEARTS, DIAMONDS, CLUBS
};
enum Suit
{
	Spades,
	Hearts,
	Diamonds,
	Clubs
}
enum Suit{
  SPADES,
  HEARTS,
  DIAMONDS,
  CLUBS
}
enum Suit {
    SPADES,
    HEARTS,
    DIAMONDS,
    CLUBS,
}
@suits %{
  "SPADES" => 1,
  "HEARTS" => 2,
  "DIAMONDS" => 3,
  "CLUBS" => 4
}

def main, do: @suits
enum, bind(c)
  enumerator :: spades, hearts, diamonds, clubs
end enum
type Suit int

const (
  Spades Suit = iota
  Hearts
  Diamonds
  Clubs
)
enum Suit{
  SPADES,
  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;
}
Suit = {
    SPADES=1,
    HEARTS=2,
    DIAMONDS=3,
    CLUBS=4
}
typedef NS_ENUM(int, Suit) {
  SPADES, HEARTS, DIAMONDS, CLUBS
};
enum Suit
{
    case SPADES;
    case HEARTS;
    case DIAMONDS;
    case CLUBS;
}
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,
);
class Suit:
	SPADES, HEARTS, DIAMONDS, CLUBS = range(4)
from enum import Enum
class Suit(Enum):
	SPADES = 1
	HEARTS = 2
	DIAMONDS = 3
	CLUBS = 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,
}
Enum Suit
    Spades
    Hearts
    Diamonds
    Clubs
End Enum