define-enumeration - define an enumeration type

LIBRARY

(import (rnrs))                     ;R6RS
(import (rnrs enums))               ;R6RS

SYNOPSIS

(define-enumeration type-name
  (symbol ...)
  constructor-syntax)

DESCRIPTION

The define-enumeration form defines an enumeration type and provides two macros for constructing its members and sets of its members.

A define-enumeration form is a definition and can appear anywhere any other definitions can appear.

The type-name argument is an identifier that is bound as a syntactic keyword (see below). The symbol arguments are the symbols that comprise the universe of the enumeration. The constructor-syntax argument is an identifier that is bound to a macro (see below).

Type name macro
(type-name symbol) is equivalent to (quote symbol) except that it verifies at macro-expansion time that the name of symbol is in the universe associated with type-name. Otherwise it is a syntax violation.
Constructor macro
(constructor-syntax symbol ...) checks at macro-expansion time whether every symbol is in the universe associated with type-name. It is a syntax violation if one or more is not. Duplicates are allowed. Otherwise (constructor-syntax symbol ...) is equivalent to ((enum-set-constructor (constructor-syntax)) '(symbol ...)).

In the (type-name symbol) and (constructor-syntax symbol ...) forms, only the names of the symbols are significant.

RETURN VALUES

This form cannot appear in a context where it returns a value.

EXAMPLES

(define-enumeration color
  (black white purple maroon)
  color-set)

(color black)                    =>  black
(color purpel)                   =>  &syntax exception

(enum-set->list (color-set))     =>  ()
(enum-set->list
 (color-set maroon white))       =>  (white maroon)

APPLICATION USAGE

Enumerations are used in code that would perhaps traditionally represent flags using bits in integers or lists of symbols.

RATIONALE

Enumerations were added to support flags in the R6RS I/O system.

ERRORS

This syntax can raise exceptions with the following condition types:
&syntax (R6RS)
Invalid arguments was passed.

SEE ALSO

make-enumeration(3scm)

STANDARDS

R6RS, SRFI-209

HISTORY

First appeared in R6RS.

AUTHORS

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.


Markup created by unroff 1.0sc,    March 04, 2023.