On this page:
enum
enum
8.15.0.12

6.5 Enumerations🔗ℹ

definition

enum id_name:

  enum_clause

  ...

 

declaration

enum id_name:

  maybe_doc

  enum_clause

  ...

 

enum_clause

 = 

id ...

 | 

~is_a: annot; ...

 | 

~is_a annot

 

maybe_doc

 = 

~doc

 | 

ϵ

Defines id_name as a predicate annotation and as a namespace, where the namespace exports each id as the symbol #'id and as a binding form that matches the symbol #'id. The annotation is satisfied by each symbol #'id and by values satisfying any of the annots specified with ~is_a. The intersection of annots’ associated static information (and Symbol’s, if any id is present) are associated with the resulting annotation.

The ids and annots are tried in sequence, even when they are interleaved. Like is_a, the converting part of any converter annotation annot will not be used.

In a declaration context, ~doc can be specified before clauses to generate documentation information for id_name in a doc submodule.

enum Mouse:

  itchy

  mickey minnie

  jerry

> Mouse.itchy

#'itchy

> #'itchy is_a Mouse

#true

> #'scratchy is_a Mouse

#false

> match #'jerry

  | Mouse.itchy: "scratchy"

  | Mouse.jerry: "tom"

"tom"

enum Cat:

  ~is_a String

  scratchy

  tom

> Cat.tom is_a Cat

#true

> "Felix" is_a Cat

#true