Logo

Programming-Idioms

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

Idiom #122 Declare an enumeration

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

enum Suit
{
	Spades,
	Hearts,
	Diamonds,
	Clubs
}
type Suit is (Spades, Hearts, Diamonds, Clubs);
enum Suit {
    SPADES,
    HEARTS,
    DIAMONDS,
    CLUBS
};
type suit = Spades | Hearts | Diamonds | Clubs
(def suit #{:SPADES :HEARTS :DIAMONDS :CLUBS})
default clojure none required
(def 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,
}
@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
};
abstract class Suit
{
  const SPADES	 = 0;
  const HEARTS	 = 1;
  const DIAMONDS = 2;
  const CLUBS	 = 3;
}
enum Suit
{
    case SPADES;
    case HEARTS;
    case DIAMONDS;
    case CLUBS;
}
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,
}
sealed trait Suit
case object Spades extends Suit
case object Hearts extends Suit
case object Diamonds extends Suit
case object Clubs extends Suit
Enum Suit
    Spades
    Hearts
    Diamonds
    Clubs
End Enum

New implementation...
< >
programming-idioms.org