Character sets

Sets of characters are useful for text-processing code, including parsing, lexing, and pattern-matching. SRFI 14 specifies a char-set type for such uses. Some examples:

(import (srfi :14 char-sets))
(define vowel (char-set #\a #\e #\i #\o #\u))
(define vowely (char-set-adjoin vowel #\y))
(char-set-contains? vowel #\y) ⇒  #f
(char-set-contains? vowely #\y) ⇒  #t

See the SRFI 14 specification for details.

Type: char-set

The type of character sets. In Kawa char-set is a type that can be used in type specifiers:

(define vowely ::char-set (char-set-adjoin vowel #\y))

Kawa uses inversion lists for an efficient implementation, using Java int arrays to represents character ranges (inversions). The char-set-contains? function uses binary search, so it takes time proportional to the logarithm of the number of inversions. Other operations may take time proportional to the number of inversions.