Future Enumeration Syntax


Enumerations as they are currently set up are a temporary mechanism using class data members of the Enum subclasses (such as EAxis.@@x) to approximate/fake true enumerations (such as #Axis.x).

Here is some info about them in a previous post:

Since this is in the “Enhancements & Evolution” category, I’ll describe the planned future enumerations more. This syntax is not finalized so please feel free to chime in about what you like, don’t like or think we should change or add.

Enumerator definition

enum-class = [class-name [@ invoke-name]] enumeration-name
enum-definition = # | enumeration-name [ ws [enumerator-defn {wsr enumerator-defn} ws] ]
enumeration-name = # alphabetic {alphanumeric}
enumerator-defn = (instance-name [ws : ws integer-literal]) | enum-class

  • enum-class: Optional class-name and invoke-name qualification only needed if it cannot be inferred from the context - so it may be omitted and inferred if inside the required scope or if the expected enumeration class type is known, etc.
  • enum-definition: May use just ‘#’ rather than enumeration-name if enum is nested then data member or parameter name is used.
  • enumerator-defn: Assigning an enumerator to an integer is discouraged though it is often handy to mirror underlying C++. enum-class option indicates inherit enumerations from specified enum at specified insertion point.

Enumerator literal

enumerator = (enum-class .) | # instance-name

  • enumerator: If desired, enumeration class type can be inferred (like when passed as an argument) then optional enum-class may be omitted.

These are some random examples of how enumerations will work with the proper syntax when it is implemented.

In data members

Can use inline/nested enumerations in data members.

// MyClass/!Data.sk

// Memberless definition
// - no data member specified, just defines enums
#Confirm[yes no]!
// Inherit yes, no and add maybe
#Answer[#Confirm maybe]!
// Can inherit in different order
#AnswerB[maybe #Confirm]!

// Used by member
// Note just #Compare enum is created, not #relation
#Compare[less equal greater] !@relation

// Unnamed / nested enum
#[up down left right] !@direction

// Using previously defined enums
#Confirm   !@confirm
#Compare   !@other_relation
#direction !other_direction

In routines

(#Compare arg1: #greater)
  @direction: #left
  @relation:  #equal
  @confirm:   #yes
  @other_dir: @direction!

  @other_comp := arg1
  !enum1: #Compare.less
  !enum2: enum1!


  // If desired type known, then enumeration class can be omitted
  // Still use # to help identify it as an enumerator.

Inferred enum classes

// When enum class type known

// In class

// Fully qualified

Argument inline/nested enumeration

  • Like an “inline” unnamed enumeration or a non-quoted Symbol that is restricted to a set of allowed/expected symbols
  • Enables custom syntax like built-in syntax - ex: ‘else’
  • Accepts valid identifier as inline
  • Returns an enumeration
// Requires at least a hash to signify as an enum
SomeClass@set_size(#[small medium large] size: #medium)
  case size
    #small  [do_small_stuff]
    #medium [do_medium_stuff]
    #large  [do_large_stuff]

// Qualify as:
SomeClass@set_size#size        // Enumeration
SomeClass@set_size#size.small  // Enumerator

// Calling routine - inferred to fully qualified

// If name provided, give higher qualification scope.
// - Must account for any dupes.


SomeClass@set_size(#Size[small medium large] size: medium)


Enum - getting ordinal index?