Various SRFI Support Modules
****************************

SRFI is an acronym for Scheme Request For Implementation.  The SRFI documents define a lot of syntactic and procedure extensions to standard Scheme as defined in R5RS.

Guile has support for a number of SRFIs.  This chapter gives an overview over the available SRFIs and some usage hints.  For complete documentation, design rationales and further examples, we advise you to get the relevant SRFI documents from the SRFI home page http://srfi.schemers.org.

SRFI-0 - cond-expand
====================

SRFI-0 defines a means for checking whether a Scheme implementation has support for a specified feature.  The syntactic form cond-expand, which implements this means, has the following syntax.

     <cond-expand>
       --> (cond-expand <cond-expand-clause>+)
         | (cond-expand <cond-expand-clause>* (else <command-or-definition>))
     <cond-expand-clause>
       --> (<feature-requirement> <command-or-definition>*)
     <feature-requirement>
       --> <feature-identifier>
         | (and <feature-requirement>*)
         | (or <feature-requirement>*)
         | (not <feature-requirement>)
     <feature-identifier>
       --> <a symbol which is the name or alias of a SRFI>

When evaluated, this form checks all clauses in order, until it finds one whose feature requirement is satisfied.  Then the form expands into the commands or definitions in the clause.  A requirement is tested as follows:

  * If it is a symbol, it is satisfied if the feature identifier is supported.

  * If it is an and form, all requirements must be satisfied.  If no requirements are given, it is satisfied, too.

  * If it is an or form, at least one of the requirements must be satisfied.  If no requirements are given, it is not satisfied.

  * If it is a not form, the feature requirement must not be satisfied.

  * If the feature requirement is the keyword else and it is the last clause, it is satisfied if no prior clause matched.

Since cond-expand is needed to tell what a Scheme implementation provides, it must be accessible without using any implementation-dependant operations, such as use-modules in Guile.  Thus, it is not necessary to use any module to get access to this form.

