Next: , Previous: , Up: char-sets   [Index]


26.5 Operations

Function: char-set-intersection cs

Return a new set representing the intersection of the arguments; the intersection is the set of characters present in all the arguments. When called with no arguments: return a new char-set representing all the characters in Unicode.

The returned set may share some structure with the arguments.

Function: char-set-union cs

Return a new set representing the union of the arguments; the union is the set of characters present in one and/or more arguments. When called with no arguments: return a new empty char-set.

The returned set may share some structure with the arguments.

Function: char-set-difference cs0 cs

Return a new set representing the difference between the arguments; the difference is the set of characters from cs0 not present in any of the cs char-set objects.

The returned set may share some structure with the arguments.

Function: char-set-difference+intersection cs0 cs

Return two values: the difference and the intersection of the arguments; it partitions its first argument. It is equivalent to:

(values (char-set-difference cs1 cs2 ...)
        (char-set-intersection cs1 (char-set-union cs2 ...)))
Function: char-set-xor cs

Return a new set representing the exclusive difference between the arguments: it is the set of characters in only one of the arguments. When called with no arguments: return the empty set.

The returned set may share some structure with the arguments.

Function: char-set-complement cs
Function: char-set-complement cs cs-universe

Return a new set representing the complement of cs in cs-universe. The complement is the set of characters present in cs-universe, which are not present in cs.

If omitted, cs-universe defaults to char-set:full.

The returned set may share some structure with the arguments.

Function: char-set-for-each proc cs

Apply proc to each character in cs.

Function: char-set-map proc cs

Apply proc to each character in cs; proc must return a character. Return a new char-set holding all the characters returned by proc.

Function: char-set-filter pred cs

Apply pred to each character in cs. Return a new char-set holding all the characters from cs for which pred returned non–false.

Function: char-set-every proc cs

Apply proc to each character in the set and return true if all the return values are true. The application stops at the first #f return value.

Function: char-set-any proc cs

Apply proc to each character in the set and return true if at least one of the returned values is true. The application stops at the first true return value.

Function: char-set-fold kons knil cs

Fold kons over the characters in the set. kons must accept two arguments: The next character from the set and the return value of the previous invocation of kons. At the first application the second argument to kons is knil.

Function: char-set->list cs

Return a list holding all the characters in the set. Beware that for some character sets the resulting list can be big.

Function: list->char-set list-of-chars
Function: list->char-set list-of-chars base-cs

Return a new char-set holding the characters in the given list and the characters in the given base-cs.

Function: string->char-set string
Function: string->char-set string base-cs

Return a new character set holding all the characters in string and the characters in base-cs.

Function: char-set->string cs

Return a new string object holding all the characters from cs. The order in which the characters appear is undefined.

Function: char-set-cursor cs
Function: char-set-ref cursor
Function: char-set-cursor-next cursor
Function: end-of-char-set? cursor

Cursors are a low–level facility for iterating over the characters in a set; a cursor is a value that indexes a character in a char set.

char-set-cursor returns a new cursor object associated to the character set cs. There can be multiple cursors associated to the same character set.

char-set-ref returns a character object representing the set element currently indexed by a cursor.

char-set-cursor-next increments a cursor index and returns a new cursor indexing the next character in the set; in this way, code can step through every character in a char set.

Stepping a cursor “past the end” of a char set produces a cursor that answers true to end-of-char-set?. It is an error to pass such a cursor to char-set-ref or to char-set-cursor-next.

A cursor value may not be used in conjunction with a different character set; if it is passed to char-set-ref or char-set-cursor-next with a character set other than the one used to create it, the results and effects are undefined.

Cursor values are not necessarily distinct from other types: they may be integers, linked lists, records, procedures or other values.

Note that these primitives are necessary to export an iteration facility for char sets to loop macros.

Example:

(define cs (char-set #\G #\a #\T #\e #\c #\h))

;; Collect elts of CS into a list.
(let lp ((cur (char-set-cursor cs)) (ans '()))
  (if (end-of-char-set? cur) ans
      (lp (char-set-cursor-next cs cur)
          (cons (char-set-ref cs cur) ans))))
  ⇒ (#\G #\T #\a #\c #\e #\h)

;; Equivalently, using a list unfold (from SRFI 1):
(unfold-right end-of-char-set?
             (curry char-set-ref cs)
      (curry char-set-cursor-next cs)
      (char-set-cursor cs))
  ⇒ (#\G #\T #\a #\c #\e #\h)

Next: , Previous: , Up: char-sets   [Index]