Currently, the feature identifiers guile, r5rs and srfi-0 are supported.  The other SRFIs are not in that list, because the SRFI modules must be explicitly used before their exported bindings can be used.  So if a Scheme program wishes to detect whether SRFI-8 is supported in the running implementation, code similar to this may be needed:

     (cond-expand
       (guile
         (use-modules (srfi srfi-8)))
       (srfi-8
         #t))
       ;; otherwise fail.

SRFI-2 - and-let*
=================

The syntactic form and-let* combines the conditional evaluation form and with the binding form LET*.  Each argument expression will be evaluated sequentially, bound to a variable (if a variable name is given), but only as long as no expression returns the false value #f.

Use (use-modules (srfi srfi-2) to access this syntax form.

A short example will demonstrate how it works.  In the first expression, X will get bound to 1, but the next expression (#f) is false, so evaluation of the form is stopped, and #f is returned. In the next expression, X is bound to 1, Y is bound to #t and since no expression in the binding section was false, the body of the and-let* expression is evaluated, which in this case returns the value of X.

     (and-let* ((x 1) (y #f)) 42)
     =>
     #f
     (and-let* ((x 1) (y #t)) x)
     =>
     1

SRFI-6 - Basic String Ports
===========================

SRFI-6 defines the procedures open-input-string, open-output-string and get-output-string.  These procedures are included in the Guile core, so using this module does not make any difference at the moment.  But it is possible that support for SRFI-6 will be factored out of the core library in the future, so using this module does not hurt, after all.

SRFI-8 - receive
================

receive is a syntax for making the handling of multiple-value procedures easier.  It is documented in see Multiple Values.

SRFI-9 - define-record-type
===========================

This is the SRFI way for defining record types.  The Guile implementation is a layer above Guile's normal record construction procedures (REFFIXME).  The nice thing about this kind of record definition method is that no new names are implicitly created, all constructor, accessor and predicates are explicitly given.  This reduces the risk of variable capture.

The syntax of a record type definition is:

     <record type definition>
       -> (define-record-type <type name>
            (<constructor name> <field tag> ...)
            <predicate name>
            <field spec> ...)
     <field spec> -> (<field tag> <accessor name>)
                  -> (<field tag> <accessor name> <modifier name>)
     <field tag>  -> <identifier>
     <... name>   -> <identifier>

Usage example:

     guile> (use-modules (srfi srfi-9))
     guile> (define-record-type :foo (make-foo x) foo?
                                (x get-x) (y get-y set-y!))
     guile> (define f (make-foo 1))
     guile> f
     #<:foo x: 1 y: #f>
     guile> (get-x f)
     1
     guile> (set-y! f 2)
     2
     guile> (get-y f)
     2
     guile> f
     #<:foo x: 1 y: 2>
     guile> (foo? f)
     #t
     guile> (foo? 1)
     #f

SRFI-10 - Hash-Comma Reader Extension
=====================================

The module (srfi srfi-10) implements the syntax extension #,(), also called hash-comma, which is defined in SRFI-10.

The support for SRFI-10 consists of the procedure define-reader-ctor for defining new reader constructors and the read syntax form

     #,(CTOR DATUM ...)

where CTOR must be a symbol for which a read constructor was defined previouly, using define-reader-ctor.

Example:

     (define-reader-ctor 'file open-input-file)
     (define f '#,(file "/etc/passwd"))
     (read-line f)
     =>
     "root:x:0:0:root:/root:/bin/bash"

Please note the quote before the #,(file ...) expression.  This is necessary because ports are not self-evaluating in Guile.

 -- procedure: define-reader-ctor symbol proc
     Define PROC as the reader constructor for hash-comma forms with a tag SYMBOL.  PROC will be applied to the datum(s) following the tag in the hash-comma expression after the complete form has been read in.  The result of PROC is returned by the Scheme reader.

SRFI-11 - let-values
====================

This module implements the binding forms for multiple values let-values and let-values*.  These forms are similar to let and let* (REFFIXME), but they support binding of the values returned by multiple-valued expressions.

Write (use-modules (srfi srfi-11)) to make the bindings available.

     (let-values (((x y) (values 1 2))
                  ((z f) (values 3 4)))
        (+ x y z f))
     =>
     10

let-values performs all bindings simultaneously, which means that no expression in the binding clauses may refer to variables bound in the same clause list.  let-values*, on the other hand, performs the bindings sequentially, just like let* does for single-valued expressions.

SRFI-13 - String Library
========================

In this section, we will describe all procedures defined in SRFI-13 (string library) and implemented by the module (srfi srfi-13).

Note that only the procedures from SRFI-13 are documented here which are not already contained in Guile.  For procedures not documented here please refer to the relevant chapters in the Guile Reference Manual, for example the documentation of strings and string procedures (REFFIXME).

All of the procedures defined in SRFI-13, which are not already included in the Guile core library, are implemented in the module (srfi srfi-13).  The procedures which are both in Guile and in SRFI-13, but which are slightly extended, have been implemented in this module, and the bindings overwrite those in the Guile core.

The procedures which are defined in the section Low-level procedures of SRFI-13 for parsing optional string indices, substring specification checking and Knuth-Morris-Pratt-Searching are not implemented.

The procedures string-contains and string-contains-ci are not implemented very efficiently at the moment.  This will be changed as soon as possible.

Loading SRFI-13
---------------

When Guile is properly installed, SRFI-13 support can be loaded into a running Guile by using the (srfi srfi-13) module.

     $ guile
     guile> (use-modules (srfi srfi-13))
     guile>

When this step causes any errors, Guile is not properly installed.

One possible reason is that Guile cannot find either the Scheme module file srfi-13.scm, or it cannot find the shared object file libguile-srfi-srfi-13-14.so.  Make sure that the former is in the Guile load path and that the latter is either installed in some default location like /usr/local/lib or that the directory it was installed to is in your LTDL_LIBRARY_PATH.  The same applies to srfi-14.scm.

Now you can test whether the SRFI-13 procedures are working by calling the string-concatenate procedure.

     guile> (string-concatenate '("Hello" " " "World!"))
     "Hello World!"

Predicates
----------

In addition to the primitives string? and string-null?, which are already in the Guile core, the string predicates string-any and string-every are defined by SRFI-13.

 -- primitive: string-any pred s [start end]
     Check if the predicate PRED is true for any character in the string S, proceeding from left (index START) to right (index END).  If string-any returns true, the returned true value is the one produced by the first successful application of PRED.

 -- primitive: string-every pred s [start end]
     Check if the predicate PRED is true for every character in the string S, proceeding from left (index START) to right (index END).  If string-every returns true, the returned true value is the one produced by the final application of PRED to the last character of S.

Constructors
------------

SRFI-13 defines several procedures for constructing new strings.  In addition to make-string and string (available in the Guile core library), the procedure string-tabulate does exist.

 -- primitive: string-tabulate proc len
     PROC is an integer->char procedure.  Construct a string of size LEN by applying PROC to each index to produce the corresponding string element.  The order in which PROC is applied to the indices is not specified.

List/String Conversion
----------------------

The procedure string->list is extended by SRFI-13, that is why it is included in (srfi srfi-13).  The other procedures are new. The Guile core already contains the procedure list->string for converting a list of characters into a string (REFFIXME).

 -- primitive: string->list str [start end]
     Convert the string STR into a list of characters.

 -- primitive: reverse-list->string chrs
     An efficient implementation of (compose string->list reverse):

          (reverse-list->string '(#\a #\B #\c)) => "cBa"

 -- primitive: string-join ls [delimiter grammar]
     Append the string in the string list LS, using the string DELIM as a delimiter between the elements of LS. GRAMMAR is a symbol which specifies how the delimiter is placed between the strings, and defaults to the symbol infix.

     infix
          Insert the separator between list elements.  An empty string will produce an empty list.

     string-infix
          Like infix, but will raise an error if given the empty list.

     suffix
          Insert the separator after every list element.

     prefix
          Insert the separator before each list element.

Selection
---------

These procedures are called selectors, because they access information about the string or select pieces of a given string.

Additional selector procedures are documented in the Strings section (REFFIXME), like string-length or string-ref.

string-copy is also available in core Guile, but this version accepts additional start/end indices.

 -- primitive: string-copy str [start end]
     Return a freshly allocated copy of the string STR.  If given, START and END delimit the portion of STR which is copied.

 -- primitive: substring/shared str start [end]
     Like substring, but the result may share memory with the argument STR.

 -- primitive: string-copy! target tstart s [start end]
     Copy the sequence of characters from index range [START, END) in string S to string TARGET, beginning at index TSTART.  The characters are copied left-to-right or right-to-left as needed - the copy is guaranteed to work, even if TARGET and S are the same string.  It is an error if the copy operation runs off the end of the target string.

 -- primitive: string-take s n
 -- primitive: string-take-right s n
     Return the N first/last characters of S.

 -- primitive: string-drop s n
 -- primitive: string-drop-right s n
     Return all but the first/last N characters of S.

 -- primitive: string-pad s len [chr start end]
 -- primitive: string-pad-right s len [chr start end]
     Take that characters from START to END from the string S and return a new string, right(left)-padded by the character CHR to length LEN.  If the resulting string is longer than LEN, it is truncated on the right (left).

 -- primitive: string-trim s [char_pred start end]
 -- primitive: string-trim-right s [char_pred start end]
 -- primitive: string-trim-both s [char_pred start end]
     Trim S by skipping over all characters on the left/right/both sides of the string that satisfy the parameter CHAR_PRED:

       * if it is the character CH, characters equal to CH are trimmed,

       * if it is a procedure PRED characters that satisfy PRED are trimmed,

       * if it is a character set, characters in that set are trimmed.

     If called without a CHAR_PRED argument, all whitespace is trimmed.

Modification
------------

The procedure string-fill! is extended from R5RS because it accepts optional start/end indices.  This bindings shadows the procedure of the same name in the Guile core.  The second modification procedure string-set! is documented in the Strings section (REFFIXME).

 -- primitive: string-fill! str chr [start end]
     Stores CHR in every element of the given STR and returns an unspecified value.

Comparison
----------

The procedures in this section are used for comparing strings in different ways.  The comparison predicates differ from those in R5RS in that they do not only return #t or #f, but the mismatch index in the case of a true return value.

string-hash and string-hash-ci are for calculating hash values for strings, useful for implementing fast lookup mechanisms.

 -- primitive: string-compare s1 s2 proc_lt proc_eq proc_gt [start1 end1 start2 end2]
 -- primitive: string-compare-ci s1 s2 proc_lt proc_eq proc_gt [start1 end1 start2 end2]
     Apply PROC_LT, PROC_EQ, PROC_GT to the mismatch index, depending upon whether S1 is less than, equal to, or greater than S2.  The mismatch index is the largest index I such that for every 0 <= J < I, S1[J] = S2[J] - that is, I is the first position that does not match.  The character comparison is done case-insensitively.

 -- primitive: string= s1 s2 [start1 end1 start2 end2]
 -- primitive: string<> s1 s2 [start1 end1 start2 end2]
 -- primitive: string< s1 s2 [start1 end1 start2 end2]
 -- primitive: string> s1 s2 [start1 end1 start2 end2]
 -- primitive: string<= s1 s2 [start1 end1 start2 end2]
 -- primitive: string>= s1 s2 [start1 end1 start2 end2]
     Compare S1 and S2 and return #f if the predicate fails.  Otherwise, the mismatch index is returned (or END1 in the case of string=.

 -- primitive: string-ci= s1 s2 [start1 end1 start2 end2]
 -- primitive: string-ci<> s1 s2 [start1 end1 start2 end2]
 -- primitive: string-ci< s1 s2 [start1 end1 start2 end2]
 -- primitive: string-ci> s1 s2 [start1 end1 start2 end2]
 -- primitive: string-ci<= s1 s2 [start1 end1 start2 end2]
 -- primitive: string-ci>= s1 s2 [start1 end1 start2 end2]
     Compare S1 and S2 and return #f if the predicate fails.  Otherwise, the mismatch index is returned (or END1 in the case of string=.  These are the case-insensitive variants.

 -- primitive: string-hash s [bound start end]
 -- primitive: string-hash-ci s [bound start end]
     Return a hash value of the string S in the range 0 ... BOUND - 1.  string-hash-ci is the case-insensitive variant.

Prefixes/Suffixes
-----------------

Using these procedures you can determine whether a given string is a prefix or suffix of another string or how long a common prefix/suffix is.

 -- primitive: string-prefix-length s1 s2 [start1 end1 start2 end2]
 -- primitive: string-prefix-length-ci s1 s2 [start1 end1 start2 end2]
 -- primitive: string-suffix-length s1 s2 [start1 end1 start2 end2]
 -- primitive: string-suffix-length-ci s1 s2 [start1 end1 start2 end2]
     Return the length of the longest common prefix/suffix of the two strings. string-prefix-length-ci and string-suffix-length-ci are the case-insensitive variants.

 -- primitive: string-prefix? s1 s2 [start1 end1 start2 end2]
 -- primitive: string-prefix-ci? s1 s2 [start1 end1 start2 end2]
 -- primitive: string-suffix? s1 s2 [start1 end1 start2 end2]
 -- primitive: string-suffix-ci? s1 s2 [start1 end1 start2 end2]
     Is S1 a prefix/suffix of S2. string-prefix-ci? and string-suffix-ci? are the case-insensitive variants.

Searching
---------

Use these procedures to find out whether a string contains a given character or a given substring, or a character from a set of characters.

 -- primitive: string-index s char_pred [start end]
 -- primitive: string-index-right s char_pred [start end]
     Search through the string S from left to right (right to left), returning the index of the first (last) occurence of a character which

       * equals CHAR_PRED, if it is character,

       * satisifies the predicate CHAR_PRED, if it is a procedure,

       * is in the set CHAR_PRED, if it is a character set.

 -- primitive: string-skip s char_pred [start end]
 -- primitive: string-skip-right s char_pred [start end]
     Search through the string S from left to right (right to left), returning the index of the first (last) occurence of a character which

       * does not equal CHAR_PRED, if it is character,

       * does not satisify the predicate CHAR_PRED, if it is a procedure.

       * is not in the set if CHAR_PRED is a character set.

 -- primitive: string-count s char_pred [start end]
     Return the count of the number of characters in the string S which

       * equals CHAR_PRED, if it is character,

       * satisifies the predicate CHAR_PRED, if it is a procedure.

       * is in the set CHAR_PRED, if it is a character set.

 -- primitive: string-contains s1 s2 [start1 end1 start2 end2]
 -- primitive: string-contains-ci s1 s2 [start1 end1 start2 end2]
     Does string S1 contain string S2?  Return the index in S1 where S2 occurs as a substring, or false. The optional start/end indices restrict the operation to the indicated substrings.

     string-contains-ci is the case-insensitive variant.

Alphabetic Case Mapping
-----------------------

These procedures convert the alphabetic case of strings.  They are similar to the procedures in the Guile core, but are extended to handle optional start/end indices.

 -- primitive: string-upcase s [start end]
 -- primitive: string-upcase! s [start end]
     Upcase every character in S.  string-upcase! is the side-effecting variant.

 -- primitive: string-downcase s [start end]
 -- primitive: string-downcase! s [start end]
     Downcase every character in S.  string-downcase! is the side-effecting variant.

 -- primitive: string-titlecase s [start end]
 -- primitive: string-titlecase! s [start end]
     Upcase every first character in every word in S, downcase the other characters.  string-titlecase! is the side-effecting variant.

Reverse/Append
--------------

One appending procedure, string-append is the same in R5RS and in SRFI-13, so it is not redefined.

 -- primitive: string-reverse str [start end]
 -- primitive: string-reverse! str [start end]
     Reverse the string STR.  The optional arguments START and END delimit the region of STR to operate on.

     string-reverse! modifies the argument string and returns an unspecified value.

 -- primitive: string-append/shared ls ...
     Like string-append, but the result may share memory with the argument strings.

 -- primitive: string-concatenate ls
     Append the elements of LS (which must be strings) together into a single string.  Guaranteed to return a freshly allocated string.

 -- primitive: string-concatenate/shared ls
     Like string-concatenate, but the result may share memory with the strings in the list LS.

 -- primitive: string-concatenate-reverse ls final_string end
     Without optional arguments, this procedure is equivalent to

          (string-concatenate (reverse ls))

     If the optional argument FINAL_STRING is specified, it is consed onto the beginning to LS before performing the list-reverse and string-concatenate operations.  If END is given, only the characters of FINAL_STRING up to index END are used.

     Guaranteed to return a freshly allocated string.

 -- primitive: string-concatenate-reverse/shared ls final_string end
     Like string-concatenate-reverse, but the result may share memory with the the strings in the LS arguments.

Fold/Unfold/Map
---------------

string-map, string-for-each etc. are for iterating over the characters a string is composed of.  The fold and unfold procedures are list iterators and constructors.

 -- primitive: string-map proc s [start end]
     PROC is a char->char procedure, it is mapped over S.  The order in which the procedure is applied to the string elements is not specified.

 -- primitive: string-map! proc s [start end]
     PROC is a char->char procedure, it is mapped over S.  The order in which the procedure is applied to the string elements is not specified.  The string S is modified in-place, the return value is not specified.

 -- primitive: string-fold kons knil s [start end]
 -- primitive: string-fold-right kons knil s [start end]
     Fold KONS over the characters of S, with KNIL as the terminating element, from left to right (or right to left, for string-fold-right).  KONS must expect two arguments: The actual character and the last result of KONS' application.

 -- primitive: string-unfold p f g seed [base make_final]
 -- primitive: string-unfold-right p f g seed [base make_final]
     These are the fundamental string constructors.

       * G is used to generate a series of seed values from the initial SEED: SEED, (G SEED), (G^2 SEED), (G^3 SEED), ...

       * P tells us when to stop - when it returns true when applied to one of these seed values.

       * F maps each seed value to the corresponding character in the result string.  These chars are assembled into the string in a left-to-right (right-to-left) order.

       * BASE is the optional initial/leftmost (rightmost) portion of the constructed string; it default to the empty string.

       * MAKE_FINAL is applied to the terminal seed value (on which P returns true) to produce the final/rightmost (leftmost) portion of the constructed string.  It defaults to (lambda (x) "").

 -- primitive: string-for-each proc s [start end]
     PROC is mapped over S in left-to-right order.  The return value is not specified.

Replicate/Rotate
----------------

These procedures are special substring procedures, which can also be used for replicating strings.  They are a bit tricky to use, but consider this code fragment, which replicates the input string "foo" so often that the resulting string has a length of six.

     (xsubstring "foo" 0 6)
     =>
     "foofoo"

 -- primitive: xsubstring s from [to start end]
     This is the extended substring procedure that implements replicated copying of a substring of some string.

     S is a string, START and END are optional arguments that demarcate a substring of S, defaulting to 0 and the length of S.  Replicate this substring up and down index space, in both the positive and negative directions. xsubstring returns the substring of this string beginning at index FROM, and ending at TO, which defaults to FROM + (END - START).

 -- primitive: string-xcopy! target tstart s sfrom [sto start end]
     Exactly the same as xsubstring, but the extracted text is written into the string TARGET starting at index TSTART.  The operation is not defined if (eq? TARGET S) or these arguments share storage - you cannot copy a string on top of itself.

Miscellaneous
-------------

string-replace is for replacing a portion of a string with another string and string-tokenize splits a string into a list of strings, breaking it up at a specified character.

 -- primitive: string-replace s1 s2 [start1 end1 start2 end2]
     Return the string S1, but with the characters START1 ... END1 replaced by the characters START2 ... END2 from S2.

 -- primitive: string-tokenize s [token_char start end]
     Split the string S into a list of substrings, where each substring is a maximal non-empty contiguous sequence of characters equal to the character TOKEN_CHAR, or whitespace, if TOKEN_CHAR is not given.  If TOKEN_CHAR is a character set, it is used for finding the token borders.

Filtering/Deleting
------------------

Filtering means to remove all characters from a string which do not match a given criteria, deleting means the opposite.

 -- primitive: string-filter s char_pred [start end]
     Filter the string S, retaining only those characters that satisfy the CHAR_PRED argument.  If the argument is a procedure, it is applied to each character as a predicate, if it is a character, it is tested for equality and if it is a character set, it is tested for membership.

 -- primitive: string-delete s char_pred [start end]
     Filter the string S, retaining only those characters that do not satisfy the CHAR_PRED argument.  If the argument is a procedure, it is applied to each character as a predicate, if it is a character, it is tested for equality and if it is a character set, it is tested for membership.

SRFI-14 - Character-set Library
===============================

SRFI-14 defines the data type character set, and also defines a lot of procedures for handling this character type, and a few standard character sets like whitespace, alphabetic characters and others.

All procedures from SRFI-14 (character-set library) are implemented in the module (srfi srfi-14), as well as the standard variables char-set:letter, char-set:digit etc.

Loading SRFI-14
---------------

When Guile is properly installed, SRFI-14 support can be loaded into a running Guile by using the (srfi srfi-14) module.

     $ guile
     guile> (use-modules (srfi srfi-14))
     guile> (char-set-union (char-set #\f #\o #\o) (string->char-set "bar"))
     #<charset {#\a #\b #\f #\o #\r}>
     guile>

Character Set Data Type
-----------------------

The data type charset implements sets of characters (REFFIXME). Because the internal representation of character sets is not visible to the user, a lot of procedures for handling them are provided.

Character sets can be created, extended, tested for the membership of a characters and be compared to other character sets.

The Guile implementation of character sets deals with 8-bit characters. In the standard variables, only the ASCII part of the character range is really used, so that for example Umlaute and other accented characters are not considered to be letters.  In the future, as Guile may get support for international character sets, this will change, so don't rely on these ``features''.

Predicates/Comparison
---------------------

Use these procedures for testing whether an object is a character set, or whether several character sets are equal or subsets of each other. char-set-hash can be used for calculating a hash value, maybe for usage in fast lookup procedures.

 -- primitive: char-set? obj
     Return #t if OBJ is a character set, #f otherwise.

 -- primitive: char-set= cs1 ...
     Return #t if all given character sets are equal.

 -- primitive: char-set<= cs1 ...
     Return #t if every character set CSi is a subset of character set CSi+1.

 -- primitive: char-set-hash cs [bound]
     Compute a hash value for the character set CS.  If BOUND is given and not #f, it restricts the returned value to the range 0 ... BOUND - 1.

Iterating Over Character Sets
-----------------------------

Character set cursors are a means for iterating over the members of a character sets.  After creating a character set cursor with char-set-cursor, a cursor can be dereferenced with char-set-ref, advanced to the next member with char-set-cursor-next.  Whether a cursor has passed past the last element of the set can be checked with end-of-char-set?.

Additionally, mapping and (un-)folding procedures for character sets are provided.

 -- primitive: char-set-cursor cs
     Return a cursor into the character set CS.

 -- primitive: char-set-ref cs cursor
     Return the character at the current cursor position CURSOR in the character set CS.  It is an error to pass a cursor for which end-of-char-set? returns true.

 -- primitive: char-set-cursor-next cs cursor
     Advance the character set cursor CURSOR to the next character in the character set CS.  It is an error if the cursor given satisfies end-of-char-set?.

 -- primitive: end-of-char-set? cursor
     Return #t if CURSOR has reached the end of a character set, #f otherwise.

 -- primitive: char-set-fold kons knil cs
     Fold the procedure KONS over the character set CS, initializing it with KNIL.

 -- primitive: char-set-unfold p f g seed [base_cs]
 -- primitive: char-set-unfold! p f g seed base_cs
     This is a fundamental constructor for character sets.

       * G is used to generate a series of ``seed'' values from the initial seed: SEED, (G SEED), (G^2 SEED), (G^3 SEED), ...

       * P tells us when to stop -- when it returns true when applied to one of the seed values.

       * F maps each seed value to a character. These characters are added to the base character set BASE_CS to form the result; BASE_CS defaults to the empty set.

     char-set-unfold! is the side-effecting variant.

 -- primitive: char-set-for-each proc cs
     Apply PROC to every character in the character set CS.  The return value is not specified.

 -- primitive: char-set-map proc cs
     Map the procedure PROC over every character in CS. PROC must be a character -> character procedure.

Creating Character Sets
-----------------------

New character sets are produced with these procedures.

 -- primitive: char-set-copy cs
     Return a newly allocated character set containing all characters in CS.

 -- primitive: char-set char1 ...
     Return a character set containing all given characters.

 -- primitive: list->char-set char_list [base_cs]
 -- primitive: list->char-set! char_list base_cs
     Convert the character list LIST to a character set.  If the character set BASE_CS is given, the character in this set are also included in the result.

     list->char-set! is the side-effecting variant.

 -- primitive: string->char-set s [base_cs]
 -- primitive: string->char-set! s base_cs
     Convert the string STR to a character set.  If the character set BASE_CS is given, the characters in this set are also included in the result.

     string->char-set! is the side-effecting variant.

 -- primitive: char-set-filter pred cs [base_cs]
 -- primitive: char-set-filter! pred cs base_cs
     Return a character set containing every character from CS so that it satisfies PRED.  If provided, the characters from BASE_CS are added to the result.

     char-set-filter! is the side-effecting variant.

 -- primitive: ucs-range->char-set lower upper [error? base_cs]
 -- primitive: uce-range->char-set! lower upper error? base_cs
     Return a character set containing all characters whose character codes lie in the half-open range [LOWER,UPPER).

     If ERROR is a true value, an error is signalled if the specified range contains characters which are not contained in the implemented character range.  If ERROR is #f, these characters are silently left out of the resultung character set.

     The characters in BASE_CS are added to the result, if given.

     ucs-range->char-set! is the side-effecting variant.

 -- procedure: ->char-set x
     Coerce X into a character set.  X may be a string, a character or a character set.

Querying Character Sets
-----------------------

Access the elements and other information of a character set with these procedures.

 -- primitive: char-set-size cs
     Return the number of elements in character set CS.

 -- primitive: char-set-count pred cs
     Return the number of the elements int the character set CS which satisfy the predicate PRED.

 -- primitive: char-set->list cs
     Return a list containing the elements of the character set CS.

 -- primitive: char-set->string cs
     Return a string containing the elements of the character set CS.  The order in which the characters are placed in the string is not defined.

 -- primitive: char-set-contains? cs char
     Return #t iff the character CH is contained in the character set CS.

 -- primitive: char-set-every pred cs
     Return a true value if every character in the character set CS satisfies the predicate PRED.

 -- primitive: char-set-any pred cs
     Return a true value if any character in the character set CS satisfies the predicate PRED.

Character-Set Algebra
---------------------

Character sets can be manipulated with the common set algebra operation, such as union, complement, intersection etc.  All of these procedures provide side-effecting variants, which modify their character set argument(s).

 -- primitive: char-set-adjoin cs char1 ...
 -- primitive: char-set-adjoin! cs char1 ...
     Add all character arguments to the first argument, which must be a character set.

 -- primitive: char-set-delete cs char1 ...
 -- primitive: char-set-delete! cs char1 ...
     Delete all character arguments from the first argument, which must be a character set.

 -- primitive: char-set-complement cs
 -- primitive: char-set-complement! cs
     Return the complement of the character set CS.

 -- primitive: char-set-union cs1 ...
 -- primitive: char-set-union! cs1 ...
     Return the union of all argument character sets.

 -- primitive: char-set-intersection cs1 ...
 -- primitive: char-set-intersection! cs1 ...
     Return the intersection of all argument character sets.

 -- primitive: char-set-difference cs1 ...
 -- primitive: char-set-difference! cs1 ...
     Return the difference of all argument character sets.

 -- primitive: char-set-xor cs1 ...
 -- primitive: char-set-xor! cs1 ...
     Return the exclusive-or of all argument character sets.

 -- primitive: char-set-diff+intersection cs1 ...
 -- primitive: char-set-diff+intersection! cs1 ...
     Return the difference and the intersection of all argument character sets.

Standard Character Sets
-----------------------

In order to make the use of the character set data type and procedures useful, several predefined character set variables exist.

 -- Variable: char-set:lower-case
     All lower-case characters.

 -- Variable: char-set:upper-case
     All upper-case characters.

 -- Variable: char-set:title-case
     This is empty, because ASCII has no titlecase characters.

 -- Variable: char-set:letter
     All letters, e.g. the union of char-set:lower-case and char-set:upper-case.

 -- Variable: char-set:digit
     All digits.

 -- Variable: char-set:letter+digit
     The union of char-set:letter and char-set:digit.

 -- Variable: char-set:graphic
     All characters which would put ink on the paper.

 -- Variable: char-set:printing
     The union of char-set:graphic and char-set:whitespace.

 -- Variable: char-set:whitespace
     All whitespace characters.

 -- Variable: char-set:blank
     All horizontal whitespace characters, that is #\space and #\tab.

 -- Variable: char-set:iso-control
     The ISO control characters with the codes 0--31 and 127.

 -- Variable: char-set:punctuation
     The characters !"#%&'()*,-./:;?@[\\]_{}

 -- Variable: char-set:symbol
     The characters $+<=>^`|~.

 -- Variable: char-set:hex-digit
     The hexadecimal digits 0123456789abcdefABCDEF.

 -- Variable: char-set:ascii
     All ASCII characters.

 -- Variable: char-set:empty
     The empty character set.

 -- Variable: char-set:full
     This character set contains all possible characters.

SRFI-16 - case-lambda
=====================

The syntactic form case-lambda creates procedures, just like lambda, but has syntactic extensions for writing procedures of varying arity easier.

The syntax of the case-lambda form is defined in the following EBNF grammar.

     <case-lambda>
        --> (case-lambda <case-lambda-clause>)
     <case-lambda-clause>
        --> (<formals> <definition-or-command>*)
     <formals>
        --> (<identifier>*)
          | (<identifier>* . <identifier>)
          | <identifier>

The value returned by a case-lambda form is a procedure which matches the number of actual arguments against the formals in the various clauses, in order.  Formals means a formal argument list just like with lambda (REFFIXME). The first matching clause is selected, the corresponding values from the actual parameter list are bound to the variable names in the clauses and the body of the clause is evaluated.  If no clause matches, an error is signalled.

The following (silly) definition creates a procedure FOO which acts differently, depending on the number of actual arguments.  If one argument is given, the constant #t is returned, two arguments are added and if more arguments are passed, their product is calculated.

     (define foo (case-lambda
                   ((x) #t)
                   ((x y) (+ x y))
                   (z
                     (apply * z))))
     (foo 'bar)
     =>
     #t
     (foo 2 4)
     =>
     6
     (foo 3 3 3)
     =>
     27
     (foo)
     =>
     1

The last expression evaluates to 1 because the last clause is matched, Z is bound to the empty list and the following multiplication, applied to zero arguments, yields 1.

SRFI-17 - Generalized set!
==========================

This is an implementation of SRFI-17: Generalized set!

It exports the Guile procedure make-procedure-with-setter under the SRFI name getter-with-setter and exports the standard procedures car, cdr, ..., cdddr, string-ref and vector-ref as procedures with setters, as required by the SRFI.

SRFI-17 was heavily criticized during its discussion period but it was finalized anyway.  One issue was its concept of globally associating setter properties with (procedure) values, which is non-Schemy. For this reason, this implementation chooses not to provide a way to set the setter of a procedure.  In fact, (set!  (setter PROC) SETTER) signals an error.  The only way to attach a setter to a procedure is to create a new object (a procedure with setter) via the getter-with-setter procedure. This procedure is also specified in the SRFI.  Using it avoids the described problems.