Scheme Index (R6RS + SRFIs)

By Artyom Bologov

Hello! This is a project borne from the frustration of using index.scheme.org: the site is extremely slow due to being written in Angular. This site here is an attempt to reproduce (most of) the functionality of index.scheme.org. But with static pre-rendered pages and zero JavaScript required. (index.scheme.org requires JavaScript to work, locking the users of older / weaker / JS-less browsers out.) Some of the features present on index.scheme.org are not present here. For reasons:

Other than that, it’s quite similar: choose the libraries you need (new sections appear after checking the respective checkbox,) and search / skim / read their docs.

This site is sourced from scheme-index repository, which itself is based on index.scheme.org data. SRFI metadata, like titles and abstracts, are taken from the srfi-common repository.

Faux types

There are some “types” that don’t have a predicate and yet are omnipresent in Scheme. Like predicates or comparators. So here’s a list of these that’s going to be referenced in the API listings:

environment
Environment (set of libraries and their identifiers,) as per R7RS section 6.12
predicate
A procedure that returns a (usually) boolean value for whether its argument has some property
file-options
Object representing special flags for file handling and I/O (R6RS)
codec
An immutable Scheme object that represents a Unicode or similar encoding scheme (R6RS)
transcoder
A transcoder is an immutable Scheme object that combines a codec with an end-of-line style and a method for handling decoding errors (R6RS)
enum-set
Finite set of enumerated values of a certain type (R6RS)
opaque-port-position
Position in a port (R6RS)
transformer-spec
Object returned by macro-creating forms
computation
A computation can be thought of as suspended code much like promises but with the difference that a computation can be executed more than once and that its results are not cached (SRFI-165)
computation-env
The computations of the environment monad are executed on an environment (SRFI-165)
computation-env-variable
Environment variables can be bound to values in computation environments (SRFI-165)
constructor-descriptor
Record constructor descriptor specifies a record constructor (or constructor for short), that can be used to construct record values of the type specified by rtd (R6RS)
endianness
(Big, little) endianness object, as returned by endianness macro (SRFI-74)
formatter
Formatter (encapsulated formatting code) object (SRFI-159)
formatter-variable
Formatting-related variables that can be overriden (SRFI-159)
generator-macro
Eager comprehension macro (SRFI-42)
option
Object representing a command line option passed to the program (SRFI-37)
random-source-state
Object representing a state of the random bit source (SRFI-27)
timer-id
ID of the task in a certain timer (SRFI-120)
time-type
Symbol representing a certain time system, e.g. time-utc (SRFI-19)
vicinity
Descriptor for a place in the file system (SRFI-59)
message-type
Message types, as used in SRFI-106 socket-recv and socket-send
socket-domain
Socket domain flag (SRFI-106)
address-family
Address family flag (SRFI-106)
address-info
Merged address info flags for socket (SRFI-106)
ip-protocol
Protocol flag for a socket (SRFI-106)
shutdown-method
Shutdown method for a socket (SRFI-106)

library (rnrs base (6))

(rnrs base (6)) procedure (* (z number?) ...) ⟹ number?

This procedure returns the product of its arguments.

(rnrs base (6)) procedure (+ (z number?) ...) ⟹ number?

This procedure returns the sum of its arguments.

(rnrs base (6)) procedure (- (z number?) ...) ⟹ number?

With two or more arguments, this procedures returns the difference of its arguments, associating to the left. With one argument, however, it returns the additive inverse of its argument.

(rnrs base (6)) procedure (/ (z1 number?) (z2 number?) ...) ⟹ number?

If all of the arguments are exact, then the divisors must all be nonzero. With two or more arguments, this procedure returns the quotient of its arguments, associating to the left. With one argument, however, it returns the multiplicative inverse of its argument.

(rnrs base (6)) procedure (< (x1 real?) (x2 real?) (x3 real?) ...) ⟹ boolean?

This procedure returns #t if its arguments are monotonically increasing, and #f otherwise.

(rnrs base (6)) procedure (<= (x1 real?) (x2 real?) (x3 real?) ...) ⟹ boolean?

This procedure returns #t if its arguments are monotonically nondecreasing, and #f otherwise.

(rnrs base (6)) procedure (= (z1 number?) (z2 number?) (z3 number?) ...) ⟹ boolean?

This procedure returns #t if its arguments are equal, and #f otherwise.

(rnrs base (6)) procedure (> (x1 real?) (x2 real?) (x3 real?) ...) ⟹ boolean?

This procedure returns #t if its arguments are decreasing, and #f otherwise.

(rnrs base (6)) procedure (>= (x1 real?) (x2 real?) (x3 real?) ...) ⟹ boolean?

This procedure returns #t if its arguments are monotonically nonincreasing, and #f otherwise.

(rnrs base (6)) procedure (abs (x real?)) ⟹ number?

Returns the absolute value of its argument.

(rnrs base (6)) syntax (and test1 ...)

Semantics: If there are no <test>s, #t is returned. Otherwise, the <test> expressions are evaluated from left to right until a <test> returns #f or the last <test> is reached. In the former case, the and expression returns #f without evaluating the remaining expressions. In the latter case, the last expression is evaluated and its values are returned.

(rnrs base (6)) procedure (append (list list?) ...) ⟹ list?

(rnrs base (6)) procedure (append (list list?) ... obj) ⟹ *

Returns a possibly improper list consisting of the elements of the first list followed by the elements of the other lists, with obj as the cdr of the final pair. An improper list results if obj is not a list.

If append constructs a nonempty chain of pairs, it is always newly allocated. If no pairs are allocated, obj is returned.

(rnrs base (6)) procedure (apply (proc procedure?) arg1 ... (rest-args list?)) ⟹ *

Rest-args must be a list. Proc should accept n arguments, where n is number of args plus the length of rest-args. The apply procedure calls proc with the elements of the list (append (list arg1 ...) rest-args) as the actual arguments.

If a call to apply occurs in a tail context, the call to proc is also in a tail context.

(rnrs base (6)) procedure (assertion-violation (who string? | symbol? | #f) (message string?) irritant1 ...) ⟹ undefined

The assertion-violation procedure should be called when an invalid call to a procedure was made, either passing an invalid number of arguments, or passing an argument that it is not specified to handle.

The who argument should describe the procedure or operation that detected the exception. The message argument should describe the exceptional situation. The irritants should be the arguments to the operation that detected the operation.

The condition object provided with the exception (see library chapter on “Exceptions and conditions”) has the following condition types:

  • If who is not #f, the condition has condition type &who, with who as the value of its field. In that case, who should be the name of the procedure or entity that detected the exception. If it is #f, the condition does not have condition type &who.
  • The condition has condition type &message, with message as the value of its field.
  • The condition has condition type &irritants, and its field has as its value a list of the irritants.
  • Moreover, the condition created by assertion-violation has condition type &assertion.

    (rnrs base (6)) syntax (assert expression)

    An assert form is evaluated by evaluating <expression>. If <expression> returns a true value, that value is returned from the assert expression. If <expression> returns #f, an exception with condition types &assertion and &message is raised. The message provided in the condition object is implementation-dependent.

    (rnrs base (6)) syntax (begin expression-or-definition ...)

    The <begin> keyword has two different roles, depending on its context:

  • It may appear as a form in a <body> (see section 11.3), <library body> (see section 7.1), or <top-level body> (see chapter 8), or directly nested in a begin form that appears in a body. In this case, the begin form must have the shape specified in the first header line. This use of begin acts as a splicing form—the forms inside the <body> are spliced into the surrounding body, as if the begin wrapper were not actually present.
  • A begin form in a <body> or <library body> must be non-empty if it appears after the first <expression> within the body.

  • It may appear as an ordinary expression and must have the shape specified in the second header line. In this case, the <expression>s are evaluated sequentially from left to right, and the values of the last <expression> are returned. This expression type is used to sequence side effects such as assignments or input and output.
  • (rnrs base (6)) procedure (boolean=? (boolean1 boolean?) (boolean2 boolean?) (boolean3 boolean?) ...) ⟹ boolean?

    Returns #t if the booleans are the same.

    (rnrs base (6)) procedure (boolean? obj) ⟹ boolean?

    Returns #t if obj is either #t or #f and returns #f otherwise.

    (rnrs base (6)) procedure (caar (pair pair?)) ⟹ *

    Composition of car and car.

    (rnrs base (6)) procedure (cadr (pair pair?)) ⟹ *

    Composition of car and cdr.

    (rnrs base (6)) procedure (call-with-current-continuation (proc procedure?)) ⟹ *

    (proc (k procedure?)) ⟹ *

    Proc should accept one argument. The procedure call-with-current-continuation (which is the same as the procedure call/cc) packages the current continuation as an "escape procedure" and passes it as an argument to proc. The escape procedure is a Scheme procedure that, if it is later called, will abandon whatever continuation is in effect at that later time and will instead reinstate the continuation that was in effect when the escape procedure was created. Calling the escape procedure may cause the invocation of before and after procedures installed using dynamic-wind.

    The escape procedure accepts the same number of arguments as the continuation of the original call to call-with-current-continuation.

    The escape procedure that is passed to proc has unlimited extent just like any other procedure in Scheme. It may be stored in variables or data structures and may be called as many times as desired.

    If a call to call-with-current-continuation occurs in a tail context, the call to proc is also in a tail context.

    Note: Calling an escape procedure reenters the dynamic extent of the call to call-with-current-continuation, and thus restores its dynamic environment; see section 5.12.

    (rnrs base (6)) procedure (call-with-values (producer procedure?) (consumer procedure?)) ⟹ *

    (producer) ⟹ *

    (consumer obj ...) ⟹ *

    The call-with-values procedure calls producer with no arguments and a continuation that, when passed some values, calls the consumer procedure with those values as arguments. The continuation for the call to consumer is the continuation of the call to call-with-values. If a call to call-with-values occurs in a tail context, the call to consumer is also in a tail context.

    Implementation responsibilities: After producer returns, the implementation must check that consumer accepts as many values as consumer has returned.

    (rnrs base (6)) procedure (call/cc (proc procedure?)) ⟹ *

    (proc (k procedure?)) ⟹ *

    Proc should accept one argument. The procedure call-with-current-continuation (which is the same as the procedure call/cc) packages the current continuation as an "escape procedure" and passes it as an argument to proc. The escape procedure is a Scheme procedure that, if it is later called, will abandon whatever continuation is in effect at that later time and will instead reinstate the continuation that was in effect when the escape procedure was created. Calling the escape procedure may cause the invocation of before and after procedures installed using dynamic-wind.

    The escape procedure accepts the same number of arguments as the continuation of the original call to call-with-current-continuation.

    The escape procedure that is passed to proc has unlimited extent just like any other procedure in Scheme. It may be stored in variables or data structures and may be called as many times as desired.

    If a call to call-with-current-continuation occurs in a tail context, the call to proc is also in a tail context.

    Note: Calling an escape procedure reenters the dynamic extent of the call to call-with-current-continuation, and thus restores its dynamic environment; see section 5.12.

    (rnrs base (6)) procedure (car (pair pair?)) ⟹ *

    Returns the contents of the car field of pair.

    (rnrs base (6)) syntax (case key clause1 clause2 ...)

    clause ⟹ ((datum1 ...) expression1 expression2 ...) | ((datum1 ...) => expression) | (else expression1 expression2 ...)

    The second form, which specifies an "else clause", may only appear as the last <case clause>. Each <datum> is an external representation of some object. The data represented by the <datum>s need not be distinct.

    Semantics: A case expression is evaluated as follows. <Key> is evaluated and its result is compared using eqv? (see section 11.5) against the data represented by the <datum>s of each <case clause> in turn, proceeding in order from left to right through the set of clauses. If the result of evaluating <key> is equivalent to a datum of a <case clause>, the corresponding <expression>s are evaluated from left to right and the results of the last expression in the <case clause> are returned as the results of the case expression. Otherwise, the comparison process continues. If the result of evaluating <key> is different from every datum in each set, then if there is an else clause its expressions are evaluated and the results of the last are the results of the case expression; otherwise the case expression returns unspecified values.

    (rnrs base (6)) procedure (cdar (pair pair?)) ⟹ *

    Composition of cdr and car.

    (rnrs base (6)) procedure (cddr (pair pair?)) ⟹ *

    Composition of cdr and cdr.

    (rnrs base (6)) procedure (cdr (pair pair?)) ⟹ *

    Returns the contents of the cdr field of pair.

    (rnrs base (6)) procedure (ceiling (x real?)) ⟹ real?

    The ceiling procedure returns the smallest integer object not smaller than x.

    Note:‌ If the argument to the procedure is inexact, then the result is also inexact. If an exact value is needed, the result should be passed to the exact procedure.

    (rnrs base (6)) procedure (char->integer (char char?)) ⟹ integer?

    Given a character, char->integer returns its Unicode scalar value as an exact integer object.

    (rnrs base (6)) procedure (char<=? (char1 char?) (char2 char?) (char3 char?) ...) ⟹ boolean?

    This procedure returns #t if the results of passing their arguments to char->integer are monotonically non-decreasing. This predicate is required to be transitive.

    (rnrs base (6)) procedure (char<? (char1 char?) (char2 char?) (char3 char?) ...) ⟹ boolean?

    This procedure returns #t if the results of passing their arguments to char->integer are monotonically increasing. This predicate is required to be transitive.

    (rnrs base (6)) procedure (char=? (char1 char?) (char2 char?) (char3 char?) ...) ⟹ boolean?

    This procedure returns #t if the results of passing their arguments to char->integer are equal. This predicate is required to be transitive.

    (rnrs base (6)) procedure (char>=? (char1 char?) (char2 char?) (char3 char?) ...) ⟹ boolean?

    This procedure returns #t if the results of passing their arguments to char->integer are monotonically non-increasing. This predicate is required to be transitive.

    (rnrs base (6)) procedure (char>? (char1 char?) (char2 char?) (char3 char?) ...) ⟹ boolean?

    This procedure returns #t if the results of passing their arguments to char->integer are monotonically decreasing. This predicate is required to be transitive.

    (rnrs base (6)) procedure (char? obj) ⟹ boolean?

    Returns #t if obj is a character, otherwise returns #f.

    (rnrs base (6)) syntax (cond clause1 clause2 ...)

    clause ⟹ (test expression1 ...) | (test => receiver) | (else expression1 expression2 ...)

    receiver ⟹ procedure?

    A cond expression is evaluated by evaluating the <test> expressions of successive <cond clause>s in order until one of them evaluates to a true value(see section 5.7). When a <test> evaluates to a true value, then the remaining <expression>s in its <cond clause> are evaluated in order, and the results of the last <expression> in the <cond clause> are returned as the results of the entire cond expression. If the selected <cond clause> contains only the <test> and no <expression>s, then the value of the <test> is returned as the result. If the selected <cond clause> uses the => alternate form, then the <expression> is evaluated. Its value must be a procedure. This procedure should accept one argument; it is called on the value of the <test> and the values returned by this procedure are returned by the cond expression. If all <test>s evaluate to #f, and there is no else clause, then the conditional expression returns unspecified values; if there is an else clause, then its <expression>s are evaluated, and the values of the last one are returned.

    (rnrs base (6)) procedure (cons obj1 obj2) ⟹ pair?

    Returns a newly allocated pair whose car is obj1 and whose cdr is obj2. The pair is guaranteed to be different (in the sense of eqv?) from every existing object.

    (rnrs base (6)) syntax (define variable expression)

    (rnrs base (6)) syntax (define variable)

    (rnrs base (6)) syntax (define (variable parameter1 ...) body)

    (rnrs base (6)) syntax (define (variable parameter1 ... . parameter) body)

    The define form described in this section is a <definition>used to create variable bindings and may appear anywhere other definitions may appear.

    The first from of define binds <variable> to a new location before assigning the value of <expression> to it. The continuation of <expression> should not be invoked more than once. Implementation responsibilities: Implementations should detect that the continuation of <expression> is invoked more than once. If the implementation detects this, it must raise an exception with condition type &assertion.

    The second form of define is equivalent to (define <variable> <unspecified>) where <unspecified> is a side-effect-free expression returning an unspecified value.

    In the third form of define, <formals> must be either a sequence of zero or more variables, or a sequence of one or more variables followed by a dot . and another variable (as in a lambda expression, see section 11.4.2). This form is equivalent to (define <variable>   (lambda (<formals>) <body>)).

    In the fourth form of define, <formal> must be a single variable. This form is equivalent to (define <variable> (lambda <formal> <body>)).

    (rnrs base (6)) syntax (define-syntax keyword transformer-spec)

    transformer-spec ⟹ transformer-spec

    Binds <keyword> to the value of <expression>, which must evaluate, at macro-expansion time, to a transformer. Macro transformers can be created using the syntax-rules and identifier-syntax forms described in section 11.19. See library section on “Transformers” for a more complete description of transformers. Keyword bindings established by define-syntax are visible throughout the body in which they appear, except where shadowed by other bindings, and nowhere else, just like variable bindings established by define. All bindings established by a set of definitions, whether keyword or variable definitions, are visible within the definitions themselves.

    Implementation responsibilities: The implementation should detect if the value of <expression> cannot possibly be a transformer.

    (rnrs base (6)) procedure (div (x1 real?) (x2 real?)) ⟹ integer?

    Number-theoretic integer division and return the results of the corresponding mathematical operations specified in section 11.7.3.1. x1 must be neither infinite nor a NaN, and x2 must be nonzero; otherwise, an exception with condition type &assertion is raised.

    (rnrs base (6)) procedure (div0 (x1 real?) (x2 real?)) ⟹ integer?

    Number-theoretic integer division and return the results of the corresponding mathematical operations specified in section 11.7.3.1. x1 must be neither infinite nor a NaN, and x2 must be nonzero; otherwise, an exception with condition type &assertion is raised.

    (rnrs base (6)) procedure (div-and-mod (x1 real?) (x2 real?)) ⟹ (values integer? real?)

    Number-theoretic integer division and return the results of the corresponding mathematical operations specified in section 11.7.3.1. x1 must be neither infinite nor a NaN, and x2 must be nonzero; otherwise, an exception with condition type &assertion is raised.

    (rnrs base (6)) procedure (div0-and-mod0 (x1 real?) (x2 real?)) ⟹ (values integer? real?)

    Number-theoretic integer division and return the results of the corresponding mathematical operations specified in section 11.7.3.1. x1 must be neither infinite nor a NaN, and x2 must be nonzero; otherwise, an exception with condition type &assertion is raised.

    (rnrs base (6)) procedure (dynamic-wind (before procedure?) (thunk procedure?) (after procedure?)) ⟹ *

    (before) ⟹ undefined

    (thunk) ⟹ *

    (after) ⟹ undefined

    Before, thunk, and after must be procedures, and each should accept zero arguments. These procedures may return any number of values. The dynamic-wind procedure calls thunk without arguments, returning the results of this call. Moreover, dynamic-wind calls before without arguments whenever the dynamic extent of the call to thunk is entered, and after without arguments whenever the dynamic extent of the call to thunk is exited. Thus, in the absence of calls to escape procedures created by call-with-current-continuation, dynamic-wind calls before, thunk, and after, in that order.

    While the calls to before and after are not considered to be within the dynamic extent of the call to thunk, calls to the before and after procedures of any other calls to dynamic-wind that occur within the dynamic extent of the call to thunk are considered to be within the dynamic extent of the call to thunk.

    More precisely, an escape procedure transfers control out of the dynamic extent of a set of zero or more active dynamic-wind calls x ... and transfer control into the dynamic extent of a set of zero or more active dynamic-wind calls y .... It leaves the dynamic extent of the most recent x and calls without arguments the corresponding after procedure. If the after procedure returns, the escape procedure proceeds to the next most recent x, and so on. Once each x has been handled in this manner, the escape procedure calls without arguments the before procedure corresponding to the least recent y. If the before procedure returns, the escape procedure reenters the dynamic extent of the least recent y and proceeds with the next least recent y, and so on. Once each y has been handled in this manner, control is transferred to the continuation packaged in the escape procedure.

    Implementation responsibilities: The implementation must check the restrictions on thunk and after only if they are actually called.

    (rnrs base (6)) procedure (eq? obj1 obj2) ⟹ boolean?

    The eq? predicate is similar to eqv? except that in some cases it is capable of discerning distinctions finer than those detectable by eqv?.

    The eq? and eqv? predicates are guaranteed to have the same behavior on symbols, booleans, the empty list, pairs, procedures, non-empty strings, bytevectors, and vectors, and records. The behavior of eq? on number objects and characters is implementation-dependent, but it always returns either #t or #f, and returns #t only when eqv? would also return #t. The eq? predicate may also behave differently from eqv? on empty vectors, empty bytevectors, and empty strings.

    (rnrs base (6)) procedure (equal? obj1 obj2) ⟹ boolean?

    The equal? predicate returns #t if and only if the (possibly infinite) unfoldings of its arguments into regular trees are equal as ordered trees.

    The equal? predicate treats pairs and vectors as nodes with outgoing edges, uses string=? to compare strings, uses bytevector=? to compare bytevectors (see library chapter on “Bytevectors”), and uses eqv? to compare other nodes.

    (rnrs base (6)) procedure (eqv? obj1 obj2) ⟹ boolean?

    The eqv? procedure defines a useful equivalence relation on objects. Briefly, it returns #t if obj1 and obj2 should normally be regarded as the same object and #f otherwise. This relation is left slightly open to interpretation, but the following partial specification of eqv? must hold for all implementations.

    The eqv? procedure returns #t if one of the following holds:

  • Obj1 and obj2 are both booleans and are the same according to the boolean=? procedure (section 11.8).
  • Obj1 and obj2 are both symbols and are the same according to the symbol=? procedure (section 11.10).
  • Obj1 and obj2 are both exactnumber objects and are numerically equal (see =, section 11.7).
  • Obj1 and obj2 are both inexactnumber objects, are numerically equal (see =, section 11.7), and yield the same results (in the sense of eqv?) when passed as arguments to any other procedure that can be defined as a finite composition of Scheme's standard arithmetic procedures.
  • Obj1 and obj2 are both characters and are the same character according to the char=? procedure (section 11.11).
  • Both obj1 and obj2 are the empty list.
  • Obj1 and obj2 are objects such as pairs, vectors, bytevectors (library chapter on “Bytevectors”), strings, hashtables, records (library chapter on “Records”), ports (library section on “Port I/O”), or hashtables (library chapter on “Hash tables”) that refer to the same locations in the store (section 5.10).
  • Obj1 and obj2 are record-type descriptors that are specified to be eqv? in library section on “Procedural layer”.
  • The eqv? procedure returns #f if one of the following holds:

  • Obj1 and obj2 are of different types (section 11.1).
  • Obj1 and obj2 are booleans for which the boolean=? procedure returns #f.
  • Obj1 and obj2 are symbols for which the symbol=? procedure returns #f.
  • One of obj1 and obj2 is an exact number object but the other is an inexact number object.
  • Obj1 and obj2 are rational number objects for which the = procedure returns #f.
  • Obj1 and obj2 yield different results (in the sense of eqv?) when passed as arguments to any other procedure that can be defined as a finite composition of Scheme's standard arithmetic procedures.
  • Obj1 and obj2 are characters for which the char=? procedure returns #f.
  • One of obj1 and obj2 is the empty list, but the other is not.
  • Obj1 and obj2 are objects such as pairs, vectors, bytevectors (library chapter on “Bytevectors”), strings, records (library chapter on “Records”), ports (library section on “Port I/O”), or hashtables (library chapter on “Hashtables”) that refer to distinct locations.
  • Obj1 and obj2 are pairs, vectors, strings, or records, or hashtables, where the applying the same accessor (i.e. car, cdr, vector-ref, string-ref, or record accessors) to both yields results for which eqv? returns #f.
  • Obj1 and obj2 are procedures that would behave differently (return different values or have different side effects) for some arguments.
  • Note:‌ The eqv? procedure returning #t when obj1 and obj2 are number objects does not imply that = would also return #t when called with obj1 and obj2 as arguments.

    (rnrs base (6)) procedure (error (who string? | symbol? | #f) (message string?) irritant1 ...) ⟹ undefined

    The error procedure should be called when an error has occurred, typically caused by something that has gone wrong in the interaction of the program with the external world or the user.

    The who argument should describe the procedure or operation that detected the exception. The message argument should describe the exceptional situation. The irritants should be the arguments to the operation that detected the operation.

    The condition object provided with the exception (see library chapter on “Exceptions and conditions”) has the following condition types:

  • If who is not #f, the condition has condition type &who, with who as the value of its field. In that case, who should be the name of the procedure or entity that detected the exception. If it is #f, the condition does not have condition type &who.
  • The condition has condition type &message, with message as the value of its field.
  • The condition has condition type &irritants, and its field has as its value a list of the irritants.
  • Moreover, the condition created by error has condition type &error.

    (rnrs base (6)) procedure (exact (z number?)) ⟹ exact?

    The exact procedure returns an exact representation of z. The value returned is the exact number object that is numerically closest to the argument; in most cases, the result of this procedure should be numerically equal to its argument. If an inexact argument has no reasonably close exact equivalent, an exception with condition type &implementation-violation may be raised.

    (rnrs base (6)) procedure (exact-integer-sqrt (k integer?)) ⟹ (values integer? integer?)

    The exact-integer-sqrt procedure returns two non-negative exact integer objects s and r where k = s^2 + r and k < (s + 1)^2.

    (rnrs base (6)) procedure (exact? (z number?)) ⟹ boolean?

    Tests for the exactness of a quantity. For any number object, precisely one of exact? or inexact? predicates is true.

    (rnrs base (6)) procedure (expt (z1 number?) (z2 number?)) ⟹ number?

    Returns z1 raised to the power z2. For nonzero z1, this is ez2 log z1. 0.0z is 1.0 if z = 0.0, and 0.0 if (real-part z) is positive. For other cases in which the first argument is zero, either an exception is raised with condition type &implementation-restriction, or an unspecified number object is returned.

    For an exact real number object z1 and an exact integer object z2, (expt z1 z2) must return an exact result. For all other values of z1 and z2, (expt z1 z2) may return an inexact result, even when both z1 and z2 are exact.

    (rnrs base (6)) procedure (floor (x real?)) ⟹ integer?

    floor returns the largest integer object not larger than x.

    (rnrs base (6)) procedure (for-each (proc procedure?) (list1 list?) (list2 list?) ...) ⟹ undefined

    (proc obj1 obj2 ...) ⟹ undefined

    The lists should all have the same length. Proc should accept as many arguments as there are lists. Proc should not mutate any of the lists.

    The for-each procedure applies proc element-wise to the elements of the lists for its side effects, in order from the first elements to the last. Proc is always called in the same dynamic environment as for-each itself. The return values of for-each are unspecified.

    (rnrs base (6)) procedure (gcd (n integer?) ...) ⟹ integer?

    Returns the greatest common divisor of its arguments. The result is always non-negative.

    (rnrs base (6)) syntax (identifier-syntax template)⟹ return

    (rnrs base (6)) syntax (identifier-syntax (id1 template1) ((set! id2 pattern) template2))

    pattern ⟹ _ | identifier | constant | (pattern ...) | (pattern pattern ... . pattern) | (pattern ... pattern ellipsis pattern ...) | (pattern ... pattern ellipsis pattern ... . pattern) | #(pattern ...) | #(pattern ... pattern ellipsis pattern ...)

    template ⟹ identifier | constant | (element ...) | (element element ... . template) | (ellipsis template) | #(element ...)

    Semantics: When a keyword is bound to a transformer produced by the first form of identifier-syntax, references to the keyword within the scope of the binding are replaced by <template>.

    The second, more general, form of identifier-syntax permits the transformer to determine what happens when set! is used. In this case, uses of the identifier by itself are replaced by <template1>, and uses of set! with the identifier are replaced by <template2>.

    (rnrs base (6)) syntax (if test consequent)

    (rnrs base (6)) syntax (if test consequent alternate)

    An if expression is evaluated as follows: first, <test> is evaluated. If it yields a true value(see section 5.7), then <consequent> is evaluated and its values are returned. Otherwise <alternate> is evaluated and its values are returned. If <test> yields #f and no <alternate> is specified, then the result of the expression is unspecified.

    (rnrs base (6)) procedure (inexact (z number?)) ⟹ inexact?

    The inexact procedure returns an inexact representation of z. If inexact number objects of the appropriate type have bounded precision, then the value returned is an inexact number object that is nearest to the argument. If an exact argument has no reasonably close inexact equivalent, an exception with condition type &implementation-violation may be raised.

    (rnrs base (6)) procedure (inexact? (z number?)) ⟹ boolean?

    Tests for the exactness of a quantity. For any number object, precisely one of exact? or inexact? predicates is true.

    (rnrs base (6)) procedure (integer-valued? obj) ⟹ boolean?

    integer-valued? procedures return #t if the object is a number object and is equal in the sense of = to some integer

    (rnrs base (6)) procedure (integer->char (n integer?)) ⟹ char?

    For a Unicode scalar value, integer->char returns its associated character.

    (rnrs base (6)) syntax (lambda formals body)⟹ return

    formals ⟹ (variable1 ...) | variable | (variable1 ... variable_n . variable_n+1)

    Semantics: A lambda expression evaluates to a procedure. The environment in effect when the lambda expression is evaluated is remembered as part of the procedure. When the procedure is later called with some arguments, the environment in which the lambda expression was evaluated is extended by binding the variables in the parameter list to fresh locations, and the resulting argument values are stored in those locations. Then, the expressions in the body of the lambda expression (which may contain definitions and thus represent a letrec* form, see section 11.3) are evaluated sequentially in the extended environment. The results of the last expression in the body are returned as the results of the procedure call.

    <Formals> must have one of the following forms:

  • (<variable1> ...): The procedure takes a fixed number of arguments; when the procedure is called, the arguments are stored in the bindings of the corresponding variables.
  • <variable>: The procedure takes any number of arguments; when the procedure is called, the sequence of arguments is converted into a newly allocated list, and the list is stored in the binding of the <variable>.
  • (<variable1> ... <variablen> . <variablen+1>): If a period . precedes the last variable, then the procedure takes n or more arguments, where n is the number of parameters before the period (there must be at least one). The value stored in the binding of the last variable is a newly allocated list of the arguments left over after all the other arguments have been matched up against the other parameters.
  • Any <variable> must not appear more than once in <formals>.

    (rnrs base (6)) procedure (lcm (n integer?) ...) ⟹ integer?

    Returns the least common multiple of its arguments. The result is always non-negative.

    (rnrs base (6)) procedure (length (list list?)) ⟹ integer?

    Returns the length of list.

    (rnrs base (6)) syntax (let ((var1 init1) ...) body)

    (rnrs base (6)) syntax (let name ((var1 init1) ...) body)

    The <init>s are evaluated in the current environment (in some unspecified order), the <variable>s are bound to fresh locations holding the results, the <body> is evaluated in the extended environment, and the values of the last expression of <body> are returned. Each binding of a <variable> has <body> as its region.

    “Named let” is a variant on the syntax of let that provides a general looping construct and may also be used to express recursion. It has the same syntax and semantics as ordinary let except that <variable> is bound within <body> to a procedure whose parameters are the bound variables and whose body is <body>. Thus the execution of <body> may be repeated by invoking the procedure named by <variable>.

    (rnrs base (6)) syntax (let* bindings body)

    bindings ⟹ ((variable1 init1) ...)

    The let* form is similar to let, but the <init>s are evaluated and bindings created sequentially from left to right, with the regionof each binding including the bindings to its right as well as <body>. Thus the second <init> is evaluated in an environment in which the first binding is visible and initialized, and so on.

    (rnrs base (6)) syntax (let*-values mv-binding-spec body)

    mv-binding-spec ⟹ ((formals1 init1) ...)

    formals ⟹ (variable1 ...) | variable | (variable1 ... variable_n . variable_n+1)

    The let*-values form is similar to let-values, but the <init>s are evaluated and bindings created sequentially from left to right, with the regionof the bindings of each <formals> including the bindings to its right as well as <body>. Thus the second <init> is evaluated in an environment in which the bindings of the first <formals> is visible and initialized, and so on.

    (rnrs base (6)) syntax (let-syntax bindings form ...)

    bindings ⟹ ((keyword transformer-spec) ...)

    transformer-spec ⟹ transformer-spec

    Each <keyword> is an identifier, and each <expression> is an expression that evaluates, at macro-expansion time, to a transformer. Transformers may be created by syntax-rules or identifier-syntax (see section 11.19) or by one of the other mechanisms described in library chapter on “syntax-case”. It is a syntax violation for <keyword> to appear more than once in the list of keywords being bound.

    Semantics: The <form>s are expanded in the syntactic environment obtained by extending the syntactic environment of the let-syntax form with macros whose keywords are the <keyword>s, bound to the specified transformers. Each binding of a <keyword> has the <form>s as its region.

    The <form>s of a let-syntax form are treated, whether in definition or expression context, as if wrapped in an implicit begin; see section 11.4.7. Thus definitions in the result of expanding the <form>s have the same region as any definition appearing in place of the let-syntax form would have.

    Implementation responsibilities: The implementation should detect if the value of <expression> cannot possibly be a transformer.

    (rnrs base (6)) syntax (let-values mv-binding-spec body)

    mv-binding-spec ⟹ ((formals1 init1) ...)

    formals ⟹ (variable1 ...) | variable | (variable1 ... variable_n . variable_n+1)

    The <init>s are evaluated in the current environment (in some unspecified order), and the variables occurring in the <formals> are bound to fresh locations containing the values returned by the <init>s, where the <formals> are matched to the return values in the same way that the <formals> in a lambda expression are matched to the arguments in a procedure call. Then, the <body> is evaluated in the extended environment, and the values of the last expression of <body> are returned. Each binding of a variable has <body> as its region.If the <formals> do not match, an exception with condition type &assertion is raised.

    (rnrs base (6)) syntax (letrec bindings body)

    bindings ⟹ ((variable1 init1) ...)

    The <variable>s are bound to fresh locations, the <init>s are evaluated in the resulting environment (in some unspecified order), each <variable> is assigned to the result of the corresponding <init>, the <body> is evaluated in the resulting environment, and the values of the last expression in <body> are returned. Each binding of a <variable> has the entire letrec expression as its region, making it possible to define mutually recursive procedures.

    (rnrs base (6)) syntax (letrec* bindings body)

    bindings ⟹ ((variable1 init1) ...)

    The <variable>s are bound to fresh locations, each <variable> is assigned in left-to-right order to the result of evaluating the corresponding <init>, the <body> is evaluated in the resulting environment, and the values of the last expression in <body> are returned. Despite the left-to-right evaluation and assignment order, each binding of a <variable> has the entire letrec* expression as its region, making it possible to define mutually recursive procedures.

    (rnrs base (6)) syntax (letrec-syntax bindings form ...)

    bindings ⟹ ((keyword transformer-spec) ...)

    The <form>s of a letrec-syntax form are treated, whether in definition or expression context, as if wrapped in an implicit begin; see section 11.4.7. Thus definitions in the result of expanding the <form>s have the same region as any definition appearing in place of the letrec-syntax form would have.

    Implementation responsibilities: The implementation should detect if the value of <expression> cannot possibly be a transformer.

    (rnrs base (6)) procedure (list obj ...) ⟹ list?

    Returns a newly allocated list of its arguments.

    (rnrs base (6)) procedure (list->string (list list?)) ⟹ string?

    list ⟹ (list char?)

    The list->string procedure returns a newly allocated string formed from the characters in list.

    (rnrs base (6)) procedure (list->vector (list list?)) ⟹ vector?

    The list->vector procedure returns a newly created vector initialized to the elements of the list list.

    (rnrs base (6)) procedure (list-ref (list list?) (k integer?)) ⟹ *

    List must be a list whose length is at least k + 1. The list-tail procedure returns the kth element of list.

    (rnrs base (6)) procedure (list-tail (list list?) (k integer?)) ⟹ list?

    List should be a list of size at least k. The list-tail procedure returns the subchain of pairs of list obtained by omitting the first k elements.

    (rnrs base (6)) procedure (list? obj) ⟹ boolean?

    Returns #t if obj is a list, #f otherwise. By definition, all lists are chains of pairs that have finite length and are terminated by the empty list.

    (rnrs base (6)) procedure (make-string (k integer?)) ⟹ string?

    (rnrs base (6)) procedure (make-string (k integer?) (char char?)) ⟹ string?

    Returns a newly allocated string of length k. If char is given, then all elements of the string are initialized to char, otherwise the contents of the string are unspecified.

    (rnrs base (6)) procedure (make-vector (k integer?)) ⟹ vector?

    (rnrs base (6)) procedure (make-vector (k integer?) fill) ⟹ vector?

    Returns a newly allocated vector of k elements. If a second argument is given, then each element is initialized to fill. Otherwise the initial contents of each element is unspecified.

    (rnrs base (6)) procedure (map (proc procedure?) (list1 list?) (list2 list?) ...) ⟹ list?

    (proc obj1 obj2 ...) ⟹ *

    The lists should all have the same length. Proc should accept as many arguments as there are lists and return a single value. Proc should not mutate any of the lists.

    The map procedure applies proc element-wise to the elements of the lists and returns a list of the results, in order. Proc is always called in the same dynamic environment as map itself. The order in which proc is applied to the elements of the lists is unspecified. If multiple returns occur from map, the values returned by earlier returns are not mutated.

    (rnrs base (6)) procedure (max (x1 real?) (x2 real?) ...) ⟹ real?

    Returns the maximum of its arguments.

    (rnrs base (6)) procedure (min (x1 real?) (x2 real?) ...) ⟹ real?

    Returns the minimum of its arguments.

    (rnrs base (6)) procedure (mod (x1 real?) (x2 real?)) ⟹ real?

    Number-theoretic integer division and return the results of the corresponding mathematical operations specified in section 11.7.3.1. x1 must be neither infinite nor a NaN, and x2 must be nonzero; otherwise, an exception with condition type &assertion is raised.

    (rnrs base (6)) procedure (mod0 (x1 real?) (x2 real?)) ⟹ real?

    Number-theoretic integer division and return the results of the corresponding mathematical operations specified in section 11.7.3.1. x1 must be neither infinite nor a NaN, and x2 must be nonzero; otherwise, an exception with condition type &assertion is raised.

    (rnrs base (6)) procedure (not obj) ⟹ boolean?

    Returns #t if obj is #f, and returns #f otherwise.

    (rnrs base (6)) procedure (null? obj) ⟹ boolean?

    Returns #t if obj is the empty list, #f otherwise.

    (rnrs base (6)) procedure (number->string (z number?)) ⟹ string?

    (rnrs base (6)) procedure (number->string (z number?) (radix integer?)) ⟹ string?

    (rnrs base (6)) procedure (number->string (z number?) (radix integer?) (precision integer?)) ⟹ string?

    Radix must be an exact integer object, either 2, 8, 10, or 16. If omitted, radix defaults to 10. If a precision is specified, then z must be an inexact complex number object, precision must be an exact positive integer object, and radix must be 10. The number->string procedure takes a number object and a radix and returns as a string an external representation of the given number object in the given radix such that

    (let ((number z) (radix radix)) (eqv? (string->number (number->string number radix) radix) number))

    is true. If no possible result makes this expression true, an exception with condition type &implementation-restriction is raised.

    Note:‌ The error case can occur only when z is not a complex number object or is a complex number object with a non-rational real or imaginary part.

    If a precision is specified, then the representations of the inexact real components of the result, unless they are infinite or NaN, specify an explicit <mantissa width> p, and p is the least p ≥ precision for which the above expression is true.

    If z is inexact, the radix is 10, and the above expression and condition can be satisfied by a result that contains a decimal point, then the result contains a decimal point and is expressed using the minimum number of digits (exclusive of exponent, trailing zeroes, and mantissa width) needed to make the above expression and condition true [4, 7]; otherwise the format of the result is unspecified.

    The result returned by number->string never contains an explicit radix prefix.

    (rnrs base (6)) procedure (pair? obj) ⟹ boolean?

    Returns #t if obj is a pair, and otherwise returns #f.

    (rnrs base (6)) procedure (procedure? obj) ⟹ boolean?

    Returns #t if obj is a procedure, otherwise returns #f.

    (rnrs base (6)) syntax (quasiquote qq-template)

    “Backquote” or “quasiquote”expressions are useful for constructing a list or vector structure when some but not all of the desired structure is known in advance.

    Syntax: <Qq template> should be as specified by the grammar at the end of this entry.

    Semantics: If no unquote or unquote-splicing forms appear within the <qq template>, the result of evaluating (quasiquote <qq template>) is equivalent to the result of evaluating (quote <qq template>).

    If an (unquote <expression> ...) form appears inside a <qq template>, however, the <expression>s are evaluated (“unquoted”) and their results are inserted into the structure instead of the unquote form.

    If an (unquote-splicing <expression> ...) form appears inside a <qq template>, then the <expression>s must evaluate to lists; the opening and closing parentheses of the lists are then “stripped away” and the elements of the lists are inserted in place of the unquote-splicing form.

    Any unquote-splicing or multi-operand unquote form must appear only within a list or vector <qq template>.

    As noted in section 4.3.5, (quasiquote <qq template>) may be abbreviated `<qq template>, (unquote <expression>) may be abbreviated ,<expression>, and (unquote-splicing <expression>) may be abbreviated ,@<expression>.

    Quasiquote forms may be nested. Substitutions are made only for unquoted components appearing at the same nesting level as the outermost quasiquote. The nesting level increases by one inside each successive quasiquotation, and decreases by one inside each unquotation.

    A quasiquote expression may return either fresh, mutable objects or literal structure for any structure that is constructed at run time during the evaluation of the expression. Portions that do not need to be rebuilt are always literal. Thus,

    (let ((a 3)) `((1 2) ,a ,4 ,'five 6))

    may be equivalent to either of the following expressions:

    '((1 2) 3 4 five 6)

    (let ((a 3)) 

      (cons '(1 2)

            (cons a (cons 4 (cons 'five '(6))))))

    However, it is not equivalent to this expression:

    (let ((a 3)) (list (list 1 2) a 4 'five 6))

    It is a syntax violation if any of the identifiers quasiquote, unquote, or unquote-splicing appear in positions within a <qq template> otherwise than as described above.

    In <quasiquotation>s, a <list qq template D> can sometimes be confused with either an <unquotation D> or a <splicing unquotation D>. The interpretation as an <unquotation> or <splicing unquotation D> takes precedence.

    (rnrs base (6)) syntax (quote datum)

    (quote <datum>) evaluates to the datum value represented by <datum> (see section 4.3). This notation is used to include constants. As noted in section 4.3.5, (quote <datum>) may be abbreviated as '<datum>. As noted in section 5.10, constants are immutable.

    Note:‌ Different constants that are the value of a quote expression may share the same locations.

    (rnrs base (6)) procedure (rational-valued? obj) ⟹ boolean?

    Return #t if the object is a number object and is equal in the sense of = to some rational number.

    (rnrs base (6)) procedure (rationalize (x1 real?) (x2 real?)) ⟹ rational?

    The rationalize procedure returns the a number object representing the simplest rational number differing from x1 by no more than x2. A rational number r1 is simpler than another rational number r2 if r1 = p1/q1 and r2 = p2/q2 (in lowest terms) and |p1| ≤ |p2| and |q1| ≤ |q2|. Thus 3/5 is simpler than 4/7. Although not all rationals are comparable in this ordering (consider 2/7 and 3/5) any interval contains a rational number that is simpler than every other rational number in that interval (the simpler 2/5 lies between 2/7 and 3/5). Note that 0 = 0/1 is the simplest rational of all.

    (rnrs base (6)) procedure (real-valued? obj) ⟹ boolean?

    The real-valued? procedure returns #t if the object is a number object and is equal in the sense of = to some real number object, or if the object is a NaN, or a complex number object whose real part is a NaN and whose imaginary part is zero in the sense of zero?.

    (rnrs base (6)) procedure (reverse (list list?)) ⟹ list?

    Returns a newly allocated list consisting of the elements of list in reverse order.

    (rnrs base (6)) procedure (round (x real?)) ⟹ integer?

    The round procedure returns the closest integer object to x, rounding to even when x represents a number halfway between two integers.

    (rnrs base (6)) syntax (set! variable expression)

    <Expression> is evaluated, and the resulting value is stored in the location to which <variable> is bound. <Variable> must be bound either in some regionenclosing the set! expression or at the top level. The result of the set! expression is unspecified.

    It is a syntax violation if <variable> refers to an immutable binding.

    (rnrs base (6)) procedure (sqrt (z number?)) ⟹ number?

    Returns the principal square root of z. For rational z, the result has either positive real part, or zero real part and non-negative imaginary part. With log defined as in section 11.7.3.2, the value of (sqrt z) could be expressed as e^(log z/2).

    The sqrt procedure may return an inexact result even when given an exact argument.

    (rnrs base (6)) procedure (string (char char?) ...) ⟹ string?

    Returns a newly allocated string composed of the arguments.

    (rnrs base (6)) procedure (string->list (string string?)) ⟹ list?

    The string->list procedure returns a newly allocated list of the characters that make up the given string.

    (rnrs base (6)) procedure (string->number (string string?)) ⟹ number?

    (rnrs base (6)) procedure (string->number (string string?) (radix integer?)) ⟹ number?

    Returns a number object with maximally precise representation expressed by the given string. Radix must be an exact integer object, either 2, 8, 10, or 16. If supplied, radix is a default radix that may be overridden by an explicit radix prefix in string (e.g., "#o177"). If radix is not supplied, then the default radix is 10. If string is not a syntactically valid notation for a number object or a notation for a rational number object with a zero denominator, then string->number returns #f.

    (rnrs base (6)) procedure (string->symbol (string string?)) ⟹ symbol?

    Returns the symbol whose name is string.

    (rnrs base (6)) procedure (string-append (string string?) ...) ⟹ string?

    Returns a newly allocated string whose characters form the concatenation of the given strings.

    (rnrs base (6)) procedure (string-copy (string string?)) ⟹ string?

    Returns a newly allocated copy of the given string.

    (rnrs base (6)) procedure (string-for-each (proc procedure?) (string1 string?) (string2 string?) ...) ⟹ undefined

    (proc (string string?) ...) ⟹ undefined

    The strings must all have the same length. Proc should accept as many arguments as there are strings. The string-for-each procedure applies proc element-wise to the characters of the strings for its side effects, in order from the first characters to the last. Proc is always called in the same dynamic environment as string-for-each itself. The return values of string-for-each are unspecified.

    Analogous to for-each.

    Implementation responsibilities: The implementation must check the restrictions on proc to the extent performed by applying it as described. An implementation may check whether proc is an appropriate argument before applying it.

    (rnrs base (6)) procedure (string-length (string string?)) ⟹ integer?

    Returns the number of characters in the given string as an exact integer object.

    (rnrs base (6)) procedure (string-ref (string string?) (k integer?)) ⟹ char?

    K must be a valid index of string. The string-ref procedure returns character

    k of string using zero-origin indexing.

    Note:‌ Implementors should make string-ref run in constant time.

    (rnrs base (6)) procedure (string<=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    Lexicographic extension to strings of the corresponding orderings on characters. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string.

    (rnrs base (6)) procedure (string<? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    Lexicographic extension to strings of the corresponding orderings on characters. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string.

    (rnrs base (6)) procedure (string=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    Returns #t if the strings are the same length and contain the same characters in the same positions. Otherwise, the string=? procedure returns #f.

    (rnrs base (6)) procedure (string>=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    Lexicographic extension to strings of the corresponding orderings on characters. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string.

    (rnrs base (6)) procedure (string>? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    Lexicographic extension to strings of the corresponding orderings on characters. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string.

    (rnrs base (6)) procedure (string? obj) ⟹ boolean?

    Returns #t if obj is a string, otherwise returns #f.

    (rnrs base (6)) procedure (substring (string string?) (start integer?) (end integer?)) ⟹ string?

    String must be a string, and start and end must be exact integer objects satisfying

    0 ≤ start ≤ end ≤ (string-length string).

    The substring procedure returns a newly allocated string formed from the characters of string beginning with index start (inclusive) and ending with index end (exclusive).

    (rnrs base (6)) procedure (symbol->string (symbol symbol?)) ⟹ string?

    Returns the name of symbol as an immutable string.

    (rnrs base (6)) procedure (symbol=? (symbol1 symbol?) (symbol2 symbol?) (symbol3 symbol?) ...) ⟹ boolean?

    Returns #t if the symbols are the same, i.e., if their names are spelled the same.

    (rnrs base (6)) procedure (symbol? obj) ⟹ boolean?

    Returns #t if obj is a symbol, otherwise returns #f.

    (rnrs base (6)) syntax (syntax-rules (literal ...) syntax-rule ...)⟹ return

    syntax-rule ⟹ (pattern template)

    pattern ⟹ _ | identifier | constant | (pattern ...) | (pattern pattern ... . pattern) | (pattern ... pattern ellipsis pattern ...) | (pattern ... pattern ellipsis pattern ... . pattern) | #(pattern ...) | #(pattern ... pattern ellipsis pattern ...)

    template ⟹ identifier | constant | (element ...) | (element element ... . template) | (ellipsis template) | #(element ...)

    element ⟹ template | template ellipsis

    Semantics: An instance of syntax-rules evaluates, at macro-expansion time, to a new macro transformer by specifying a sequence of hygienic rewrite rules. A use of a macro whose keyword is associated with a transformer specified by syntax-rules is matched against the patterns contained in the <syntax rule>s, beginning with the leftmost <syntax rule>. When a match is found, the macro use is transcribed hygienically according to the template. It is a syntax violation when no match is found.

    An identifier appearing within a <pattern> may be an underscore ( _ ), a literal identifier listed in the list of literals (<literal> ...), or an ellipsis ( ... ). All other identifiers appearing within a <pattern> are pattern variables. It is a syntax violation if an ellipsis or underscore appears in (<literal> ...).

    While the first subform of <srpattern> may be an identifier, the identifier is not involved in the matching and is not considered a pattern variable or literal identifier.

    Pattern variables match arbitrary input subforms and are used to refer to elements of the input. It is a syntax violation if the same pattern variable appears more than once in a <pattern>.

    Underscores also match arbitrary input subforms but are not pattern variables and so cannot be used to refer to those elements. Multiple underscores may appear in a <pattern>.

    A literal identifier matches an input subform if and only if the input subform is an identifier and either both its occurrence in the input expression and its occurrence in the list of literals have the same lexical binding, or the two identifiers have the same name and both have no lexical binding.

    A subpattern followed by an ellipsis can match zero or more elements of the input.

    More formally, an input form F matches a pattern P if and only if one of the following holds:

  • P is an underscore ( _ ).
  • P is a pattern variable.
  • P is a literal identifier and F is an identifier such that both P and F would refer to the same binding if both were to appear in the output of the macro outside of any bindings inserted into the output of the macro. (If neither of two like-named identifiers refers to any binding, i.e., both are undefined, they are considered to refer to the same binding.)
  • P is of the form (P1 ... Pn) and F is a list of n elements that match P1 through Pn.
  • P is of the form (P1 ... Pn . Px) and F is a list or improper list of n or more elements whose first n elements match P1 through Pn and whose nth cdr matches Px.
  • P is of the form (P1 ... Pk Pe <ellipsis> Pm+1 ... Pn), where <ellipsis> is the identifier ... and F is a list of n elements whose first k elements match P1 through Pk, whose next m−k elements each match Pe, and whose remaining n−m elements match Pm+1 through Pn.
  • P is of the form (P1 ... Pk Pe <ellipsis> Pm+1 ... Pn . Px), where <ellipsis> is the identifier ... and F is a list or improper list of n elements whose first k elements match P1 through Pk, whose next m−k elements each match Pe, whose next n−m elements match Pm+1 through Pn, and whose nth and final cdr matches Px.
  • P is of the form #(P1 ... Pn) and F is a vector of n elements that match P1 through Pn.
  • P is of the form #(P1 ... Pk Pe <ellipsis> Pm+1 ... Pn), where <ellipsis> is the identifier ... and F is a vector of n or more elements whose first k elements match P1 through Pk, whose next m−k elements each match Pe, and whose remaining n−m elements match Pm+1 through Pn.
  • P is a pattern datum (any nonlist, nonvector, nonsymbol datum) and F is equal to P in the sense of the equal? procedure.
  • When a macro use is transcribed according to the template of the matching <syntax rule>, pattern variables that occur in the template are replaced by the subforms they match in the input.

    Pattern data and identifiers that are not pattern variables or ellipses are copied into the output. A subtemplate followed by an ellipsis expands into zero or more occurrences of the subtemplate. Pattern variables that occur in subpatterns followed by one or more ellipses may occur only in subtemplates that are followed by (at least) as many ellipses. These pattern variables are replaced in the output by the input subforms to which they are bound, distributed as specified. If a pattern variable is followed by more ellipses in the subtemplate than in the associated subpattern, the input form is replicated as necessary. The subtemplate must contain at least one pattern variable from a subpattern followed by an ellipsis, and for at least one such pattern variable, the subtemplate must be followed by exactly as many ellipses as the subpattern in which the pattern variable appears. (Otherwise, the expander would not be able to determine how many times the subform should be repeated in the output.) It is a syntax violation if the constraints of this paragraph are not met.

    A template of the form (<ellipsis> <template>) is identical to <template>, except that ellipses within the template have no special meaning. That is, any ellipses contained within <template> are treated as ordinary identifiers. In particular, the template (... ...) produces a single ellipsis, .... This allows syntactic abstractions to expand into forms containing ellipses.

    (rnrs base (6)) procedure (truncate (x real?)) ⟹ integer?

    The truncate procedure returns the integer object closest to x whose absolute value is not larger than the absolute value of x.

    (rnrs base (6)) syntax (unquote expression)

    “Backquote” or “quasiquote”expressions are useful for constructing a list or vector structure when some but not all of the desired structure is known in advance.

    Syntax: <Qq template> should be as specified by the grammar at the end of this entry.

    Semantics: If no unquote or unquote-splicing forms appear within the <qq template>, the result of evaluating (quasiquote <qq template>) is equivalent to the result of evaluating (quote <qq template>).

    If an (unquote <expression> ...) form appears inside a <qq template>, however, the <expression>s are evaluated (“unquoted”) and their results are inserted into the structure instead of the unquote form.

    If an (unquote-splicing <expression> ...) form appears inside a <qq template>, then the <expression>s must evaluate to lists; the opening and closing parentheses of the lists are then “stripped away” and the elements of the lists are inserted in place of the unquote-splicing form.

    Any unquote-splicing or multi-operand unquote form must appear only within a list or vector <qq template>.

    As noted in section 4.3.5, (quasiquote <qq template>) may be abbreviated `<qq template>, (unquote <expression>) may be abbreviated ,<expression>, and (unquote-splicing <expression>) may be abbreviated ,@<expression>.

    Quasiquote forms may be nested. Substitutions are made only for unquoted components appearing at the same nesting level as the outermost quasiquote. The nesting level increases by one inside each successive quasiquotation, and decreases by one inside each unquotation.

    A quasiquote expression may return either fresh, mutable objects or literal structure for any structure that is constructed at run time during the evaluation of the expression. Portions that do not need to be rebuilt are always literal. Thus,

    (let ((a 3)) `((1 2) ,a ,4 ,'five 6))

    may be equivalent to either of the following expressions:

    '((1 2) 3 4 five 6)

    (let ((a 3)) 

      (cons '(1 2)

            (cons a (cons 4 (cons 'five '(6))))))

    However, it is not equivalent to this expression:

    (let ((a 3)) (list (list 1 2) a 4 'five 6))

    It is a syntax violation if any of the identifiers quasiquote, unquote, or unquote-splicing appear in positions within a <qq template> otherwise than as described above.

    In <quasiquotation>s, a <list qq template D> can sometimes be confused with either an <unquotation D> or a <splicing unquotation D>. The interpretation as an <unquotation> or <splicing unquotation D> takes precedence.

    (rnrs base (6)) syntax (unquote-splicing expression)

    “Backquote” or “quasiquote”expressions are useful for constructing a list or vector structure when some but not all of the desired structure is known in advance.

    Syntax: <Qq template> should be as specified by the grammar at the end of this entry.

    Semantics: If no unquote or unquote-splicing forms appear within the <qq template>, the result of evaluating (quasiquote <qq template>) is equivalent to the result of evaluating (quote <qq template>).

    If an (unquote <expression> ...) form appears inside a <qq template>, however, the <expression>s are evaluated (“unquoted”) and their results are inserted into the structure instead of the unquote form.

    If an (unquote-splicing <expression> ...) form appears inside a <qq template>, then the <expression>s must evaluate to lists; the opening and closing parentheses of the lists are then “stripped away” and the elements of the lists are inserted in place of the unquote-splicing form.

    Any unquote-splicing or multi-operand unquote form must appear only within a list or vector <qq template>.

    As noted in section 4.3.5, (quasiquote <qq template>) may be abbreviated `<qq template>, (unquote <expression>) may be abbreviated ,<expression>, and (unquote-splicing <expression>) may be abbreviated ,@<expression>.

    Quasiquote forms may be nested. Substitutions are made only for unquoted components appearing at the same nesting level as the outermost quasiquote. The nesting level increases by one inside each successive quasiquotation, and decreases by one inside each unquotation.

    A quasiquote expression may return either fresh, mutable objects or literal structure for any structure that is constructed at run time during the evaluation of the expression. Portions that do not need to be rebuilt are always literal. Thus,

    (let ((a 3)) `((1 2) ,a ,4 ,'five 6))

    may be equivalent to either of the following expressions:

    '((1 2) 3 4 five 6)

    (let ((a 3)) 

      (cons '(1 2)

            (cons a (cons 4 (cons 'five '(6))))))

    However, it is not equivalent to this expression:

    (let ((a 3)) (list (list 1 2) a 4 'five 6))

    It is a syntax violation if any of the identifiers quasiquote, unquote, or unquote-splicing appear in positions within a <qq template> otherwise than as described above.

    In <quasiquotation>s, a <list qq template D> can sometimes be confused with either an <unquotation D> or a <splicing unquotation D>. The interpretation as an <unquotation> or <splicing unquotation D> takes precedence.

    (rnrs base (6)) procedure (values obj ...) ⟹ (values * ...)

    Delivers all of its arguments to its continuation. The continuations of all non-final expressions within a sequence of expressions, such as in lambda, begin, let, let*, letrec, letrec*, let-values, let*-values, case, and cond forms, usually take an arbitrary number of values. Except for these and the continuations created by call-with-values, let-values, and let*-values, continuations implicitly accepting a single value, such as the continuations of <operator> and <operand>s of procedure calls or the <test> expressions in conditionals, take exactly one value. The effect of passing an inappropriate number of values to such a continuation is undefined.

    (rnrs base (6)) procedure (vector obj ...) ⟹ vector?

    Returns a newly allocated vector whose elements contain the given arguments. Analogous to list.

    (rnrs base (6)) procedure (vector->list (vector vector?)) ⟹ list?

    The vector->list procedure returns a newly allocated list of the objects contained in the elements of vector.

    (rnrs base (6)) procedure (vector-fill! (vector vector?) fill) ⟹ undefined

    Stores fill in every element of vector and returns unspecified values.

    (rnrs base (6)) procedure (vector-for-each (proc procedure?) (vector1 vector?) (vector2 vector?) ...) ⟹ undefined

    (proc obj ...) ⟹ undefined

    The vectors must all have the same length. Proc should accept as many arguments as there are vectors. The vector-for-each procedure applies proc element-wise to the elements of the vectors for its side effects, in order from the first elements to the last. Proc is always called in the same dynamic environment as vector-for-each itself. The return values of vector-for-each are unspecified.

    Analogous to for-each.

    Implementation responsibilities: The implementation must check the restrictions on proc to the extent performed by applying it as described. An implementation may check whether proc is an appropriate argument before applying it.

    (rnrs base (6)) procedure (vector-length (vector vector?)) ⟹ integer?

    Returns the number of elements in vector as an exact integer object.

    (rnrs base (6)) procedure (vector-map (proc procedure?) (vector1 vector?) (vector2 vector?) ...) ⟹ vector?

    (proc obj ...) ⟹ *

    The vectors must all have the same length. Proc should accept as many arguments as there are vectors and return a single value.

    The vector-map procedure applies proc element-wise to the elements of the vectors and returns a vector of the results, in order. Proc is always called in the same dynamic environment as vector-map itself. The order in which proc is applied to the elements of the vectors is unspecified. If multiple returns occur from vector-map, the return values returned by earlier returns are not mutated.

    Analogous to map.

    Implementation responsibilities: The implementation must check the restrictions on proc to the extent performed by applying it as described. An implementation may check whether proc is an appropriate argument before applying it.

    (rnrs base (6)) procedure (vector-ref (vector vector?) (k integer?)) ⟹ *

    K must be a valid index of vector. The vector-ref procedure returns the contents of element k of vector.

    (rnrs base (6)) procedure (vector-set! (vector vector?) (k integer?) obj) ⟹ undefined

    K must be a valid index of vector. The vector-set! procedure stores obj in element k of vector, and returns unspecified values. Passing an immutable vector to vector-set! should cause an exception with condition type &assertion to be raised.

    (rnrs base (6)) procedure (vector? obj) ⟹ boolean?

    Returns #t if obj is a vector. Otherwise the procedure returns #f.

    (rnrs base (6)) procedure (complex? obj) ⟹ boolean?

    (rnrs base (6)) procedure (number? obj) ⟹ boolean?

    (rnrs base (6)) procedure (real? obj) ⟹ boolean?

    (rnrs base (6)) procedure (rational? obj) ⟹ boolean?

    (rnrs base (6)) procedure (integer? obj) ⟹ boolean?

    These numerical type predicates can be applied to any kind of argument. They return #t if the object is a number object of the named type, and #f otherwise. In general, if a type predicate is true of a number object then all higher type predicates are also true of that number object. Consequently, if a type predicate is false of a number object, then all lower type predicates are also false of that number object.

    If z is a complex number object, then (real? z ) is true if and only if (zero? (imag-part z )) and (exact? (imag-part z )) are both true.

    If x is a real number object, then (rational? x ) is true if and only if there exist exact integer objects k1 and k2 such that (= x (/ k1 k2)) and (= (numerator x ) k1) and (= (denominator x ) k2) are all true. Thus infinities and NaNs are not rational number objects.

    If q is a rational number objects, then (integer? q) is true if and only if (= (denominator q) 1) is true. If q is not a rational number object, then (integer? q) is #f.

    (rnrs base (6)) procedure (zero? (z number?)) ⟹ boolean?

    (rnrs base (6)) procedure (positive? (x real?)) ⟹ boolean?

    (rnrs base (6)) procedure (negative? (x real?)) ⟹ boolean?

    (rnrs base (6)) procedure (odd? (n integer?)) ⟹ boolean?

    (rnrs base (6)) procedure (even? (n integer?)) ⟹ boolean?

    (rnrs base (6)) procedure (finite? (z number?)) ⟹ boolean?

    (rnrs base (6)) procedure (infinite? (z number?)) ⟹ boolean?

    (rnrs base (6)) procedure (nan? (z number?)) ⟹ boolean?

    These numerical predicates test a number object for a particular property, returning #t or #f. The zero? procedure tests if the number object is = to zero, positive? tests whether it is greater than zero, negative? tests whether it is less than zero, odd? tests whether it is odd, even? tests whether it is even, finite? tests whether it is not an infinity and not a NaN, infinite? tests whether it is an infinity, nan? tests whether it is a NaN.

    (rnrs base (6)) procedure (exp (z number?)) ⟹ number?

    (rnrs base (6)) procedure (log (z number?)) ⟹ number?

    (rnrs base (6)) procedure (log (z1 number?) (z2 number?)) ⟹ number?

    (rnrs base (6)) procedure (sin (z number?)) ⟹ number?

    (rnrs base (6)) procedure (cos (z number?)) ⟹ number?

    (rnrs base (6)) procedure (tan (z number?)) ⟹ number?

    (rnrs base (6)) procedure (asin (z number?)) ⟹ number?

    (rnrs base (6)) procedure (acos (z number?)) ⟹ number?

    (rnrs base (6)) procedure (atan (z number?)) ⟹ number?

    (rnrs base (6)) procedure (atan (x1 real?) (x2 real?)) ⟹ number?

    These procedures compute the usual transcendental functions. The exp procedure computes the base-e exponential of z . The log procedure with a single argument computes the natural logarithm of z (not the base-ten logarithm); (log z1 z2) computes the base-z2 logarithm of z1. The asin, acos, and atan procedures compute arcsine, arccosine, and arctangent, respectively. The two-argument variant of atan computes (angle (make-rectangular x2 x1)). These procedures may return inexact results even when given exact arguments.

    (rnrs base (6)) procedure (numerator (q rational?)) ⟹ integer?

    (rnrs base (6)) procedure (denominator (q rational?)) ⟹ integer?

    These procedures return the numerator or denominator of their argument; the result is computed as if the argument was represented as a fraction in lowest terms. The denominator is always positive. The denominator of 0 is defined to be 1.

    (rnrs base (6)) procedure (make-polar (x3 real?) (x4 real?)) ⟹ complex?

    (rnrs base (6)) procedure (make-rectangular (x1 real?) (x2 real?)) ⟹ complex?

    (rnrs base (6)) procedure (real-part (z complex?)) ⟹ real?

    (rnrs base (6)) procedure (imag-part (z complex?)) ⟹ real?

    (rnrs base (6)) procedure (magnitude (z complex?)) ⟹ real?

    (rnrs base (6)) procedure (angle (z complex?)) ⟹ real?

    Suppose a1, a2, a3, and a4 are real numbers, and c is a complex number such that the following holds:

    c = a1 + a2*i = a3*e^(i*a4)

    Then, if x1, x2, x3, and x4 are number objects representing a1, a2, a3, and a4, respectively, (make-rectangular x1 x2) returns c, and (make-polar x3 x4) returns c.

    Conversely, if −pi <= a4 <= pi, and if z is a number object representing c, then (real-part z ) returns a1 (imag-part z ) returns a2, (magnitude z ) returns a3, and (angle z ) returns a4.

    Moreover, suppose x1, x2 are such that either x1 or x2 is an infinity, then

    (make-rectangular x1 x2) => z

    (magnitude z ) => +inf.0

    The make-polar, magnitude, and angle procedures may return inexact results even when given exact arguments.

    library (rnrs arithmetic bitwise (6))

    (rnrs arithmetic bitwise (6)) procedure (bitwise-not (ei integer?)) ⟹ integer?

    Returns the exact integer object whose two's complement representation is the one's complement of the two's complement representation of ei.

    (rnrs arithmetic bitwise (6)) procedure (bitwise-and (i integer?) ...) ⟹ integer?

    This procedure returns the exact integer object that is the bit-wise "and" of the two's complement representations of its arguments. If it is passed only one argument, it returns that argument. If it is passed no arguments, it returns -1 that acts as identity for the operation.

    (rnrs arithmetic bitwise (6)) procedure (bitwise-ior (i integer?) ...) ⟹ integer?

    This procedure returns the exact integer object that is the bit-wise "inclusive-or" of the two's complement representations of its arguments. If it is passed only one argument, it returns that argument. If it is passed no arguments, it returns 0 that acts as identity for the operation.

    (rnrs arithmetic bitwise (6)) procedure (bitwise-xor (i integer?) ...) ⟹ integer?

    This procedure returns the exact integer object that is the bit-wise "exclusive-or" of the two's complement representations of its arguments. If it is passed only one argument, it returns that argument. If it is passed no arguments, it returns 0 that acts as identity for the operation.

    (rnrs arithmetic bitwise (6)) procedure (bitwise-if (ei1 integer?) (ei2 integer?) (ei3 integer?)) ⟹ integer?

    Returns the exact integer object that is the bit-wise "if" of the two's complement representations of its arguments, i.e. for each bit, if it is 1 in ei1, the corresponding bit in ei2 becomes the value of the corresponding bit in the result, and if it is 0, the corresponding bit in ei3 becomes the corresponding bit in the value of the result. This is the result of the following computation:

    (bitwise-ior (bitwise-and ei1 ei2) (bitwise-and (bitwise-not ei1) ei3))

    (rnrs arithmetic bitwise (6)) procedure (bitwise-bit-count (ei integer?)) ⟹ integer?

    If ei is non-negative, this procedure returns the number of 1 bits in the two's complement representation of ei. Otherwise it returns the result of the following computation:

    (bitwise-not (bitwise-bit-count (bitwise-not ei)))

    (rnrs arithmetic bitwise (6)) procedure (bitwise-length (ei integer?)) ⟹ integer?

    Returns the number of bits needed to represent ei if it is positive, and the number of bits needed to represent (bitwise-not ei) if it is negative.

    (rnrs arithmetic bitwise (6)) procedure (bitwise-first-bit-set (ei integer?)) ⟹ integer?

    Returns the index of the least significant 1 bit in the two's complement representation of ei. If ei is 0, then −1 is returned.

    (rnrs arithmetic bitwise (6)) procedure (bitwise-bit-set? (ei1 integer?) (ei2 integer?)) ⟹ boolean?

    Ei2 must be non-negative. The bitwise-bit-set? procedure returns #t if the ei2th bit is 1 in the two's complement representation of ei1, and #f otherwise.

    (rnrs arithmetic bitwise (6)) procedure (bitwise-copy-bit (ei1 integer?) (ei2 integer?) (ei3 integer?)) ⟹ integer?

    Ei2 must be non-negative, and ei3 must be either 0 or 1. The bitwise-copy-bit procedure returns the result of replacing the ei2th bit of ei1 by the ei2th bit of ei3

    (rnrs arithmetic bitwise (6)) procedure (bitwise-bit-field (ei1 integer?) (ei2 integer?) (ei3 integer?)) ⟹ integer?

    Ei2 and ei3 must be non-negative, and ei2 must be less than or equal to ei3. The bitwise-bit-field procedure returns the number represented by the bits at the positions from ei2 (inclusive) to ei3 (exclusive)

    (rnrs arithmetic bitwise (6)) procedure (bitwise-copy-bit-field (ei1 integer?) (ei2 integer?) (ei3 integer?) (ei4 integer?)) ⟹ integer?

    Ei2 and ei3 must be non-negative, and ei2 must be less than or equal to ei3. The bitwise-copy-bit-field procedure returns the result of replacing in ei1 the bits at positions from ei2 (inclusive) to ei3 (exclusive) by the corresponding bits in ei4

    (rnrs arithmetic bitwise (6)) procedure (bitwise-arithmetic-shift (ei1 integer?) (ei2 integer?)) ⟹ integer?

    Returns the result of the following computation:

    (floor (* ei1 (expt 2 ei2)))

    (rnrs arithmetic bitwise (6)) procedure (bitwise-arithmetic-shift-left (ei1 integer?) (ei2 integer?)) ⟹ integer?

    Ei2 must be non-negative. The bitwise-arithmetic-shift-left procedure returns the same result as bitwise-arithmetic-shift

    (rnrs arithmetic bitwise (6)) procedure (bitwise-arithmetic-shift-right (ei1 integer?) (ei2 integer?)) ⟹ integer?

    Ei2 must be non-negative. The bitwise-arithmetic-shift-left procedure returns the same result as (bitwise-arithmetic-shift ei1 (- ei2))

    (rnrs arithmetic bitwise (6)) procedure (bitwise-rotate-bit-field (ei1 integer?) (ei2 integer?) (ei3 integer?) (ei4 integer?)) ⟹ integer?

    Ei2, ei3, ei4 must be non-negative, ei2 must be less than or equal to ei3, and ei4 must be non-negative. procedure returns the result of cyclically permuting in ei1 the bits at positions from ei2 (inclusive) to ei3 (exclusive) by ei4 bits towards the more significant bits

    (rnrs arithmetic bitwise (6)) procedure (bitwise-reverse-bit-field (ei1 integer?) (ei2 integer?) (ei3 integer?)) ⟹ integer?

    Ei2 and ei3 must be non-negative, and ei2 must be less than or equal to ei3. The bitwise-reverse-bit-field procedure returns the result obtained from ei1 by reversing the order of the bits at positions from ei2 (inclusive) to ei3 (exclusive).

    library (rnrs arithmetic fixnums (6))

    (rnrs arithmetic fixnums (6)) procedure (fixnum? obj) ⟹ boolean?

    Returns #t if obj is an exact integer object within the fixnum range, #f otherwise.

    (rnrs arithmetic fixnums (6)) procedure (fixnum-width) ⟹ fixnum?

    Fixnum type size in bits

    (rnrs arithmetic fixnums (6)) procedure (least-fixnum) ⟹ fixnum?

    Smallest fixnum value

    (rnrs arithmetic fixnums (6)) procedure (greatest-fixnum) ⟹ fixnum?

    Biggest fixnum value

    (rnrs arithmetic fixnums (6)) procedure (fx=? (i fixnum?) ...) ⟹ boolean?

    Return #t if arguments are equal, #f otherwise.

    (rnrs arithmetic fixnums (6)) procedure (fx<? (i fixnum?) ...) ⟹ boolean?

    Return #t if arguments are monotonically increasing, #f otherwise.

    (rnrs arithmetic fixnums (6)) procedure (fx>? (i fixnum?) ...) ⟹ boolean?

    Return #t if arguments are monotonically decreasing, #f otherwise.

    (rnrs arithmetic fixnums (6)) procedure (fx<=? (i fixnum?) ...) ⟹ boolean?

    Return #t if arguments are monotonically nondecreasing, #f otherwise.

    (rnrs arithmetic fixnums (6)) procedure (fx>=? (i fixnum?) ...) ⟹ boolean?

    Return #t if arguments are monotonically nonincreasing, #f otherwise.

    (rnrs arithmetic fixnums (6)) procedure (fxzero? (i fixnum?)) ⟹ boolean?

    Number equal to 0?

    (rnrs arithmetic fixnums (6)) procedure (fxpositive? (i fixnum?)) ⟹ boolean?

    Number greater than 0?

    (rnrs arithmetic fixnums (6)) procedure (fxnegative? (i fixnum?)) ⟹ boolean?

    Number less than 0?

    (rnrs arithmetic fixnums (6)) procedure (fxodd? (i fixnum?)) ⟹ boolean?

    Number is odd?

    (rnrs arithmetic fixnums (6)) procedure (fxeven? (i fixnum?)) ⟹ boolean?

    Number is even?

    (rnrs arithmetic fixnums (6)) procedure (fxmax (i fixnum?) (j fixnum?) ...) ⟹ fixnum?

    Return maximum of its arguments.

    (rnrs arithmetic fixnums (6)) procedure (fxmin (i fixnum?) (j fixnum?) ...) ⟹ fixnum?

    Return minimum of its arguments.

    (rnrs arithmetic fixnums (6)) procedure (fx+ (i fixnum?) (j fixnum?)) ⟹ fixnum?

    The procedure returns the sum of its arguments, provided that sum is a fixnum. An exception with condition type &implementation-restriction is raised if that sum is not a fixnum.

    (rnrs arithmetic fixnums (6)) procedure (fx* (i fixnum?) (j fixnum?)) ⟹ fixnum?

    The procedure returns the product of its arguments, provided that product is a fixnum. An exception with condition type &implementation-restriction is raised if that product is not a fixnum.

    (rnrs arithmetic fixnums (6)) procedure (fx- (i fixnum?) (j fixnum?)) ⟹ fixnum?

    (rnrs arithmetic fixnums (6)) procedure (fx- (i fixnum?)) ⟹ fixnum?

    With two arguments, this procedure returns the difference fx1−fx2, provided that difference is a fixnum. With one argument, this procedure returns the additive inverse of its argument, provided that integer object is a fixnum. An exception with condition type &assertion is raised if the mathematically correct result of this procedure is not a fixnum.

    (rnrs arithmetic fixnums (6)) procedure (fxdiv (x1 fixnum?) (x2 fixnum?)) ⟹ fixnum?

    Procedure implements number-theoretic integer division and returns the result of the mathematical operations specified in report section on “Integer division”.

    (rnrs arithmetic fixnums (6)) procedure (fxdiv0 (x1 fixnum?) (x2 fixnum?)) ⟹ fixnum?

    Procedure implements number-theoretic integer division and returns the result of the mathematical operations specified in report section on “Integer division”.

    (rnrs arithmetic fixnums (6)) procedure (fxdiv-and-mod (x1 fixnum?) (x2 fixnum?)) ⟹ (values fixnum? fixnum?)

    Procedure implements number-theoretic integer division and returns the result of the mathematical operations specified in report section on “Integer division”.

    (rnrs arithmetic fixnums (6)) procedure (fxdiv0-and-mod0 (x1 fixnum?) (x2 fixnum?)) ⟹ (values fixnum? fixnum?)

    Procedure implements number-theoretic integer division and returns the result of the mathematical operations specified in report section on “Integer division”.

    (rnrs arithmetic fixnums (6)) procedure (fxmod (x1 fixnum?) (x2 fixnum?)) ⟹ fixnum?

    Procedure implements number-theoretic integer division and returns the result of the mathematical operations specified in report section on “Integer division”.

    (rnrs arithmetic fixnums (6)) procedure (fxmod0 (x1 fixnum?) (x2 fixnum?)) ⟹ fixnum?

    Procedure implements number-theoretic integer division and returns the result of the mathematical operations specified in report section on “Integer division”.

    (rnrs arithmetic fixnums (6)) procedure (fx+/carry (i fixnum?) (j fixnum?) (k fixnum?)) ⟹ (values fixnum? fixnum?)

    Returns the two fixnum results of the following computation:

    (let* ((s (+ fx1 fx2 fx3))

    (s0 (mod0 s (expt 2 (fixnum-width))))

    (s1 (div0 s (expt 2 (fixnum-width)))))

    (values s0 s1))

    (rnrs arithmetic fixnums (6)) procedure (fx-/carry (i fixnum?) (j fixnum?) (k fixnum?)) ⟹ (values fixnum? fixnum?)

    Returns the two fixnum results of the following computation:

    (let* ((d (- fx1 fx2 fx3))

    (d0 (mod0 d (expt 2 (fixnum-width))))

    (d1 (div0 d (expt 2 (fixnum-width)))))

    (values d0 d1))

    (rnrs arithmetic fixnums (6)) procedure (fx*/carry (i fixnum?) (j fixnum?) (k fixnum?)) ⟹ (values fixnum? fixnum?)

    Returns the two fixnum results of the following computation:

    (let* ((s (+ (* fx1 fx2) fx3))

    (s0 (mod0 s (expt 2 (fixnum-width))))

    (s1 (div0 s (expt 2 (fixnum-width)))))

    (values s0 s1))

    (rnrs arithmetic fixnums (6)) procedure (fxnot (fx fixnum?)) ⟹ fixnum?

    Returns the unique fixnum that is congruent mod 2^w to the one's-complement of fx.

    (rnrs arithmetic fixnums (6)) procedure (fxand (i fixnum?) ...) ⟹ fixnum?

    Procedure returns the fixnum that is the bit-wise "and" of the two's complement representations of its arguments. If it is passed only one argument, it returns that argument. If it is passed no arguments, it returns -1 that acts as identity for the operation.

    (rnrs arithmetic fixnums (6)) procedure (fxior (i fixnum?) ...) ⟹ fixnum?

    Procedure returns the fixnum that is the bit-wise "inclusive or" of the two's complement representations of its arguments. If it is passed only one argument, it returns that argument. If it is passed no arguments, it returns 0 that acts as identity for the operation.

    (rnrs arithmetic fixnums (6)) procedure (fxxor (i fixnum?) ...) ⟹ fixnum?

    Procedure returns the fixnum that is the bit-wise "exclusive or" of the two's complement representations of its arguments. If it is passed only one argument, it returns that argument. If it is passed no arguments, it returns 0 that acts as identity for the operation.

    (rnrs arithmetic fixnums (6)) procedure (fxif (fx1 fixnum?) (fx2 fixnum?) (fx3 fixnum?)) ⟹ fixnum?

    Returns the fixnum that is the bit-wise "if" of the two's complement representations of its arguments, i.e. for each bit, if it is 1 in fx1, the corresponding bit in fx2 becomes the value of the corresponding bit in the result, and if it is 0, the corresponding bit in fx3 becomes the corresponding bit in the value of the result.

    (rnrs arithmetic fixnums (6)) procedure (fxbit-count (fx fixnum?)) ⟹ fixnum?

    If fx is non-negative, this procedure returns the number of 1 bits in the two's complement representation of fx. Otherwise it returns the result of the following computation:

    (fxnot (fxbit-count (fxnot ei)))

    (rnrs arithmetic fixnums (6)) procedure (fxlength (fx fixnum?)) ⟹ fixnum?

    Returns the number of bits needed to represent fx if it is positive, and the number of bits needed to represent (fxnot fx) if it is negative.

    (rnrs arithmetic fixnums (6)) procedure (fxfirst-bit-set (fx fixnum?)) ⟹ fixnum?

    Returns the index of the least significant 1 bit in the two's complement representation of fx. If fx is 0, then −1 is returned.

    (rnrs arithmetic fixnums (6)) procedure (fxbit-set? (fx1 fixnum?) (fx2 fixnum?)) ⟹ boolean?

    Fx2 must be non-negative and less than (fixnum-width). The fxbit-set? procedure returns #t if the fx2th bit is 1 in the two's complement representation of fx1, and #f otherwise.

    (rnrs arithmetic fixnums (6)) procedure (fxcopy-bit (fx1 fixnum?) (fx2 fixnum?) (fx3 fixnum?)) ⟹ fixnum?

    Fx2 must be non-negative and less than (fixnum-width). Fx3 must be 0 or 1. The fxcopy-bit procedure returns the result of replacing the fx2th bit of fx1 by fx3

    (rnrs arithmetic fixnums (6)) procedure (fxbit-field (fx1 fixnum?) (fx2 fixnum?) (fx3 fixnum?)) ⟹ fixnum?

    Fx2 and fx3 must be non-negative and less than (fixnum-width). Moreover, fx2 must be less than or equal to fx3. The fxbit-field procedure returns the number represented by the bits at the positions from fx2 (inclusive) to fx3 (exclusive)

    (rnrs arithmetic fixnums (6)) procedure (fxcopy-bit-field (fx1 fixnum?) (fx2 fixnum?) (fx3 fixnum?) (fx4 fixnum?)) ⟹ fixnum?

    Fx2 and fx3 must be non-negative and less than (fixnum-width). Moreover, fx2 must be less than or equal to fx3. The fxcopy-bit-field procedure returns the result of replacing in fx1 the bits at positions from fx2 (inclusive) to fx3 (exclusive) by the corresponding bits in fx4

    (rnrs arithmetic fixnums (6)) procedure (fxarithmetic-shift (fx1 fixnum?) (fx2 fixnum?)) ⟹ fixnum?

    The absolute value of fx2 must be less than (fixnum-width). If (floor (* fx1 (expt 2 fx2))) is a fixnum, then that fixnum is returned. Otherwise an exception with condition type &implementation-restriction is raised.

    (rnrs arithmetic fixnums (6)) procedure (fxarithmetic-shift-left (fx1 fixnum?) (fx2 fixnum?)) ⟹ fixnum?

    Fx2 must be non-negative, and less than (fixnum-width). The fxarithmetic-shift-left procedure behaves the same as fxarithmetic-shift

    (rnrs arithmetic fixnums (6)) procedure (fxarithmetic-shift-right (fx1 fixnum?) (fx2 fixnum?)) ⟹ fixnum?

    Fx2 must be non-negative, and less than (fixnum-width). (fxarithmetic-shift-right fx1 fx2) behaves the same as (fxarithmetic-shift fx1 (fx- fx2)).

    (rnrs arithmetic fixnums (6)) procedure (fxrotate-bit-field (i fixnum?) (from fixnum?) (to fixnum?) (count fixnum?)) ⟹ fixnum?

    Fx2, fx3, and fx4 must be non-negative and less than (fixnum-width). Fx2 must be less than or equal to fx3. Fx4 must be less than the difference between fx3 and fx2. The fxrotate-bit-field procedure returns the result of cyclically permuting in fx1 the bits at positions from fx2 (inclusive) to fx3 (exclusive) by fx4 bits towards the more significant bits.

    (rnrs arithmetic fixnums (6)) procedure (fxreverse-bit-field (fx1 fixnum?) (fx2 fixnum?) (fx3 fixnum?)) ⟹ fixnum?

    Fx2 and fx3 must be non-negative and less than (fixnum-width). Moreover, fx2 must be less than or equal to fx3. The fxreverse-bit-field procedure returns the fixnum obtained from fx1 by reversing the order of the bits at positions from fx2 (inclusive) to fx3 (exclusive).

    library (rnrs arithmetic flonums (6))

    (rnrs arithmetic flonums (6)) procedure (flonum? obj) ⟹ boolean?

    Returns #t if obj is a flonum, #f otherwise.

    (rnrs arithmetic flonums (6)) procedure (real->flonum (x real?)) ⟹ flonum?

    Returns the best flonum representation of x. The value returned is a flonum that is numerically closest to the argument.

    Note: If flonums are represented in binary floating point, then implementations should break ties by preferring the floating-point representation whose least significant bit is zero.

    (rnrs arithmetic flonums (6)) procedure (fl=? (x flonum?) (y flonum?) (z flonum?) ...) ⟹ boolean?

    The procedure returns #t if its arguments are equal, #f otherwise. The predicate must be transitive.

    (rnrs arithmetic flonums (6)) procedure (fl<? (x flonum?) (y flonum?) (z flonum?) ...) ⟹ boolean?

    The procedure returns #t if its arguments are monotonically increasing, #f otherwise. The predicate must be transitive.

    (rnrs arithmetic flonums (6)) procedure (fl>? (x flonum?) (y flonum?) (z flonum?) ...) ⟹ boolean?

    The procedure returns #t if its arguments are monotonically decreasing, #f otherwise. The predicate must be transitive.

    (rnrs arithmetic flonums (6)) procedure (fl<=? (x flonum?) (y flonum?) (z flonum?) ...) ⟹ boolean?

    The procedure returns #t if its arguments are monotonically nondecreasing, #f otherwise. The predicate must be transitive.

    (rnrs arithmetic flonums (6)) procedure (fl>=? (x flonum?) (y flonum?) (z flonum?) ...) ⟹ boolean?

    The procedure returns #t if its arguments are monotonically nonincreasing, #f otherwise. The predicate must be transitive.

    (rnrs arithmetic flonums (6)) procedure (flinteger? (x flonum?)) ⟹ boolean?

    Test the number is an integer

    (rnrs arithmetic flonums (6)) procedure (flzero? (x flonum?)) ⟹ boolean?

    Test the number is a zero

    (rnrs arithmetic flonums (6)) procedure (flpositive? (x flonum?)) ⟹ boolean?

    Test the number is greater than zero

    (rnrs arithmetic flonums (6)) procedure (flnegative? (x flonum?)) ⟹ boolean?

    Test the number is less than zero

    (rnrs arithmetic flonums (6)) procedure (flodd? (x flonum?)) ⟹ boolean?

    Test the number is odd

    (rnrs arithmetic flonums (6)) procedure (fleven? (x flonum?)) ⟹ boolean?

    Test the number is even

    (rnrs arithmetic flonums (6)) procedure (flfinite? (x flonum?)) ⟹ boolean?

    Test the number is not infinite

    (rnrs arithmetic flonums (6)) procedure (flinfinite? (x flonum?)) ⟹ boolean?

    Test the number is an infinity

    (rnrs arithmetic flonums (6)) procedure (flnan? (x flonum?)) ⟹ boolean?

    Test the number is Not A Number

    (rnrs arithmetic flonums (6)) procedure (flmax (x flonum?) ...) ⟹ flonum?

    The procedure returns the maximum of its arguments. It always returns a NaN when one or more of the arguments is a NaN.

    (rnrs arithmetic flonums (6)) procedure (flmin (x flonum?) ...) ⟹ flonum?

    The procedure returns the minimum of its arguments. It always returns a NaN when one or more of the arguments is a NaN.

    (rnrs arithmetic flonums (6)) procedure (fl+ (x flonum?) ...) ⟹ flonum?

    The procedure returns the flonum sum of its flonum arguments. In general, it should return the flonum that best approximates the mathematical sum. (For implementations that represent flonums using IEEE binary floating point, the meaning of "best" is defined by the IEEE standards.)

    (rnrs arithmetic flonums (6)) procedure (fl* (x flonum?) ...) ⟹ flonum?

    The procedure returns the flonum product of its flonum arguments. In general, it should return the flonum that best approximates the mathematical product. (For implementations that represent flonums using IEEE binary floating point, the meaning of "best" is defined by the IEEE standards.)

    (rnrs arithmetic flonums (6)) procedure (fl- (x flonum?)) ⟹ flonum?

    (rnrs arithmetic flonums (6)) procedure (fl- (x flonum?) (y flonum?) ...) ⟹ flonum?

    With two or more arguments, the procedure returns the flonum difference of its flonum arguments, associating to the left. With one argument, however, it returns the additive flonum inverse of its argument. In general, it should return the flonum that best approximates the mathematical difference. (For implementations that represent flonums using IEEE binary floating point, the meaning of "best" is reasonably well-defined by the IEEE standards.)

    (rnrs arithmetic flonums (6)) procedure (fl/ (x flonum?)) ⟹ flonum?

    (rnrs arithmetic flonums (6)) procedure (fl/ (x flonum?) (y flonum?) ...) ⟹ flonum?

    With two or more arguments, the procedure returns the flonum quotient of its flonum arguments, associating to the left. With one argument, however, it returns the multiplicative flonum inverse of its argument. In general, it should return the flonum that best approximates the mathematical quotient. (For implementations that represent flonums using IEEE binary floating point, the meaning of "best" is reasonably well-defined by the IEEE standards.)

    (rnrs arithmetic flonums (6)) procedure (flabs (fl flonum?)) ⟹ flonum?

    Returns the absolute value of fl.

    (rnrs arithmetic flonums (6)) procedure (fldiv (x1 flonum?) (x2 flonum?)) ⟹ flonum?

    Implements number-theoretic integer division and returns the results of the corresponding mathematical operations specified in report section on "Integer division". For zero divisors, the procedure may return a NaN or some unspecified flonum.

    (rnrs arithmetic flonums (6)) procedure (fldiv0 (x1 flonum?) (x2 flonum?)) ⟹ flonum?

    Implements number-theoretic integer division and returns the results of the corresponding mathematical operations specified in report section on "Integer division". For zero divisors, the procedure may return a NaN or some unspecified flonum.

    (rnrs arithmetic flonums (6)) procedure (fldiv-and-mod (x1 flonum?) (x2 flonum?)) ⟹ (values flonum? flonum?)

    Implements number-theoretic integer division and returns the results of the corresponding mathematical operations specified in report section on "Integer division". For zero divisors, the procedure may return a NaN or some unspecified flonum.

    (rnrs arithmetic flonums (6)) procedure (fldiv0-and-mod0 (x1 flonum?) (x2 flonum?)) ⟹ (values flonum? flonum?)

    Implements number-theoretic integer division and returns the results of the corresponding mathematical operations specified in report section on "Integer division". For zero divisors, the procedure may return a NaN or some unspecified flonum.

    (rnrs arithmetic flonums (6)) procedure (flmod (x1 flonum?) (x2 flonum?)) ⟹ flonum?

    Implements number-theoretic integer division and returns the results of the corresponding mathematical operations specified in report section on "Integer division". For zero divisors, the procedure may return a NaN or some unspecified flonum.

    (rnrs arithmetic flonums (6)) procedure (flmod0 (x1 flonum?) (x2 flonum?)) ⟹ flonum?

    Implements number-theoretic integer division and returns the results of the corresponding mathematical operations specified in report section on "Integer division". For zero divisors, the procedure may return a NaN or some unspecified flonum.

    (rnrs arithmetic flonums (6)) procedure (flnumerator (fl flonum?)) ⟹ flonum?

    The procedure returns the numerator of fl as a flonum; the result is computed as if fl was represented as a fraction in lowest terms.

    (rnrs arithmetic flonums (6)) procedure (fldenominator (fl flonum?)) ⟹ flonum?

    The procedure returns the denominator of fl as a flonum; the result is computed as if fl was represented as a fraction in lowest terms. The denominator is always positive. The denominator of 0.0 is defined to be 1.0.

    (rnrs arithmetic flonums (6)) procedure (flfloor (fl flonum?)) ⟹ flonum?

    Returns the largest integral flonum not larger than fl. Returns an infinity when given an infinity as an argument, and a NaN when given a NaN.

    (rnrs arithmetic flonums (6)) procedure (flceiling (fl flonum?)) ⟹ flonum?

    Returns the smallest integral flonum not smaller than fl. Returns an infinity when given an infinity as an argument, and a NaN when given a NaN.

    (rnrs arithmetic flonums (6)) procedure (flround (fl flonum?)) ⟹ flonum?

    Returns the closest integral flonum to fl, rounding to even when fl represents a number halfway between two integers. Returns an infinity when given an infinity as an argument, and a NaN when given a NaN.

    (rnrs arithmetic flonums (6)) procedure (fltruncate (fl flonum?)) ⟹ flonum?

    Returns the integral flonum closest to fl whose absolute value is not larger than the absolute value of fl. Returns an infinity when given an infinity as an argument, and a NaN when given a NaN.

    (rnrs arithmetic flonums (6)) procedure (flexp (fl flonum?)) ⟹ flonum?

    (rnrs arithmetic flonums (6)) procedure (fllog (fl flonum?)) ⟹ flonum?

    (rnrs arithmetic flonums (6)) procedure (fllog (fl flonum?) (base flonum?)) ⟹ flonum?

    (rnrs arithmetic flonums (6)) procedure (flsin (x flonum?)) ⟹ flonum?

    (rnrs arithmetic flonums (6)) procedure (flcos (x flonum?)) ⟹ flonum?

    (rnrs arithmetic flonums (6)) procedure (fltan (x flonum?)) ⟹ flonum?

    (rnrs arithmetic flonums (6)) procedure (flasin (x flonum?)) ⟹ flonum?

    (rnrs arithmetic flonums (6)) procedure (flacos (x flonum?)) ⟹ flonum?

    (rnrs arithmetic flonums (6)) procedure (flatan (x flonum?)) ⟹ flonum?

    (rnrs arithmetic flonums (6)) procedure (flatan (y flonum?) (x flonum?)) ⟹ flonum?

    These procedures compute the usual transcendental functions. The flexp procedure computes the base-e exponential of fl. The fllog procedure with a single argument computes the natural logarithm of fl (not the base ten logarithm); (fllog fl1 fl2) computes the base-fl2 logarithm of fl1. The flasin, flacos, and flatan procedures compute arcsine, arccosine, and arctangent, respectively. (flatan fl1 fl2) computes the arc tangent of fl1/fl2.

    See report section on "Transcendental functions" for the underlying mathematical operations. In the event that these operations do not yield a real result for the given arguments, the result may be a NaN, or may be some unspecified flonum.

    Implementations that use IEEE binary floating-point arithmetic should follow the relevant standards for these procedures.

    (rnrs arithmetic flonums (6)) procedure (flsqrt (fl flonum?)) ⟹ flonum?

    Returns the principal square root of fl. For −0.0, flsqrt should return −0.0; for other negative arguments, the result may be a NaN or some unspecified flonum.

    (rnrs arithmetic flonums (6)) procedure (flexpt (base flonum?) (power flonum?)) ⟹ flonum?

    Either base should be non-negative, or, if base is negative, power should be an integer object. The flexpt procedure returns base raised to the power power. If base is negative and power is not an integer object, the result may be a NaN, or may be some unspecified flonum. If base is zero, then the result is zero.

    (rnrs arithmetic flonums (6)) value &no-infinities ⟹ record-type-descriptor?

    (rnrs arithmetic flonums (6)) procedure (make-no-infinities-violation obj) ⟹ no-infinities-violation?

    (rnrs arithmetic flonums (6)) procedure (no-infinities-violation? obj) ⟹ boolean?

    (rnrs arithmetic flonums (6)) value &no-nans ⟹ record-type-descriptor?

    (rnrs arithmetic flonums (6)) procedure (make-no-nans-violation obj) ⟹ no-nans-violation?

    (rnrs arithmetic flonums (6)) procedure (no-nans-violation? obj) ⟹ boolean?

    These condition types could be defined by the following code:

    (define-condition-type &no-infinities

    &implementation-restriction

    make-no-infinities-violation

    no-infinities-violation?)

    (define-condition-type &no-nans

    &implementation-restriction

    make-no-nans-violation

    no-nans-violation?)

    These types describe that a program has executed an arithmetic operations that is specified to return an infinity or a NaN, respectively, on a Scheme implementation that is not able to represent the infinity or NaN. (See report section on "Representability of infinities and NaNs".)

    (rnrs arithmetic flonums (6)) procedure (fixnum->flonum (fx fixnum?)) ⟹ flonum?

    Returns a flonum that is numerically closest to fx.

    library (rnrs bytevectors (6))

    (rnrs bytevectors (6)) syntax (endianness endianness-symbol)

    The name of <endianness symbol> must be a symbol describing an endianness. An implementation must support at least the symbols big and little, but may support other endianness symbols. (endianness <endianness symbol>) evaluates to the symbol named <endianness symbol>. Whenever one of the procedures operating on bytevectors accepts an endianness as an argument, that argument must be one of these symbols. It is a syntax violation for <endianness symbol> to be anything other than an endianness symbol supported by the implementation.

    Note: Implementors should use widely accepted designations for endianness symbols other than big and little.

    Note: Only the name of <endianness symbol> is significant.

    (rnrs bytevectors (6)) procedure (native-endianness) ⟹ symbol?

    Returns the endianness symbol associated implementation's preferred endianness (usually that of the underlying machine architecture). This may be any <endianness symbol>, including a symbol other than big and little.

    (rnrs bytevectors (6)) procedure (bytevector? obj) ⟹ boolean?

    Returns #t if obj is a bytevector, otherwise returns #f.

    (rnrs bytevectors (6)) procedure (make-bytevector (k integer?)) ⟹ bytevector?

    (rnrs bytevectors (6)) procedure (make-bytevector (k integer?) (byte integer?)) ⟹ bytevector?

    Returns a newly allocated bytevector of k bytes. If the fill argument is missing, the initial contents of the returned bytevector are unspecified. If the fill argument is present, it must be an exact integer object in the interval {−128, ... 255} that specifies the initial value for the bytes of the bytevector: If fill is positive, it is interpreted as an octet; if it is negative, it is interpreted as a byte.

    (rnrs bytevectors (6)) procedure (bytevector-length (bytevector bytevector?)) ⟹ integer?

    Returns, as an exact integer object, the number of bytes in bytevector.

    (rnrs bytevectors (6)) procedure (bytevector=? (bytevector1 bytevector?) (bytevector2 bytevector?)) ⟹ boolean?

    Returns #t if bytevector1 and bytevector2 are equal - that is, if they have the same length and equal bytes at all valid indices. It returns #f otherwise.

    (rnrs bytevectors (6)) procedure (bytevector-fill! (bytevector bytevector?) (k integer?)) ⟹ undefined

    The fill argument is as in the description of the make-bytevector procedure. The bytevector-fill! procedure stores fill in every element of bytevector and returns unspecified values. Analogous to vector-fill!.

    (rnrs bytevectors (6)) procedure (bytevector-copy! (source bytevector?) (source-start integer?) (target bytevector?) (target-start integer?) (k integer?)) ⟹ undefined

    Source and target must be bytevectors. Source-start, target-start, and k must be non-negative exact integer objects that satisfy

    0 <= source-start <= source-start + k <= lsource

    0 <= target-start <= target-start + k <= ltarget

    where lsource is the length of source and ltarget is the length of target. The bytevector-copy! procedure copies the bytes from source at indices source-start, ..., source-start + k - 1 to consecutive indices in target starting at target-index. This must work even if the memory regions for the source and the target overlap, i.e., the bytes at the target location after the copy must be equal to the bytes at the source location before the copy. This returns unspecified values.

    (rnrs bytevectors (6)) procedure (bytevector-copy (bytevector bytevector?)) ⟹ bytevector?

    Returns a newly allocated copy of bytevector.

    (rnrs bytevectors (6)) procedure (bytevector-u8-ref (bytevector bytevector?) (k integer?)) ⟹ integer?

    K must be a valid index of bytevector. The bytevector-u8-ref procedure returns the byte at index k of bytevector, as an octet.

    (rnrs bytevectors (6)) procedure (bytevector-s8-ref (bytevector bytevector?) (k integer?)) ⟹ integer?

    K must be a valid index of bytevector. The bytevector-s8-ref procedure returns the byte at index k of bytevector, as a (signed) byte.

    (rnrs bytevectors (6)) procedure (bytevector-u8-set! (bytevector bytevector?) (k integer?) (octet integer?)) ⟹ undefined

    K must be a valid index of bytevector. The bytevector-u8-set! procedure stores octet in element k of bytevector.

    (rnrs bytevectors (6)) procedure (bytevector-s8-set! (bytevector bytevector?) (k integer?) (byte integer?)) ⟹ undefined

    K must be a valid index of bytevector. The bytevector-s8-set! procedure stores the two's-complement representation of byte in element k of bytevector.

    (rnrs bytevectors (6)) procedure (bytevector->u8-list (bytevector bytevector?)) ⟹ list?

    The bytevector->u8-list procedure returns a newly allocated list of the octets of bytevector in the same order.

    (rnrs bytevectors (6)) procedure (u8-list->bytevector (list list?)) ⟹ bytevector?

    list ⟹ (list (octet integer?))

    List must be a list of octets. The u8-list->bytevector procedure returns a newly allocated bytevector whose elements are the elements of list list, in the same order. It is analogous to list->vector.

    (rnrs bytevectors (6)) procedure (bytevector-uint-ref (bytevector bytevector?) (k integer?) (endianness symbol?) (size integer?)) ⟹ integer?

    The bytevector-uint-ref procedure retrieves the exact integer object corresponding to the unsigned representation of size size and specified by endianness at indices k, ..., k + size − 1.

    (rnrs bytevectors (6)) procedure (bytevector-sint-ref (bytevector bytevector?) (k integer?) (endianness symbol?) (size integer?)) ⟹ integer?

    The bytevector-sint-ref procedure retrieves the exact integer object corresponding to the two's-complement representation of size size and specified by endianness at indices k, ..., k + size − 1.

    (rnrs bytevectors (6)) procedure (bytevector-uint-set! (bytevector bytevector?) (k integer?) (n integer?) (endianness symbol?) (size integer?)) ⟹ undefined

    The bytevector-uint-set! procedure stores the unsigned representation of size size and specified by endianness into bytevector at indices k, ..., k + size − 1.

    (rnrs bytevectors (6)) procedure (bytevector-sint-set! (bytevector bytevector?) (k integer?) (n integer?) (endianness symbol?) (size integer?)) ⟹ undefined

    bytevector-sint-set! stores the two's-complement representation of size size and specified by endianness into bytevector at indices k, ..., k + size − 1.

    (rnrs bytevectors (6)) procedure (bytevector->uint-list (bytevector bytevector?) (endianness symbol?) (size integer?)) ⟹ list?

    (rnrs bytevectors (6)) procedure (bytevector->sint-list (bytevector bytevector?) (endianness symbol?) (size integer?)) ⟹ list?

    (rnrs bytevectors (6)) procedure (uint-list->bytevector (list list?) (endianness symbol?) (size integer?)) ⟹ bytevector?

    (rnrs bytevectors (6)) procedure (sint-list->bytevector (list list?) (endianness symbol?) (size integer?)) ⟹ bytevector?

    Size must be a positive exact integer object. For uint-list->bytevector, list must be a list of exact integer objects in the interval {0, ..., 256^mathitsize−1}. For sint-list->bytevector, list must be a list of exact integer objects in the interval {−256^mathitsize/2, ..., 256^mathitsize/2−1}. The length of bytevector or, respectively, of list must be divisible by size.

    These procedures convert between lists of integer objects and their consecutive representations according to size and endianness in the bytevector objects in the same way as bytevector->u8-list and u8-list->bytevector do for one-byte representations.

    (rnrs bytevectors (6)) procedure (bytevector-u16-ref (bytevector bytevector?) (k integer?) (endianness symbol?) (size integer?)) ⟹ integer?

    (rnrs bytevectors (6)) procedure (bytevector-s16-ref (bytevector bytevector?) (k integer?) (endianness symbol?) (size integer?)) ⟹ integer?

    (rnrs bytevectors (6)) procedure (bytevector-u16-native-ref (bytevector bytevector?) (k integer?) (size integer?)) ⟹ integer?

    (rnrs bytevectors (6)) procedure (bytevector-s16-native-ref (bytevector bytevector?) (k integer?) (size integer?)) ⟹ integer?

    (rnrs bytevectors (6)) procedure (bytevector-u16-set! (bytevector bytevector?) (k integer?) (n integer?) (endianness symbol?) (size integer?)) ⟹ undefined

    (rnrs bytevectors (6)) procedure (bytevector-s16-set! (bytevector bytevector?) (k integer?) (n integer?) (endianness symbol?) (size integer?)) ⟹ undefined

    (rnrs bytevectors (6)) procedure (bytevector-u16-native-set! (bytevector bytevector?) (k integer?) (n integer?) (size integer?)) ⟹ undefined

    (rnrs bytevectors (6)) procedure (bytevector-s16-native-set! (bytevector bytevector?) (k integer?) (n integer?) (size integer?)) ⟹ undefined

    K must be a valid index of bytevector; so must k + 1. For bytevector-u16-set! and bytevector-u16-native-set!, n must be an exact integer object in the interval {0, ..., 2^16−1}. For bytevector-s16-set! and bytevector-s16-native-set!, n must be an exact integer object in the interval {−2^15, ..., 2^15−1}.

    These retrieve and set two-byte representations of numbers at indices k and k + 1, according to the endianness specified by endianness. The procedures with u16 in their names deal with the unsigned representation; those with s16 in their names deal with the two's-complement representation.

    The procedures with native in their names employ the native endianness, and work only at aligned indices: k must be a multiple of 2.

    The ...-set! procedures return unspecified values.

    (rnrs bytevectors (6)) procedure (bytevector-u32-ref (bytevector bytevector?) (k integer?) (endianness symbol?) (size integer?)) ⟹ integer?

    (rnrs bytevectors (6)) procedure (bytevector-s32-ref (bytevector bytevector?) (k integer?) (endianness symbol?) (size integer?)) ⟹ integer?

    (rnrs bytevectors (6)) procedure (bytevector-u32-native-ref (bytevector bytevector?) (k integer?) (size integer?)) ⟹ integer?

    (rnrs bytevectors (6)) procedure (bytevector-s32-native-ref (bytevector bytevector?) (k integer?) (size integer?)) ⟹ integer?

    (rnrs bytevectors (6)) procedure (bytevector-u32-set! (bytevector bytevector?) (k integer?) (n integer?) (endianness symbol?) (size integer?)) ⟹ undefined

    (rnrs bytevectors (6)) procedure (bytevector-s32-set! (bytevector bytevector?) (k integer?) (n integer?) (endianness symbol?) (size integer?)) ⟹ undefined

    (rnrs bytevectors (6)) procedure (bytevector-u32-native-set! (bytevector bytevector?) (k integer?) (n integer?) (size integer?)) ⟹ undefined

    (rnrs bytevectors (6)) procedure (bytevector-s32-native-set! (bytevector bytevector?) (k integer?) (n integer?) (size integer?)) ⟹ undefined

    K, ..., k + 3 must be valid indices of bytevector. For bytevector-u32-set! and bytevector-u32-native-set!, n must be an exact integer object in the interval {0, ..., 2^32−1}. For bytevector-s32-set! and bytevector-s32-native-set!, n must be an exact integer object in the interval {−2^31, ..., 2^32−1}.

    These retrieve and set four-byte representations of numbers at indices k, ..., k + 3, according to the endianness specified by endianness. The procedures with u32 in their names deal with the unsigned representation; those with s32 with the two's-complement representation.

    The procedures with native in their names employ the native endianness, and work only at aligned indices: k must be a multiple of 4.

    The ...-set! procedures return unspecified values.

    (rnrs bytevectors (6)) procedure (bytevector-u64-ref (bytevector bytevector?) (k integer?) (endianness symbol?) (size integer?)) ⟹ integer?

    (rnrs bytevectors (6)) procedure (bytevector-s64-ref (bytevector bytevector?) (k integer?) (endianness symbol?) (size integer?)) ⟹ integer?

    (rnrs bytevectors (6)) procedure (bytevector-u64-native-ref (bytevector bytevector?) (k integer?) (size integer?)) ⟹ integer?

    (rnrs bytevectors (6)) procedure (bytevector-s64-native-ref (bytevector bytevector?) (k integer?) (size integer?)) ⟹ integer?

    (rnrs bytevectors (6)) procedure (bytevector-u64-set! (bytevector bytevector?) (k integer?) (n integer?) (endianness symbol?) (size integer?)) ⟹ undefined

    (rnrs bytevectors (6)) procedure (bytevector-s64-set! (bytevector bytevector?) (k integer?) (n integer?) (endianness symbol?) (size integer?)) ⟹ undefined

    (rnrs bytevectors (6)) procedure (bytevector-u64-native-set! (bytevector bytevector?) (k integer?) (n integer?) (size integer?)) ⟹ undefined

    (rnrs bytevectors (6)) procedure (bytevector-s64-native-set! (bytevector bytevector?) (k integer?) (n integer?) (size integer?)) ⟹ undefined

    K, ..., k + 7 must be valid indices of bytevector. For bytevector-u64-set! and bytevector-u64-native-set!, n must be an exact integer object in the interval {0, ..., 2^64−1}. For bytevector-s64-set! and bytevector-s64-native-set!, n must be an exact integer object in the interval {−2^63, ..., 2^64−1}.

    These retrieve and set eight-byte representations of numbers at indices k, ..., k + 7, according to the endianness specified by endianness. The procedures with u64 in their names deal with the unsigned representation; those with s64 with the two's-complement representation.

    The procedures with native in their names employ the native endianness, and work only at aligned indices: k must be a multiple of 8.

    The ...-set! procedures return unspecified values.

    (rnrs bytevectors (6)) procedure (bytevector-ieee-single-ref (bytevector bytevector?) (k integer?) (endianness symbol?) (size integer?)) ⟹ real?

    K, ..., k + 3 must be valid indices of bytevector. The procedure returns the inexact real number object that best represents the IEEE-754 single-precision number represented by the four bytes beginning at index k.

    (rnrs bytevectors (6)) procedure (bytevector-ieee-double-ref (bytevector bytevector?) (k integer?) (endianness symbol?) (size integer?)) ⟹ real?

    K, ..., k + 7 must be valid indices of bytevector. The procedure returns the inexact real number object that best represents the IEEE-754 double-precision number represented by the eight bytes beginning at index k.

    (rnrs bytevectors (6)) procedure (bytevector-ieee-single-native-ref (bytevector bytevector?) (k integer?) (size integer?)) ⟹ real?

    K, ..., k + 3 must be valid indices of bytevector. K must be a multiple of 4. The procedure returns the inexact real number object that best represents the IEEE-754 single-precision number represented by the four bytes beginning at index k.

    (rnrs bytevectors (6)) procedure (bytevector-ieee-double-native-ref (bytevector bytevector?) (k integer?) (size integer?)) ⟹ real?

    K, ..., k + 7 must be valid indices of bytevector. K must be a multiple of 8. The procedure returns the inexact real number object that best represents the IEEE-754 double-precision number represented by the eight bytes beginning at index k.

    (rnrs bytevectors (6)) procedure (bytevector-ieee-single-set! (bytevector bytevector?) (k integer?) (x real?) (endianness symbol?) (size integer?)) ⟹ undefined

    K, ..., k + 3 must be valid indices of bytevector. The procedure stores an IEEE-754 single-precision representation of x into elements k through k + 3 of bytevector, and returns unspecified values.

    (rnrs bytevectors (6)) procedure (bytevector-ieee-double-set! (bytevector bytevector?) (k integer?) (x real?) (endianness symbol?) (size integer?)) ⟹ undefined

    K, ..., k + 7 must be valid indices of bytevector. The procedure stores an IEEE-754 double-precision representation of x into elements k through k + 7 of bytevector, and returns unspecified values.

    (rnrs bytevectors (6)) procedure (bytevector-ieee-single-native-set! (bytevector bytevector?) (k integer?) (x real?) (size integer?)) ⟹ undefined

    K, ..., k + 3 must be valid indices of bytevector. K must be a multiple of 4. The procedure stores an IEEE-754 single-precision representation of x into elements k through k + 3 of bytevector, and returns unspecified values.

    (rnrs bytevectors (6)) procedure (bytevector-ieee-double-native-set! (bytevector bytevector?) (k integer?) (x real?) (size integer?)) ⟹ undefined

    K, ..., k + 7 must be valid indices of bytevector. K must be a multiple of 8. The procedure stores an IEEE-754 double-precision representation of x into elements k through k + 7 of bytevector, and returns unspecified values.

    (rnrs bytevectors (6)) procedure (string->utf8 (string string?)) ⟹ bytevector?

    Returns a newly allocated (unless empty) bytevector that contains the UTF-8 encoding of the given string.

    (rnrs bytevectors (6)) procedure (string->utf16 (string string?)) ⟹ bytevector?

    (rnrs bytevectors (6)) procedure (string->utf16 (string string?) (endianness symbol?)) ⟹ bytevector?

    If endianness is specified, it must be the symbol big or the symbol little. The string->utf16 procedure returns a newly allocated (unless empty) bytevector that contains the UTF-16BE or UTF-16LE encoding of the given string (with no byte-order mark). If endianness is not specified or is big, then UTF-16BE is used. If endianness is little, then UTF-16LE is used.

    (rnrs bytevectors (6)) procedure (string->utf32 (string string?)) ⟹ bytevector?

    (rnrs bytevectors (6)) procedure (string->utf32 (string string?) (endianness symbol?)) ⟹ bytevector?

    If endianness is specified, it must be the symbol big or the symbol little. The string->utf32 procedure returns a newly allocated (unless empty) bytevector that contains the UTF-32BE or UTF-32LE encoding of the given string (with no byte mark). If endianness is not specified or is big, then UTF-32BE is used. If endianness is little, then UTF-32LE is used.

    (rnrs bytevectors (6)) procedure (utf8->string (bytevector bytevector?)) ⟹ string?

    Returns a newly allocated (unless empty) string whose character sequence is encoded by the given bytevector.

    (rnrs bytevectors (6)) procedure (utf16->string (bytevector bytevector?) (endianness symbol?)) ⟹ string?

    (rnrs bytevectors (6)) procedure (utf16->string (bytevector bytevector?) (endianness symbol?) (endianness-mandatory? boolean?)) ⟹ string?

    Endianness must be the symbol big or the symbol little. The utf16->string procedure returns a newly allocated (unless empty) string whose character sequence is encoded by the given bytevector. Bytevector is decoded according to UTF-16BE or UTF-16LE: If endianness-mandatory? is absent or #f, utf16->string determines the endianness according to a UTF-16 BOM at the beginning of bytevector if a BOM is present; in this case, the BOM is not decoded as a character. Also in this case, if no UTF-16 BOM is present, endianness specifies the endianness of the encoding. If endianness-mandatory? is a true value, endianness specifies the endianness of the encoding, and any UTF-16 BOM in the encoding is decoded as a regular character.

    Note: A UTF-16 BOM is either a sequence of bytes #xFE, #xFF specifying big and UTF-16BE, or #xFF, #xFE specifying little and UTF-16LE.

    (rnrs bytevectors (6)) procedure (utf32->string (bytevector bytevector?) (endianness symbol?)) ⟹ string?

    (rnrs bytevectors (6)) procedure (utf32->string (bytevector bytevector?) (endianness symbol?) (endianness-mandatory? boolean?)) ⟹ string?

    Endianness must be the symbol big or the symbol little. The utf32->string procedure returns a newly allocated (unless empty) string whose character sequence is encoded by the given bytevector. Bytevector is decoded according to UTF-32BE or UTF-32LE: If endianness-mandatory? is absent or #f, utf32->string determines the endianness according to a UTF-32 BOM at the beginning of bytevector if a BOM is present; in this case, the BOM is not decoded as a character. Also in this case, if no UTF-32 BOM is present, endianness specifies the endianness of the encoding. If endianness-mandatory? is a true value, endianness specifies the endianness of the encoding, and any UTF-32 BOM in the encoding is decoded as a regular character.

    Note: A UTF-32 BOM is either a sequence of bytes #x00, #x00, #xFE, #xFF specifying big and UTF-32BE, or #xFF, #xFE, #x00, #x00, specifying little and UTF-32LE.

    library (rnrs conditions (6))

    (rnrs conditions (6)) value &condition ⟹ record-type-descriptor?

    Simple conditions are records of subtypes of the &condition record type. The &condition type has no fields and is neither sealed nor opaque.

    (rnrs conditions (6)) procedure (condition (condition1 condition?) ...) ⟹ condition?

    The condition procedure returns a condition object with the components of the conditions as its components, in the same order, i.e., with the components of condition1 appearing first in the same order as in condition1, then with the components of condition2, and so on. The returned condition is compound if the total number of components is zero or greater than one. Otherwise, it may be compound or simple.

    (rnrs conditions (6)) procedure (simple-conditions (condition condition?)) ⟹ list?

    The simple-conditions procedure returns a list of the components of condition, in the same order as they appeared in the construction of condition. The returned list is immutable. If the returned list is modified, the effect on condition is unspecified.

    Note: Because condition decomposes its arguments into simple conditions, simple-conditions always returns a “flattened” list of simple conditions.

    (rnrs conditions (6)) procedure (condition? obj) ⟹ boolean?

    Returns #t if obj is a (simple or compound) condition, otherwise returns #f.

    (rnrs conditions (6)) procedure (condition-predicate (rtd record-type-descriptor?)) ⟹ procedure?

    (return obj) ⟹ boolean?

    Rtd must be a record-type descriptor of a subtype of &condition. The condition-predicate procedure returns a procedure that takes one argument. This procedure returns #t if its argument is a condition of the condition type represented by rtd, i.e., if it is either a simple condition of that record type (or one of its subtypes) or a compound conditition with such a simple condition as one of its components, and #f otherwise.

    (rnrs conditions (6)) procedure (condition-accessor (rtd record-type-descriptor?) (proc procedure?)) ⟹ procedure?

    (proc record) ⟹ *

    (return record) ⟹ *

    Rtd must be a record-type descriptor of a subtype of &condition. Proc should accept one argument, a record of the record type of rtd. The condition-accessor procedure returns a procedure that accepts a single argument, which must be a condition of the type represented by rtd. This procedure extracts the first component of the condition of the type represented by rtd, and returns the result of applying proc to that component.

    (rnrs conditions (6)) syntax (define-condition-type condition-type supertype constructor predicate field-spec1 ...)

    field-spec ⟹ (field accessor)

    The define-condition-type form expands into a record-type definition for a record type <condition-type> (see section 6.2). The record type will be non-opaque, non-sealed, and its fields will be immutable. It will have <supertype> has its parent type. The remaining identifiers will be bound as follows:

  • <Constructor> is bound to a default constructor for the type (see section 6.3): It accepts one argument for each of the record type's complete set of fields (including parent types, with the fields of the parent coming before those of the extension in the arguments) and returns a condition object initialized to those arguments.
  • <Predicate> is bound to a predicate that identifies conditions of type <condition-type> or any of its subtypes.
  • Each <accessor> is bound to a procedure that extracts the corresponding field from a condition of type <condition-type>.
  • (rnrs conditions (6)) value &message ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-message-condition message) ⟹ message-condition?

    (rnrs conditions (6)) procedure (message-condition? obj) ⟹ boolean?

    (rnrs conditions (6)) procedure (condition-message (condition message-condition?)) ⟹ *

    This condition type could be defined by

    (define-condition-type &message &condition

    make-message-condition message-condition?

    (message condition-message))

    It carries a message further describing the nature of the condition to humans.

    (rnrs conditions (6)) value &warning ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-warning) ⟹ warning?

    (rnrs conditions (6)) procedure (warning? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &warning &condition

    make-warning warning?)

    This type describes conditions that do not, in principle, prohibit immediate continued execution of the program, but may interfere with the program's execution later.

    (rnrs conditions (6)) value &serious ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-serious-condition) ⟹ serious?

    (rnrs conditions (6)) procedure (serious-condition? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &serious &condition

    make-serious-condition serious-condition?)

    This type describes conditions serious enough that they cannot safely be ignored. This condition type is primarily intended as a supertype of other condition types.

    (rnrs conditions (6)) value &error ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-error) ⟹ error?

    (rnrs conditions (6)) procedure (error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &error &serious

    make-error error?)

    This type describes errors, typically caused by something that has gone wrong in the interaction of the program with the external world or the user.

    (rnrs conditions (6)) value &violation ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-violation) ⟹ violation?

    (rnrs conditions (6)) procedure (violation? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &violation &serious

    make-violation violation?)

    This type describes violations of the language standard or a library standard, typically caused by a programming error.

    (rnrs conditions (6)) value &assertion ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-assertion-violation) ⟹ assertion-violation?

    (rnrs conditions (6)) procedure (assertion-violation? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &assertion &violation

    make-assertion-violation assertion-violation?)

    This type describes an invalid call to a procedure, either passing an invalid number of arguments, or passing an argument of the wrong type.

    (rnrs conditions (6)) value &irritants ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-irritants-condition (irritants list?)) ⟹ irritants-condition?

    (rnrs conditions (6)) procedure (irritants-condition? obj) ⟹ boolean?

    (rnrs conditions (6)) procedure (condition-irritants (condition irritants-condition?)) ⟹ list?

    This condition type could be defined by

    (define-condition-type &irritants &condition

    make-irritants-condition irritants-condition?

    (irritants condition-irritants))

    Irritants should be a list of objects. This condition provides additional information about a condition, typically the argument list of a procedure that detected an exception. Conditions of this type are created by the error and assertion-violation procedures of report section on "Errors and violations".

    (rnrs conditions (6)) value &who ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-who-condition (who string? | symbol?)) ⟹ who-condition?

    (rnrs conditions (6)) procedure (who-condition? obj) ⟹ boolean?

    (rnrs conditions (6)) procedure (condition-who (condition who-condition?)) ⟹ string? | symbol?

    This condition type could be defined by

    (define-condition-type &who &condition

    make-who-condition who-condition?

    (who condition-who))

    Who should be a symbol or string identifying the entity reporting the exception. Conditions of this type are created by the error and assertion-violation procedures (report section on "Errors and violations"), and the syntax-violation procedure (section on "Syntax violations").

    (rnrs conditions (6)) value &non-continuable ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-non-continuable-violation) ⟹ non-continuable-violation?

    (rnrs conditions (6)) procedure (non-continuable-violation? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &non-continuable &violation

    make-non-continuable-violation

    non-continuable-violation?)

    This type indicates that an exception handler invoked via raise has returned.

    (rnrs conditions (6)) value &implementation-restriction ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-implementation-restriction-violation) ⟹ implementation-restriction-violation?

    (rnrs conditions (6)) procedure (implementation-restriction-violation? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &implementation-restriction

    &violation

    make-implementation-restriction-violation

    implementation-restriction-violation?)

    This type describes a violation of an implementation restriction allowed by the specification, such as the absence of representations for NaNs and infinities. (See section 11.3.)

    (rnrs conditions (6)) value &lexical ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-lexical-violation) ⟹ lexical-violation?

    (rnrs conditions (6)) procedure (lexical-violation? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &lexical &violation

    make-lexical-violation lexical-violation?)

    This type describes syntax violations at the level of the datum syntax.

    (rnrs conditions (6)) value &syntax ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-syntax-violation form subform) ⟹ syntax-violation?

    (rnrs conditions (6)) procedure (syntax-violation? obj) ⟹ boolean?

    (rnrs conditions (6)) procedure (syntax-violation-form (condition syntax-violation?)) ⟹ *

    (rnrs conditions (6)) procedure (syntax-violation-subform (condition syntax-violation?)) ⟹ *

    This condition type could be defined by

    (define-condition-type &syntax &violation

    make-syntax-violation syntax-violation?

    (form syntax-violation-form)

    (subform syntax-violation-subform))

    This type describes syntax violations. Form should be the erroneous syntax object or a datum representing the code of the erroneous form. Subform should be an optional syntax object or datum within the erroneous form that more precisely locates the violation. It can be #f to indicate the absence of more precise information.

    (rnrs conditions (6)) value &undefined ⟹ record-type-descriptor?

    (rnrs conditions (6)) procedure (make-undefined-violation) ⟹ undefined-violation?

    (rnrs conditions (6)) procedure (undefined-violation? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &undefined &violation

    make-undefined-violation undefined-violation?)

    This type describes unbound identifiers in the program.

    library (rnrs control (6))

    (rnrs control (6)) syntax (when test expression1 expression2 ...)

    A when expression is evaluated by evaluating the <test> expression. If <test> evaluates to a true value, the remaining <expression>s are evaluated in order, and the results of the last <expression> are returned as the results of the entire when expression. Otherwise, the when expression returns unspecified values.

    The final <expression> is in tail context if the when form is itself in tail context.

    (rnrs control (6)) syntax (unless test expression1 expression2 ...)

    An unless expression is evaluated by evaluating the <test> expression. If <test> evaluates to #f, the remaining <expression>s are evaluated in order, and the results of the last <expression> are returned as the results of the entire unless expression. Otherwise, the unless expression returns unspecified values.

    The final <expression> is in tail context if the unless form is itself in tail context.

    (rnrs control (6)) syntax (do (variable-decl1 ...) (test expression ...) command ...)

    variable-decl ⟹ (variable init step) | (variable init)

    The do expression is an iteration construct. It specifies a set of variables to be bound, how they are to be initialized at the start, and how they are to be updated on each iteration.

    A do expression is evaluated as follows: The <init> expressions are evaluated (in some unspecified order), the <variable>s are bound to fresh locations, the results of the <init> expressions are stored in the bindings of the <variable>s, and then the iteration phase begins.

    Each iteration begins by evaluating <test>; if the result is #f, then the <command>s are evaluated in order for effect, the <step> expressions are evaluated in some unspecified order, the <variable>s are bound to fresh locations holding the results, and the next iteration begins.

    If <test> evaluates to a true value, the <expression>s are evaluated from left to right and the values of the last <expression> are returned. If no <expression>s are present, then the do expression returns unspecified values.

    The regionof the binding of a <variable> consists of the entire do expression except for the <init>s.

    A <step> may be omitted, in which case the effect is the same as if (<variable> <init> <variable>) had been written instead of (<variable> <init>).

    If a do expression appears in a tail context, the <expression>s are a <tail sequence> in the sense of report section on “Tail calls and tail contexts”, i.e., the last <expression> is also in a tail context.

    (rnrs control (6)) syntax (case-lambda clause ...)⟹ return

    clause ⟹ (formals body)

    formals ⟹ (variable1 ...) | variable | (variable1 ... variable_n . variable_n+1)

    A case-lambda expression evaluates to a procedure. This procedure, when applied, tries to match its arguments to the <case-lambda clause>s in order. The arguments match a clause if one of the following conditions is fulfilled:

  • <Formals> has the form (<variable> ...) and the number of arguments is the same as the number of formal parameters in <formals>.
  • <Formals> has the form (<variable1> ...<variablen> . <variablen+1)> and the number of arguments is at least n.
  • <Formals> has the form <variable>.
  • For the first clause matched by the arguments, the variables of the <formals> are bound to fresh locations containing the argument values in the same arrangement as with lambda. The last expression of a <body> in a case-lambda expression is in tail context. If the arguments match none of the clauses, an exception with condition type &assertion is raised.

    library (rnrs enums (6))

    (rnrs enums (6)) procedure (make-enumeration (symbol-list list?)) ⟹ enum-set

    Symbol-list must be a list of symbols. The make-enumeration procedure creates a new enumeration type whose universe consists of those symbols (in canonical order of their first appearance in the list) and returns that universe as an enumeration set whose universe is itself and whose enumeration type is the newly created enumeration type.

    (rnrs enums (6)) procedure (enum-set-universe (enum-set enum-set)) ⟹ enum-set

    Returns the set of all symbols that comprise the universe of its argument, as an enumeration set.

    (rnrs enums (6)) procedure (enum-set-indexer (enum-set enum-set)) ⟹ procedure?

    (return (el symbol?)) ⟹ #f | integer?

    Returns a unary procedure that, given a symbol that is in the universe of enum-set, returns its 0-origin index within the canonical ordering of the symbols in the universe; given a value not in the universe, the unary procedure returns #f.

    (rnrs enums (6)) procedure (enum-set-constructor (enum-set enum-set)) ⟹ procedure?

    (rnrs enums (6)) procedure (enum-set-constructor (enum-set enum-set)) ⟹ procedure?

    (return (elements list?)) ⟹ enum-set

    Returns a unary procedure that, given a list of symbols that belong to the universe of enum-set, returns a subset of that universe that contains exactly the symbols in the list. The values in the list must all belong to the universe.

    (rnrs enums (6)) procedure (enum-set->list (enum-set enum-set)) ⟹ list?

    Returns a list of the symbols that belong to its argument, in the canonical order of the universe of enum-set.

    (rnrs enums (6)) procedure (enum-set-member? (element symbol?) (enum-set enum-set)) ⟹ boolean?

    The enum-set-member? procedure returns #t if its first argument is an element of its second argument, #f otherwise.

    (rnrs enums (6)) procedure (enum-set-subset? (set1 enum-set) (set2 enum-set)) ⟹ boolean?

    The enum-set-subset? procedure returns #t if the universe of enum-set1 is a subset of the universe of enum-set2 (considered as sets of symbols) and every element of enum-set1 is a member of enum-set2. It returns #f otherwise.

    (rnrs enums (6)) procedure (enum-set=? (set1 enum-set) (set2 enum-set)) ⟹ boolean?

    The enum-set=? procedure returns #t if enum-set1 is a subset of enum-set2 and vice versa, as determined by the enum-set-subset? procedure. This implies that the universes of the two sets are equal as sets of symbols, but does not imply that they are equal as enumeration types. Otherwise, #f is returned.

    (rnrs enums (6)) procedure (enum-set-union (set1 enum-set) (set2 enum-set)) ⟹ enum-set

    The enum-set-union procedure returns the union of enum-set1 and enum-set2.

    (rnrs enums (6)) procedure (enum-set-intersection (set1 enum-set) (set2 enum-set)) ⟹ enum-set

    The enum-set-intersection procedure returns the intersection of enum-set1 and enum-set2.

    (rnrs enums (6)) procedure (enum-set-difference (set1 enum-set) (set2 enum-set)) ⟹ enum-set

    The enum-set-difference procedure returns the difference of enum-set1 and enum-set2.

    (rnrs enums (6)) procedure (enum-set-complement (set enum-set)) ⟹ enum-set

    Returns enum-set's complement with respect to its universe.

    (rnrs enums (6)) procedure (enum-set-projection (set1 enum-set) (set2 enum-set)) ⟹ enum-set

    Projects enum-set1 into the universe of enum-set2, dropping any elements of enum-set1 that do not belong to the universe of enum-set2. (If enum-set1 is a subset of the universe of its second, no elements are dropped, and the injection is returned.)

    (rnrs enums (6)) syntax (define-enumeration type-name (symbol ...) constructor-syntax)

    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 <definition> can appear. <Type-name> is an identifier that is bound as a syntactic keyword; <symbol> ... are the symbols that comprise the universe of the enumeration (in order). (<type-name> <symbol>) checks at macro-expansion time whether the name of <symbol> is in the universe associated with <type-name>. If it is, (<type-name> <symbol>) is equivalent to <symbol>. It is a syntax violation if it is not. <Constructor-syntax> is an identifier that is bound to a macro that, given any finite sequence of the symbols in the universe, possibly with duplicates, expands into an expression that evaluates to the enumeration set of those symbols. (<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. Otherwise (<constructor-syntax> <symbol> ...) is equivalent to ((enum-set-constructor (<constructor-syntax>)) '(<symbol> ...)).

    library (rnrs eval (6))

    (rnrs eval (6)) procedure (environment (list1 list?) ...) ⟹ environment

    This procedure returns a specifier for the environment that results by starting with an empty environment and then importing each list, considered as an import set, into it. (See section 5.6 for a description of import sets.) The bindings of the environment represented by the specifier are immutable, as is the environment itself.

    (rnrs eval (6)) procedure (eval expr-or-def (environment-specifier environment)) ⟹ *

    If expr-or-def is an expression, it is evaluated in the specified environment and its values are returned. If it is a definition, the specified identifier(s) are defined in the specified environment, provided the environment is not immutable. Implementations may extend eval to allow other objects.

    library (rnrs exceptions (6))

    (rnrs exceptions (6)) procedure (with-exception-handler (handler procedure?) (thunk procedure?)) ⟹ *

    (handler obj) ⟹ *

    (thunk) ⟹ *

    Handler must be a procedure and should accept one argument. Thunk must be a procedure that accepts zero arguments. The with-exception-handler procedure returns the results of invoking thunk. Handler is installed as the current exception handler for the dynamic extent (as determined by dynamic-wind) of the invocation of thunk.

    Implementation responsibilities: The implementation must check the restrictions on handler to the extent performed by applying it as described when it is called as a result of a call to raise or raise-continuable. An implementation may check whether handler is an appropriate argument before applying it.

    (rnrs exceptions (6)) syntax (guard (variable cond-clause1 cond-clause2 ...) body)

    cond-clause ⟹ (test expression1 ...) | (test => expression) | (else expression1 expression2 ...)

    Evaluating a guard form evaluates <body> with an exception handler that binds the raised object to <variable> and within the scope of that binding evaluates the clauses as if they were the clauses of a cond expression. That implicit cond expression is evaluated with the continuation and dynamic environment of the guard expression. If every <cond clause>'s <test> evaluates to #f and there is no else clause, then raise is re-invoked on the raised object within the dynamic environment of the original call to raise except that the current exception handler is that of the guard expression. The final expression in a <cond> clause is in a tail context if the guard expression itself is.

    (rnrs exceptions (6)) procedure (raise obj) ⟹ undefined

    Raises a non-continuable exception by invoking the current exception handler on obj. The handler is called with a continuation whose dynamic environment is that of the call to raise, except that the current exception handler is the one that was in place when the handler being called was installed. When the handler returns, a non-continuable exception with condition type &non-continuable is raised in the same dynamic environment as the handler.

    (rnrs exceptions (6)) procedure (raise-continuable obj) ⟹ undefined

    Raises a continuable exception by invoking the current exception handler on obj. The handler is called with a continuation that is equivalent to the continuation of the call to raise-continuable, with these two exceptions: (1) the current exception handler is the one that was in place when the handler being called was installed, and (2) if the handler being called returns, then it will again become the current exception handler. If the handler returns, the values it returns become the values returned by the call to raise-continuable.

    library (rnrs files (6))

    (rnrs files (6)) procedure (file-exists? (filename string?)) ⟹ boolean?

    Filename must be a file name (see section 8.2.1). The file-exists? procedure returns #t if the named file exists at the time the procedure is called, #f otherwise.

    (rnrs files (6)) procedure (delete-file (filename string?)) ⟹ undefined

    Filename must be a file name (see section 8.2.1). The delete-file procedure deletes the named file if it exists and can be deleted, and returns unspecified values. If the file does not exist or cannot be deleted, an exception with condition type &i/o-filename is raised.

    (rnrs files (6)) value &i/o ⟹ record-type-descriptor?

    (rnrs files (6)) procedure (make-i/o-error) ⟹ i/o-error?

    (rnrs files (6)) procedure (i/o-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o &error

    make-i/o-error i/o-error?)

    This is a supertype for a set of more specific I/O errors.

    (rnrs files (6)) value &i/o-read ⟹ record-type-descriptor?

    (rnrs files (6)) procedure (make-i/o-read-error) ⟹ i/o-read-error?

    (rnrs files (6)) procedure (i/o-read-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-read &i/o

    make-i/o-read-error i/o-read-error?)

    This condition type describes read errors that occurred during an I/O operation.

    (rnrs files (6)) value &i/o-write ⟹ record-type-descriptor?

    (rnrs files (6)) procedure (make-i/o-write-error) ⟹ i/o-write-error?

    (rnrs files (6)) procedure (i/o-write-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-write &i/o

    make-i/o-write-error i/o-write-error?)

    This condition type describes write errors that occurred during an I/O operation.

    (rnrs files (6)) value &i/o-invalid-position ⟹ record-type-descriptor?

    (rnrs files (6)) procedure (make-i/o-invalid-position-error position) ⟹ i/o-invalid-position-error?

    (rnrs files (6)) procedure (i/o-invalid-position-error? obj) ⟹ boolean?

    (rnrs files (6)) procedure (i/o-error-position (condition i/o-invalid-position-error?)) ⟹ *

    This condition type could be defined by

    (define-condition-type &i/o-invalid-position &i/o

    make-i/o-invalid-position-error

    i/o-invalid-position-error?

    (position i/o-error-position))

    This condition type describes attempts to set the file position to an invalid position. Position should be the file position that the program intended to set. This condition describes a range error, but not an assertion violation.

    (rnrs files (6)) value &i/o-filename ⟹ record-type-descriptor?

    (rnrs files (6)) procedure (make-i/o-filename-error filename) ⟹ i/o-filename-error?

    (rnrs files (6)) procedure (i/o-filename-error? obj) ⟹ boolean?

    (rnrs files (6)) procedure (i/o-error-filename (condition i/o-filename-error?)) ⟹ *

    This condition type could be defined by

    (define-condition-type &i/o-filename &i/o

    make-i/o-filename-error i/o-filename-error?

    (filename i/o-error-filename))

    This condition type describes an I/O error that occurred during an operation on a named file. Filename should be the name of the file.

    (rnrs files (6)) value &i/o-file-protection ⟹ record-type-descriptor?

    (rnrs files (6)) procedure (make-i/o-file-protection-error file) ⟹ i/o-file-protection-error?

    (rnrs files (6)) procedure (i/o-file-protection-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-file-protection

    &i/o-filename

    make-i/o-file-protection-error

    i/o-file-protection-error?)

    A condition of this type specifies that an operation tried to operate on a named file with insufficient access rights.

    (rnrs files (6)) value &i/o-file-is-read-only ⟹ record-type-descriptor?

    (rnrs files (6)) procedure (make-i/o-file-is-read-only-error file) ⟹ i/o-file-is-read-only-error?

    (rnrs files (6)) procedure (i/o-file-is-read-only-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-file-is-read-only

    &i/o-file-protection

    make-i/o-file-is-read-only-error

    i/o-file-is-read-only-error?)

    A condition of this type specifies that an operation tried to operate on a named read-only file under the assumption that it is writeable.

    (rnrs files (6)) value &i/o-file-already-exists ⟹ record-type-descriptor?

    (rnrs files (6)) procedure (make-i/o-file-already-exists-error file) ⟹ i/o-file-already-exists-error?

    (rnrs files (6)) procedure (i/o-file-already-exists-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-file-already-exists

    &i/o-filename

    make-i/o-file-already-exists-error

    i/o-file-already-exists-error?)

    A condition of this type specifies that an operation tried to operate on an existing named file under the assumption that it did not exist.

    (rnrs files (6)) value &i/o-file-does-not-exist ⟹ record-type-descriptor?

    (rnrs files (6)) procedure (make-i/o-file-does-not-exist-error file) ⟹ i/o-file-does-not-exist-error?

    (rnrs files (6)) procedure (i/o-file-does-not-exist-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-file-does-not-exist

    &i/o-filename

    make-i/o-file-does-not-exist-error

    i/o-file-does-not-exist-error?)

    A condition of this type specifies that an operation tried to operate on an non-existent named file under the assumption that it existed.

    (rnrs files (6)) value &i/o-port ⟹ record-type-descriptor?

    (rnrs files (6)) procedure (make-i/o-port-error (port port?)) ⟹ i/o-port-error?

    (rnrs files (6)) procedure (i/o-port-error? obj) ⟹ boolean?

    (rnrs files (6)) procedure (i/o-error-port (condition i/o-port-error?)) ⟹ port?

    This condition type could be defined by

    (define-condition-type &i/o-port &i/o

    make-i/o-port-error i/o-port-error?

    (port i/o-error-port))

    This condition type specifies the port with which an I/O error is associated. Port should be the port. Conditions raised by procedures accepting a port as an argument should include an &i/o-port-error condition.

    library (rnrs hashtables (6))

    (rnrs hashtables (6)) procedure (make-eq-hashtable ) ⟹ hashtable?

    (rnrs hashtables (6)) procedure (make-eq-hashtable (k integer?)) ⟹ hashtable?

    Returns a newly allocated mutable hashtable that accepts arbitrary objects as keys, and compares those keys with eq?. If an argument is given, the initial capacity of the hashtable is set to approximately k elements.

    (rnrs hashtables (6)) procedure (make-eqv-hashtable ) ⟹ hashtable?

    (rnrs hashtables (6)) procedure (make-eqv-hashtable (k integer?)) ⟹ hashtable?

    Returns a newly allocated mutable hashtable that accepts arbitrary objects as keys, and compares those keys with eqv?. If an argument is given, the initial capacity of the hashtable is set to approximately k elements.

    (rnrs hashtables (6)) procedure (make-hashtable (hash-function procedure?) (equiv procedure?)) ⟹ hashtable?

    (rnrs hashtables (6)) procedure (make-hashtable (hash-function procedure?) (equiv procedure?) (k integer?)) ⟹ hashtable?

    (hash-function key) ⟹ integer?

    (equiv a b) ⟹ boolean?

    Hash-function and equiv must be procedures. Hash-function should accept a key as an argument and should return a non-negative exact integer object. Equiv should accept two keys as arguments and return a single value. Neither procedure should mutate the hashtable returned by make-hashtable. The make-hashtable procedure returns a newly allocated mutable hashtable using hash-function as the hash function and equiv as the equivalence function used to compare keys. If a third argument is given, the initial capacity of the hashtable is set to approximately k elements. Both hash-function and equiv should behave like pure functions on the domain of keys. For example, the string-hash and string=? procedures are permissible only if all keys are strings and the contents of those strings are never changed so long as any of them continues to serve as a key in the hashtable. Furthermore, any pair of keys for which equiv returns true should be hashed to the same exact integer objects by hash-function.

    Implementation responsibilities: The implementation must check the restrictions on hash-function and equiv to the extent performed by applying them as described.

    Note: Hashtables are allowed to cache the results of calling the hash function and equivalence function, so programs cannot rely on the hash function being called for every lookup or update. Furthermore any hashtable operation may call the hash function more than once.

    (rnrs hashtables (6)) procedure (hashtable? obj) ⟹ boolean?

    Returns #t if obj is a hashtable, #f otherwise.

    (rnrs hashtables (6)) procedure (hashtable-size (hashtable hashtable?)) ⟹ integer?

    Returns the number of keys contained in hashtable as an exact integer object.

    (rnrs hashtables (6)) procedure (hashtable-ref (hashtable hashtable?) key default) ⟹ *

    Returns the value in hashtable associated with key. If hashtable does not contain an association for key, default is returned.

    (rnrs hashtables (6)) procedure (hashtable-set! (hashtable hashtable?) key obj) ⟹ undefined

    Changes hashtable to associate key with obj, adding a new association or replacing any existing association for key, and returns unspecified values.

    (rnrs hashtables (6)) procedure (hashtable-delete! (hashtable hashtable?) key) ⟹ undefined

    Removes any association for key within hashtable and returns unspecified values.

    (rnrs hashtables (6)) procedure (hashtable-contains? (hashtable hashtable?) key) ⟹ boolean?

    Returns #t if hashtable contains an association for key, #f otherwise.

    (rnrs hashtables (6)) procedure (hashtable-update! (hashtable hashtable?) key (proc procedure?) default) ⟹ boolean?

    (proc value) ⟹ *

    Proc should accept one argument, should return a single value, and should not mutate hashtable. The hashtable-update! procedure applies proc to the value in hashtable associated with key, or to default if hashtable does not contain an association for key. The hashtable is then changed to associate key with the value returned by proc.

    (rnrs hashtables (6)) procedure (hashtable-copy (hashtable hashtable?)) ⟹ hashtable?

    (rnrs hashtables (6)) procedure (hashtable-copy (hashtable hashtable?) (mutable boolean?)) ⟹ hashtable?

    Returns a copy of hashtable. If the mutable argument is provided and is true, the returned hashtable is mutable; otherwise it is immutable.

    (rnrs hashtables (6)) procedure (hashtable-clear! (hashtable hashtable?)) ⟹ undefined

    (rnrs hashtables (6)) procedure (hashtable-clear! (hashtable hashtable?) (k integer?)) ⟹ undefined

    Removes all associations from hashtable and returns unspecified values.

    (rnrs hashtables (6)) procedure (hashtable-keys (hashtable hashtable?)) ⟹ vector?

    Returns a vector of all keys in hashtable. The order of the vector is unspecified.

    (rnrs hashtables (6)) procedure (hashtable-entries (hashtable hashtable?)) ⟹ (values vector? vector?)

    Returns two values, a vector of the keys in hashtable, and a vector of the corresponding values.

    (rnrs hashtables (6)) procedure (hashtable-equivalence-function (hashtable hashtable?)) ⟹ procedure?

    (return a b) ⟹ boolean?

    Returns the equivalence function used by hashtable to compare keys. For hashtables created with make-eq-hashtable and make-eqv-hashtable, returns eq? and eqv? respectively.

    (rnrs hashtables (6)) procedure (hashtable-hash-function (hashtable hashtable?)) ⟹ procedure?

    (return key) ⟹ integer?

    Returns the hash function used by hashtable. For hashtables created by make-eq-hashtable or make-eqv-hashtable, #f is returned.

    (rnrs hashtables (6)) procedure (hashtable-mutable? (hashtable hashtable?)) ⟹ boolean?

    Returns #t if hashtable is mutable, otherwise #f.

    (rnrs hashtables (6)) procedure (equal-hash obj) ⟹ integer?

    Returns an integer hash value for obj, based on its structure and current contents. This hash function is suitable for use with equal? as an equivalence function.

    Note: Like equal?, the equal-hash procedure must always terminate, even if its arguments contain cycles.

    (rnrs hashtables (6)) procedure (string-hash (string string?)) ⟹ integer?

    Returns an integer hash value for string, based on its current contents. This hash function is suitable for use with string=? as an equivalence function.

    (rnrs hashtables (6)) procedure (string-ci-hash (string string?)) ⟹ integer?

    Returns an integer hash value for string based on its current contents, ignoring case. This hash function is suitable for use with string-ci=? as an equivalence function.

    (rnrs hashtables (6)) procedure (symbol-hash (symbol symbol?)) ⟹ integer?

    Returns an integer hash value for symbol.

    library (rnrs io ports (6))

    (rnrs io ports (6)) syntax (file-options file-options-symbol ...)⟹ return

    Each <file-options symbol> must be a symbol. The file-options syntax returns a file-options object that encapsulates the specified options.

    When supplied to an operation that opens a file for output, the file-options object returned by (file-options) specifies that the file is created if it does not exist and an exception with condition type &i/o-file-already-exists is raised if it does exist. The following standard options can be included to modify the default behavior.

    no-create: If the file does not already exist, it is not created; instead, an exception with condition type &i/o-file-does-not-exist is raised. If the file already exists, the exception with condition type &i/o-file-already-exists is not raised and the file is truncated to zero length.

    no-fail: If the file already exists, the exception with condition type &i/o-file-already-exists is not raised, even if no-create is not included, and the file is truncated to zero length.

    no-truncate: If the file already exists and the exception with condition type &i/o-file-already-exists has been inhibited by inclusion of no-create or no-fail, the file is not truncated, but the port's current position is still set to the beginning of the file.

    These options have no effect when a file is opened only for input. Symbols other than those listed above may be used as <file-options symbol>s; they have implementation-specific meaning, if any.

    (rnrs io ports (6)) syntax (buffer-mode buffer-mode-symbol)⟹ return

    <Buffer-mode symbol> must be a symbol whose name is one of none, line, and block. The result is the corresponding symbol, and specifies the associated buffer mode.

    (rnrs io ports (6)) procedure (buffer-mode? obj) ⟹ boolean?

    Returns #t if the argument is a valid buffer-mode symbol, and returns #f otherwise.

    (rnrs io ports (6)) procedure (latin-1-codec) ⟹ codec

    (rnrs io ports (6)) procedure (utf-8-codec) ⟹ codec

    (rnrs io ports (6)) procedure (utf-16-codec) ⟹ codec

    These are predefined codecs for the ISO 8859-1, UTF-8, and UTF-16 encoding schemes.

    A call to any of these procedures returns a value that is equal in the sense of eqv? to the result of any other call to the same procedure.

    (rnrs io ports (6)) syntax (eol-style eol-style-symbol)⟹ return

    <Eol-style symbol> should be a symbol whose name is one of lf, cr, crlf, nel, crnel, ls, and none. The form evaluates to the corresponding symbol. If the name of eol-style symbol is not one of these symbols, the effect and result are implementation-dependent; in particular, the result may be an eol-style symbol acceptable as an eol-style argument to make-transcoder. Otherwise, an exception is raised. For a textual port with a transcoder, and whose transcoder has an eol-style symbol none, no conversion occurs. For a textual input port, any eol-style symbol other than none means that all of the above line-ending encodings are recognized and are translated into a single linefeed. For a textual output port, none and lf are equivalent. Linefeed characters are encoded according to the specified eol-style symbol, and all other characters that participate in possible line endings are encoded as is.

    (rnrs io ports (6)) procedure (native-eol-style) ⟹ symbol?

    Returns the default end-of-line style of the underlying platform, e.g., lf on Unix and crlf on Windows.

    (rnrs io ports (6)) value &i/o-decoding ⟹ record-type-descriptor?

    (rnrs io ports (6)) procedure (make-i/o-decoding-error (port port?)) ⟹ i/o-decoding-error?

    (rnrs io ports (6)) procedure (i/o-decoding-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-decoding &i/o-port

    make-i/o-decoding-error i/o-decoding-error?)

    An exception with this type is raised when one of the operations for textual input from a port encounters a sequence of bytes that cannot be translated into a character or string by the input direction of the port's transcoder. When such an exception is raised, the port's position is past the invalid encoding.

    (rnrs io ports (6)) value &i/o-encoding ⟹ record-type-descriptor?

    (rnrs io ports (6)) procedure (make-i/o-encoding-error (port port?) (char char?)) ⟹ i/o-encoding-error?

    (rnrs io ports (6)) procedure (i/o-encoding-error? obj) ⟹ boolean?

    (rnrs io ports (6)) procedure (i/o-encoding-error-char (condition i/o-encoding-error?)) ⟹ char?

    This condition type could be defined by

    (define-condition-type &i/o-encoding &i/o-port

    make-i/o-encoding-error i/o-encoding-error?

    (char i/o-encoding-error-char))

    An exception with this type is raised when one of the operations for textual output to a port encounters a character that cannot be translated into bytes by the output direction of the port's transcoder. Char is the character that could not be encoded.

    (rnrs io ports (6)) syntax (error-handling-mode error-handling-mode-symbol)⟹ return

    <Error-handling-mode symbol> should be a symbol whose name is one of ignore, raise, and replace. The form evaluates to the corresponding symbol. If error-handling-mode symbol is not one of these identifiers, effect and result are implementation-dependent: The result may be an error-handling-mode symbol acceptable as a handling-mode argument to make-transcoder. If it is not acceptable as a handling-mode argument to make-transcoder, an exception is raised.

    The error-handling mode of a transcoder specifies the behavior of textual I/O operations in the presence of encoding or decoding errors.

    If a textual input operation encounters an invalid or incomplete character encoding, and the error-handling mode is ignore, an appropriate number of bytes of the invalid encoding are ignored and decoding continues with the following bytes. If the error-handling mode is replace, the replacement character U+FFFD is injected into the data stream, an appropriate number of bytes are ignored, and decoding continues with the following bytes. If the error-handling mode is raise, an exception with condition type &i/o-decoding is raised.

    If a textual output operation encounters a character it cannot encode, and the error-handling mode is ignore, the character is ignored and encoding continues with the next character. If the error-handling mode is replace, a codec-specific replacement character is emitted by the transcoder, and encoding continues with the next character. The replacement character is U+FFFD for transcoders whose codec is one of the Unicode encodings, but is the ? character for the Latin-1 encoding. If the error-handling mode is raise, an exception with condition type &i/o-encoding is raised.

    (rnrs io ports (6)) procedure (make-transcoder (codec codec)) ⟹ transcoder

    (rnrs io ports (6)) procedure (make-transcoder (codec codec) (eol-style symbol?)) ⟹ transcoder

    (rnrs io ports (6)) procedure (make-transcoder (codec codec) (eol-style symbol?) (handling-mode symbol?)) ⟹ transcoder

    Codec must be a codec; eol-style, if present, an eol-style symbol; and handling-mode, if present, an error-handling-mode symbol. Eol-style may be omitted, in which case it defaults to the native end-of-line style of the underlying platform. Handling-mode may be omitted, in which case it defaults to replace. The result is a transcoder with the behavior specified by its arguments.

    (rnrs io ports (6)) procedure (native-transcoder) ⟹ transcoder

    Returns an implementation-dependent transcoder that represents a possibly locale-dependent "native" transcoding.

    (rnrs io ports (6)) procedure (transcoder-codec (transcoder transcoder)) ⟹ codec

    (rnrs io ports (6)) procedure (transcoder-eol-style (transcoder transcoder)) ⟹ symbol?

    (rnrs io ports (6)) procedure (transcoder-error-handling-mode (transcoder transcoder)) ⟹ symbol?

    These are accessors for transcoder objects; when applied to a transcoder returned by make-transcoder, they return the codec, eol-style, and handling-mode arguments, respectively

    (rnrs io ports (6)) procedure (bytevector->string (bytevector bytevector?) (transcoder transcoder)) ⟹ string?

    Returns the string that results from transcoding the bytevector according to the input direction of the transcoder.

    (rnrs io ports (6)) procedure (string->bytevector (string string?) (transcoder transcoder)) ⟹ bytevector?

    Returns the bytevector that results from transcoding the string according to the output direction of the transcoder.

    (rnrs io ports (6)) procedure (eof-object) ⟹ eof-object?

    Returns the end-of-file object.

    (rnrs io ports (6)) procedure (eof-object? obj) ⟹ boolean?

    Returns #t if obj is the end-of-file object, #f otherwise.

    (rnrs io ports (6)) procedure (port? obj) ⟹ boolean?

    Returns #t if the argument is a port, and returns #f otherwise.

    (rnrs io ports (6)) procedure (port-transcoder (port port?)) ⟹ transcoder

    Returns the transcoder associated with port if port is textual and has an associated transcoder, and returns #f if port is binary or does not have an associated transcoder.

    (rnrs io ports (6)) procedure (textual-port? obj) ⟹ boolean?

    The textual-port? procedure returns #t if port is textual, and returns #f otherwise.

    (rnrs io ports (6)) procedure (binary-port? obj) ⟹ boolean?

    The binary-port? procedure returns #t if port is binary, and returns #f otherwise.

    (rnrs io ports (6)) procedure (transcoded-port (port binary-port?) (transcoder transcoder)) ⟹ textual-port?

    The transcoded-port procedure returns a new textual port with the specified transcoder. Otherwise the new textual port's state is largely the same as that of binary-port. If binary-port is an input port, the new textual port will be an input port and will transcode the bytes that have not yet been read from binary-port. If binary-port is an output port, the new textual port will be an output port and will transcode output characters into bytes that are written to the byte sink represented by binary-port.

    As a side effect, however, transcoded-port closes binary-port in a special way that allows the new textual port to continue to use the byte source or sink represented by binary-port, even though binary-port itself is closed and cannot be used by the input and output operations described in this chapter.

    (rnrs io ports (6)) procedure (port-has-port-position? (port port?)) ⟹ boolean?

    (rnrs io ports (6)) procedure (port-position (port binary-port?)) ⟹ integer?

    (rnrs io ports (6)) procedure (port-position (port textual-port?)) ⟹ opaque-port-position

    The port-has-port-position? procedure returns #t if the port supports the port-position operation, and #f otherwise.

    For a binary port, the port-position procedure returns the index of the position at which the next byte would be read from or written to the port as an exact non-negative integer object. For a textual port, port-position returns a value of some implementation-dependent type representing the port's position; this value may be useful only as the pos argument to set-port-position!, if the latter is supported on the port (see below).

    If the port does not support the operation, port-position raises an exception with condition type &assertion.

    (rnrs io ports (6)) procedure (port-has-set-port-position!? (port port?)) ⟹ boolean?

    (rnrs io ports (6)) procedure (set-port-position! (port binary-port?) (pos integer?)) ⟹ undefined

    (rnrs io ports (6)) procedure (set-port-position! (port textual-port?) (pos opaque-port-position)) ⟹ undefined

    If port is a binary port, pos should be a non-negative exact integer object. If port is a textual port, pos should be the return value of a call to port-position on port.

    The port-has-set-port-position!? procedure returns #t if the port supports the set-port-position! operation, and #f otherwise.

    The set-port-position! procedure raises an exception with condition type &assertion if the port does not support the operation, and an exception with condition type &i/o-invalid-position if pos is not in the range of valid positions of port. Otherwise, it sets the current position of the port to pos. If port is an output port, set-port-position! first flushes port. (See flush-output-port, section 8.2.10.)

    If port is a binary output port and the current position is set beyond the current end of the data in the underlying data sink, the object is not extended until new data is written at that position. The contents of any intervening positions are unspecified. Binary ports created by open-file-output-port and open-file-input/output-port can always be extended in this manner within the limits of the underlying operating system. In other cases, attempts to set the port beyond the current end of data in the underlying object may result in an exception with condition type &i/o-invalid-position.

    (rnrs io ports (6)) procedure (close-port (port port?)) ⟹ undefined

    Closes the port, rendering the port incapable of delivering or accepting data. If port is an output port, it is flushed before being closed. This has no effect if the port has already been closed. A closed port is still a port. The close-port procedure returns unspecified values.

    (rnrs io ports (6)) procedure (call-with-port (port port?) (proc procedure?)) ⟹ *

    (proc (port port?)) ⟹ *

    Proc must accept one argument. The call-with-port procedure calls proc with port as an argument. If proc returns, port is closed automatically and the values returned by proc are returned. If proc does not return, port is not closed automatically, except perhaps when it is possible to prove that port will never again be used for an input or output operation

    (rnrs io ports (6)) procedure (input-port? obj) ⟹ boolean?

    Returns #t if the argument is an input port (or a combined input and output port), and returns #f otherwise.

    (rnrs io ports (6)) procedure (port-eof? (port input-port?)) ⟹ boolean?

    Returns #t if the lookahead-u8 procedure (if input-port is a binary port) or the lookahead-char procedure (if input-port is a textual port) would return the end-of-file object, and #f otherwise. The operation may block indefinitely if no data is available but the port cannot be determined to be at end of file.

    (rnrs io ports (6)) procedure (open-file-input-port (string string?)) ⟹ input-port?

    (rnrs io ports (6)) procedure (open-file-input-port (string string?) (options file-options)) ⟹ input-port?

    (rnrs io ports (6)) procedure (open-file-input-port (string string?) (options file-options) (buffer-mode buffer-mode?)) ⟹ input-port?

    (rnrs io ports (6)) procedure (open-file-input-port (string string?) (options file-options) (buffer-mode buffer-mode?) (transcoder #f | transcoder)) ⟹ input-port?

    Maybe-transcoder must be either a transcoder or #f.

    The open-file-input-port procedure returns an input port for the named file. The file-options and maybe-transcoder arguments are optional.

    The file-options argument, which may determine various aspects of the returned port (see section 8.2.2), defaults to the value of (file-options).

    The buffer-mode argument, if supplied, must be one of the symbols that name a buffer mode. The buffer-mode argument defaults to block.

    If maybe-transcoder is a transcoder, it becomes the transcoder associated with the returned port.

    If maybe-transcoder is #f or absent, the port will be a binary port and will support the port-position and set-port-position! operations. Otherwise the port will be a textual port, and whether it supports the port-position and set-port-position! operations is implementation-dependent (and possibly transcoder-dependent).

    (rnrs io ports (6)) procedure (open-bytevector-input-port (bytevector bytevector?)) ⟹ input-port?

    (rnrs io ports (6)) procedure (open-bytevector-input-port (bytevector bytevector?) (transcoder #f | transcoder)) ⟹ input-port?

    Maybe-transcoder must be either a transcoder or #f.

    The open-bytevector-input-port procedure returns an input port whose bytes are drawn from bytevector. If transcoder is specified, it becomes the transcoder associated with the returned port.

    If maybe-transcoder is #f or absent, the port will be a binary port and will support the port-position and set-port-position! operations. Otherwise the port will be a textual port, and whether it supports the port-position and set-port-position! operations will be implementation-dependent (and possibly transcoder-dependent).

    If bytevector is modified after open-bytevector-input-port has been called, the effect on the returned port is unspecified.

    (rnrs io ports (6)) procedure (open-string-input-port (string string?)) ⟹ input-port?

    Returns a textual input port whose characters are drawn from string. The port may or may not have an associated transcoder; if it does, the transcoder is implementation-dependent. The port should support the port-position and set-port-position! operations. If string is modified after open-string-input-port has been called, the effect on the returned port is unspecified.

    (rnrs io ports (6)) procedure (standard-input-port) ⟹ binary-port?

    Returns a fresh binary input port connected to standard input. Whether the port supports the port-position and set-port-position! operations is implementation-dependent.

    (rnrs io ports (6)) procedure (current-input-port) ⟹ textual-port?

    This returns a default textual port for input. Normally, this default port is associated with standard input, but can be dynamically re-assigned using the with-input-from-file procedure from the (rnrs io simple (6)) library (see section 8.3). The port may or may not have an associated transcoder; if it does, the transcoder is implementation-dependent.

    (rnrs io ports (6)) procedure (make-custom-binary-input-port (id string?) (read! procedure?) (get-position #f | procedure?) (set-position! #f | procedure?) (close #f | procedure?)) ⟹ input-port?

    (read! (bytevector bytevector?) (start integer?) (count integer?)) ⟹ integer?

    (get-position) ⟹ integer?

    (set-position! (position integer?)) ⟹ undefined

    (close) ⟹ undefined

    Returns a newly created binary input port whose byte source is an arbitrary algorithm represented by the read! procedure. Id must be a string naming the new port, provided for informational purposes only. Read! must be a procedure and should behave as specified below; it will be called by operations that perform binary input.

    Each of the remaining arguments may be #f; if any of those arguments is not #f, it must be a procedure and should behave as specified below.

    (read! bytevector start count) Start will be a non-negative exact integer object, count will be a positive exact integer object, and bytevector will be a bytevector whose length is at least start + count. The read! procedure should obtain up to count bytes from the byte source, and should write those bytes into bytevector starting at index start. The read! procedure should return an exact integer object. This integer object should represent the number of bytes that it has read. To indicate an end of file, the read! procedure should write no bytes and return 0.

    (get-position) The get-position procedure (if supplied) should return an exact integer object representing the current position of the input port. If not supplied, the custom port will not support the port-position operation.

    (set-position! pos) Pos will be a non-negative exact integer object. The set-position! procedure (if supplied) should set the position of the input port to pos. If not supplied, the custom port will not support the set-port-position! operation.

    (close) The close procedure (if supplied) should perform any actions that are necessary when the input port is closed.

    (rnrs io ports (6)) procedure (make-custom-textual-input-port (id string?) (read! procedure?) (get-position #f | procedure?) (set-position! #f | procedure?) (close #f | procedure?)) ⟹ input-port?

    (read! (string string?) (start integer?) (count integer?)) ⟹ integer?

    (get-position) ⟹ opaque-port-position

    (set-position! (position opaque-port-position)) ⟹ undefined

    (close) ⟹ undefined

    Returns a newly created textual input port whose character source is an arbitrary algorithm represented by the read! procedure. Id must be a string naming the new port, provided for informational purposes only. Read! must be a procedure and should behave as specified below; it will be called by operations that perform textual input.

    Each of the remaining arguments may be #f; if any of those arguments is not #f, it must be a procedure and should behave as specified below.

    (read! string start count) Start will be a non-negative exact integer object, count will be a positive exact integer object, and string will be a string whose length is at least start + count. The read! procedure should obtain up to count characters from the character source, and should write those characters into string starting at index start. The read! procedure should return an exact integer object representing the number of characters that it has written. To indicate an end of file, the read! procedure should write no bytes and return 0.

    (get-position) The get-position procedure (if supplied) should return a single value. The return value should represent the current position of the input port. If not supplied, the custom port will not support the port-position operation.

    (set-position! pos) The set-position! procedure (if supplied) should set the position of the input port to pos if pos is the return value of a call to get-position. If not supplied, the custom port will not support the set-port-position! operation.

    (close) The close procedure (if supplied) should perform any actions that are necessary when the input port is closed.

    The port may or may not have an an associated transcoder; if it does, the transcoder is implementation-dependent.

    (rnrs io ports (6)) procedure (get-u8 (input-port input-port?)) ⟹ eof-object? | integer?

    Reads from binary-input-port, blocking as necessary, until a byte is available from binary-input-port or until an end of file is reached. If a byte becomes available, get-u8 returns the byte as an octet and updates binary-input-port to point just past that byte. If no input byte is seen before an end of file is reached, the end-of-file object is returned.

    (rnrs io ports (6)) procedure (lookahead-u8 (input-port input-port?)) ⟹ eof-object? | integer?

    The lookahead-u8 procedure is like get-u8, but it does not update binary-input-port to point past the byte.

    (rnrs io ports (6)) procedure (get-bytevector-n (input-port input-port?) (count integer?)) ⟹ eof-object? | bytevector?

    Count must be an exact, non-negative integer object representing the number of bytes to be read. The get-bytevector-n procedure reads from binary-input-port, blocking as necessary, until count bytes are available from binary-input-port or until an end of file is reached. If count bytes are available before an end of file, get-bytevector-n returns a bytevector of size count. If fewer bytes are available before an end of file, get-bytevector-n returns a bytevector containing those bytes. In either case, the input port is updated to point just past the bytes read. If an end of file is reached before any bytes are available, get-bytevector-n returns the end-of-file object.

    (rnrs io ports (6)) procedure (get-bytevector-n! (input-port input-port?) (bytevector bytevector?) (start integer?) (count integer?)) ⟹ integer? | eof-object?

    Count must be an exact, non-negative integer object, representing the number of bytes to be read. bytevector must be a bytevector with at least start + count elements.

    The get-bytevector-n! procedure reads from binary-input-port, blocking as necessary, until count bytes are available from binary-input-port or until an end of file is reached. If count bytes are available before an end of file, they are written into bytevector starting at index start, and the result is count. If fewer bytes are available before the next end of file, the available bytes are written into bytevector starting at index start, and the result is a number object representing the number of bytes actually read. In either case, the input port is updated to point just past the bytes read. If an end of file is reached before any bytes are available, get-bytevector-n! returns the end-of-file object.

    (rnrs io ports (6)) procedure (get-bytevector-some (input-port input-port?)) ⟹ bytevector? | eof-object?

    Reads from binary-input-port, blocking as necessary, until bytes are available from binary-input-port or until an end of file is reached. If bytes become available, get-bytevector-some returns a freshly allocated bytevector containing the initial available bytes (at least one), and it updates binary-input-port to point just past these bytes. If no input bytes are seen before an end of file is reached, the end-of-file object is returned.

    (rnrs io ports (6)) procedure (get-bytevector-all (input-port input-port?)) ⟹ bytevector? | eof-object?

    Attempts to read all bytes until the next end of file, blocking as necessary. If one or more bytes are read, get-bytevector-all returns a bytevector containing all bytes up to the next end of file. Otherwise, get-bytevector-all returns the end-of-file object. The operation may block indefinitely waiting to see if more bytes will become available, even if some bytes are already available.

    (rnrs io ports (6)) procedure (get-char (input-port input-port?)) ⟹ eof-object? | char?

    Reads from textual-input-port, blocking as necessary, until a complete character is available from textual-input-port, or until an end of file is reached.

    If a complete character is available before the next end of file, get-char returns that character and updates the input port to point past the character. If an end of file is reached before any character is read, get-char returns the end-of-file object.

    (rnrs io ports (6)) procedure (lookahead-char (input-port input-port?)) ⟹ eof-object? | char?

    The lookahead-char procedure is like get-char, but it does not update textual-input-port to point past the character.

    (rnrs io ports (6)) procedure (get-string-n (input-port input-port?) (count integer?)) ⟹ eof-object? | string?

    Count must be an exact, non-negative integer object, representing the number of characters to be read.

    The get-string-n procedure reads from textual-input-port, blocking as necessary, until count characters are available, or until an end of file is reached.

    If count characters are available before end of file, get-string-n returns a string consisting of those count characters. If fewer characters are available before an end of file, but one or more characters can be read, get-string-n returns a string containing those characters. In either case, the input port is updated to point just past the characters read. If no characters can be read before an end of file, the end-of-file object is returned.

    (rnrs io ports (6)) procedure (get-string-n! (input-port input-port?) (string string?) (start integer?) (count integer?)) ⟹ eof-object? | integer?

    Start and count must be exact, non-negative integer objects, with count representing the number of characters to be read. String must be a string with at least start + count characters.

    The get-string-n! procedure reads from textual-input-port in the same manner as get-string-n. If count characters are available before an end of file, they are written into string starting at index start, and count is returned. If fewer characters are available before an end of file, but one or more can be read, those characters are written into string starting at index start and the number of characters actually read is returned as an exact integer object. If no characters can be read before an end of file, the end-of-file object is returned.

    (rnrs io ports (6)) procedure (get-string-all (input-port input-port?)) ⟹ eof-object? | string?

    Reads from textual-input-port until an end of file, decoding characters in the same manner as get-string-n and get-string-n!. If characters are available before the end of file, a string containing all the characters decoded from that data are returned. If no character precedes the end of file, the end-of-file object is returned.

    (rnrs io ports (6)) procedure (get-line (input-port input-port?)) ⟹ eof-object? | string?

    Reads from textual-input-port up to and including the linefeed character or end of file, decoding characters in the same manner as get-string-n and get-string-n!.

    If a linefeed character is read, a string containing all of the text up to (but not including) the linefeed character is returned, and the port is updated to point just past the linefeed character. If an end of file is encountered before any linefeed character is read, but some characters have been read and decoded as characters, a string containing those characters is returned. If an end of file is encountered before any characters are read, the end-of-file object is returned.

    (rnrs io ports (6)) procedure (get-datum (input-port input-port?)) ⟹ *

    Reads an external representation from textual-input-port and returns the datum it represents. The get-datum procedure returns the next datum that can be parsed from the given textual-input-port, updating textual-input-port to point exactly past the end of the external representation of the object.

    Any <interlexeme space> (see report section on “Lexical syntax”) in the input is first skipped. If an end of file occurs after the <interlexeme space>, the end-of-file object (see section 8.2.5) is returned.

    If a character inconsistent with an external representation is encountered in the input, an exception with condition types &lexical and &i/o-read is raised. Also, if the end of file is encountered after the beginning of an external representation, but the external representation is incomplete and therefore cannot be parsed, an exception with condition types &lexical and &i/o-read is raised.

    (rnrs io ports (6)) procedure (output-port? obj) ⟹ boolean?

    Returns #t if the argument is an output port (or a combined input and output port), #f otherwise.

    (rnrs io ports (6)) procedure (flush-output-port (port output-port?)) ⟹ undefined

    Flushes any buffered output from the buffer of output-port to the underlying file, device, or object. The flush-output-port procedure returns unspecified values.

    (rnrs io ports (6)) procedure (output-port-buffer-mode (port output-port?)) ⟹ buffer-mode?

    Returns the symbol that represents the buffer mode of output-port.

    (rnrs io ports (6)) procedure (open-file-output-port (filename string?)) ⟹ output-port?

    (rnrs io ports (6)) procedure (open-file-output-port (filename string?) (file-options file-options)) ⟹ output-port?

    (rnrs io ports (6)) procedure (open-file-output-port (filename string?) (file-options file-options) (buffer-mode buffer-mode?)) ⟹ output-port?

    (rnrs io ports (6)) procedure (open-file-output-port (filename string?) (file-options file-options) (buffer-mode buffer-mode?) (maybe-transcoder transcoder | #f)) ⟹ output-port?

    Maybe-transcoder must be either a transcoder or #f.

    The open-file-output-port procedure returns an output port for the named file.

    The file-options argument, which may determine various aspects of the returned port (see section 8.2.2), defaults to the value of (file-options).

    The buffer-mode argument, if supplied, must be one of the symbols that name a buffer mode. The buffer-mode argument defaults to block.

    If maybe-transcoder is a transcoder, it becomes the transcoder associated with the port.

    If maybe-transcoder is #f or absent, the port will be a binary port and will support the port-position and set-port-position! operations. Otherwise the port will be a textual port, and whether it supports the port-position and set-port-position! operations is implementation-dependent (and possibly transcoder-dependent).

    (rnrs io ports (6)) procedure (open-bytevector-output-port ) ⟹ (values output-port? procedure?)

    (rnrs io ports (6)) procedure (open-bytevector-output-port (maybe-transcoder #f | transcoder)) ⟹ (values output-port? procedure?)

    (return) ⟹ bytevector?

    Maybe-transcoder must be either a transcoder or #f.

    The open-bytevector-output-port procedure returns two values: an output port and an extraction procedure. The output port accumulates the bytes written to it for later extraction by the procedure.

    If maybe-transcoder is a transcoder, it becomes the transcoder associated with the port. If maybe-transcoder is #f or absent, the port will be a binary port and will support the port-position and set-port-position! operations. Otherwise the port will be a textual port, and whether it supports the port-position and set-port-position! operations is implementation-dependent (and possibly transcoder-dependent).

    The extraction procedure takes no arguments. When called, it returns a bytevector consisting of all the port's accumulated bytes (regardless of the port's current position), removes the accumulated bytes from the port, and resets the port's position.

    (rnrs io ports (6)) procedure (call-with-bytevector-output-port (proc procedure?)) ⟹ bytevector?

    (rnrs io ports (6)) procedure (call-with-bytevector-output-port (proc procedure?) (maybe-transcoder #f | transcoder)) ⟹ bytevector?

    (proc (port output-port?)) ⟹ *

    Proc must accept one argument. Maybe-transcoder must be either a transcoder or #f.

    The call-with-bytevector-output-port procedure creates an output port that accumulates the bytes written to it and calls proc with that output port as an argument. Whenever proc returns, a bytevector consisting of all of the port's accumulated bytes (regardless of the port's current position) is returned and the port is closed.

    The transcoder associated with the output port is determined as for a call to open-bytevector-output-port.

    (rnrs io ports (6)) procedure (open-string-output-port) ⟹ (values output-port? procedure?)

    (return) ⟹ string?

    Returns two values: a textual output port and an extraction procedure. The output port accumulates the characters written to it for later extraction by the procedure.

    The port may or may not have an associated transcoder; if it does, the transcoder is implementation-dependent. The port should support the port-position and set-port-position! operations.

    The extraction procedure takes no arguments. When called, it returns a string consisting of all of the port's accumulated characters (regardless of the current position), removes the accumulated characters from the port, and resets the port's position.

    (rnrs io ports (6)) procedure (call-with-string-output-port (proc procedure?)) ⟹ string?

    (proc (port output-port?)) ⟹ *

    Proc must accept one argument. The call-with-string-output-port procedure creates a textual output port that accumulates the characters written to it and calls proc with that output port as an argument. Whenever proc returns, a string consisting of all of the port's accumulated characters (regardless of the port's current position) is returned and the port is closed.

    The port may or may not have an associated transcoder; if it does, the transcoder is implementation-dependent. The port should support the port-position and set-port-position! operations.

    (rnrs io ports (6)) procedure (standard-output-port) ⟹ output-port?

    (rnrs io ports (6)) procedure (standard-error-port) ⟹ output-port?

    Returns a fresh binary output port connected to the standard output or standard error respectively. Whether the port supports the port-position and set-port-position! operations is implementation-dependent.

    (rnrs io ports (6)) procedure (current-output-port) ⟹ output-port?

    (rnrs io ports (6)) procedure (current-error-port) ⟹ output-port?

    These return default textual ports for regular output and error output. Normally, these default ports are associated with standard output, and standard error, respectively. The return value of current-output-port can be dynamically re-assigned using the with-output-to-file procedure from the (rnrs io simple (6)) library (see section 8.3). A port returned by one of these procedures may or may not have an associated transcoder; if it does, the transcoder is implementation-dependent.

    (rnrs io ports (6)) procedure (make-custom-binary-output-port (id string?) (write! procedure?) (get-position #f | procedure?) (set-position! #f | procedure?) (close #f | procedure?)) ⟹ output-port?

    (write! (bytevector bytevector?) (start integer?) (count integer?)) ⟹ integer?

    (get-position) ⟹ integer?

    (set-position! (position integer?)) ⟹ undefined

    (close) ⟹ undefined

    Returns a newly created binary output port whose byte sink is an arbitrary algorithm represented by the write! procedure. Id must be a string naming the new port, provided for informational purposes only. Write! must be a procedure and should behave as specified below; it will be called by operations that perform binary output.

    Each of the remaining arguments may be #f; if any of those arguments is not #f, it must be a procedure and should behave as specified in the description of make-custom-binary-input-port.

    (write! bytevector start count) Start and count will be non-negative exact integer objects, and bytevector will be a bytevector whose length is at least start + count. The write! procedure should write up to count bytes from bytevector starting at index start to the byte sink. If count is 0, the write! procedure should have the effect of passing an end-of-file object to the byte sink. In any case, the write! procedure should return the number of bytes that it wrote, as an exact integer object.

    (rnrs io ports (6)) procedure (make-custom-textual-output-port (id string?) (write! procedure?) (get-position #f | procedure?) (set-position! #f | procedure?) (close #f | procedure?)) ⟹ output-port?

    (write! (string string?) (start integer?) (count integer?)) ⟹ integer?

    (get-position) ⟹ integer?

    (set-position! (position integer?)) ⟹ undefined

    (close) ⟹ undefined

    Returns a newly created textual output port whose byte sink is an arbitrary algorithm represented by the write! procedure. Id must be a string naming the new port, provided for informational purposes only. Write! must be a procedure and should behave as specified below; it will be called by operations that perform textual output.

    Each of the remaining arguments may be #f; if any of those arguments is not #f, it must be a procedure and should behave as specified in the description of make-custom-textual-input-port.

    (write! string start count) Start and count will be non-negative exact integer objects, and string will be a string whose length is at least start + count. The write! procedure should write up to count characters from string starting at index start to the character sink. If count is 0, the write! procedure should have the effect of passing an end-of-file object to the character sink. In any case, the write! procedure should return the number of characters that it wrote, as an exact integer object.

    The port may or may not have an associated transcoder; if it does, the transcoder is implementation-dependent.

    (rnrs io ports (6)) procedure (put-u8 (port output-port?) (octet integer?)) ⟹ undefined

    Writes octet to the output port and returns unspecified values.

    (rnrs io ports (6)) procedure (put-bytevector (port output-port?) (bytevector bytevector?)) ⟹ undefined

    (rnrs io ports (6)) procedure (put-bytevector (port output-port?) (bytevector bytevector?) (start integer?)) ⟹ undefined

    (rnrs io ports (6)) procedure (put-bytevector (port output-port?) (bytevector bytevector?) (start integer?) (count integer?)) ⟹ undefined

    Start and count must be non-negative exact integer objects that default to 0 and (bytevector-length bytevector) − start, respectively. Bytevector must have a length of at least start + count. The put-bytevector procedure writes the count bytes of the bytevector bytevector starting at index start to the output port. The put-bytevector procedure returns unspecified values.

    (rnrs io ports (6)) procedure (put-char (port output-port?) (char char?)) ⟹ undefined

    Writes char to the port. The put-char procedure returns unspecified values.

    (rnrs io ports (6)) procedure (put-string (port output-port?) (string string?)) ⟹ undefined

    (rnrs io ports (6)) procedure (put-string (port output-port?) (string string?) (start integer?)) ⟹ undefined

    (rnrs io ports (6)) procedure (put-string (port output-port?) (string string?) (start integer?) (count integer?)) ⟹ undefined

    Start and count must be non-negative exact integer objects. String must have a length of at least start + count. Start defaults to 0. Count defaults to (string-length string) − start. The put-string procedure writes the count characters of string starting at index start to the port. The put-string procedure returns unspecified values.

    (rnrs io ports (6)) procedure (put-datum (port output-port?) datum) ⟹ undefined

    Datum should be a datum value. The put-datum procedure writes an external representation of datum to textual-output-port. The specific external representation is implementation-dependent. However, whenever possible, an implementation should produce a representation for which get-datum, when reading the representation, will return an object equal (in the sense of equal?) to datum.

    (rnrs io ports (6)) procedure (open-file-input/output-port (string string?)) ⟹ port?

    (rnrs io ports (6)) procedure (open-file-input/output-port (string string?) (options file-options)) ⟹ port?

    (rnrs io ports (6)) procedure (open-file-input/output-port (string string?) (options file-options) (buffer-mode buffer-mode?)) ⟹ port?

    (rnrs io ports (6)) procedure (open-file-input/output-port (string string?) (options file-options) (buffer-mode buffer-mode?) (transcoder #f | transcoder)) ⟹ port?

    Returns a single port that is both an input port and an output port for the named file. The optional arguments default as described in the specification of open-file-output-port. If the input/output port supports port-position and/or set-port-position!, the same port position is used for both input and output.

    (rnrs io ports (6)) procedure (make-custom-binary-input/output-port (id string?) (read! procedure?) (write! procedure?) (get-position #f | procedure?) (set-position! #f | procedure?) (close #f | procedure?)) ⟹ port?

    (read! (bytevector bytevector?) (start integer?) (count integer?)) ⟹ integer?

    (write! (bytevector bytevector?) (start integer?) (count integer?)) ⟹ integer?

    (get-position) ⟹ integer?

    (set-position! (position integer?)) ⟹ undefined

    (close) ⟹ undefined

    Returns a newly created binary input/output port whose byte source and sink are arbitrary algorithms represented by the read! and write! procedures. Id must be a string naming the new port, provided for informational purposes only. Read! and write! must be procedures, and should behave as specified for the make-custom-binary-input-port and make-custom-binary-output-port procedures.

    Each of the remaining arguments may be #f; if any of those arguments is not #f, it must be a procedure and should behave as specified in the description of make-custom-binary-input-port.

    (rnrs io ports (6)) procedure (make-custom-textual-input/output-port (id string?) (read! procedure?) (write! procedure?) (get-position #f | procedure?) (set-position! #f | procedure?) (close #f | procedure?)) ⟹ port?

    (read! (string string?) (start integer?) (count integer?)) ⟹ integer?

    (write! (string string?) (start integer?) (count integer?)) ⟹ integer?

    (get-position) ⟹ opaque-port-position

    (set-position! (position opaque-port-position)) ⟹ undefined

    (close) ⟹ undefined

    Returns a newly created textual input/output port whose textual source and sink are arbitrary algorithms represented by the read! and write! procedures. Id must be a string naming the new port, provided for informational purposes only. Read! and write! must be procedures, and should behave as specified for the make-custom-textual-input-port and make-custom-textual-output-port procedures.

    Each of the remaining arguments may be #f; if any of those arguments is not #f, it must be a procedure and should behave as specified in the description of make-custom-textual-input-port.

    (rnrs io ports (6)) value &i/o ⟹ record-type-descriptor?

    (rnrs io ports (6)) procedure (make-i/o-error) ⟹ i/o-error?

    (rnrs io ports (6)) procedure (i/o-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o &error

    make-i/o-error i/o-error?)

    This is a supertype for a set of more specific I/O errors.

    (rnrs io ports (6)) value &i/o-read ⟹ record-type-descriptor?

    (rnrs io ports (6)) procedure (make-i/o-read-error) ⟹ i/o-read-error?

    (rnrs io ports (6)) procedure (i/o-read-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-read &i/o

    make-i/o-read-error i/o-read-error?)

    This condition type describes read errors that occurred during an I/O operation.

    (rnrs io ports (6)) value &i/o-write ⟹ record-type-descriptor?

    (rnrs io ports (6)) procedure (make-i/o-write-error) ⟹ i/o-write-error?

    (rnrs io ports (6)) procedure (i/o-write-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-write &i/o

    make-i/o-write-error i/o-write-error?)

    This condition type describes write errors that occurred during an I/O operation.

    (rnrs io ports (6)) value &i/o-invalid-position ⟹ record-type-descriptor?

    (rnrs io ports (6)) procedure (make-i/o-invalid-position-error position) ⟹ i/o-invalid-position-error?

    (rnrs io ports (6)) procedure (i/o-invalid-position-error? obj) ⟹ boolean?

    (rnrs io ports (6)) procedure (i/o-error-position (condition i/o-invalid-position-error?)) ⟹ *

    This condition type could be defined by

    (define-condition-type &i/o-invalid-position &i/o

    make-i/o-invalid-position-error

    i/o-invalid-position-error?

    (position i/o-error-position))

    This condition type describes attempts to set the file position to an invalid position. Position should be the file position that the program intended to set. This condition describes a range error, but not an assertion violation.

    (rnrs io ports (6)) value &i/o-filename ⟹ record-type-descriptor?

    (rnrs io ports (6)) procedure (make-i/o-filename-error filename) ⟹ i/o-filename-error?

    (rnrs io ports (6)) procedure (i/o-filename-error? obj) ⟹ boolean?

    (rnrs io ports (6)) procedure (i/o-error-filename (condition i/o-filename-error?)) ⟹ *

    This condition type could be defined by

    (define-condition-type &i/o-filename &i/o

    make-i/o-filename-error i/o-filename-error?

    (filename i/o-error-filename))

    This condition type describes an I/O error that occurred during an operation on a named file. Filename should be the name of the file.

    (rnrs io ports (6)) value &i/o-file-protection ⟹ record-type-descriptor?

    (rnrs io ports (6)) procedure (make-i/o-file-protection-error file) ⟹ i/o-file-protection-error?

    (rnrs io ports (6)) procedure (i/o-file-protection-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-file-protection

    &i/o-filename

    make-i/o-file-protection-error

    i/o-file-protection-error?)

    A condition of this type specifies that an operation tried to operate on a named file with insufficient access rights.

    (rnrs io ports (6)) value &i/o-file-is-read-only ⟹ record-type-descriptor?

    (rnrs io ports (6)) procedure (make-i/o-file-is-read-only-error file) ⟹ i/o-file-is-read-only-error?

    (rnrs io ports (6)) procedure (i/o-file-is-read-only-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-file-is-read-only

    &i/o-file-protection

    make-i/o-file-is-read-only-error

    i/o-file-is-read-only-error?)

    A condition of this type specifies that an operation tried to operate on a named read-only file under the assumption that it is writeable.

    (rnrs io ports (6)) value &i/o-file-already-exists ⟹ record-type-descriptor?

    (rnrs io ports (6)) procedure (make-i/o-file-already-exists-error file) ⟹ i/o-file-already-exists-error?

    (rnrs io ports (6)) procedure (i/o-file-already-exists-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-file-already-exists

    &i/o-filename

    make-i/o-file-already-exists-error

    i/o-file-already-exists-error?)

    A condition of this type specifies that an operation tried to operate on an existing named file under the assumption that it did not exist.

    (rnrs io ports (6)) value &i/o-file-does-not-exist ⟹ record-type-descriptor?

    (rnrs io ports (6)) procedure (make-i/o-file-does-not-exist-error file) ⟹ i/o-file-does-not-exist-error?

    (rnrs io ports (6)) procedure (i/o-file-does-not-exist-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-file-does-not-exist

    &i/o-filename

    make-i/o-file-does-not-exist-error

    i/o-file-does-not-exist-error?)

    A condition of this type specifies that an operation tried to operate on an non-existent named file under the assumption that it existed.

    (rnrs io ports (6)) value &i/o-port ⟹ record-type-descriptor?

    (rnrs io ports (6)) procedure (make-i/o-port-error (port port?)) ⟹ i/o-port-error?

    (rnrs io ports (6)) procedure (i/o-port-error? obj) ⟹ boolean?

    (rnrs io ports (6)) procedure (i/o-error-port (condition i/o-port-error?)) ⟹ port?

    This condition type could be defined by

    (define-condition-type &i/o-port &i/o

    make-i/o-port-error i/o-port-error?

    (port i/o-error-port))

    This condition type specifies the port with which an I/O error is associated. Port should be the port. Conditions raised by procedures accepting a port as an argument should include an &i/o-port-error condition.

    library (rnrs io simple (6))

    (rnrs io simple (6)) procedure (eof-object) ⟹ eof-object?

    Returns the end-of-file object.

    (rnrs io simple (6)) procedure (eof-object? obj) ⟹ boolean?

    Returns #t if obj is the end-of-file object, #f otherwise.

    (rnrs io simple (6)) procedure (call-with-input-file (string string?) (proc procedure?)) ⟹ *

    (proc (port input-port?)) ⟹ *

    (rnrs io simple (6)) procedure (call-with-output-file (string string?) (proc procedure?)) ⟹ *

    (proc (port output-port?)) ⟹ *

    Proc should accept one argument. These procedures open the file named by filename for input or for output, with no specified file options, and call proc with the obtained port as an argument. If proc returns, the port is closed automatically and the values returned by proc are returned. If proc does not return, the port is not closed automatically, unless it is possible to prove that the port will never again be used for an I/O operation.

    (rnrs io simple (6)) procedure (input-port? obj) ⟹ boolean?

    Returns #t if the argument is an input port (or a combined input and output port), and returns #f otherwise.

    (rnrs io simple (6)) procedure (output-port? obj) ⟹ boolean?

    Returns #t if the argument is an output port (or a combined input and output port), #f otherwise.

    (rnrs io simple (6)) procedure (current-error-port) ⟹ output-port?

    This returns a default textual port for input. Normally, this default port is associated with standard input, but can be dynamically re-assigned using the with-input-from-file procedure from the (rnrs io simple (6)) library (see section 8.3). The port may or may not have an associated transcoder; if it does, the transcoder is implementation-dependent.

    (rnrs io simple (6)) procedure (current-input-port) ⟹ input-port?

    (rnrs io simple (6)) procedure (current-output-port) ⟹ output-port?

    These return default textual ports for regular output and error output. Normally, these default ports are associated with standard output, and standard error, respectively. The return value of current-output-port can be dynamically re-assigned using the with-output-to-file procedure. A port returned by one of these procedures may or may not have an associated transcoder; if it does, the transcoder is implementation-dependent.

    (rnrs io simple (6)) procedure (with-input-from-file (string string?) (thunk procedure?)) ⟹ *

    (thunk) ⟹ *

    (rnrs io simple (6)) procedure (with-output-to-file (string string?) (thunk procedure?)) ⟹ *

    (thunk) ⟹ *

    Thunk must be a procedure and must accept zero arguments. The file is opened for input or output using empty file options, and thunk is called with no arguments. During the dynamic extent of the call to thunk, the obtained port is made the value returned by current-input-port or current-output-port procedures; the previous default values are reinstated when the dynamic extent is exited. When thunk returns, the port is closed automatically. The values returned by thunk are returned. If an escape procedure is used to escape back into the call to thunk after thunk is returned, the behavior is unspecified.

    (rnrs io simple (6)) procedure (open-input-file (string string?)) ⟹ input-port?

    Opens filename for input, with empty file options, and returns the obtained port.

    (rnrs io simple (6)) procedure (open-output-file (string string?)) ⟹ output-port?

    Opens filename for output, with empty file options, and returns the obtained port.

    (rnrs io simple (6)) procedure (close-input-port (input-port input-port?)) ⟹ undefined

    (rnrs io simple (6)) procedure (close-output-port (output-port output-port?)) ⟹ undefined

    Closes input-port or output-port, respectively.

    (rnrs io simple (6)) procedure (read-char ) ⟹ eof-object? | char?

    (rnrs io simple (6)) procedure (read-char (port input-port?)) ⟹ eof-object? | char?

    Reads from textual-input-port, blocking as necessary until a character is available from textual-input-port, or the data that are available cannot be the prefix of any valid encoding, or an end of file is reached.

    If a complete character is available before the next end of file, read-char returns that character, and updates the input port to point past that character. If an end of file is reached before any data are read, read-char returns the end-of-file object.

    If textual-input-port is omitted, it defaults to the value returned by current-input-port.

    (rnrs io simple (6)) procedure (peek-char ) ⟹ eof-object? | char?

    (rnrs io simple (6)) procedure (peek-char (port input-port?)) ⟹ eof-object? | char?

    This is the same as read-char, but does not consume any data from the port.

    (rnrs io simple (6)) procedure (read ) ⟹ *

    (rnrs io simple (6)) procedure (read (port input-port?)) ⟹ *

    Reads an external representation from textual-input-port and returns the datum it represents. The read procedure operates in the same way as get-datum, see section 8.2.9.

    If textual-input-port is omitted, it defaults to the value returned by current-input-port.

    (rnrs io simple (6)) procedure (write-char (char char?)) ⟹ undefined

    (rnrs io simple (6)) procedure (write-char (char char?) (port output-port?)) ⟹ undefined

    Writes an encoding of the character char to the textual-output-port, and returns unspecified values.

    If textual-output-port is omitted, it defaults to the value returned by current-output-port.

    (rnrs io simple (6)) procedure (newline ) ⟹ undefined

    (rnrs io simple (6)) procedure (newline (port output-port?)) ⟹ undefined

    This is equivalent to using write-char to write #\linefeed to textual-output-port.

    If textual-output-port is omitted, it defaults to the value returned by current-output-port.

    (rnrs io simple (6)) procedure (display obj) ⟹ undefined

    (rnrs io simple (6)) procedure (display obj (port output-port?)) ⟹ undefined

    Writes a representation of obj to the given textual-output-port. Strings that appear in the written representation are not enclosed in doublequotes, and no characters are escaped within those strings. Character objects appear in the representation as if written by write-char instead of by write. The display procedure returns unspecified values. The textual-output-port argument may be omitted, in which case it defaults to the value returned by current-output-port.

    (rnrs io simple (6)) procedure (write obj) ⟹ undefined

    (rnrs io simple (6)) procedure (write obj (port output-port?)) ⟹ undefined

    Writes the external representation of obj to textual-output-port. The write procedure operates in the same way as put-datum; see section 8.2.12.

    If textual-output-port is omitted, it defaults to the value returned by current-output-port.

    (rnrs io simple (6)) value &i/o ⟹ record-type-descriptor?

    (rnrs io simple (6)) procedure (make-i/o-error) ⟹ i/o-error?

    (rnrs io simple (6)) procedure (i/o-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o &error

    make-i/o-error i/o-error?)

    This is a supertype for a set of more specific I/O errors.

    (rnrs io simple (6)) value &i/o-read ⟹ record-type-descriptor?

    (rnrs io simple (6)) procedure (make-i/o-read-error) ⟹ i/o-read-error?

    (rnrs io simple (6)) procedure (i/o-read-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-read &i/o

    make-i/o-read-error i/o-read-error?)

    This condition type describes read errors that occurred during an I/O operation.

    (rnrs io simple (6)) value &i/o-write ⟹ record-type-descriptor?

    (rnrs io simple (6)) procedure (make-i/o-write-error) ⟹ i/o-write-error?

    (rnrs io simple (6)) procedure (i/o-write-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-write &i/o

    make-i/o-write-error i/o-write-error?)

    This condition type describes write errors that occurred during an I/O operation.

    (rnrs io simple (6)) value &i/o-invalid-position ⟹ record-type-descriptor?

    (rnrs io simple (6)) procedure (make-i/o-invalid-position-error position) ⟹ i/o-invalid-position-error?

    (rnrs io simple (6)) procedure (i/o-invalid-position-error? obj) ⟹ boolean?

    (rnrs io simple (6)) procedure (i/o-error-position (condition i/o-invalid-position-error?)) ⟹ *

    This condition type could be defined by

    (define-condition-type &i/o-invalid-position &i/o

    make-i/o-invalid-position-error

    i/o-invalid-position-error?

    (position i/o-error-position))

    This condition type describes attempts to set the file position to an invalid position. Position should be the file position that the program intended to set. This condition describes a range error, but not an assertion violation.

    (rnrs io simple (6)) value &i/o-filename ⟹ record-type-descriptor?

    (rnrs io simple (6)) procedure (make-i/o-filename-error filename) ⟹ i/o-filename-error?

    (rnrs io simple (6)) procedure (i/o-filename-error? obj) ⟹ boolean?

    (rnrs io simple (6)) procedure (i/o-error-filename (condition i/o-filename-error?)) ⟹ *

    This condition type could be defined by

    (define-condition-type &i/o-filename &i/o

    make-i/o-filename-error i/o-filename-error?

    (filename i/o-error-filename))

    This condition type describes an I/O error that occurred during an operation on a named file. Filename should be the name of the file.

    (rnrs io simple (6)) value &i/o-file-protection ⟹ record-type-descriptor?

    (rnrs io simple (6)) procedure (make-i/o-file-protection-error file) ⟹ i/o-file-protection-error?

    (rnrs io simple (6)) procedure (i/o-file-protection-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-file-protection

    &i/o-filename

    make-i/o-file-protection-error

    i/o-file-protection-error?)

    A condition of this type specifies that an operation tried to operate on a named file with insufficient access rights.

    (rnrs io simple (6)) value &i/o-file-is-read-only ⟹ record-type-descriptor?

    (rnrs io simple (6)) procedure (make-i/o-file-is-read-only-error file) ⟹ i/o-file-is-read-only-error?

    (rnrs io simple (6)) procedure (i/o-file-is-read-only-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-file-is-read-only

    &i/o-file-protection

    make-i/o-file-is-read-only-error

    i/o-file-is-read-only-error?)

    A condition of this type specifies that an operation tried to operate on a named read-only file under the assumption that it is writeable.

    (rnrs io simple (6)) value &i/o-file-already-exists ⟹ record-type-descriptor?

    (rnrs io simple (6)) procedure (make-i/o-file-already-exists-error file) ⟹ i/o-file-already-exists-error?

    (rnrs io simple (6)) procedure (i/o-file-already-exists-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-file-already-exists

    &i/o-filename

    make-i/o-file-already-exists-error

    i/o-file-already-exists-error?)

    A condition of this type specifies that an operation tried to operate on an existing named file under the assumption that it did not exist.

    (rnrs io simple (6)) value &i/o-file-does-not-exist ⟹ record-type-descriptor?

    (rnrs io simple (6)) procedure (make-i/o-file-does-not-exist-error file) ⟹ i/o-file-does-not-exist-error?

    (rnrs io simple (6)) procedure (i/o-file-does-not-exist-error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &i/o-file-does-not-exist

    &i/o-filename

    make-i/o-file-does-not-exist-error

    i/o-file-does-not-exist-error?)

    A condition of this type specifies that an operation tried to operate on an non-existent named file under the assumption that it existed.

    (rnrs io simple (6)) value &i/o-port ⟹ record-type-descriptor?

    (rnrs io simple (6)) procedure (make-i/o-port-error (port port?)) ⟹ i/o-port-error?

    (rnrs io simple (6)) procedure (i/o-port-error? obj) ⟹ boolean?

    (rnrs io simple (6)) procedure (i/o-error-port (condition i/o-port-error?)) ⟹ port?

    This condition type could be defined by

    (define-condition-type &i/o-port &i/o

    make-i/o-port-error i/o-port-error?

    (port i/o-error-port))

    This condition type specifies the port with which an I/O error is associated. Port should be the port. Conditions raised by procedures accepting a port as an argument should include an &i/o-port-error condition.

    library (rnrs lists (6))

    (rnrs lists (6)) procedure (find (pred predicate) (list list?)) ⟹ *

    Proc should accept one argument and return a single value. Proc should not mutate list. The find procedure applies proc to the elements of list in order. If proc returns a true value for an element, find immediately returns that element. If proc returns #f for all elements of the list, find returns #f. Proc is always called in the same dynamic environment as find itself.

    (rnrs lists (6)) procedure (for-all (pred procedure?) (list1 list?) (list2 list?) ...) ⟹ *

    (pred obj1 obj2 ...) ⟹ *

    The lists should all have the same length, and proc should accept n arguments and return a single value. Proc should not mutate the list arguments. For natural numbers i = 0, 1, ..., the for-all procedure successively applies proc to arguments xi1 ... xin, where xij is the ith element of listj, until #f is returned. If proc returns true values for all but the last element of list1, for-all performs a tail call of proc on the kth elements, where k is the length of list1. If proc returns #f on any set of elements, for-all returns #f after the first such application of proc. If the lists are all empty, for-all returns #t.

    (rnrs lists (6)) procedure (exists (pred procedure?) (list1 list?) (list2 list?) ...) ⟹ *

    (pred obj1 obj2 ...) ⟹ *

    The lists should all have the same length, and proc should accept n arguments and return a single value. Proc should not mutate the list arguments. For natural numbers i = 0, 1, ..., the exists procedure applies proc successively to arguments xi1 ... xin, where xij is the ith element of listj, until a true value is returned. If proc returns #f for all but the last elements of the lists, exists performs a tail call of proc on the kth elements, where k is the length of list1. If proc returns a true value on any set of elements, exists returns that value after the first such application of proc. If the lists are all empty, exists returns #f.

    (rnrs lists (6)) procedure (filter (pred predicate) (list list?)) ⟹ list?

    Proc should accept one argument and return a single value. Proc should not mutate list. The filter procedure applies proc to each element of list and returns a list of the elements of list for which proc returned a true value. The elements of the result list are in the same order as they appear in the input list. Proc is always called in the same dynamic environment as filter. If multiple returns occur from filter, the return values returned by earlier returns are not mutated.

    (rnrs lists (6)) procedure (partition (pred predicate) (list list?)) ⟹ (values list? list?)

    Proc should accept one argument and return a single value. Proc should not mutate list. The partition procedure also applies proc to each element of list, but returns two values, the first one a list of the elements of list for which proc returned a true value, and the second a list of the elements of list for which proc returned #f. The elements of the result lists are in the same order as they appear in the input list. Proc is always called in the same dynamic environment as partition itself. If multiple returns occur from partitions, the return values returned by earlier returns are not mutated.

    (rnrs lists (6)) procedure (fold-left (kons procedure?) knil (list1 list?) (list2 list?) ...) ⟹ *

    (kons obj1 obj2 ... fold-state) ⟹ *

    The lists should all have the same length. Combine must be a procedure. It should accept one more argument than there are lists and return a single value. It should not mutate the list arguments. The fold-left procedure iterates the combine procedure over an accumulator value and the elements of the lists from left to right, starting with an accumulator value of nil. More specifically, fold-left returns nil if the lists are empty. If they are not empty, combine is first applied to nil and the respective first elements of the lists in order. The result becomes the new accumulator value, and combine is applied to the new accumulator value and the respective next elements of the list. This step is repeated until the end of the list is reached; then the accumulator value is returned. Combine is always called in the same dynamic environment as fold-left itself.

    (rnrs lists (6)) procedure (fold-right (kons procedure?) knil (list1 list?) (list2 list?) ...) ⟹ *

    (kons obj1 obj2 ... fold-state) ⟹ *

    The lists should all have the same length. Combine must be a procedure. It should accept one more argument than there are lists and return a single value. Combine should not mutate the list arguments. The fold-right procedure iterates the combine procedure over the elements of the lists from right to left and an accumulator value, starting with an accumulator value of nil. More specifically, fold-right returns nil if the lists are empty. If they are not empty, combine is first applied to the respective last elements of the lists in order and nil. The result becomes the new accumulator value, and combine is applied to the respective previous elements of the lists and the new accumulator value. This step is repeated until the beginning of the list is reached; then the accumulator value is returned. Proc is always called in the same dynamic environment as fold-right itself.

    (rnrs lists (6)) procedure (remp (pred predicate) (list list?)) ⟹ list?

    The remp procedure applies proc to each element of list and returns a list of the elements of list for which proc returned #f.

    (rnrs lists (6)) procedure (remove obj (list list?)) ⟹ list?

    The remove procedure return a list of the elements that are not obj as according to equal?.

    (rnrs lists (6)) procedure (remv obj (list list?)) ⟹ list?

    The remv procedure return a list of the elements that are not obj as according to eqv?.

    (rnrs lists (6)) procedure (remq obj (list list?)) ⟹ list?

    The remq procedure return a list of the elements that are not obj as according to eq?.

    (rnrs lists (6)) procedure (memp (pred predicate) (list list?)) ⟹ #f | list?

    Proc should accept one argument and return a single value. Proc should not mutate list. Returns the first sublist of list whose car satisfies a given condition, where the sublists of lists are the lists returned by (list-tail list k) for k less than the length of list. The memp procedure applies proc to the cars of the sublists of list until it finds one for which proc returns a true value. Proc is always called in the same dynamic environment as memp itself. If list does not contain an element satisfying the condition, then #f (not the empty list) is returned.

    (rnrs lists (6)) procedure (member obj (list list?)) ⟹ #f | list?

    Returns the first sublist of list whose car satisfies a given condition, where the sublists of lists are the lists returned by (list-tail list k) for k less than the length of list. The member procedure looks for the first occurrence of obj. If list does not contain an element satisfying the condition, then #f (not the empty list) is returned. The member procedure uses equal? to compare obj with the elements of list.

    (rnrs lists (6)) procedure (memq obj (list list?)) ⟹ #f | list?

    Returns the first sublist of list whose car satisfies a given condition, where the sublists of lists are the lists returned by (list-tail list k) for k less than the length of list. The memq procedure looks for the first occurrence of obj. If list does not contain an element satisfying the condition, then #f (not the empty list) is returned. The memq procedure uses eq? to compare obj with the elements of list.

    (rnrs lists (6)) procedure (memv obj (list list?)) ⟹ #f | list?

    Returns the first sublist of list whose car satisfies a given condition, where the sublists of lists are the lists returned by (list-tail list k) for k less than the length of list. The memv procedure looks for the first occurrence of obj. If list does not contain an element satisfying the condition, then #f (not the empty list) is returned. The memv procedure uses eqv? to compare obj with the elements of list.

    (rnrs lists (6)) procedure (assp (pred predicate) (alist list?)) ⟹ pair? | #f

    alist ⟹ (alist key : value)

    Alist (for "association list") should be a list of pairs. Proc should accept one argument and return a single value. Proc should not mutate alist. The procedure finds the first pair in alist whose car field satisfies a given condition, and returns that pair without traversing alist further. If no pair in alist satisfies the condition, then #f is returned. The assp procedure successively applies proc to the car fields of alist and looks for a pair for which it returns a true value. Proc is always called in the same dynamic environment as assp itself.

    (rnrs lists (6)) procedure (assoc obj (alist list?)) ⟹ pair? | #f

    alist ⟹ (alist key : value)

    Alist (for "association list") should be a list of pairs. The procedure finds the first pair in alist whose car field satisfies a given condition, and returns that pair without traversing alist further. If no pair in alist satisfies the condition, then #f is returned. The assoc procedure looks for a pair that has obj as its car. The assoc procedure uses equal? to compare obj with the car fields of the pairs in alist.

    (rnrs lists (6)) procedure (assq obj (alist list?)) ⟹ pair? | #f

    alist ⟹ (alist key : value)

    Alist (for "association list") should be a list of pairs. The procedure finds the first pair in alist whose car field satisfies a given condition, and returns that pair without traversing alist further. If no pair in alist satisfies the condition, then #f is returned. The assoc procedure looks for a pair that has obj as its car. The assq procedure uses eq? to compare obj with the car fields of the pairs in alist.

    (rnrs lists (6)) procedure (assv obj (alist list?)) ⟹ pair? | #f

    alist ⟹ (alist key : value)

    Alist (for "association list") should be a list of pairs. The procedure finds the first pair in alist whose car field satisfies a given condition, and returns that pair without traversing alist further. If no pair in alist satisfies the condition, then #f is returned. The assoc procedure looks for a pair that has obj as its car. The assv procedure uses eqv? to compare obj with the car fields of the pairs in alist.

    (rnrs lists (6)) procedure (cons* elt1 elt2 ...) ⟹ *

    If called with at least two arguments, cons* returns a freshly allocated chain of pairs whose cars are obj1, ..., objn, and whose last cdr is obj. If called with only one argument, cons* returns that argument.

    library (rnrs mutable-pairs (6))

    (rnrs mutable-pairs (6)) procedure (set-car! (pair pair?) obj) ⟹ undefined

    Stores obj in the car field of pair. The set-car! procedure returns unspecified values. If an immutable pair is passed to set-car!, an exception with condition type &assertion should be raised.

    (rnrs mutable-pairs (6)) procedure (set-cdr! (pair pair?) obj) ⟹ undefined

    Stores obj in the cdr field of pair. The set-cdr! procedure returns unspecified values. If an immutable pair is passed to set-car!, an exception with condition type &assertion should be raised.

    library (rnrs mutable-strings (6))

    (rnrs mutable-strings (6)) procedure (string-set! (string string?) (k integer?) (char char?)) ⟹ undefined

    K must be a valid index of string. The string-set! procedure stores char in element k of string and returns unspecified values. Passing an immutable string to string-set! should cause an exception with condition type &assertion to be raised.

    (rnrs mutable-strings (6)) procedure (string-fill! (string string?) (fill char?)) ⟹ undefined

    Stores char in every element of the given string and returns unspecified values.

    library (rnrs programs (6))

    (rnrs programs (6)) procedure (command-line) ⟹ list?

    Returns a nonempty list of strings. The first element is an implementation-specific name for the running top-level program. The remaining elements are command-line arguments according to the operating system's conventions.

    (rnrs programs (6)) procedure (exit ) ⟹ undefined

    (rnrs programs (6)) procedure (exit obj) ⟹ undefined

    Exits the running program and communicates an exit value to the operating system. If no argument is supplied, the exit procedure should communicate to the operating system that the program exited normally. If an argument is supplied, the exit procedure should translate the argument into an appropriate exit value for the operating system. If obj is #f, the exit is assumed to be abnormal.

    library (rnrs r5rs (6))

    (rnrs r5rs (6)) procedure (exact->inexact (z number?)) ⟹ inexact?

    (rnrs r5rs (6)) procedure (inexact->exact (z number?)) ⟹ exact?

    These are the same as the inexact and exact procedures

    (rnrs r5rs (6)) procedure (quotient (n1 integer?) (n2 integer?)) ⟹ integer?

    (rnrs r5rs (6)) procedure (remainder (n1 integer?) (n2 integer?)) ⟹ integer?

    (rnrs r5rs (6)) procedure (modulo (n1 integer?) (n2 integer?)) ⟹ integer?

    These procedures implement number-theoretic (integer) division. N2 must be non-zero.

    (rnrs r5rs (6)) syntax (delay expression)⟹ return

    The delay construct is used together with the procedure force to implement lazy evaluation or call by need. (delay <expression>) returns an object called a promise which at some point in the future may be asked (by the force procedure) to evaluate <expression>, and deliver the resulting value. The effect of <expression> returning multiple values is unspecified.

    (rnrs r5rs (6)) procedure (force (promise promise?)) ⟹ *

    Promise must be a promise. The force procedure forces the value of promise. If no value has been computed for the promise, then a value is computed and returned. The value of the promise is cached (or “memoized”) so that if it is forced a second time, the previously computed value is returned.

    (rnrs r5rs (6)) procedure (null-environment (n integer?)) ⟹ environment

    (rnrs r5rs (6)) procedure (null-environment (n integer?)) ⟹ environment

    N must be the exact integer object 5. The null-environment procedure returns an environment specifier suitable for use with eval (see chapter 16) representing an environment that is empty except for the (syntactic) bindings for all keywords described in the previous revision of this report, including bindings for =>, ..., else, and _ that are the same as those in the (rnrs base (6)) library.

    (rnrs r5rs (6)) procedure (scheme-report-environment (n integer?)) ⟹ environment

    N must be the exact integer object 5. The scheme-report-environment procedure returns an environment specifier for an environment that is empty except for the bindings for the identifiers described in the previous revision of this report, omitting load, interaction-environment, transcript-on, transcript-off, and char-ready?. The variable bindings have as values the procedures of the same names described in this report, and the keyword bindings, including =>, ..., else, and _ are the same as those described in this report.

    library (rnrs records inspection (6))

    (rnrs records inspection (6)) procedure (record? obj) ⟹ boolean?

    Returns #t if obj is a record, and its record type is not opaque, and returns #f otherwise.

    (rnrs records inspection (6)) procedure (record-rtd (record record?)) ⟹ record-type-descriptor?

    Returns the rtd representing the type of record if the type is not opaque. The rtd of the most precise type is returned; that is, the type t such that record is of type t but not of any type that extends t. If the type is opaque, an exception is raised with condition type &assertion.

    (rnrs records inspection (6)) procedure (record-type-name (rtd record-type-descriptor?)) ⟹ symbol?

    Returns the name of the record-type descriptor rtd.

    (rnrs records inspection (6)) procedure (record-type-parent (rtd record-type-descriptor?)) ⟹ #f | record-type-descriptor?

    Returns the parent of the record-type descriptor rtd, or #f if it has none.

    (rnrs records inspection (6)) procedure (record-type-uid (rtd record-type-descriptor?)) ⟹ symbol? | #f

    Returns the uid of the record-type descriptor rtd, or #f if it has none. (An implementation may assign a generated uid to a record type even if the type is generative, so the return of a uid does not necessarily imply that the type is nongenerative.)

    (rnrs records inspection (6)) procedure (record-type-generative? (rtd record-type-descriptor?)) ⟹ boolean?

    Returns #t if rtd is generative, and #f if not.

    (rnrs records inspection (6)) procedure (record-type-sealed? (rtd record-type-descriptor?)) ⟹ boolean?

    Returns #t if the record-type descriptor is sealed, and #f if not.

    (rnrs records inspection (6)) procedure (record-type-opaque? (rtd record-type-descriptor?)) ⟹ boolean?

    Returns #t if the the record-type descriptor is opaque, and #f if not.

    (rnrs records inspection (6)) procedure (record-type-field-names (rtd record-type-descriptor?)) ⟹ vector?

    Returns a vector of symbols naming the fields of the type represented by rtd (not including the fields of parent types) where the fields are ordered as described under make-record-type-descriptor. The returned vector may be immutable. If the returned vector is modified, the effect on rtd is unspecified.

    (rnrs records inspection (6)) procedure (record-field-mutable? (rtd record-type-descriptor?) (k integer?)) ⟹ boolean?

    Returns #t if the field specified by k of the type represented by rtd is mutable, and #f if not. K is as in record-accessor.

    library (rnrs records procedural (6))

    (rnrs records procedural (6)) procedure (make-record-type-descriptor (name symbol?) (parent #f | record-type-descriptor?) (uid #f | symbol?) (sealed? boolean?) (opaque? boolean?) (fields vector?)) ⟹ record-type-descriptor?

    Returns a record-type descriptor, or rtd, representing a record type distinct from all built-in types and other record types.

    The name argument must be a symbol. It names the record type, and is intended purely for informational purposes and may be used for printing by the underlying Scheme system.

    The parent argument must be either #f or an rtd. If it is an rtd, the returned record type, t, extends the record type p represented by parent. An exception with condition type &assertion is raised if parent is sealed (see below).

    The uid argument must be either #f or a symbol. If uid is a symbol, the record-creation operation is nongenerative i.e., a new record type is created only if no previous call to make-record-type-descriptor was made with the uid. If uid is #f, the record-creation operation is generative, i.e., a new record type is created even if a previous call to make-record-type-descriptor was made with the same arguments.

    If make-record-type-descriptor is called twice with the same uid symbol, the parent arguments in the two calls must be eqv?, the fields arguments equal?, the sealed? arguments boolean-equivalent (both #f or both true), and the opaque? arguments boolean-equivalent. If these conditions are not met, an exception with condition type &assertion is raised when the second call occurs. If they are met, the second call returns, without creating a new record type, the same record-type descriptor (in the sense of eqv?) as the first call.

    Note: Users are encouraged to use symbol names constructed using the UUID namespace [10] (for example, using the record-type name as a prefix) for the uid argument.

    The sealed? flag must be a boolean. If true, the returned record type is sealed, i.e., it cannot be extended.

    The opaque? flag must be a boolean. If true, the record type is opaque. If passed an instance of the record type, record? returns #f. Moreover, if record-rtd (see “Inspection” below) is called with an instance of the record type, an exception with condition type &assertion is raised. The record type is also opaque if an opaque parent is supplied. If opaque? is #f and an opaque parent is not supplied, the record is not opaque.

    The fields argument must be a vector of field specifiers. Each field specifier must be a list of the form (mutable name) or a list of the form (immutable name). Each name must be a symbol and names the corresponding field of the record type; the names need not be distinct. A field identified as mutable may be modified, whereas, when a program attempts to obtain a mutator for a field identified as immutable, an exception with condition type &assertion is raised. Where field order is relevant, e.g., for record construction and field access, the fields are considered to be ordered as specified, although no particular order is required for the actual representation of a record instance.

    The specified fields are added to the parent fields, if any, to determine the complete set of fields of the returned record type. If fields is modified after make-record-type-descriptor has been called, the effect on the returned rtd is unspecified.

    A generative record-type descriptor created by a call to make-record-type-descriptor is not eqv? to any record-type descriptor (generative or nongenerative) created by another call to make-record-type-descriptor. A generative record-type descriptor is eqv? only to itself, i.e., (eqv? rtd1 rtd2) iff (eq? rtd1 rtd2). Also, two nongenerative record-type descriptors are eqv? iff they were created by calls to make-record-type-descriptor with the same uid arguments.

    (rnrs records procedural (6)) procedure (record-type-descriptor? obj) ⟹ boolean?

    Returns #t if the argument is a record-type descriptor, #f otherwise.

    (rnrs records procedural (6)) procedure (make-record-constructor-descriptor (rtd record-type-descriptor?) (parent-constructor-descriptor constructor-descriptor | #f) (protocol #f | procedure?)) ⟹ constructor-descriptor

    (protocol (p procedure?)) ⟹ procedure?

    Returns a record-constructor descriptor (or constructor descriptor for short) that specifies a record constructor (or constructor for short), that can be used to construct record values of the type specified by rtd, and which can be obtained via record-constructor. A constructor descriptor can also be used to create other constructor descriptors for subtypes of its own record type. Rtd must be a record-type descriptor. Protocolmust be a procedure or #f. If it is #f, a default protocol procedure is supplied.

    If protocol is a procedure, it is handled analogously to the protocol expression in a define-record-type form.

    If rtd is a base record type and protocol is a procedure, parent-constructor-descriptor must be #f. In this case, protocol is called by record-constructor with a single argument p. P is a procedure that expects one argument for every field of rtd and returns a record with the fields of rtd initialized to these arguments. The procedure returned by protocol should call p once with the number of arguments p expects and return the resulting record as shown in the simple example below:

    (lambda (p)

    (lambda (v1 v2 v3)

    (p v1 v2 v3)))

    Here, the call to p returns a record whose fields are initialized with the values of v1, v2, and v3. The expression above is equivalent to (lambda (p) p). Note that the procedure returned by protocol is otherwise unconstrained; specifically, it can take any number of arguments.

    If rtd is an extension of another record type parent-rtd and protocol is a procedure, parent-constructor-descriptor must be a constructor descriptor of parent-rtd or #f. If parent-constructor-descriptor is a constructor descriptor, protocol it is called by record-constructor with a single argument n, which is a procedure that accepts the same number of arguments as the constructor of parent-constructor-descriptor and returns a procedure p that, when called, constructs the record itself. The p procedure expects one argument for every field of rtd (not including parent fields) and returns a record with the fields of rtd initialized to these arguments, and the fields of parent-rtd and its parents initialized as specified by parent-constructor-descriptor.

    The procedure returned by protocol should call n once with the number of arguments n expects, call the procedure p it returns once with the number of arguments p expects and return the resulting record. A simple protocol in this case might be written as follows:

    (lambda (n)

    (lambda (v1 v2 v3 x1 x2 x3 x4)

    (let ((p (n v1 v2 v3)))

    (p x1 x2 x3 x4))))

    This passes arguments v1, v2, v3 to n for parent-constructor-descriptor and calls p with x1, ..., x4 to initialize the fields of rtd itself.

    Thus, the constructor descriptors for a record type form a sequence of protocols parallel to the sequence of record-type parents. Each constructor descriptor in the chain determines the field values for the associated record type. Child record constructors need not know the number or contents of parent fields, only the number of arguments accepted by the parent constructor.

    Protocol may be #f, specifying a default constructor that accepts one argument for each field of rtd (including the fields of its parent type, if any). Specifically, if rtd is a base type, the default protocol procedure behaves as if it were (lambda (p) p). If rtd is an extension of another type, then parent-constructor-descriptor must be either #f or itself specify a default constructor, and the default protocol procedure behaves as if it were:

    (lambda (n)

    (lambda (v1 ... vj x1 ... xk)

    (let ((p (n v1 ... vj)))

    (p x1 ... xk))))

    The resulting constructor accepts one argument for each of the record type's complete set of fields (including those of the parent record type, the parent's parent record type, etc.) and returns a record with the fields initialized to those arguments, with the field values for the parent coming before those of the extension in the argument list. (In the example, j is the complete number of fields of the parent type, and k is the number of fields of rtd itself.)

    If rtd is an extension of another record type, and parent-constructor-descriptor or the protocol of parent-constructor-descriptor is #f, protocol must also be #f, and a default constructor descriptor as described above is also assumed.

    (rnrs records procedural (6)) procedure (record-constructor (constructor-descriptor constructor-descriptor)) ⟹ procedure?

    Calls the protocol of constructor-descriptor (as described for make-record-constructor-descriptor) and returns the resulting constructor constructor for records of the record type associated with constructor-descriptor.

    (rnrs records procedural (6)) procedure (record-predicate (rtd record-type-descriptor?)) ⟹ predicate

    Returns a procedure that, given an object obj, returns #t if obj is a record of the type represented by rtd, and #f otherwise.

    (rnrs records procedural (6)) procedure (record-accessor (rtd record-type-descriptor?) (k integer?)) ⟹ procedure?

    (return record) ⟹ *

    K must be a valid field index of rtd. The record-accessor procedure returns a one-argument procedure whose argument must be a record of the type represented by rtd. This procedure returns the value of the selected field of that record.

    The field selected corresponds to the kth element (0-based) of the fields argument to the invocation of make-record-type-descriptor that created rtd. Note that k cannot be used to specify a field of any type rtd extends.

    (rnrs records procedural (6)) procedure (record-mutator (rtd record-type-descriptor?) (k integer?)) ⟹ procedure?

    (return record obj) ⟹ undefined

    K must be a valid field index of rtd. The record-mutator procedure returns a two-argument procedure whose arguments must be a record record r of the type represented by rtd and an object obj. This procedure stores obj within the field of r specified by k. The k argument is as in record-accessor. If k specifies an immutable field, an exception with condition type &assertion is raised. The mutator returns unspecified values.

    library (rnrs records syntactic (6))

    (rnrs records syntactic (6)) syntax (define-record-type name-spec record-clause ...)

    name-spec ⟹ (record-name constructor-name predicate-name) | record-name

    record-clause ⟹ (fields field-spec ...) | (parent parent-name) | (protocol expression) | (sealed #t) | (sealed #f) | (opaque #t) | (opaque #f) | (nongenerative uid) | (nongenerative) | (parent-rtd parentrtd parentcd)

    field-spec ⟹ (immutable field-name accessor-name) | (mutable field-name accessor-name mutator-name) | (immutable field-name) | (mutable field-name) | field-name

    A define-record-type form defines a record type along with associated constructor descriptor and constructor, predicate, field accessors, and field mutators. The define-record-type form expands into a set of definitions in the environment where define-record-type appears; hence, it is possible to refer to the bindings (except for that of the record type itself) recursively.

    The <name spec> specifies the names of the record type, constructor, and predicate. It must take one of the following forms:

    (<record name> <constructor name> <predicate name>)

    <record name>

    <Record name>, <constructor name>, and <predicate name> must all be identifiers.

    <Record name>, taken as a symbol, becomes the name of the record type. (See the description of make-record-type-descriptor below.) Additionally, it is bound by this definition to an expand-time or run-time representation of the record type and can be used as parent name in syntactic record-type definitions that extend this definition. It can also be used as a handle to gain access to the underlying record-type descriptor and constructor descriptor (see record-type-descriptor and record-constructor-descriptor below).

    <Constructor name> is defined by this definition to be a constructor for the defined record type, with a protocol specified by the protocol clause, or, in its absence, using a default protocol. For details, see the description of the protocol clause below.

    <Predicate name> is defined by this definition to a predicate for the defined record type.

    The second form of <name spec> is an abbreviation for the first form, where the name of the constructor is generated by prefixing the record name with make-, and the predicate name is generated by adding a question mark (?) to the end of the record name. For example, if the record name is frob, the name of the constructor is make-frob, and the predicate name is frob?.

    Each <record clause> must take one of the following forms; it is a syntax violation if multiple <record clause>s of the same kind appear in a define-record-type form.

    (fields <field spec>*)

    Each <field spec> has one of the following forms

    (immutable <field name> <accessor name>)

    (mutable <field name>

    <accessor name> <mutator name>)

    (immutable <field name>)

    (mutable <field name>)

    <field name>

    <Field name>, <accessor name>, and <mutator name> must all be identifiers. The first form declares an immutable field called <field name>, with the corresponding accessor named <accessor name>. The second form declares a mutable field called <field name>, with the corresponding accessor named <accessor name>, and with the corresponding mutator named <mutator name>.

    If <field spec> takes the third or fourth form, the accessor name is generated by appending the record name and field name with a hyphen separator, and the mutator name (for a mutable field) is generated by adding a -set! suffix to the accessor name. For example, if the record name is frob and the field name is widget, the accessor name is frob-widget and the mutator name is frob-widget-set!.

    If <field spec> is just a <field name> form, it is an abbreviation for (immutable <field name>).

    The <field name>s become, as symbols, the names of the fields in the record-type descriptor being created, in the same order.

    The fields clause may be absent; this is equivalent to an empty fields clause.

    (parent <parent name>)

    Specifies that the record type is to have parent type <parent name>, where <parent name> is the <record name> of a record type previously defined using define-record-type. The record-type definition associated with <parent name> must not be sealed. If no parent clause and no parent-rtd (see below) clause is present, the record type is a base type.

    (protocol <expression>)

    <Expression> is evaluated in the same environment as the define-record-type form, and must evaluate to a protocol appropriate for the record type being defined.

    The protocol is used to create a record-constructor descriptor as described below. If no protocol clause is specified, a constructor descriptor is still created using a default protocol. The clause can be absent only if the record type being defined has no parent type, or if the parent definition does not specify a protocol.

    (sealed #t)

    (sealed #f)

    If this option is specified with operand #t, the defined record type is sealed, i.e., no extensions of the record type can be created. If this option is specified with operand #f, or is absent, the defined record type is not sealed.

    (opaque #t)

    (opaque #f)

    If this option is specified with operand #t, or if an opaque parent record type is specified, the defined record type is opaque. Otherwise, the defined record type is not opaque. See the specification of record-rtd below for details.

    (nongenerative <uid>)

    (nongenerative)

    This specifies that the record type is nongenerative with uid <uid>, which must be an <identifier>. If <uid> is absent, a unique uid is generated at macro-expansion time. If two record-type definitions specify the same uid, then the record-type definitions should be equivalent, i.e., the implied arguments to make-record-type-descriptor must be equivalent as described under make-record-type-descriptor. See section 6.3. If this condition is not met, it is either considered a syntax violation or an exception with condition type &assertion is raised. If the condition is met, a single record type is generated for both definitions.

    In the absence of a nongenerative clause, a new record type is generated every time a define-record-type form is evaluated:

    (let ((f (lambda (x)

    (define-record-type r ...)

    (if x r? (make-r ...)))))

    ((f #t) (f #f))) => #f

    (parent-rtd <parent rtd> <parent cd>)

    Specifies that the record type is to have its parent type specified by <parent rtd>, which should be an expression evaluating to a record-type descriptor, and <parent cd>, which should be an expression evaluating to a constructor descriptor (see below). The record-type definition associated with the value of <parent rtd> must not be sealed. Moreover, a record-type definition must not have both a parent and a parent-rtd clause.

    Note: The syntactic layer is designed to allow record-instance sizes and field offsets to be determined at expand time, i.e., by a macro definition of define-record-type, as long as the parent (if any) is known. Implementations that take advantage of this may generate less efficient constructor, accessor, and mutator code when the parent-rtd clause is used, since the type of the parent is generally not known until run time. The parent clause should therefore be used instead when possible.

    All bindings created by define-record-type (for the record type, the constructor, the predicate, the accessors, and the mutators) must have names that are pairwise distinct.

    The constructor created by a define-record-type form is a procedure as follows:

  • If there is no parent clause and no protocol clause, the constructor accepts as many arguments as there are fields, in the same order as they appear in the fields clause, and returns a record object with the fields initialized to the corresponding arguments.
  • If there is no parent or parent-rtd clause and a protocol clause, the protocol expression must evaluate to a procedure that accepts a single argument. The protocol procedure is called once during the evaluation of the define-record-type form with a procedure p as its argument. It should return a procedure, which will become the constructor bound to <constructor name>. The procedure p accepts as many arguments as there are fields, in the same order as they appear in the fields clause, and returns a record object with the fields initialized to the corresponding arguments.
  • The constructor returned by the protocol procedure can accept an arbitrary number of arguments, and should call p once to construct a record object, and return that record object.

    For example, the following protocol expression for a record-type definition with three fields creates a constructor that accepts values for all fields, and initialized them in the reverse order of the arguments:

    (lambda (p)

    (lambda (v1 v2 v3)

    (p v3 v2 v1)))

  • If there is both a parent clause and a protocol clause, then the protocol procedure is called once with a procedure n as its argument. As in the previous case, the protocol procedure should return a procedure, which will become the constructor bound to <constructor name>. However, n is different from p in the previous case: It accepts arguments corresponding to the arguments of the constructor of the parent type. It then returns a procedure p that accepts as many arguments as there are (additional) fields in this type, in the same order as in the fields clause, and returns a record object with the fields of the parent record types initialized according to their constructors and the arguments to n, and the fields of this record type initialized to its arguments of p.
  • The constructor returned by the protocol procedure can accept an arbitrary number of arguments, and should call n once to construct the procedure p, and call p once to create the record object, and finally return that record object.

    For example, the following protocol expression assumes that the constructor of the parent type takes three arguments:

    (lambda (n)

    (lambda (v1 v2 v3 x1 x2 x3 x4)

    (let ((p (n v1 v2 v3)))

    (p x1 x2 x3 x4))))

    The resulting constructor accepts seven arguments, and initializes the fields of the parent types according to the constructor of the parent type, with v1, v2, and v3 as arguments. It also initializes the fields of this record type to the values of x1, ..., x4.

  • If there is a parent clause, but no protocol clause, then the parent type must not have a protocol clause itself. The constructor bound to <constructor name> is a procedure that accepts arguments corresponding to the parent types' constructor first, and then one argument for each field in the same order as in the fields clause. The constructor returns a record object with the fields initialized to the corresponding arguments.
  • If there is a parent-rtd clause, then the constructor is as with a parent clause, except that the constructor of the parent type is determined by the constructor descriptor of the parent-rtd clause.
  • A protocol may perform other actions consistent with the requirements described above, including mutation of the new record or other side effects, before returning the record.

    Any definition that takes advantage of implicit naming for the constructor, predicate, accessor, and mutator names can be rewritten trivially to a definition that specifies all names explicitly. For example, the implicit-naming record definition:

    (define-record-type frob

    (fields (mutable widget))

    (protocol

    (lambda (p)

    (lambda (n) (p (make-widget n))))))

    is equivalent to the following explicit-naming record definition.

    (define-record-type (frob make-frob frob?)

    (fields (mutable widget

    frob-widget

    frob-widget-set!))

    (protocol

    (lambda (p)

    (lambda (n) (p (make-widget n))))))

    Also, the implicit-naming record definition:

    (define-record-type point (fields x y))

    is equivalent to the following explicit-naming record definition:

    (define-record-type (point make-point point?)

    (fields

    (immutable x point-x)

    (immutable y point-y)))

    With implicit naming, it is still possible to specify some of the names explicitly; for example, the following overrides the choice of accessor and mutator names for the widget field.

    (define-record-type frob

    (fields (mutable widget getwid setwid!))

    (protocol

    (lambda (p)

    (lambda (n) (p (make-widget n))))))

    (rnrs records syntactic (6)) syntax (record-type-descriptor record-name)

    Evaluates to the record-type descriptor associated with the type specified by <record name>.

    (rnrs records syntactic (6)) syntax (record-constructor-descriptor record-name)

    Evaluates to the record-constructor descriptor associated with <record name>.

    library (rnrs sorting (6))

    (rnrs sorting (6)) procedure (list-sort (< procedure?) (lis list?)) ⟹ list?

    (< obj1 obj2) ⟹ boolean?

    Proc should accept any two elements of list, and should not have any side effects. Proc should return a true value when its first argument is strictly less than its second, and #f otherwise.

    The list-sort procedure performs a stable sort of list in ascending order according to proc, without changing list in any way. The results may be eq? to the argument when the argument is already sorted, and the result of list-sort may share structure with a tail of the original list. The sorting algorithm performs O(n lg n) calls to proc where n is the length of list, and all arguments passed to proc are elements of the list being sorted, but the pairing of arguments and the sequencing of calls to proc are not specified. If multiple returns occur from list-sort, the return values returned by earlier returns are not mutated.

    (rnrs sorting (6)) procedure (vector-sort (< procedure?) (v vector?)) ⟹ boolean?

    (< obj1 obj2) ⟹ boolean?

    Proc should accept any two elements of vector, and should not have any side effects. Proc should return a true value when its first argument is strictly less than its second, and #f otherwise.

    The vector-sort procedure performs a stable sort of vector in ascending order according to proc, without changing vector in any way. The results may be eq? to the argument when the argument is already sorted, and the result of list-sort may share structure with a tail of the original list. The sorting algorithm performs O(n lg n) calls to proc where n is the length of list or vector, and all arguments passed to proc are elements of the list or vector being sorted, but the pairing of arguments and the sequencing of calls to proc are not specified. If multiple returns occur from vector-sort, the return values returned by earlier returns are not mutated.

    (rnrs sorting (6)) procedure (vector-sort! (< procedure?) (v vector?)) ⟹ boolean?

    (< obj1 obj2) ⟹ boolean?

    Proc should accept any two elements of the vector, and should not have any side effects. Proc should return a true value when its first argument is strictly less than its second, and #f otherwise. The vector-sort! procedure destructively sorts vector in ascending order according to proc. The sorting algorithm performs O(n2) calls to proc where n is the length of vector, and all arguments passed to proc are elements of the vector being sorted, but the pairing of arguments and the sequencing of calls to proc are not specified. The sorting algorithm may be unstable. The procedure returns unspecified values.

    library (rnrs unicode (6))

    (rnrs unicode (6)) procedure (char-upcase (char char?)) ⟹ char?

    (rnrs unicode (6)) procedure (char-downcase (char char?)) ⟹ char?

    (rnrs unicode (6)) procedure (char-titlecase (char char?)) ⟹ char?

    (rnrs unicode (6)) procedure (char-foldcase (char char?)) ⟹ char?

    These procedures take a character argument and return a character result. If the argument is an upper-case or title-case character, and if there is a single character that is its lower-case form, then char-downcase returns that character. If the argument is a lower-case or title-case character, and there is a single character that is its upper-case form, then char-upcase returns that character. If the argument is a lower-case or upper-case character, and there is a single character that is its title-case form, then char-titlecase returns that character. If the argument is not a title-case character and there is no single character that is its title-case form, then char-titlecase returns the upper-case form of the argument. Finally, if the character has a case-folded character, then char-foldcase returns that character. Otherwise the character returned is the same as the argument. For Turkic characters İ (#\x130) and ı (#\x131), char-foldcase behaves as the identity function; otherwise char-foldcase is the same as char-downcase composed with char-upcase.

    (rnrs unicode (6)) procedure (char-ci<=? (char1 char?) (char2 char?) (char3 char?) ...) ⟹ boolean?

    (rnrs unicode (6)) procedure (char-ci<? (char1 char?) (char2 char?) (char3 char?) ...) ⟹ boolean?

    (rnrs unicode (6)) procedure (char-ci=? (char1 char?) (char2 char?) (char3 char?) ...) ⟹ boolean?

    (rnrs unicode (6)) procedure (char-ci>=? (char1 char?) (char2 char?) (char3 char?) ...) ⟹ boolean?

    (rnrs unicode (6)) procedure (char-ci>? (char1 char?) (char2 char?) (char3 char?) ...) ⟹ boolean?

    These procedures are similar to char=?, etc., but operate on the case-folded versions of the characters.

    (rnrs unicode (6)) procedure (char-alphabetic? (char char?)) ⟹ boolean?

    (rnrs unicode (6)) procedure (char-numeric? (char char?)) ⟹ boolean?

    (rnrs unicode (6)) procedure (char-whitespace? (char char?)) ⟹ boolean?

    (rnrs unicode (6)) procedure (char-upper-case? (char char?)) ⟹ boolean?

    (rnrs unicode (6)) procedure (char-lower-case? (char char?)) ⟹ boolean?

    (rnrs unicode (6)) procedure (char-title-case? (char char?)) ⟹ boolean?

    These procedures return #t if their arguments are alphabetic, numeric, whitespace, upper-case, lower-case, or title-case characters, respectively; otherwise they return #f.

    A character is alphabetic if it has the Unicode "Alphabetic" property. A character is numeric if it has the Unicode "Numeric" property. A character is whitespace if has the Unicode "White_Space" property. A character is upper case if it has the Unicode "Uppercase" property, lower case if it has the "Lowercase" property, and title case if it is in the Lt general category.

    (rnrs unicode (6)) procedure (char-general-category (char char?)) ⟹ symbol?

    Returns a symbol representing the Unicode general category of char, one of Lu, Ll, Lt, Lm, Lo, Mn, Mc, Me, Nd, Nl, No, Ps, Pe, Pi, Pf, Pd, Pc, Po, Sc, Sm, Sk, So, Zs, Zp, Zl, Cc, Cf, Cs, Co, or Cn.

    (rnrs unicode (6)) procedure (string-upcase (string string?)) ⟹ string?

    (rnrs unicode (6)) procedure (string-downcase (string string?)) ⟹ string?

    (rnrs unicode (6)) procedure (string-titlecase (string string?)) ⟹ string?

    (rnrs unicode (6)) procedure (string-foldcase (string string?)) ⟹ string?

    These procedures take a string argument and return a string result. They are defined in terms of Unicode's locale-independent case mappings from Unicode scalar-value sequences to scalar-value sequences. In particular, the length of the result string can be different from the length of the input string. When the specified result is equal in the sense of string=? to the argument, these procedures may return the argument instead of a newly allocated string.

    The string-upcase procedure converts a string to upper case; string-downcase converts a string to lower case. The string-foldcase procedure converts the string to its case-folded counterpart, using the full case-folding mapping, but without the special mappings for Turkic languages. The string-titlecase procedure converts the first cased character of each word via char-titlecase, and downcases all other cased characters.

    (rnrs unicode (6)) procedure (string-ci<=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (rnrs unicode (6)) procedure (string-ci<? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (rnrs unicode (6)) procedure (string-ci=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (rnrs unicode (6)) procedure (string-ci>=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (rnrs unicode (6)) procedure (string-ci>? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    These procedures are similar to string=?, etc., but operate on the case-folded versions of the strings.

    (rnrs unicode (6)) procedure (string-normalize-nfd (string string?)) ⟹ string?

    (rnrs unicode (6)) procedure (string-normalize-nfkd (string string?)) ⟹ string?

    (rnrs unicode (6)) procedure (string-normalize-nfc (string string?)) ⟹ string?

    (rnrs unicode (6)) procedure (string-normalize-nfkc (string string?)) ⟹ string?

    These procedures take a string argument and return a string result, which is the input string normalized to Unicode normalization form D, KD, C, or KC, respectively. When the specified result is equal in the sense of string=? to the argument, these procedures may return the argument instead of a newly allocated string.

    library (srfi 0) Feature-based conditional expansion construct

    It is desirable that programs which depend on additions to standard Scheme name those additions. SRFIs provide the specifications of these additions ("features"), and SRFI 0 provides the means to actually check that these features are present in the Scheme system by means of the cond-expand construct. It is anticipated that there will be two main classes of features:

    • sets of value and syntax bindings
    • reader syntax extensions

    ("Reader syntax" refers to aspects of the syntax described by the grammars in the Scheme reports.)

    The former class of features will probably include most SRFIs, exemplified by the list library specified in SRFI 1. The latter class includes Unicode source code support and different kinds of parentheses.

    Control over the presence of individual features will vary over different Scheme systems. A given feature may be absent or provided by default in some Scheme systems and in others some mechanism (such as an "import" clause in the code or a program configuration file, a command line option, a dependency declaration in a module definition, etc.) will be required for the feature to be present in the system.

    Moreover, in some systems a given feature may be in effect throughout the entire program if it is in effect anywhere at all. Other systems may have more precise mechanisms to control the scope of a feature (this might be the case for example when a module system is supported). In general it is thus possible that a feature is in effect in some parts of the program and not in others. This allows conflicting SRFIs to be present in a given program as long as their scope do not intersect.

    SRFI 0 does not prescribe a particular mechanism for controlling the presence of a feature as it is our opinion that this should be the role of a module system. We expect that future module system SRFIs will need to extend the semantics of SRFI 0 for their purposes, for example by defining feature scoping rules or by generalizing the feature testing construct.

    See (scheme base)

    library (srfi 1) List Library

    R5RS Scheme has an impoverished set of list-processing utilities, which is a problem for authors of portable code. This SRFI proposes a coherent and comprehensive set of list-processing procedures; it is accompanied by a reference implementation of the spec. The reference implementation is

    • portable
    • efficient
    • completely open, public-domain source

    See (scheme list)

    library (srfi 2) AND-LET*: an AND with local bindings, a guarded LET* special form

    Like an ordinary AND, an AND-LET* special form evaluates its arguments -- expressions -- one after another in order, till the first one that yields #f. Unlike AND, however, a non-#f result of one expression can be bound to a fresh variable and used in the subsequent expressions. AND-LET* is a cross-breed between LET* and AND.

    (srfi 2) syntax (and-let* (claw ...) body)

    claw ⟹ (variable expression) | (expression) | bound-variable

    In case of an ordinary AND formed of proper boolean expressions: (AND E1 E2 ...) expression E2, if it gets to be evaluated, knows that E1 has returned non-#f. Moreover, E2 knows exactly what the result of E1 was -- #t -- which E2 can use to its advantage. If E1 however is an extended boolean expression, E2 can no longer tell which particular non-#f value E1 has returned. Chances are it took a lot of work to evaluate E1, and the produced result (a number, a vector, a string, etc) may be of value to E2. Alas, the AND form merely checks that the result is not an #f, and throws it away. If E2 needs it, it has to compute that value anew. This proposed AND-LET* special form lets constituent expressions get hold of the results of already evaluated expressions, without re-doing their work.

    AND-LET* can be thought of as a combination of LET* and AND, or a generalization of COND's send operator =>. An AND-LET* form can also be considered a sequence of guarded expressions. In a regular program, forms may produce results, bind them to variables and let other forms use these results. AND-LET* differs in that it checks to make sure that every produced result "makes sense" (that is, not an #f). The first "failure" triggers the guard and aborts the rest of the sequence (which presumably would not make any sense to execute anyway).

    library (srfi 4) Homogeneous numeric vector datatypes

    This SRFI describes a set of datatypes for vectors whose elements are of the same numeric type (signed or unsigned exact integer or inexact real of a given precision). These datatypes support operations analogous to the Scheme vector type, but they are distinct datatypes. An external representation is specified which must be supported by the read and write procedures and by the program parser (i.e. programs can contain references to literal homogeneous vectors).

    (srfi 4) procedure (u8vector? obj) ⟹ boolean?

    Returns #t if the if an object is homogenous u8vector, #f otherwise.

    (srfi 4) procedure (make-u8vector (size integer?)) ⟹ u8vector?

    (srfi 4) procedure (make-u8vector (size integer?) (fill integer?)) ⟹ u8vector?

    Create homogenous u8 vector. If fill is given, it must be unsigned exact integer in the range 0 to (2^8)-1. If fill isn't given, vector is filled with unspecified values which are guaranteed to fit into the range of the u8vector.

    (srfi 4) procedure (u8vector (value integer?) ...) ⟹ u8vector?

    Create homogenous u8 vector. Each value must be unsigned exact integer in the range 0 to (2^8)-1.

    (srfi 4) procedure (u8vector-length (vec u8vector?)) ⟹ integer?

    Returns the number of elements in u8vector as an exact integer.

    (srfi 4) procedure (u8vector-ref (vec u8vector?) (i integer?)) ⟹ integer?

    Returns i-th element in the vector. i must be in range [0, (u8vector-length vec))

    (srfi 4) procedure (u8vector-set! (vec u8vector?) (i integer?) (value integer?)) ⟹ undefined

    u8vector-set! stores value in element k of vector. Value must be unsigned exact integer in the range 0 to (2^8)-1. i must be in range [0, (u8vector-length vec))

    (srfi 4) procedure (u8vector->list (vec u8vector?)) ⟹ list?

    Converts a homogenous vector to a list.

    (srfi 4) procedure (list->u8vector (proper-list list?)) ⟹ u8vector?

    proper-list ⟹ (list integer?)

    Converts a list to a homogenous u8vector. Each element in input list must be unsigned exact integer in the range 0 to (2^8)-1.

    (srfi 4) procedure (s8vector? obj) ⟹ boolean?

    Returns #t if the if an object is homogenous s8vector, #f otherwise.

    (srfi 4) procedure (make-s8vector (size integer?)) ⟹ s8vector?

    (srfi 4) procedure (make-s8vector (size integer?) (fill integer?)) ⟹ s8vector?

    Create homogenous s8 vector. If fill is given, it must be signed exact integer in the range -(2^7) to (2^7)-1. If fill isn't given, vector is filled with unspecified values which are guaranteed to fit into the range of the s8vector.

    (srfi 4) procedure (s8vector (value integer?) ...) ⟹ s8vector?

    Create homogenous s8 vector. Each value must be signed exact integer in the range -(2^7) to (2^7)-1.

    (srfi 4) procedure (s8vector-length (vec s8vector?)) ⟹ integer?

    Returns the number of elements in s8vector as an exact integer.

    (srfi 4) procedure (s8vector-ref (vec s8vector?) (i integer?)) ⟹ integer?

    Returns i-th element in the vector. i must be in range [0, (s8vector-length vec))

    (srfi 4) procedure (s8vector-set! (vec s8vector?) (i integer?) (value integer?)) ⟹ undefined

    s8vector-set! stores value in element k of vector. Value must be signed exact integer in the range -(2^7) to (2^7)-1. i must be in range [0, (s8vector-length vec))

    (srfi 4) procedure (s8vector->list (vec s8vector?)) ⟹ list?

    Converts a homogenous vector to a list.

    (srfi 4) procedure (list->s8vector (proper-list list?)) ⟹ s8vector?

    proper-list ⟹ (list integer?)

    Converts a list to a homogenous s8vector. Each element in input list must be signed exact integer in the range -(2^7) to (2^7)-1.

    (srfi 4) procedure (u16vector? obj) ⟹ boolean?

    Returns #t if the if an object is homogenous u16vector, #f otherwise.

    (srfi 4) procedure (make-u16vector (size integer?)) ⟹ u16vector?

    (srfi 4) procedure (make-u16vector (size integer?) (fill integer?)) ⟹ u16vector?

    Create homogenous u16 vector. If fill is given, it must be unsigned exact integer in the range 0 to (2^16)-1. If fill isn't given, vector is filled with unspecified values which are guaranteed to fit into the range of the u16vector.

    (srfi 4) procedure (u16vector (value integer?) ...) ⟹ u16vector?

    Create homogenous u16 vector. Each value must be unsigned exact integer in the range 0 to (2^16)-1.

    (srfi 4) procedure (u16vector-length (vec u16vector?)) ⟹ integer?

    Returns the number of elements in u16vector as an exact integer.

    (srfi 4) procedure (u16vector-ref (vec u16vector?) (i integer?)) ⟹ integer?

    Returns i-th element in the vector. i must be in range [0, (u16vector-length vec))

    (srfi 4) procedure (u16vector-set! (vec u16vector?) (i integer?) (value integer?)) ⟹ undefined

    u16vector-set! stores value in element k of vector. Value must be unsigned exact integer in the range 0 to (2^16)-1. i must be in range [0, (u16vector-length vec))

    (srfi 4) procedure (u16vector->list (vec u16vector?)) ⟹ list?

    Converts a homogenous vector to a list.

    (srfi 4) procedure (list->u16vector (proper-list list?)) ⟹ u16vector?

    proper-list ⟹ (list integer?)

    Converts a list to a homogenous u16vector. Each element in input list must be unsigned exact integer in the range 0 to (2^16)-1.

    (srfi 4) procedure (s16vector? obj) ⟹ boolean?

    Returns #t if the if an object is homogenous s16vector, #f otherwise.

    (srfi 4) procedure (make-s16vector (size integer?)) ⟹ s16vector?

    (srfi 4) procedure (make-s16vector (size integer?) (fill integer?)) ⟹ s16vector?

    Create homogenous s16 vector. If fill is given, it must be signed exact integer in the range -(2^15) to (2^15)-1. If fill isn't given, vector is filled with unspecified values which are guaranteed to fit into the range of the s16vector.

    (srfi 4) procedure (s16vector (value integer?) ...) ⟹ s16vector?

    Create homogenous s16 vector. Each value must be signed exact integer in the range -(2^15) to (2^15)-1.

    (srfi 4) procedure (s16vector-length (vec s16vector?)) ⟹ integer?

    Returns the number of elements in s16vector as an exact integer.

    (srfi 4) procedure (s16vector-ref (vec s16vector?) (i integer?)) ⟹ integer?

    Returns i-th element in the vector. i must be in range [0, (s16vector-length vec))

    (srfi 4) procedure (s16vector-set! (vec s16vector?) (i integer?) (value integer?)) ⟹ undefined

    s16vector-set! stores value in element k of vector. Value must be signed exact integer in the range -(2^15) to (2^15)-1. i must be in range [0, (s16vector-length vec))

    (srfi 4) procedure (s16vector->list (vec s16vector?)) ⟹ list?

    Converts a homogenous vector to a list.

    (srfi 4) procedure (list->s16vector (proper-list list?)) ⟹ s16vector?

    proper-list ⟹ (list integer?)

    Converts a list to a homogenous s16vector. Each element in input list must be signed exact integer in the range -(2^15) to (2^15)-1.

    (srfi 4) procedure (u32vector? obj) ⟹ boolean?

    Returns #t if the if an object is homogenous u32vector, #f otherwise.

    (srfi 4) procedure (make-u32vector (size integer?)) ⟹ u32vector?

    (srfi 4) procedure (make-u32vector (size integer?) (fill integer?)) ⟹ u32vector?

    Create homogenous u32 vector. If fill is given, it must be unsigned exact integer in the range 0 to (2^32)-1. If fill isn't given, vector is filled with unspecified values which are guaranteed to fit into the range of the u32vector.

    (srfi 4) procedure (u32vector (value integer?) ...) ⟹ u32vector?

    Create homogenous u32 vector. Each value must be unsigned exact integer in the range 0 to (2^32)-1.

    (srfi 4) procedure (u32vector-length (vec u32vector?)) ⟹ integer?

    Returns the number of elements in u32vector as an exact integer.

    (srfi 4) procedure (u32vector-ref (vec u32vector?) (i integer?)) ⟹ integer?

    Returns i-th element in the vector. i must be in range [0, (u32vector-length vec))

    (srfi 4) procedure (u32vector-set! (vec u32vector?) (i integer?) (value integer?)) ⟹ undefined

    u32vector-set! stores value in element k of vector. Value must be unsigned exact integer in the range 0 to (2^32)-1. i must be in range [0, (u32vector-length vec))

    (srfi 4) procedure (u32vector->list (vec u32vector?)) ⟹ list?

    Converts a homogenous vector to a list.

    (srfi 4) procedure (list->u32vector (proper-list list?)) ⟹ u32vector?

    proper-list ⟹ (list integer?)

    Converts a list to a homogenous u32vector. Each element in input list must be unsigned exact integer in the range 0 to (2^32)-1.

    (srfi 4) procedure (s32vector? obj) ⟹ boolean?

    Returns #t if the if an object is homogenous s32vector, #f otherwise.

    (srfi 4) procedure (make-s32vector (size integer?)) ⟹ s32vector?

    (srfi 4) procedure (make-s32vector (size integer?) (fill integer?)) ⟹ s32vector?

    Create homogenous s32 vector. If fill is given, it must be signed exact integer in the range -(2^31) to (2^31)-1. If fill isn't given, vector is filled with unspecified values which are guaranteed to fit into the range of the s32vector.

    (srfi 4) procedure (s32vector (value integer?) ...) ⟹ s32vector?

    Create homogenous s32 vector. Each value must be signed exact integer in the range -(2^31) to (2^31)-1.

    (srfi 4) procedure (s32vector-length (vec s32vector?)) ⟹ integer?

    Returns the number of elements in s32vector as an exact integer.

    (srfi 4) procedure (s32vector-ref (vec s32vector?) (i integer?)) ⟹ integer?

    Returns i-th element in the vector. i must be in range [0, (s32vector-length vec))

    (srfi 4) procedure (s32vector-set! (vec s32vector?) (i integer?) (value integer?)) ⟹ undefined

    s32vector-set! stores value in element k of vector. Value must be signed exact integer in the range -(2^31) to (2^31)-1. i must be in range [0, (s32vector-length vec))

    (srfi 4) procedure (s32vector->list (vec s32vector?)) ⟹ list?

    Converts a homogenous vector to a list.

    (srfi 4) procedure (list->s32vector (proper-list list?)) ⟹ s32vector?

    proper-list ⟹ (list integer?)

    Converts a list to a homogenous s32vector. Each element in input list must be signed exact integer in the range -(2^31) to (2^31)-1.

    (srfi 4) procedure (u64vector? obj) ⟹ boolean?

    Returns #t if the if an object is homogenous u64vector, #f otherwise.

    (srfi 4) procedure (make-u64vector (size integer?)) ⟹ u64vector?

    (srfi 4) procedure (make-u64vector (size integer?) (fill integer?)) ⟹ u64vector?

    Create homogenous u64 vector. If fill is given, it must be unsigned exact integer in the range 0 to (2^64)-1. If fill isn't given, vector is filled with unspecified values which are guaranteed to fit into the range of the u64vector.

    (srfi 4) procedure (u64vector (value integer?) ...) ⟹ u64vector?

    Create homogenous u64 vector. Each value must be unsigned exact integer in the range 0 to (2^64)-1.

    (srfi 4) procedure (u64vector-length (vec u64vector?)) ⟹ integer?

    Returns the number of elements in u64vector as an exact integer.

    (srfi 4) procedure (u64vector-ref (vec u64vector?) (i integer?)) ⟹ integer?

    Returns i-th element in the vector. i must be in range [0, (u64vector-length vec))

    (srfi 4) procedure (u64vector-set! (vec u64vector?) (i integer?) (value integer?)) ⟹ undefined

    u64vector-set! stores value in element k of vector. Value must be unsigned exact integer in the range 0 to (2^64)-1. i must be in range [0, (u64vector-length vec))

    (srfi 4) procedure (u64vector->list (vec u64vector?)) ⟹ list?

    Converts a homogenous vector to a list.

    (srfi 4) procedure (list->u64vector (proper-list list?)) ⟹ u64vector?

    proper-list ⟹ (list integer?)

    Converts a list to a homogenous u64vector. Each element in input list must be unsigned exact integer in the range 0 to (2^64)-1.

    (srfi 4) procedure (s64vector? obj) ⟹ boolean?

    Returns #t if the if an object is homogenous s64vector, #f otherwise.

    (srfi 4) procedure (make-s64vector (size integer?)) ⟹ s64vector?

    (srfi 4) procedure (make-s64vector (size integer?) (fill integer?)) ⟹ s64vector?

    Create homogenous s64 vector. If fill is given, it must be signed exact integer in the range -(2^63) to (2^63)-1. If fill isn't given, vector is filled with unspecified values which are guaranteed to fit into the range of the s64vector.

    (srfi 4) procedure (s64vector (value integer?) ...) ⟹ s64vector?

    Create homogenous s64 vector. Each value must be signed exact integer in the range -(2^63) to (2^63)-1.

    (srfi 4) procedure (s64vector-length (vec s64vector?)) ⟹ integer?

    Returns the number of elements in s64vector as an exact integer.

    (srfi 4) procedure (s64vector-ref (vec s64vector?) (i integer?)) ⟹ integer?

    Returns i-th element in the vector. i must be in range [0, (s64vector-length vec))

    (srfi 4) procedure (s64vector-set! (vec s64vector?) (i integer?) (value integer?)) ⟹ undefined

    s64vector-set! stores value in element k of vector. Value must be signed exact integer in the range -(2^63) to (2^63)-1. i must be in range [0, (s64vector-length vec))

    (srfi 4) procedure (s64vector->list (vec s64vector?)) ⟹ list?

    Converts a homogenous vector to a list.

    (srfi 4) procedure (list->s64vector (proper-list list?)) ⟹ s64vector?

    proper-list ⟹ (list integer?)

    Converts a list to a homogenous s64vector. Each element in input list must be signed exact integer in the range -(2^63) to (2^63)-1.

    (srfi 4) procedure (f32vector? obj) ⟹ boolean?

    Returns #t if the if an object is homogenous f32vector, #f otherwise.

    (srfi 4) procedure (make-f32vector (size integer?)) ⟹ f32vector?

    (srfi 4) procedure (make-f32vector (size integer?) (fill real?)) ⟹ f32vector?

    Create homogenous f32 vector. If fill is given, it must be inexact real. If fill isn't given, vector is filled with unspecified values which are guaranteed to fit into the range of the f32vector.

    (srfi 4) procedure (f32vector (value real?) ...) ⟹ f32vector?

    Create homogenous f32 vector. Each value must be inexact real.

    (srfi 4) procedure (f32vector-length (vec f32vector?)) ⟹ integer?

    Returns the number of elements in f32vector as an exact integer.

    (srfi 4) procedure (f32vector-ref (vec f32vector?) (i integer?)) ⟹ real?

    Returns i-th element in the vector. i must be in range [0, (f32vector-length vec))

    (srfi 4) procedure (f32vector-set! (vec f32vector?) (i integer?) (value real?)) ⟹ undefined

    f32vector-set! stores value in element k of vector. Value must be inexact real. i must be in range [0, (f32vector-length vec))

    (srfi 4) procedure (f32vector->list (vec f32vector?)) ⟹ list?

    Converts a homogenous vector to a list.

    (srfi 4) procedure (list->f32vector (proper-list list?)) ⟹ f32vector?

    proper-list ⟹ (list real?)

    Converts a list to a homogenous f32vector. Each element in input list must be inexact real.

    (srfi 4) procedure (f64vector? obj) ⟹ boolean?

    Returns #t if the if an object is homogenous f64vector, #f otherwise.

    (srfi 4) procedure (make-f64vector (size integer?)) ⟹ f64vector?

    (srfi 4) procedure (make-f64vector (size integer?) (fill real?)) ⟹ f64vector?

    Create homogenous f64 vector. If fill is given, it must be inexact real. If fill isn't given, vector is filled with unspecified values which are guaranteed to fit into the range of the f64vector.

    (srfi 4) procedure (f64vector (value real?) ...) ⟹ f64vector?

    Create homogenous f64 vector. Each value must be inexact real.

    (srfi 4) procedure (f64vector-length (vec f64vector?)) ⟹ integer?

    Returns the number of elements in f64vector as an exact integer.

    (srfi 4) procedure (f64vector-ref (vec f64vector?) (i integer?)) ⟹ real?

    Returns i-th element in the vector. i must be in range [0, (f64vector-length vec))

    (srfi 4) procedure (f64vector-set! (vec f64vector?) (i integer?) (value real?)) ⟹ undefined

    f64vector-set! stores value in element k of vector. Value must be inexact real. i must be in range [0, (f64vector-length vec))

    (srfi 4) procedure (f64vector->list (vec f64vector?)) ⟹ list?

    Converts a homogenous vector to a list.

    (srfi 4) procedure (list->f64vector (proper-list list?)) ⟹ f64vector?

    proper-list ⟹ (list real?)

    Converts a list to a homogenous f64vector. Each element in input list must be inexact real.

    library (srfi 5) A compatible let form with signatures and rest arguments

    The named-let incarnation of the let form has two slight inconsistencies with the define form. As defined, the let form makes no accommodation for rest arguments, an issue of functionality and consistency. As defined, the let form does not accommodate signature-style syntax, an issue of aesthetics and consistency. Both issues are addressed here in a manner which is compatible with the traditional let form but for minor extensions.

    (srfi 5) syntax (let ((var1 init1) ...) body)

    (srfi 5) syntax (let name ((var1 init1) ...) body)

    (srfi 5) syntax (let name ((var1 init1) ... var-rest rest-init ...) body)

    (srfi 5) syntax (let (name (var1 init1) ...) body)

    (srfi 5) syntax (let (name (var1 init1) ... var-rest rest-init ...) body)

    An informal specification follows.

    Unnamed

    (let ((<parameter> <argument>)...)

    <body>...)

    Named, non-signature-style, no rest argument

    (let <name> ((<parameter> <argument>)...)

    <body>...)

    Named, signature-style, no rest argument

    (let (<name> (<parameter> <argument>)...)

    <body>...)

    Named, non-signature-style, rest argument

    (let <name> ((<parameter> <argument>)...

    . (<rest-parameter> <rest-argument>...))

    <body>...)

    Named, signature-style, rest argument

    (let (<name> (<parameter> <argument>)...

    . (<rest-parameter> <rest-argument>...))

    <body>...)

    Let $lambda and $letrec be hygienic bindings for the lambda and letrec forms, respectively.

    For informal syntax 1:

    (($lambda (<parameter>...) <body>...) <argument>...)

    For informal syntaxes 2 and 3:

    ($letrec ((<name> ($lambda (<parameter>...) <body>...)))

    (<name> <argument>...))

    For informal syntaxes 4 and 5:

    ($letrec ((<name> ($lambda (<parameter>...

    . <rest-parameter>) <body>...)))

    (<name> <argument>... <rest-argument>...))

    library (srfi 6) Basic String Ports

    Scheme's i/o primitives are extended by adding three new procedures that

    • create an input port from a string,
    • create an output port whose contents are accumulated in Scheme's working memory instead of an external file, and
    • extract the accumulated contents of an in-memory output port and return them in the form of a string.

    See (scheme base)

    library (srfi 8) receive: Binding to multiple values

    The only mechanism that R5RS provides for binding identifiers to the values of a multiple-valued expression is the primitive call-with-values. This SRFI proposes a more concise, more readable syntax for creating such bindings.

    (srfi 8) syntax (receive formals expression body)

    formals ⟹ (variable1 ...) | variable | (variable1 ... variable_n . variable_n+1)

    <Formals>, <expression>, and <body> are as described in R5RS. Specifically, <formals> can have any of three forms:

  • (<variable1> ... <variablen>): The environment in which the receive-expression is evaluated is extended by binding <variable1>, ..., <variablen> to fresh locations. The <expression> is evaluated, and its values are stored into those locations. (It is an error if <expression> does not have exactly n values.)
  • <variable>: The environment in which the receive-expression is evaluated is extended by binding <variable> to a fresh location. The <expression> is evaluated, its values are converted into a newly allocated list, and the list is stored in the location bound to <variable>.
  • (<variable1> ... <variablen> . <variablen + 1>): The environment in which the receive-expression is evaluated is extended by binding <variable1>, ..., <variablen + 1> to fresh locations. The <expression> is evaluated. Its first n values are stored into the locations bound to <variable1> ... <variablen>. Any remaining values are converted into a newly allocated list, which is stored into the location bound to <variablen + 1>. (It is an error if <expression> does not have at least n values.)
  • library (srfi 9) Defining Record Types

    This SRFI describes syntax for creating new data types, called record types. A predicate, constructor, and field accessors and modifiers are defined for each record type. Each new record type is distinct from all existing types, including other record types and Scheme's predefined types.

    See (scheme base)

    library (srfi 11) Syntax for receiving multiple values

    The SRFI introduces syntactic forms LET-VALUES and LET*-VALUES that bind the values of expressions that return multiple values.

    See (scheme base)

    library (srfi 13) String Libraries

    R5RS Scheme has an impoverished set of string-processing utilities, which is a problem for authors of portable code. This SRFI proposes a coherent and comprehensive set of string-processing procedures; it is accompanied by a reference implementation of the spec. The reference implementation is

    • portable
    • efficient
    • open source

    The routines in this SRFI are backwards-compatible with the string-processing routines of R5RS.

    (srfi 13) procedure (string? obj) ⟹ boolean?

    Returns #t if obj is a string, otherwise returns #f.

    (srfi 13) procedure (string-null? (s string?)) ⟹ boolean?

    Is s the empty string?

    (srfi 13) procedure (string-every (c char? | char-set? | predicate) (s string?)) ⟹ *

    (srfi 13) procedure (string-every (c char? | char-set? | predicate) (s string?) (start integer?)) ⟹ *

    (srfi 13) procedure (string-every (c char? | char-set? | predicate) (s string?) (start integer?) (end integer?)) ⟹ *

    Checks to see if the given criteria is true of every character in s, proceeding from left (index start) to right (index end). If char/char-set/pred is a character, it is tested for equality with the elements of s. If char/char-set/pred is a character set, the elements of s are tested for membership in the set. If char/char-set/pred is a predicate procedure, it is applied to the elements of s. The predicate is "witness-generating:". If string-every returns true, the returned true value is the one produced by the final application of the predicate to s[end-1]. If string-every is applied to an empty sequence of characters, it simply returns #t. If string-every applies the predicate to the final element of the selected sequence (i.e., s[end-1]), that final application is a tail call.

    (srfi 13) procedure (string-any (c char? | char-set? | predicate) (s string?)) ⟹ *

    (srfi 13) procedure (string-any (c char? | char-set? | predicate) (s string?) (start integer?)) ⟹ *

    (srfi 13) procedure (string-any (c char? | char-set? | predicate) (s string?) (start integer?) (end integer?)) ⟹ *

    Checks to see if the given criteria is true of every character in s, proceeding from left (index start) to right (index end). If char/char-set/pred is a character, it is tested for equality with the elements of s. If char/char-set/pred is a character set, the elements of s are tested for membership in the set. If char/char-set/pred is a predicate procedure, it is applied to the elements of s. The predicate is "witness-generating:". If string-any returns true, the returned true value is the one produced by the application of the predicate. If string-any is applied to an empty sequence of characters, it simply returns #t. If string-every applies the predicate to the final element of the selected sequence (i.e., s[end-1]), that final application is a tail call.

    (srfi 13) procedure (make-string (k integer?)) ⟹ string?

    (srfi 13) procedure (make-string (k integer?) (char char?)) ⟹ string?

    make-string returns a newly allocated string of length len. If char is given, then all elements of the string are initialized to char, otherwise the contents of the string are unspecified.

    (srfi 13) procedure (string (char char?) ...) ⟹ string?

    Returns a newly allocated string composed of the argument characters.

    (srfi 13) procedure (string-tabulate (proc procedure?) (len integer?)) ⟹ string?

    (proc (index integer?)) ⟹ char?

    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.

    (srfi 13) procedure (string->list (string string?)) ⟹ list?

    (srfi 13) procedure (string->list (string string?) (start integer?)) ⟹ list?

    (srfi 13) procedure (string->list (string string?) (start integer?) (end integer?)) ⟹ list?

    string->list returns a newly allocated list of the characters that make up the given string.

    (srfi 13) procedure (list->string (list list?)) ⟹ string?

    list->string returns a newly allocated string formed from the characters in the list char-list, which must be a list of characters.

    (srfi 13) procedure (reverse-list->string (list list?)) ⟹ string?

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

    (srfi 13) procedure (string-join (string-list list?)) ⟹ string?

    (srfi 13) procedure (string-join (string-list list?) (delimiter string?)) ⟹ string?

    (srfi 13) procedure (string-join (string-list list?) (delimiter string?) (grammar symbol?)) ⟹ string?

    This procedure is a simple unparser --- it pastes strings together using the delimiter string.

    The grammar argument is a symbol that determines how the delimiter is used, and defaults to 'infix.

    'infix means an infix or separator grammar: insert the delimiter between list elements. An empty list will produce an empty string -- note, however, that parsing an empty string with an infix or separator grammar is ambiguous. Is it an empty list, or a list of one element, the empty string?

    'strict-infix means the same as 'infix, but will raise an error if given an empty list.

    'suffix means a suffix or terminator grammar: insert the delimiter after every list element. This grammar has no ambiguities.

    'prefix means a prefix grammar: insert the delimiter before every list element. This grammar has no ambiguities.

    The delimiter is the string used to delimit elements; it defaults to a single space " ".

    (srfi 13) procedure (string-length (string string?)) ⟹ integer?

    Returns the number of characters in the string s.

    (srfi 13) procedure (string-ref (string string?) (k integer?)) ⟹ char?

    Returns character s[i] using zero-origin indexing. I must be a valid index of s.

    (srfi 13) procedure (string-copy (string string?)) ⟹ string?

    (srfi 13) procedure (string-copy (string string?) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-copy (string string?) (start integer?) (end integer?)) ⟹ string?

    string-copy is extended from its R5RS definition by the addition of its optional start/end parameters. In contrast to substring/shared, it is guaranteed to produce a freshly-allocated string.

    (srfi 13) procedure (substring/shared (string string?)) ⟹ string?

    (srfi 13) procedure (substring/shared (string string?) (start integer?)) ⟹ string?

    (srfi 13) procedure (substring/shared (string string?) (start integer?) (end integer?)) ⟹ string?

    substring/shared returns a string whose contents are the characters of s beginning with index start (inclusive) and ending with index end (exclusive). It differs from the R5RS substring in two ways:

  • The end parameter is optional, not required.
  • substring/shared may return a value that shares memory with s or is eq? to s.
  • (srfi 13) procedure (string-copy! (to string?) (at integer?) (from string?)) ⟹ undefined

    (srfi 13) procedure (string-copy! (to string?) (at integer?) (from string?) (start integer?)) ⟹ undefined

    (srfi 13) procedure (string-copy! (to string?) (at integer?) (from string?) (start integer?) (end integer?)) ⟹ undefined

    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.

    (srfi 13) procedure (string-take (s string?) (nchars integer?)) ⟹ string?

    string-take returns the first nchars of s

    (srfi 13) procedure (string-drop (s string?) (nchars integer?)) ⟹ string?

    string-drop returns all but the first nchars of s.

    (srfi 13) procedure (string-take-right (s string?) (nchars integer?)) ⟹ string?

    string-take-right returns the last nchars of s

    (srfi 13) procedure (string-drop-right (s string?) (nchars integer?)) ⟹ string?

    string-drop-right returns all but the last nchars of s.

    (srfi 13) procedure (string-pad (s string?) (len integer?)) ⟹ string?

    (srfi 13) procedure (string-pad (s string?) (len integer?) (char char?)) ⟹ string?

    (srfi 13) procedure (string-pad (s string?) (len integer?) (char char?) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-pad (s string?) (len integer?) (char char?) (start integer?) (end integer?)) ⟹ string?

    Build a string of length len comprised of s padded on the left by as many occurrences of the character char as needed. If s has more than len chars, it is truncated on the left to length len. Char defaults to #\space. If len <= end-start, the returned value is allowed to share storage with s, or be exactly s (if len = end-start).

    (srfi 13) procedure (string-pad-right (s string?) (len integer?)) ⟹ string?

    (srfi 13) procedure (string-pad-right (s string?) (len integer?) (char char?)) ⟹ string?

    (srfi 13) procedure (string-pad-right (s string?) (len integer?) (char char?) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-pad-right (s string?) (len integer?) (char char?) (start integer?) (end integer?)) ⟹ string?

    Build a string of length len comprised of s padded on the right by as many occurrences of the character char as needed. If s has more than len chars, it is truncated on the right to length len. Char defaults to #\space. If len <= end-start, the returned value is allowed to share storage with s, or be exactly s (if len = end-start).

    (srfi 13) procedure (string-trim (s string?) (c char? | char-set? | predicate)) ⟹ string?

    (srfi 13) procedure (string-trim (s string?) (c char? | char-set? | predicate) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-trim (s string?) (c char? | char-set? | predicate) (start integer?) (end integer?)) ⟹ string?

    Trim s by skipping over all characters on the left that satisfy the second parameter char/char-set/pred:

  • if it is a character char, characters equal to char are trimmed;
  • if it is a char set cs, characters contained in cs are trimmed;
  • if it is a predicate pred, it is a test predicate that is applied to the characters in s; a character causing it to return true is skipped.
  • Char/char-set/pred defaults to the character set char-set:whitespace defined in SRFI 14.

    (srfi 13) procedure (string-trim-right (s string?) (c char? | char-set? | predicate)) ⟹ string?

    (srfi 13) procedure (string-trim-right (s string?) (c char? | char-set? | predicate) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-trim-right (s string?) (c char? | char-set? | predicate) (start integer?) (end integer?)) ⟹ string?

    Trim s by skipping over all characters on the right that satisfy the second parameter char/char-set/pred:

  • if it is a character char, characters equal to char are trimmed;
  • if it is a char set cs, characters contained in cs are trimmed;
  • if it is a predicate pred, it is a test predicate that is applied to the characters in s; a character causing it to return true is skipped.
  • Char/char-set/pred defaults to the character set char-set:whitespace defined in SRFI 14.

    (srfi 13) procedure (string-trim-both (s string?) (c char? | char-set? | predicate)) ⟹ string?

    (srfi 13) procedure (string-trim-both (s string?) (c char? | char-set? | predicate) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-trim-both (s string?) (c char? | char-set? | predicate) (start integer?) (end integer?)) ⟹ string?

    Trim s by skipping over all characters on both sides that satisfy the second parameter char/char-set/pred:

  • if it is a character char, characters equal to char are trimmed;
  • if it is a char set cs, characters contained in cs are trimmed;
  • if it is a predicate pred, it is a test predicate that is applied to the characters in s; a character causing it to return true is skipped.
  • Char/char-set/pred defaults to the character set char-set:whitespace defined in SRFI 14.

    (srfi 13) procedure (string-set! (string string?) (i integer?) (char char?)) ⟹ undefined

    i must be a valid index of s. string-set! stores char in element i of s. Constant string literals appearing in code are immutable; it is an error to use them in a string-set!.

    (srfi 13) procedure (string-fill! (s string?) (fill char?)) ⟹ undefined

    (srfi 13) procedure (string-fill! (s string?) (fill char?) (start integer?)) ⟹ undefined

    (srfi 13) procedure (string-fill! (s string?) (fill char?) (start integer?) (end integer?)) ⟹ undefined

    Stores char in every element of s. string-fill is extended from the R5RS definition to take optional start/end arguments.

    (srfi 13) procedure (string-compare (s1 string?) (s2 string?) (proc< procedure?) (proc= procedure?) (proc> procedure?)) ⟹ *

    (srfi 13) procedure (string-compare (s1 string?) (s2 string?) (proc< procedure?) (proc= procedure?) (proc> procedure?) (start1 integer?)) ⟹ *

    (srfi 13) procedure (string-compare (s1 string?) (s2 string?) (proc< procedure?) (proc= procedure?) (proc> procedure?) (start1 integer?) (end1 integer?)) ⟹ *

    (srfi 13) procedure (string-compare (s1 string?) (s2 string?) (proc< procedure?) (proc= procedure?) (proc> procedure?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ *

    (srfi 13) procedure (string-compare (s1 string?) (s2 string?) (proc< procedure?) (proc= procedure?) (proc> procedure?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ *

    (proc< (index integer?)) ⟹ *

    (proc= (index integer?)) ⟹ *

    (proc> (index integer?)) ⟹ *

    Apply proc<, proc=, or proc> 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 doesn't match. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2. The mismatch index is always an index into s1; in the case of proc=, it is always end1; we observe the protocol in this redundant case for uniformity.

    (srfi 13) procedure (string-compare-ci (s1 string?) (s2 string?) (proc< procedure?) (proc= procedure?) (proc> procedure?)) ⟹ *

    (srfi 13) procedure (string-compare-ci (s1 string?) (s2 string?) (proc< procedure?) (proc= procedure?) (proc> procedure?) (start1 integer?)) ⟹ *

    (srfi 13) procedure (string-compare-ci (s1 string?) (s2 string?) (proc< procedure?) (proc= procedure?) (proc> procedure?) (start1 integer?) (end1 integer?)) ⟹ *

    (srfi 13) procedure (string-compare-ci (s1 string?) (s2 string?) (proc< procedure?) (proc= procedure?) (proc> procedure?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ *

    (srfi 13) procedure (string-compare-ci (s1 string?) (s2 string?) (proc< procedure?) (proc= procedure?) (proc> procedure?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ *

    (proc< (index integer?)) ⟹ *

    (proc= (index integer?)) ⟹ *

    (proc> (index integer?)) ⟹ *

    Apply proc<, proc=, or proc> to the mismatch index, depending upon whether s1 is less than, equal to, or greater than s2 in case-insensitive way. 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 doesn't match. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2. The mismatch index is always an index into s1; in the case of proc=, it is always end1; we observe the protocol in this redundant case for uniformity.

    (srfi 13) procedure (string= (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string= (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Lexicographic extensions to strings of the corresponding ordering on characters. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string<> (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string<> (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string<> (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string<> (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string<> (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Lexicographic extensions to strings of the corresponding ordering on characters. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string< (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string< (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string< (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string< (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string< (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Lexicographic extensions to strings of the corresponding ordering on characters. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string> (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string> (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string> (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string> (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string> (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Lexicographic extensions to strings of the corresponding ordering on characters. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string<= (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string<= (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string<= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string<= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string<= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Lexicographic extensions to strings of the corresponding ordering on characters. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string>= (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string>= (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string>= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string>= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string>= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Lexicographic extensions to strings of the corresponding ordering on characters. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string-ci= (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string-ci= (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Lexicographic extensions to strings of the corresponding ordering on characters, case-insensitive. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string-ci<> (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string-ci<> (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci<> (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci<> (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci<> (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Lexicographic extensions to strings of the corresponding ordering on characters, case-insensitive. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string-ci< (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string-ci< (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci< (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci< (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci< (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Lexicographic extensions to strings of the corresponding ordering on characters, case-insensitive. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string-ci> (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string-ci> (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci> (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci> (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci> (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Lexicographic extensions to strings of the corresponding ordering on characters, case-insensitive. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string-ci<= (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string-ci<= (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci<= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci<= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci<= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Lexicographic extensions to strings of the corresponding ordering on characters, case-insensitive. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string-ci>= (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string-ci>= (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci>= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci>= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-ci>= (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Lexicographic extensions to strings of the corresponding ordering on characters, case-insensitive. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string-hash (s string?)) ⟹ integer?

    (srfi 13) procedure (string-hash (s string?) (bound integer?)) ⟹ integer?

    (srfi 13) procedure (string-hash (s string?) (bound integer?) (start integer?)) ⟹ integer?

    (srfi 13) procedure (string-hash (s string?) (bound integer?) (start integer?) (end integer?)) ⟹ integer?

    Compute a hash value for the string s. Bound is a non-negative exact integer specifying the range of the hash function. A positive value restricts the return value to the range [0,bound). If bound is either zero or not given, the implementation may use an implementation-specific default value, chosen to be as large as is efficiently practical. For instance, the default range might be chosen for a given implementation to map all strings into the range of integers that can be represented with a single machine word. The optional start/end indices restrict the hash operation to the indicated substring of s.

    (srfi 13) procedure (string-hash-ci (s string?)) ⟹ integer?

    (srfi 13) procedure (string-hash-ci (s string?) (bound integer?)) ⟹ integer?

    (srfi 13) procedure (string-hash-ci (s string?) (bound integer?) (start integer?)) ⟹ integer?

    (srfi 13) procedure (string-hash-ci (s string?) (bound integer?) (start integer?) (end integer?)) ⟹ integer?

    Compute a hash value for the string s, case-insensitive. Bound is a non-negative exact integer specifying the range of the hash function. A positive value restricts the return value to the range [0,bound). If bound is either zero or not given, the implementation may use an implementation-specific default value, chosen to be as large as is efficiently practical. For instance, the default range might be chosen for a given implementation to map all strings into the range of integers that can be represented with a single machine word. The optional start/end indices restrict the hash operation to the indicated substring of s.

    (srfi 13) procedure (string-prefix-length (s1 string?) (s2 string?)) ⟹ integer?

    (srfi 13) procedure (string-prefix-length (s1 string?) (s2 string?) (start1 integer?)) ⟹ integer?

    (srfi 13) procedure (string-prefix-length (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ integer?

    (srfi 13) procedure (string-prefix-length (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ integer?

    (srfi 13) procedure (string-prefix-length (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ integer?

    Return the length of the longest common prefix of the two strings.

    (srfi 13) procedure (string-suffix-length (s1 string?) (s2 string?)) ⟹ integer?

    (srfi 13) procedure (string-suffix-length (s1 string?) (s2 string?) (start1 integer?)) ⟹ integer?

    (srfi 13) procedure (string-suffix-length (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ integer?

    (srfi 13) procedure (string-suffix-length (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ integer?

    (srfi 13) procedure (string-suffix-length (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ integer?

    Return the length of the longest common suffix of the two strings.

    (srfi 13) procedure (string-prefix-length-ci (s1 string?) (s2 string?)) ⟹ integer?

    (srfi 13) procedure (string-prefix-length-ci (s1 string?) (s2 string?) (start1 integer?)) ⟹ integer?

    (srfi 13) procedure (string-prefix-length-ci (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ integer?

    (srfi 13) procedure (string-prefix-length-ci (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ integer?

    (srfi 13) procedure (string-prefix-length-ci (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ integer?

    Return the length of the longest common prefix of the two strings, case-insensitive.

    (srfi 13) procedure (string-suffix-length-ci (s1 string?) (s2 string?)) ⟹ integer?

    (srfi 13) procedure (string-suffix-length-ci (s1 string?) (s2 string?) (start1 integer?)) ⟹ integer?

    (srfi 13) procedure (string-suffix-length-ci (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ integer?

    (srfi 13) procedure (string-suffix-length-ci (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ integer?

    (srfi 13) procedure (string-suffix-length-ci (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ integer?

    Return the length of the longest common suffix of the two strings, case-insensitive.

    (srfi 13) procedure (string-prefix? (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string-prefix? (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-prefix? (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-prefix? (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-prefix? (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Is s1 a prefix of s2? The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string-suffix? (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string-suffix? (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-suffix? (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-suffix? (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-suffix? (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Is s1 a suffix of s2? The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string-prefix-ci? (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string-prefix-ci? (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-prefix-ci? (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-prefix-ci? (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-prefix-ci? (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Is s1 a prefix of s2, case-insensitive? The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string-suffix-ci? (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 13) procedure (string-suffix-ci? (s1 string?) (s2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-suffix-ci? (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-suffix-ci? (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 13) procedure (string-suffix-ci? (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Is s1 a suffix of s2, case-insensitive? The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 13) procedure (string-index (c char? | char-set? | predicate) (s string?)) ⟹ integer? | #f

    (srfi 13) procedure (string-index (c char? | char-set? | predicate) (s string?) (start integer?)) ⟹ integer? | #f

    (srfi 13) procedure (string-index (c char? | char-set? | predicate) (s string?) (start integer?) (end integer?)) ⟹ integer? | #f

    string-index searches through the string from the left, returning the index of the first occurrence of a character which

  • equals char/char-set/pred (if it is a character);
  • is in char/char-set/pred (if it is a character set);
  • satisfies the predicate char/char-set/pred (if it is a procedure).
  • If no match is found, the functions return false. The start and end parameters specify the beginning and end indices of the search; the search includes the start index, but not the end index.

    (srfi 13) procedure (string-index-right (c char? | char-set? | predicate) (s string?)) ⟹ integer? | #f

    (srfi 13) procedure (string-index-right (c char? | char-set? | predicate) (s string?) (start integer?)) ⟹ integer? | #f

    (srfi 13) procedure (string-index-right (c char? | char-set? | predicate) (s string?) (start integer?) (end integer?)) ⟹ integer? | #f

    string-index-right searches through the string from the right, returning the index of the first occurrence of a character which

  • equals char/char-set/pred (if it is a character);
  • is in char/char-set/pred (if it is a character set);
  • satisfies the predicate char/char-set/pred (if it is a procedure).
  • If no match is found, the functions return false. The start and end parameters specify the beginning and end indices of the search; the search includes the start index, but not the end index.

    (srfi 13) procedure (string-skip (c char? | char-set? | predicate) (s string?)) ⟹ integer? | #f

    (srfi 13) procedure (string-skip (c char? | char-set? | predicate) (s string?) (start integer?)) ⟹ integer? | #f

    (srfi 13) procedure (string-skip (c char? | char-set? | predicate) (s string?) (start integer?) (end integer?)) ⟹ integer? | #f

    string-skip searches through the string from the left, returning the index of the first occurrence of a character which doesn't

  • equals char/char-set/pred (if it is a character);
  • is in char/char-set/pred (if it is a character set);
  • satisfies the predicate char/char-set/pred (if it is a procedure).
  • If no match is found, the functions return false. The start and end parameters specify the beginning and end indices of the search; the search includes the start index, but not the end index.

    (srfi 13) procedure (string-skip-right (c char? | char-set? | predicate) (s string?)) ⟹ integer? | #f

    (srfi 13) procedure (string-skip-right (c char? | char-set? | predicate) (s string?) (start integer?)) ⟹ integer? | #f

    (srfi 13) procedure (string-skip-right (c char? | char-set? | predicate) (s string?) (start integer?) (end integer?)) ⟹ integer? | #f

    string-skip-right searches through the string from the right, returning the index of the first occurrence of a character which doesn't

  • equals char/char-set/pred (if it is a character);
  • is in char/char-set/pred (if it is a character set);
  • satisfies the predicate char/char-set/pred (if it is a procedure).
  • If no match is found, the functions return false. The start and end parameters specify the beginning and end indices of the search; the search includes the start index, but not the end index.

    (srfi 13) procedure (string-count (c char? | char-set? | predicate) (s string?)) ⟹ integer?

    (srfi 13) procedure (string-count (c char? | char-set? | predicate) (s string?) (start integer?)) ⟹ integer?

    (srfi 13) procedure (string-count (c char? | char-set? | predicate) (s string?) (start integer?) (end integer?)) ⟹ integer?

    Return a count of the number of characters in s that satisfy the char/char-set/pred argument. If this argument is a procedure, it is applied to the character as a predicate; if it is a character set, the character is tested for membership; if it is a character, it is used in an equality test.

    (srfi 13) procedure (string-contains (s1 string?) (s2 string?)) ⟹ integer? | #f

    (srfi 13) procedure (string-contains (s1 string?) (s2 string?) (start1 integer?)) ⟹ integer? | #f

    (srfi 13) procedure (string-contains (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ integer? | #f

    (srfi 13) procedure (string-contains (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ integer? | #f

    (srfi 13) procedure (string-contains (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ integer? | #f

    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.

    (srfi 13) procedure (string-contains-ci (s1 string?) (s2 string?)) ⟹ integer? | #f

    (srfi 13) procedure (string-contains-ci (s1 string?) (s2 string?) (start1 integer?)) ⟹ integer? | #f

    (srfi 13) procedure (string-contains-ci (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ integer? | #f

    (srfi 13) procedure (string-contains-ci (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ integer? | #f

    (srfi 13) procedure (string-contains-ci (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ integer? | #f

    Does string s1 contain string s2, case-insensitive? 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.

    (srfi 13) procedure (string-titlecase (s string?)) ⟹ string?

    (srfi 13) procedure (string-titlecase (s string?) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-titlecase (s string?) (start integer?) (end integer?)) ⟹ string?

    For every character c in the selected range of s, if c is preceded by a cased character, it is downcased; otherwise it is titlecased.

    (srfi 13) procedure (string-titlecase! (s string?)) ⟹ undefined

    (srfi 13) procedure (string-titlecase! (s string?) (start integer?)) ⟹ undefined

    (srfi 13) procedure (string-titlecase! (s string?) (start integer?) (end integer?)) ⟹ undefined

    For every character c in the selected range of s, if c is preceded by a cased character, it is downcased; otherwise it is titlecased. String is changed in-place.

    (srfi 13) procedure (string-upcase (s string?)) ⟹ string?

    (srfi 13) procedure (string-upcase (s string?) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-upcase (s string?) (start integer?) (end integer?)) ⟹ string?

    Raise the case of the alphabetic characters in the string.

    (srfi 13) procedure (string-upcase! (s string?)) ⟹ undefined

    (srfi 13) procedure (string-upcase! (s string?) (start integer?)) ⟹ undefined

    (srfi 13) procedure (string-upcase! (s string?) (start integer?) (end integer?)) ⟹ undefined

    Raise the case of the alphabetic characters in the string. String is changed in-place.

    (srfi 13) procedure (string-downcase (s string?)) ⟹ string?

    (srfi 13) procedure (string-downcase (s string?) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-downcase (s string?) (start integer?) (end integer?)) ⟹ string?

    Lower the case of the alphabetic characters in the string.

    (srfi 13) procedure (string-downcase! (s string?)) ⟹ undefined

    (srfi 13) procedure (string-downcase! (s string?) (start integer?)) ⟹ undefined

    (srfi 13) procedure (string-downcase! (s string?) (start integer?) (end integer?)) ⟹ undefined

    Lower the case of the alphabetic characters in the string. String is changed in-place.

    (srfi 13) procedure (string-reverse (s string?)) ⟹ string?

    (srfi 13) procedure (string-reverse (s string?) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-reverse (s string?) (start integer?) (end integer?)) ⟹ string?

    Reverse the string.

    (srfi 13) procedure (string-reverse! (s string?)) ⟹ undefined

    (srfi 13) procedure (string-reverse! (s string?) (start integer?)) ⟹ undefined

    (srfi 13) procedure (string-reverse! (s string?) (start integer?) (end integer?)) ⟹ undefined

    Reverse the string. String is changed in-place.

    (srfi 13) procedure (string-append (string string?) ...) ⟹ string?

    Returns a newly allocated string whose characters form the concatenation of the given strings.

    (srfi 13) procedure (string-concatenate (string-list list?)) ⟹ string?

    Append the elements of string-list together into a single string. Guaranteed to return a freshly allocated string. Note that the (apply string-append string-list) idiom is not robust for long lists of strings, as some Scheme implementations limit the number of arguments that may be passed to an n-ary procedure.

    (srfi 13) procedure (string-append/shared (string string?) ...) ⟹ string?

    Variant of string-append that is permitted to return result that shares storage with its parameters. If string-append/shared is applied to just one argument, it may return exactly that argument, whereas string-append is required to allocate a fresh string.

    (srfi 13) procedure (string-concatenate/shared (string-list list?)) ⟹ string?

    Variant of string-concatenate that is permitted to return result that shares storage with its parameters.

    (srfi 13) procedure (string-concatenate-reverse (string-list list?)) ⟹ string?

    (srfi 13) procedure (string-concatenate-reverse (string-list list?) (final-string string?)) ⟹ string?

    (srfi 13) procedure (string-concatenate-reverse (string-list list?) (final-string string?) (end integer?)) ⟹ string?

    With no optional arguments, the function is equivalent to (string-concatenate (reverse string-list)). If the optional argument final-string is specified, it is consed onto the beginning of string-list before performing the list-reverse and string-concatenate operations. If the optional argument end is given, only the first end characters of final-string are added to the string list.

    (srfi 13) procedure (string-concatenate-reverse/shared (string-list list?)) ⟹ string?

    (srfi 13) procedure (string-concatenate-reverse/shared (string-list list?) (final-string string?)) ⟹ string?

    (srfi 13) procedure (string-concatenate-reverse/shared (string-list list?) (final-string string?) (end integer?)) ⟹ string?

    With no optional arguments, the function is equivalent to (string-concatenate/shared (reverse string-list)). If the optional argument final-string is specified, it is consed onto the beginning of string-list before performing the list-reverse and string-concatenate operations. If the optional argument end is given, only the first end characters of final-string are added to the string list.

    (srfi 13) procedure (string-map (proc procedure?) (s string?)) ⟹ string?

    (srfi 13) procedure (string-map (proc procedure?) (s string?) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-map (proc procedure?) (s string?) (start integer?) (end integer?)) ⟹ string?

    (proc (c char?) ...) ⟹ char?

    Proc is a char->char procedure; it is mapped over s. string-map returns the result string and does not alter its s parameter.

    (srfi 13) procedure (string-map! (proc procedure?) (s string?)) ⟹ undefined

    (srfi 13) procedure (string-map! (proc procedure?) (s string?) (start integer?)) ⟹ undefined

    (srfi 13) procedure (string-map! (proc procedure?) (s string?) (start integer?) (end integer?)) ⟹ undefined

    (proc (c char?) ...) ⟹ char?

    Proc is a char->char procedure; it is mapped over s. string-map! is the in-place side-effecting variant.

    (srfi 13) procedure (string-fold (kons procedure?) knil (s string?)) ⟹ *

    (srfi 13) procedure (string-fold (kons procedure?) knil (s string?) (start integer?)) ⟹ *

    (srfi 13) procedure (string-fold (kons procedure?) knil (s string?) (start integer?) (end integer?)) ⟹ *

    (kons (c char?) state) ⟹ *

    The left-fold operator maps the kons procedure across the string from left to right (... (kons s[2] (kons s[1] (kons s[0] knil))))

    (srfi 13) procedure (string-fold-right (kons procedure?) knil (s string?)) ⟹ *

    (srfi 13) procedure (string-fold-right (kons procedure?) knil (s string?) (start integer?)) ⟹ *

    (srfi 13) procedure (string-fold-right (kons procedure?) knil (s string?) (start integer?) (end integer?)) ⟹ *

    (kons (c char?) state) ⟹ *

    The right-fold operator maps the kons procedure across the string from right to left (kons s[0] (... (kons s[end-3] (kons s[end-2] (kons s[end-1] knil)))))

    (srfi 13) procedure (string-unfold (stop? predicate) (mapper procedure?) (successor procedure?) seed) ⟹ string?

    (srfi 13) procedure (string-unfold (stop? predicate) (mapper procedure?) (successor procedure?) seed (base string?)) ⟹ string?

    (srfi 13) procedure (string-unfold (stop? predicate) (mapper procedure?) (successor procedure?) seed (base string?) (make-final procedure?)) ⟹ string?

    (mapper seed) ⟹ *

    (successor seed) ⟹ *

    (make-final seed) ⟹ string?

    This is a fundamental constructor for strings.

  • successor is used to generate a series of "seed" values from the initial seed: seed, (successor seed), (successor^2 seed), (successor^3 seed), ...
  • stop? tells us when to stop -- when it returns true when applied to one of these seed values.
  • mapper maps each seed value to the corresponding character in the result string. These chars are assembled into the string in a left-to-right order.
  • Base is the optional initial/leftmost portion of the constructed string; it defaults to the empty string "".
  • Make-final is applied to the terminal seed value (on which p returns true) to produce the final/rightmost portion of the constructed string. It defaults to (lambda (x) "").
  • The final string constructed does not share storage with either base or the value produced by make-final.

    (srfi 13) procedure (string-unfold-right (stop? predicate) (mapper procedure?) (successor procedure?) seed) ⟹ string?

    (srfi 13) procedure (string-unfold-right (stop? predicate) (mapper procedure?) (successor procedure?) seed (base string?)) ⟹ string?

    (srfi 13) procedure (string-unfold-right (stop? predicate) (mapper procedure?) (successor procedure?) seed (base string?) (make-final procedure?)) ⟹ string?

    (mapper seed) ⟹ *

    (successor seed) ⟹ *

    (make-final seed) ⟹ string?

    This is a fundamental constructor for strings.

  • successor is used to generate a series of "seed" values from the initial seed: seed, (successor seed), (successor2 seed), (successor3 seed), ...
  • stop? tells us when to stop -- when it returns true when applied to one of these seed values.
  • mapper maps each seed value to the corresponding character in the result string. These chars are assembled into the string in a right-to-left order.
  • Base is the optional initial/rightmost portion of the constructed string; it defaults to the empty string "".
  • Make-final is applied to the terminal seed value (on which P returns true) to produce the final/leftmost portion of the constructed string. It defaults to (lambda (x) "").
  • The final string constructed does not share storage with either base or the value produced by make-final.

    (srfi 13) procedure (string-for-each (proc procedure?) (s string?)) ⟹ undefined

    (srfi 13) procedure (string-for-each (proc procedure?) (s string?) (start integer?)) ⟹ undefined

    (srfi 13) procedure (string-for-each (proc procedure?) (s string?) (start integer?) (end integer?)) ⟹ undefined

    (proc (c char?)) ⟹ undefined

    Apply proc to each character in s. string-for-each is required to iterate from start to end in increasing order.

    (srfi 13) procedure (string-for-each-index (proc procedure?) (s string?)) ⟹ undefined

    (srfi 13) procedure (string-for-each-index (proc procedure?) (s string?) (start integer?)) ⟹ undefined

    (srfi 13) procedure (string-for-each-index (proc procedure?) (s string?) (start integer?) (end integer?)) ⟹ undefined

    (proc (index integer?)) ⟹ undefined

    Apply proc to each index of s, in order. The optional start/end pairs restrict the endpoints of the loop. This is simply a method of looping over a string that is guaranteed to be safe and correct.

    (srfi 13) procedure (xsubstring (s string?) (from integer?)) ⟹ string?

    (srfi 13) procedure (xsubstring (s string?) (from integer?) (to integer?)) ⟹ string?

    (srfi 13) procedure (xsubstring (s string?) (from integer?) (to integer?) (start integer?)) ⟹ string?

    (srfi 13) procedure (xsubstring (s string?) (from integer?) (to integer?) (start integer?) (end integer?)) ⟹ string?

    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 (i.e., the whole string). 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)).

    (srfi 13) procedure (string-xcopy! (target string?) (tstart integer?) (s string?) (sfrom integer?)) ⟹ undefined

    (srfi 13) procedure (string-xcopy! (target string?) (tstart integer?) (s string?) (sfrom integer?) (sto integer?)) ⟹ undefined

    (srfi 13) procedure (string-xcopy! (target string?) (tstart integer?) (s string?) (sfrom integer?) (sto integer?) (start integer?)) ⟹ undefined

    (srfi 13) procedure (string-xcopy! (target string?) (tstart integer?) (s string?) (sfrom integer?) (sto integer?) (start integer?) (end integer?)) ⟹ undefined

    Exactly the same as xsubstring, but the extracted text is written into the string target starting at index tstart. This operation is not defined if (eq? target s) or these two arguments share storage -- you cannot copy a string on top of itself.

    (srfi 13) procedure (string-replace (s1 string?) (s2 string?) (start1 integer?) (end1 integer?)) ⟹ string?

    (srfi 13) procedure (string-replace (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ string?

    (srfi 13) procedure (string-replace (s1 string?) (s2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ string?

    Segment of characters in s1 from start1 to end1 is replaced by the segment of characters in s2 from start2 to end2. If start1=end1, this simply splices the s2 characters into s1 at the specified index.

    (srfi 13) procedure (string-tokenize (s string?)) ⟹ list?

    (srfi 13) procedure (string-tokenize (s string?) (token-set char-set?)) ⟹ list?

    (srfi 13) procedure (string-tokenize (s string?) (token-set char-set?) (start integer?)) ⟹ list?

    (srfi 13) procedure (string-tokenize (s string?) (token-set char-set?) (start integer?) (end integer?)) ⟹ list?

    Split the string s into a list of substrings, where each substring is a maximal non-empty contiguous sequence of characters from the character set token-set.

  • token-set defaults to char-set:graphic (see SRFI 14 for more on character sets and char-set:graphic).
  • If start or end indices are provided, they restrict string-tokenize to operating on the indicated substring of s.
  • This function provides a minimal parsing facility for simple applications. More sophisticated parsers that handle quoting and backslash effects can easily be constructed using regular-expression systems; be careful not to use string-tokenize in contexts where more serious parsing is needed.

    (srfi 13) procedure (string-filter (c char? | char-set? | predicate) (s string?)) ⟹ string?

    (srfi 13) procedure (string-filter (c char? | char-set? | predicate) (s string?) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-filter (c char? | char-set? | predicate) (s string?) (start integer?) (end integer?)) ⟹ string?

    Filter the string s, retaining only those characters that satisfy the char/char-set/pred argument. If this argument is a procedure, it is applied to the character as a predicate; if it is a char-set, the character is tested for membership; if it is a character, it is used in an equality test. If the string is unaltered by the filtering operation, the function may return either s or a copy of s.

    (srfi 13) procedure (string-delete (c char? | char-set? | predicate) (s string?)) ⟹ string?

    (srfi 13) procedure (string-delete (c char? | char-set? | predicate) (s string?) (start integer?)) ⟹ string?

    (srfi 13) procedure (string-delete (c char? | char-set? | predicate) (s string?) (start integer?) (end integer?)) ⟹ string?

    Filter the string s, retaining only those characters that do not satisfy the char/char-set/pred argument. If this argument is a procedure, it is applied to the character as a predicate; if it is a char-set, the character is tested for membership; if it is a character, it is used in an equality test. If the string is unaltered by the filtering operation, the function may return either s or a copy of s.

    (srfi 13) procedure (string-parse-start+end (proc procedure?) (s string?) (args list?)) ⟹ (values list? integer? integer?)

    string-parse-start+end may be used to parse a pair of optional start/end arguments from an argument list, defaulting them to 0 and the length of some string s, respectively. Let the length of string s be slen.

  • If args = (), the function returns (values '() 0 slen)
  • If args = (i), i is checked to ensure it is an exact integer, and that 0 <= i <= slen. Returns (values (cdr args) i slen).
  • If args = (i j ...), i and j are checked to ensure they are exact integers, and that 0 <= i <= j <= slen. Returns (values (cddr args) i j).
  • If any of the checks fail, an error condition is raised, and proc is used as part of the error condition -- it should be the client procedure whose argument list string-parse-start+end is parsing.

    (srfi 13) procedure (string-parse-final-start+end (proc procedure?) (s string?) (args list?)) ⟹ (values integer? integer?)

    string-parse-final-start+end is exactly the same as string-parse-start+end, except that the args list passed to it is required to be of length two or less; if it is longer, an error condition is raised. It may be used when the optional start/end parameters are final arguments to the procedure.

    (srfi 13) syntax (let-string-start+end (start end) proc s args body ...)

    (srfi 13) syntax (let-string-start+end (rest start end) proc s args body ...)

    proc ⟹ procedure?

    s ⟹ string?

    args ⟹ list?

    Syntactic sugar for an application of string-parse-start+end or string-parse-final-start+end. If a rest variable is given, the form is equivalent to

    (call-with-values

    (lambda () (string-parse-start+end proc-exp s-exp args-exp))

    (lambda (rest start end) body ...))

    If no rest variable is given, the form is equivalent to

    (call-with-values

    (lambda () (string-parse-final-start+end proc-exp s-exp args-exp))

    (lambda (start end) body ...))

    (srfi 13) procedure (check-substring-spec (proc procedure?) (s string?) (start integer?) (end integer?)) ⟹ undefined

    Check values s, start and end to ensure they specify a valid substring. This means that s is a string, start and end are exact integers, and 0 <= start <= end <= (string-length s). If the values are not proper check-substring-spec raises an error condition. proc is used as part of the error condition, and should be the procedure whose parameters we are checking.

    (srfi 13) procedure (substring-spec-ok? (s string?) (start integer?) (end integer?)) ⟹ boolean?

    Check values s, start and end to ensure they specify a valid substring. This means that s is a string, start and end are exact integers, and 0 <= start <= end <= (string-length s). If the values are not proper substring-spec-ok? returns false.

    (srfi 13) procedure (make-kmp-restart-vector (s string?)) ⟹ vector?

    (srfi 13) procedure (make-kmp-restart-vector (s string?) (c= procedure?)) ⟹ vector?

    (srfi 13) procedure (make-kmp-restart-vector (s string?) (c= procedure?) (start integer?)) ⟹ vector?

    (srfi 13) procedure (make-kmp-restart-vector (s string?) (c= procedure?) (start integer?) (end integer?)) ⟹ vector?

    (c= (a char?) (b char?)) ⟹ boolean?

    Build a Knuth-Morris-Pratt "restart vector," which is useful for quickly searching character sequences for the occurrence of string s (or the substring of s demarcated by the optional start/end parameters, if provided). C= is a character-equality function used to construct the restart vector. It defaults to char=?; use char-ci=? instead for case-folded string search.

    The definition of the restart vector rv for string s is: If we have matched chars 0..i-1 of s against some search string ss, and s[i] doesn't match ss[k], then reset i := rv[i], and try again to match ss[k]. If rv[i] = -1, then punt ss[k] completely, and move on to ss[k+1] and s[0].

    In other words, if you have matched the first i chars of s, but the i+1'th char doesn't match, rv[i] tells you what the next-longest prefix of s is that you have matched.

    The optional start/end parameters restrict the restart vector to the indicated substring of pat; rv is end - start elements long. If start > 0, then rv is offset by start elements from pat. That is, rv[i] describes pattern element pat[i + start]. Elements of rv are themselves indices that range just over [0, end-start), not [start, end).

    (srfi 13) procedure (kmp-step (pat string?) (rv vector?) (c char?) (i integer?) (c= procedure?) (p-start integer?)) ⟹ integer?

    (c= (a char?) (b char?)) ⟹ boolean?

    This function encapsulates the work performed by one step of the KMP string search; it can be used to scan strings, input ports, or other on-line character sources for fixed strings.

    Pat is the non-empty string specifying the text for which we are searching. Rv is the Knuth-Morris-Pratt restart vector for the pattern, as constructed by make-kmp-restart-vector. The pattern begins at pat[p-start], and is (vector-length rv) characters long. C= is the character-equality function used to construct the restart vector, typically char=? or char-ci=?.

    Suppose the pattern is N characters in length: pat[p-start, p-start + n). We have already matched i characters: pat[p-start, p-start + i). (P-start is typically zero.) C is the next character in the input stream. kmp-step returns the new i value -- that is, how much of the pattern we have matched, including character c. When i reaches n, the entire pattern has been matched.

    (c= (a char?) (b char?)) ⟹ boolean?

    Applies kmp-step across s; optional s-start/s-end bounds parameters restrict search to a substring of s. The pattern is (vector-length rv) characters long; optional p-start index indicates non-zero start of pattern in pat.

    Suppose plen = (vector-length rv) is the length of the pattern. I is an integer index into the pattern (that is, 0 <= i < plen) indicating how much of the pattern has already been matched. (This means the pattern must be non-empty -- plen > 0.)

  • On success, returns -j, where j is the index in s bounding the end of the pattern -- e.g., a value that could be used as the end parameter in a call to substring/shared.
  • On continue, returns the current search state i' (an index into rv) when the search reached the end of the string. This is a non-negative integer.
  • Hence:

  • A negative return value indicates success, and says where in the string the match occured.
  • A non-negative return value provides the i to use for continued search in a following string.
  • This utility is designed to allow searching for occurrences of a fixed string that might extend across multiple buffers of text. This is why, for example, we do not provide the index of the start of the match on success -- it may have occurred in a previous buffer.

    library (srfi 14) Character-set Library

    The ability to efficiently represent and manipulate sets of characters is an unglamorous but very useful capability for text-processing code -- one that tends to pop up in the definitions of other libraries. Hence it is useful to specify a general substrate for this functionality early. This SRFI defines a general library that provides this functionality.

    It is accompanied by a reference implementation for the spec. The reference implementation is fairly efficient, straightforwardly portable, and has a "free software" copyright. The implementation is tuned for "small" 7 or 8 bit character types, such as ASCII or Latin-1; the data structures and algorithms would have to be altered for larger 16 or 32 bit character types such as Unicode -- however, the specs have been carefully designed with these larger character types in mind.

    Several forthcoming SRFIs can be defined in terms of this one:

    • string library
    • delimited input procedures (e.g., read-line)
    • regular expressions

    See (scheme charset)

    library (srfi 16) Syntax for procedures of variable arity

    CASE-LAMBDA, a syntax for procedures with a variable number of arguments, is introduced.

    See (scheme case-lambda)

    library (srfi 17) Generalized set!

    This is a proposal to allow procedure calls that evaluate to the "value of a location" to be used to set the value of the location, when used as the first operand of set!.For example:

    (set! (car x) (car y))
    
    becomes equivalent to
    (set-car! x (car y))
    

    Many programming languages have the concept of an lvalue. that is an "expression" that "evaluates" to a location, and which can appear on the left-hand-side of an assignment. Common Lisp has a related concept of "generalized variables" which can be used in setf and some other special forms. However, the Common Lisp concept is based on the idea of compile-time recognition of special "location-producing" functions; this does not seem to be in the "spirit of Scheme".

    This SRFI proposes an extension of set! so that it provides similar functionality as Common Lisp's setf, except that the updater is associated with a procedure value, rather than a name.

    (srfi 17) syntax (set! variable expression)

    (srfi 17) syntax (set! (proc args ...) expression)

    The special form set! is extended so the first operand can be a procedure application, and not just a variable. The procedure is typically one that extracts a component from some data structure. Informally, when the procedure is called in the first operand of set!, it causes the corresponding component to be replaced by the second operand. For example, (set! (vector-ref x i) v) would be equivalent to (vector-set! x i v).

    Each procedure that may be used as the first operand to set! must have a corresponding "setter" procedure. The builtin procedure setter takes a procedure and returns the corresponding setter procedure.

    The following standard procedures have pre-defined setters:

    (set! (car x) v) == (set-car! x v)

    (set! (cdr x) v) == (set-cdr! x v)

    (set! (caar x) v) == (set-car! (car x) v)

    (set! (cadr x) v) == (set-car! (cdr x) v)

    ....

    (set! (caXXr x) v) == (set-car! (cXXr x) v)

    (set! (cdXXr x) v) == (set-cdr! (cXXr x) v)

    (set! (string-ref x i) v) == (string-set! x i v)

    (set! (vector-ref x i) v) == (vector-set! x i v)

    (srfi 17) procedure (setter (proc procedure?)) ⟹ procedure?

    Returns an associated setter procedure. We define:

    (set! (proc arg ...) value)

    as:

    ((setter proc) arg ... value)

    This SRFI specifies the special case for the setter property. This is defined such that:

    (set! (setter proc) setter)

    sets the setter procedure associated with proc to setter. For example, we can assume

    (set! (setter car) set-car!)

    has been executed by the Scheme prologue.

    (srfi 17) procedure (getter-with-setter (getter procedure?) (setter procedure?)) ⟹ procedure?

    This evaluates to a new anonymous procedure which when applied invokes getter, and whose setter is setter. It is an error for a program to subsequently try to modify the setter of the resulting compound.

    For example, we could define:

    (define car (getter-with-setter %primitive-car %primitive-set-car!))

    (define set-car! %primitive-set-car!)

    library (srfi 18) Multithreading support

    This SRFI defines the following multithreading datatypes for Scheme

    • Thread
    • Mutex
    • Condition variable
    • Time

    It also defines a mechanism to handle exceptions and some multithreading exception datatypes.

    (srfi 18) procedure (current-thread) ⟹ thread?

    Returns the current thread.

    (srfi 18) procedure (thread? object) ⟹ boolean?

    Returns #t if obj is a thread, otherwise returns #f.

    (srfi 18) procedure (make-thread (thunk procedure?)) ⟹ thread?

    (srfi 18) procedure (make-thread (thunk procedure?) name) ⟹ thread?

    (thunk) ⟹ *

    Returns a new thread. This thread is not automatically made runnable (the procedure thread-start! must be used for this). A thread has the following fields: name, specific, end-result, end-exception, and a list of locked/owned mutexes it owns. The thread's execution consists of a call to thunk with the "initial continuation". This continuation causes the (then) current thread to store the result in its end-result field, abandon all mutexes it owns, and finally terminate. The dynamic-wind stack of the initial continuation is empty. The optional name is an arbitrary Scheme object which identifies the thread (useful for debugging); it defaults to an unspecified value. The specific field is set to an unspecified value. The thread inherits the dynamic environment from the current thread. Moreover, in this dynamic environment the exception handler is bound to the "initial exception handler" which is a unary procedure which causes the (then) current thread to store in its end-exception field an "uncaught exception" object whose "reason" is the argument of the handler, abandon all mutexes it owns, and finally terminate.

    (srfi 18) procedure (thread-name (thread thread?)) ⟹ *

    Returns the name of the thread.

    (srfi 18) procedure (thread-specific (thread thread?)) ⟹ *

    Returns the content of the thread's specific field.

    (srfi 18) procedure (thread-specific-set! (thread thread?) obj) ⟹ undefined

    Stores obj into the thread's specific field. thread-specific-set! returns an unspecified value.

    (srfi 18) procedure (thread-start! (thread thread?)) ⟹ undefined

    Makes thread runnable. The thread must be a new thread. thread-start! returns the thread.

    (srfi 18) procedure (thread-yield! (thread thread?)) ⟹ undefined

    The current thread exits the running state as if its quantum had expired. thread-yield! returns an unspecified value.

    (srfi 18) procedure (thread-sleep! (timeout integer?)) ⟹ undefined

    The current thread waits until the timeout is reached. This blocks the thread only if timeout represents a point in the future. It is an error for timeout to be #f. thread-sleep! returns an unspecified value.

    (srfi 18) procedure (thread-terminate! (thread thread?)) ⟹ undefined

    Causes an abnormal termination of the thread. If the thread is not already terminated, all mutexes owned by the thread become unlocked/abandoned and a "terminated thread exception" object is stored in the thread's end-exception field. If thread is the current thread, thread-terminate! does not return. Otherwise thread-terminate! returns an unspecified value; the termination of the thread will occur before thread-terminate! returns.

    (srfi 18) procedure (thread-join! (thread thread?)) ⟹ *

    (srfi 18) procedure (thread-join! (thread thread?) (timeout integer?)) ⟹ *

    (srfi 18) procedure (thread-join! (thread thread?) (timeout integer?) timeout-val) ⟹ *

    The current thread waits until the thread terminates (normally or not) or until the timeout is reached if timeout is supplied. If the timeout is reached, thread-join! returns timeout-val if it is supplied, otherwise a "join timeout exception" is raised. If the thread terminated normally, the content of the end-result field is returned, otherwise the content of the end-exception field is raised.

    (srfi 18) procedure (mutex? object) ⟹ boolean?

    Returns #t if obj is a mutex, otherwise returns #f.

    (srfi 18) procedure (make-mutex ) ⟹ mutex?

    (srfi 18) procedure (make-mutex name) ⟹ mutex?

    Returns a new mutex in the unlocked/not-abandoned state. The optional name is an arbitrary Scheme object which identifies the mutex (useful for debugging); it defaults to an unspecified value. The mutex's specific field is set to an unspecified value.

    (srfi 18) procedure (mutex-name (mutex mutex?)) ⟹ *

    Returns the name of the mutex.

    (srfi 18) procedure (mutex-specific (mutex mutex?)) ⟹ *

    Returns the content of the mutex's specific field.

    (srfi 18) procedure (mutex-specific-set! (mutex mutex?) obj) ⟹ undefined

    Stores obj into the mutex's specific field. mutex-specific-set! returns an unspecified value.

    (srfi 18) procedure (mutex-state (mutex mutex?)) ⟹ thread? | symbol?

    Returns information about the state of the mutex. The possible results are:

  • thread T: the mutex is in the locked/owned state and thread T is the owner of the mutex
  • symbol not-owned: the mutex is in the locked/not-owned state
  • symbol abandoned: the mutex is in the unlocked/abandoned state
  • symbol not-abandoned: the mutex is in the unlocked/not-abandoned state
  • (srfi 18) procedure (mutex-lock! (mutex mutex?)) ⟹ boolean?

    (srfi 18) procedure (mutex-lock! (mutex mutex?) (timeout integer?)) ⟹ boolean?

    (srfi 18) procedure (mutex-lock! (mutex mutex?) (timeout integer?) (thread #f | thread?)) ⟹ boolean?

    If the mutex is currently locked, the current thread waits until the mutex is unlocked, or until the timeout is reached if timeout is supplied. If the timeout is reached, mutex-lock! returns #f. Otherwise, the state of the mutex is changed as follows:

  • if thread is #f the mutex becomes locked/not-owned,
  • otherwise, let T be thread (or the current thread if thread is not supplied),
  • if T is terminated the mutex becomes unlocked/abandoned,

    otherwise mutex becomes locked/owned with T as the owner.

    After changing the state of the mutex, an "abandoned mutex exception" is raised if the mutex was unlocked/abandoned before the state change, otherwise mutex-lock! returns #t. It is not an error if the mutex is owned by the current thread (but the current thread will have to wait).

    (srfi 18) procedure (mutex-unlock! (mutex mutex?)) ⟹ boolean?

    (srfi 18) procedure (mutex-unlock! (mutex mutex?) (condition-variable condition-variable?)) ⟹ boolean?

    (srfi 18) procedure (mutex-unlock! (mutex mutex?) (condition-variable condition-variable?) (timeout integer?)) ⟹ boolean?

    Unlocks the mutex by making it unlocked/not-abandoned. It is not an error to unlock an unlocked mutex and a mutex that is owned by any thread. If condition-variable is supplied, the current thread is blocked and added to the condition-variable before unlocking mutex; the thread can unblock at any time but no later than when an appropriate call to condition-variable-signal! or condition-variable-broadcast! is performed (see below), and no later than the timeout (if timeout is supplied). If there are threads waiting to lock this mutex, the scheduler selects a thread, the mutex becomes locked/owned or locked/not-owned, and the thread is unblocked. mutex-unlock! returns #f when the timeout is reached, otherwise it returns #t.

    NOTE: The reason the thread can unblock at any time (when condition-variable is supplied) is to allow extending this SRFI with primitives that force a specific blocked thread to become runnable. For example a primitive to interrupt a thread so that it performs a certain operation, whether the thread is blocked or not, may be useful to handle the case where the scheduler has detected a serious problem (such as a deadlock) and it must unblock one of the threads (such as the primordial thread) so that it can perform some appropriate action. After a thread blocked on a condition-variable has handled such an interrupt it would be wrong for the scheduler to return the thread to the blocked state, because any calls to condition-variable-broadcast! during the interrupt will have gone unnoticed. It is necessary for the thread to remain runnable and return from the call to mutex-unlock! with a result of #t.

    NOTE: mutex-unlock! is related to the "wait" operation on condition variables available in other thread systems. The main difference is that "wait" automatically locks mutex just after the thread is unblocked. This operation is not performed by mutex-unlock! and so must be done by an explicit call to mutex-lock!. This has the advantages that a different timeout and exception handler can be specified on the mutex-lock! and mutex-unlock! and the location of all the mutex operations is clearly apparent.

    (srfi 18) procedure (condition-variable? object) ⟹ boolean?

    Returns #t if obj is a condition variable, otherwise returns #f.

    (srfi 18) procedure (make-condition-variable ) ⟹ condition-variable?

    (srfi 18) procedure (make-condition-variable name) ⟹ condition-variable?

    (srfi 18) procedure (make-condition-variable name) ⟹ condition-variable?

    Returns a new empty condition variable. The optional name is an arbitrary Scheme object which identifies the condition variable (useful for debugging); it defaults to an unspecified value. The condition variable's specific field is set to an unspecified value.

    (srfi 18) procedure (condition-variable-name (condition-variable condition-variable?)) ⟹ *

    Returns the name of the condition-variable.

    (srfi 18) procedure (condition-variable-specific (condition-variable condition-variable?)) ⟹ *

    Returns the content of the condition-variable's specific field.

    (srfi 18) procedure (condition-variable-specific-set! (condition-variable condition-variable?) obj) ⟹ undefined

    Stores obj into the condition-variable's specific field. condition-variable-specific-set! returns an unspecified value.

    (srfi 18) procedure (condition-variable-signal! (condition-variable condition-variable?)) ⟹ undefined

    If there are threads blocked on the condition-variable, the scheduler selects a thread and unblocks it. condition-variable-signal! returns an unspecified value.

    (srfi 18) procedure (condition-variable-broadcast! (condition-variable condition-variable?)) ⟹ undefined

    Unblocks all the threads blocked on the condition-variable. condition-variable-broadcast! returns an unspecified value.

    (srfi 18) procedure (current-time) ⟹ time?

    Returns the time object corresponding to the current time.

    (srfi 18) procedure (time? obj) ⟹ boolean?

    Returns #t if obj is a time object, otherwise returns #f.

    (srfi 18) procedure (time->seconds (time time?)) ⟹ real?

    Converts the time object time into an exact or inexact real number representing the number of seconds elapsed since some implementation dependent reference point.

    (srfi 18) procedure (seconds->time (seconds real?)) ⟹ time?

    Converts into a time object the exact or inexact real number x representing the number of seconds elapsed since some implementation dependent reference point.

    (srfi 18) procedure (current-exception-handler) ⟹ procedure?

    (return err) ⟹ *

    Returns the current exception handler.

    (srfi 18) procedure (with-exception-handler (handler procedure?) (thunk procedure?)) ⟹ *

    (handler err) ⟹ *

    (thunk) ⟹ *

    Returns the result(s) of calling thunk with no arguments. The handler, which must be a procedure, is installed as the current exception handler in the dynamic environment in effect during the call to thunk.

    (srfi 18) procedure (raise obj) ⟹ undefined

    Calls the current exception handler with obj as the single argument. obj may be any Scheme object.

    (srfi 18) procedure (join-timeout-exception? obj) ⟹ boolean?

    Returns #t if obj is a "join timeout exception" object, otherwise returns #f. A join timeout exception is raised when thread-join! is called, the timeout is reached and no timeout-val is supplied.

    (srfi 18) procedure (abandoned-mutex-exception? obj) ⟹ boolean?

    Returns #t if obj is an "abandoned mutex exception" object, otherwise returns #f. An abandoned mutex exception is raised when the current thread locks a mutex that was owned by a thread which terminated (see mutex-lock!).

    (srfi 18) procedure (terminated-thread-exception? obj) ⟹ boolean?

    Returns #t if obj is a "terminated thread exception" object, otherwise returns #f. A terminated thread exception is raised when thread-join! is called and the target thread has terminated as a result of a call to thread-terminate!.

    (srfi 18) procedure (uncaught-exception? obj) ⟹ boolean?

    Returns #t if obj is an "uncaught exception" object, otherwise returns #f. An uncaught exception is raised when thread-join! is called and the target thread has terminated because it raised an exception that called the initial exception handler of that thread.

    (srfi 18) procedure (uncaught-exception-reason (exc uncaught-exception?)) ⟹ *

    exc must be an "uncaught exception" object. uncaught-exception-reason returns the object which was passed to the initial exception handler of that thread.

    library (srfi 19) Time Data Types and Procedures

    Points in time are represented as the number of seconds (with nanosecond precision) since "the epoch," a zero point in time. Several standard variants are defined, including UTC (universal coordinated time), TAI (international atomic time), and monotonic time. A point in time can also be represented as a Julian Day or Modified Julian Day number. Time durations, including time spent in a process or thread, are defined. Conversion routines are provided. The procedure CURRENT-TIME queries the current time in a specified variant, with a system-dependent resolution. Procedures for time arithmetic and time comparisons are also provided.

    A date is a representation of a point in time in the Gregorian calendar, a 24 hour clock (with nanosecond precision) and a time zone offset from UTC. Procedures for converting between time and dates are provided, as well as for reading and writing string representations of dates.

    (srfi 19) value time-duration ⟹ time-type

    Symbol representing Time duration.

    (srfi 19) value time-monotonic ⟹ time-type

    Symbol representing monotonic time.

    (srfi 19) value time-process ⟹ time-type

    Symbol representing time spent in current process.

    (srfi 19) value time-tai ⟹ time-type

    Symbol representing TAI time.

    (srfi 19) value time-thread ⟹ time-type

    Symbol representing time spent in current thread.

    (srfi 19) value time-utc ⟹ time-type

    Symbol representing UTC time.

    (srfi 19) procedure (current-date ) ⟹ date?

    (srfi 19) procedure (current-date (tz-offset integer?)) ⟹ date?

    Date corresponding to the current UTC time.

    (srfi 19) procedure (current-julian-day) ⟹ real?

    Current Julian Day.

    (srfi 19) procedure (current-modified-julian-day) ⟹ real?

    Current Modified Julian Day.

    (srfi 19) procedure (current-time ) ⟹ time?

    (srfi 19) procedure (current-time (type time-type)) ⟹ time?

    Current time, of type time-type system, which defaults to TIME-UTC.

    (srfi 19) procedure (time-resolution ) ⟹ integer?

    (srfi 19) procedure (time-resolution (type time-type)) ⟹ integer?

    Clock resolution, in nanoseconds, of the system clock of type type time-type system, which defaults to TIME-UTC.

    (srfi 19) procedure (make-time (type time-type) (nanosecond integer?) (second integer?)) ⟹ time?

    Creates a time object.

    (srfi 19) procedure (time? obj) ⟹ boolean?

    #t if object is a time object, otherwise, #f.

    (srfi 19) procedure (time-type (time time?)) ⟹ time-type

    Time type.

    (srfi 19) procedure (time-nanosecond (time time?)) ⟹ integer?

    Time nanosecond.

    (srfi 19) procedure (time-second (time time?)) ⟹ integer?

    Time second.

    (srfi 19) procedure (set-time-type! (time time?) (time-type time-type)) ⟹ undefined

    Changes time type. Note: This changes the semantics of the time object. To convert a time to another system of representation, use one of the conversion procedures.

    (srfi 19) procedure (set-time-nanosecond! (time time?) (nanosecond integer?)) ⟹ undefined

    Changes time nanosecond.

    (srfi 19) procedure (set-time-second! (time time?) (second integer?)) ⟹ undefined

    Changes time second.

    (srfi 19) procedure (copy-time (time time?)) ⟹ time?

    Creates a new time object, with the same time type, nanosecond, and second as time1.

    (srfi 19) procedure (time<=? (time1 time?) (time2 time?)) ⟹ boolean?

    #t if time1 is before or at (less than or equal to) time2, #f otherwise.

    (srfi 19) procedure (time<? (time1 time?) (time2 time?)) ⟹ boolean?

    #t if time1 is before (less than) time2, #f otherwise.

    (srfi 19) procedure (time=? (time1 time?) (time2 time?)) ⟹ boolean?

    #t if time1 at (equal) time2, #f otherwise.

    (srfi 19) procedure (time>=? (time1 time?) (time2 time?)) ⟹ boolean?

    #t if time1 is at or after (greater than or equal to) time2, #f otherwise.

    (srfi 19) procedure (time>? (time1 time?) (time2 time?)) ⟹ boolean?

    #t if time1 is after (greater than) time2, #f otherwise.

    (srfi 19) procedure (time-difference (time1 time?) (time2 time?)) ⟹ time?

    The TIME-DURATION between time1 and time2. It is an error if time1 and time2 are of different time types. A new time object is created.

    (srfi 19) procedure (time-difference! (time1 time?) (time2 time?)) ⟹ time?

    The TIME-DURATION between time1 and time2. It is an error if time1 and time2 are of different time types. Time1 may be used to create the resulting TIME-DURATION object.

    (srfi 19) procedure (add-duration (time1 time?) (time-duration time?)) ⟹ time?

    The time resulting from adding time-duration to time1, which is a time object of the same time type as time1. A new time object is created.

    (srfi 19) procedure (add-duration! (time1 time?) (time-duration time?)) ⟹ time?

    The time resulting from adding time-duration to time1, which is a time object of the same time type as time1. Time1 may used to create the resulting time object.

    (srfi 19) procedure (subtract-duration (time1 time?) (time-duration time?)) ⟹ time?

    The time resulting from subtracting time-duration from time1, which is a time object of the same time type as time1. A new time object is created.

    (srfi 19) procedure (subtract-duration! (time1 time?) (time-duration time?)) ⟹ time?

    The time resulting from subtracting time-duration from time1, which is a time object of the same time type as time1. Time1 may used to create the resulting time object.

    (srfi 19) procedure (make-date (nanosecond integer?) (second integer?) (minute integer?) (hour integer?) (day integer?) (month integer?) (year integer?) (zone-offset integer?)) ⟹ date?

    Creates a date object.

    (srfi 19) procedure (date? obj) ⟹ boolean?

    #t if object is a time object, otherwise, #f.

    (srfi 19) procedure (date-nanosecond (date date?)) ⟹ integer?

    Date nanosecond.

    (srfi 19) procedure (date-second (date date?)) ⟹ integer?

    Date second.

    (srfi 19) procedure (date-minute (date date?)) ⟹ integer?

    Date minute.

    (srfi 19) procedure (date-hour (date date?)) ⟹ integer?

    Date hour.

    (srfi 19) procedure (date-day (date date?)) ⟹ integer?

    Date day.

    (srfi 19) procedure (date-month (date date?)) ⟹ integer?

    Date month.

    (srfi 19) procedure (date-year (date date?)) ⟹ integer?

    Date year.

    (srfi 19) procedure (date-zone-offset (date date?)) ⟹ integer?

    Date time zone offset.

    (srfi 19) procedure (date-year-day (date date?)) ⟹ integer?

    The ordinal day of the year of this date. January 1 is 1, etc.

    (srfi 19) procedure (date-week-day (date date?)) ⟹ integer?

    The day of the week of this date, where Sunday=0, Monday=1, etc.

    (srfi 19) procedure (date-week-number (date date?) (day-of-week-starting-week integer?)) ⟹ integer?

    The ordinal week of the year which holds this date, ignoring a first partial week. 'Day-of-week-starting-week' is the integer corresponding to the day of the week which is to be considered the first day of the week (Sunday=0, Monday=1, etc.).

    (srfi 19) procedure (date->julian-day (date date?)) ⟹ real?

    Convert date to Julian Day.

    (srfi 19) procedure (date->modified-julian-day (date date?)) ⟹ real?

    Convert date to Modified Julian Day.

    (srfi 19) procedure (date->time-monotonic (date date?)) ⟹ time?

    Convert date to monotonic time.

    (srfi 19) procedure (date->time-tai (date date?)) ⟹ time?

    Convert date to TAI time.

    (srfi 19) procedure (date->time-utc (date date?)) ⟹ time?

    Convert date to UTC time.

    (srfi 19) procedure (julian-day->date (jd real?)) ⟹ date?

    (srfi 19) procedure (julian-day->date (jd real?) (tz-offset integer?)) ⟹ date?

    Convert Julian Day to date, , using time zone offset, which defaults to the local time zone.

    (srfi 19) procedure (julian-day->time-monotonic (jd real?)) ⟹ time?

    Convert Julian Day to monotonic time.

    (srfi 19) procedure (julian-day->time-tai (jd real?)) ⟹ time?

    Convert Julian Day to TAI time.

    (srfi 19) procedure (julian-day->time-utc (jd real?)) ⟹ time?

    Convert Julian Day to UTC time.

    (srfi 19) procedure (modified-julian-day->date (jd real?)) ⟹ date?

    (srfi 19) procedure (modified-julian-day->date (jd real?) (tz-offset integer?)) ⟹ date?

    Convert Modified Julian Day to date, using time zone offset, which defaults to the local time zone.

    (srfi 19) procedure (modified-julian-day->time-monotonic (jd real?)) ⟹ time?

    Convert Modified Julian Day to monotonic time.

    (srfi 19) procedure (modified-julian-day->time-tai (jd real?)) ⟹ time?

    Convert Modified Julian Day to TAI time.

    (srfi 19) procedure (modified-julian-day->time-utc (jd real?)) ⟹ time?

    Convert Modified Julian Day to UTC time.

    (srfi 19) procedure (time-monotonic->date (time-monotonic time?)) ⟹ date?

    (srfi 19) procedure (time-monotonic->date (time-monotonic time?) (tz-offset integer?)) ⟹ date?

    Convert monotonic time to date, using time zone offset, which defaults to the local time zone.

    (srfi 19) procedure (time-monotonic->julian-day (time-monotonic time?)) ⟹ real?

    Convert monotonic time to Julian Day.

    (srfi 19) procedure (time-monotonic->modified-julian-day (time-monotonic time?)) ⟹ real?

    Convert monotonic time to Modified Julian Day.

    (srfi 19) procedure (time-monotonic->time-tai (time-monotonic time?)) ⟹ time?

    Convert monotonic time to TAI time.

    (srfi 19) procedure (time-monotonic->time-tai! (time-monotonic time?)) ⟹ time?

    Convert monotonic time to TAI time. The time structure may be reused.

    (srfi 19) procedure (time-monotonic->time-utc (time-monotonic time?)) ⟹ time?

    Convert monotonic time to UTC time.

    (srfi 19) procedure (time-monotonic->time-utc! (time-monotonic time?)) ⟹ time?

    Convert monotonic time to UTC time. The time structure may be reused.

    (srfi 19) procedure (time-tai->date (time-tai time?)) ⟹ date?

    (srfi 19) procedure (time-tai->date (time-tai time?) (tz-offset integer?)) ⟹ date?

    Convert TAI time to date, using time zone offset, which defaults to the local time zone.

    (srfi 19) procedure (time-tai->julian-day (time-tai time?)) ⟹ real?

    Convert TAI time to Julian Day.

    (srfi 19) procedure (time-tai->modified-julian-day (time-tai time?)) ⟹ real?

    Convert TAI time to Modified Julian Day.

    (srfi 19) procedure (time-tai->time-monotonic (time-tai time?)) ⟹ time?

    Convert TAI time to monotonic time.

    (srfi 19) procedure (time-tai->time-monotonic! (time-tai time?)) ⟹ time?

    Convert TAI time to monotonic time. The time structure may be reused.

    (srfi 19) procedure (time-tai->time-utc (time-tai time?)) ⟹ time?

    Convert TAI time to UTC time.

    (srfi 19) procedure (time-tai->time-utc! (time-tai time?)) ⟹ time?

    Convert TAI time to UTC time. The time structure may be reused.

    (srfi 19) procedure (time-utc->date (time-utc time?)) ⟹ date?

    (srfi 19) procedure (time-utc->date (time-utc time?) (tz-offset integer?)) ⟹ date?

    Convert UTC time to date, using time zone offset, which defaults to the local time zone.

    (srfi 19) procedure (time-utc->julian-day (time-utc time?)) ⟹ real?

    Convert UTC time to Julian Day

    (srfi 19) procedure (time-utc->modified-julian-day (time-utc time?)) ⟹ real?

    Convert UTC time to Modified Julian Day.

    (srfi 19) procedure (time-utc->time-tai (time-utc time?)) ⟹ time?

    Convert UTC time to TAI time.

    (srfi 19) procedure (time-utc->time-tai! (time-utc time?)) ⟹ time?

    Convert UTC time to TAI time. The time structure may be reused.

    (srfi 19) procedure (date->string (date date?)) ⟹ string?

    (srfi 19) procedure (date->string (date date?) (format-string string?)) ⟹ string?

    Converts a date to a string, using the format string. The format string is copied as is; except escape characters (indicated by the tilde) are replaced with specific conversions.

    ~~ a literal ~

    ~a locale's abbreviated weekday name (Sun...Sat)

    ~A locale's full weekday name (Sunday...Saturday)

    ~b locale's abbreviate month name (Jan...Dec)

    ~B locale's full month day (January...December)

    ~c locale's date and time (e.g., "Fri Jul 14 20:28:42-0400 2000")

    ~d day of month, zero padded (01...31)

    ~D date (mm/dd/yy)

    ~e day of month, blank padded ( 1...31)

    ~f seconds+fractional seconds, using locale's decimal separator (e.g. 5.2).

    ~h same as ~b

    ~H hour, zero padded, 24-hour clock (00...23)

    ~I hour, zero padded, 12-hour clock (01...12)

    ~j day of year, zero padded

    ~k hour, blank padded, 24-hour clock ( 0...23)

    ~l hour, blank padded, 12-hour clock ( 1...12)

    ~m month, zero padded (01...12)

    ~M minute, zero padded (00...59)

    ~n new line

    ~N nanosecond, zero padded

    ~p locale's AM or PM

    ~r time, 12 hour clock, same as "~I:~M:~S ~p"

    ~s number of full seconds since "the epoch" (in UTC)

    ~S second, zero padded (00...60)

    ~t horizontal tab

    ~T time, 24 hour clock, same as "~H:~M:~S"

    ~U week number of year with Sunday as first day of week (00...53)

    ~V ISO 8601 week number of the year with Monday as first day of week (01..53)[1]

    ~w day of week (0...6)

    ~W week number of year with Monday as first day of week (01...52)

    ~x locale's date representation[1]

    ~X locale's time representation[1]

    ~y last two digits of year (00...99)

    ~Y year

    ~z time zone in RFC-822 style

    ~Z symbol time zone (not-implemented)

    ~1 ISO-8601 year-month-day format

    ~2 ISO-8601 hour-minute-second-timezone format

    ~3 ISO-8601 hour-minute-second format

    ~4 ISO-8601 year-month-day-hour-minute-second-timezone format

    ~5 ISO-8601 year-month-day-hour-minute-second format

    (srfi 19) procedure (string->date (input-string string?) (template-string string?)) ⟹ date?

    Converts an input string to a date, using the template string. The input string must match the template string as is; except escape characters (indicate by the tilde) indicate special converters which (1) move to the next character in the input string fulfilling a criterion; (2) read a value, and (3) act on this value in some way.

    Char: ~~. Skip to: any. Read: read literal ~ . Set: nothing.

    Char: ~a. Skip to: char-alphabetic?. Read: abbreviated weekday in locale . Set: nothing.

    Char: ~A. Skip to: char-alphabetic?. Read: full weekday in locale . Set: nothing.

    Char: ~b. Skip to: char-alphabetic?. Read: abbreviated month name in locale . Set: nothing.

    Char: ~B. Skip to: char-alphabetic?. Read: full month name in locale . Set: nothing.

    Char: ~d. Skip to: char-numeric?. Read: day of month . Set: date-day.

    Char: ~e. Skip to: any. Read: day of month, blank padded . Set: date-day.

    Char: ~h. Skip to: char-alphabetic?. Read: same as ~b . Set: nothing.

    Char: ~H. Skip to: char-numeric?. Read: hour . Set: date-hour.

    Char: ~k. Skip to: any. Read: hour, blank padded . Set: date-hour.

    Char: ~m. Skip to: char-numeric?. Read: month . Set: date-month.

    Char: ~M. Skip to: char-numeric?. Read: minute . Set: date-minute.

    Char: ~S. Skip to: char-numeric?. Read: second . Set: date-second.

    Char: ~y. Skip to: any. Read: 2-digit year . Set: date-year within 50 years.

    Char: ~Y. Skip to: char-numeric?. Read: year . Set: date-year.

    Char: ~z. Skip to: any. Read: time zone . Set: date-zone-offset.

    library (srfi 21) Real-time multithreading support

    This SRFI defines the following multithreading datatypes for Scheme

    • Thread
    • Mutex
    • Condition variable
    • Time

    It also defines a mechanism to handle exceptions and some multithreading exception datatypes.

    (srfi 21) procedure (current-thread) ⟹ thread?

    Returns the current thread.

    (srfi 21) procedure (thread? object) ⟹ boolean?

    Returns #t if obj is a thread, otherwise returns #f.

    (srfi 21) procedure (make-thread (thunk procedure?)) ⟹ thread?

    (srfi 21) procedure (make-thread (thunk procedure?) name) ⟹ thread?

    (thunk) ⟹ *

    Returns a new thread. This thread is not automatically made runnable (the procedure thread-start! must be used for this). A thread has the following fields: base priority, priority boost, boosted flag, quantum, name, specific, end-result, end-exception, and a list of locked/owned mutexes it owns. The thread's execution consists of a call to thunk with the "initial continuation". This continuation causes the (then) current thread to store the result in its end-result field, abandon all mutexes it owns, and finally terminate. The dynamic-wind stack of the initial continuation is empty. The optional name is an arbitrary Scheme object which identifies the thread (useful for debugging); it defaults to an unspecified value. The specific field is set to an unspecified value. The base priority, priority boost, and quantum of the thread are set to the same value as the current thread and the boosted flag is set to false. The thread inherits the dynamic environment from the current thread. Moreover, in this dynamic environment the exception handler is bound to the "initial exception handler" which is a unary procedure which causes the (then) current thread to store in its end-exception field an "uncaught exception" object whose "reason" is the argument of the handler, abandon all mutexes it owns, and finally terminate.

    (srfi 21) procedure (thread-name (thread thread?)) ⟹ *

    Returns the name of the thread.

    (srfi 21) procedure (thread-specific (thread thread?)) ⟹ *

    Returns the content of the thread's specific field.

    (srfi 21) procedure (thread-specific-set! (thread thread?) obj) ⟹ undefined

    Stores obj into the thread's specific field. thread-specific-set! returns an unspecified value.

    (srfi 21) procedure (thread-base-priority (thread thread?)) ⟹ real?

    Returns a real number which corresponds to the base priority of the thread.

    (srfi 21) procedure (thread-base-priority-set! (thread thread?) (priority real?)) ⟹ undefined

    Changes the base priority of the thread to priority. The priority must be a real number. thread-base-priority-set! returns an unspecified value.

    (srfi 21) procedure (thread-priority-boost (thread thread?)) ⟹ real?

    Returns a real number which corresponds to the priority boost of the thread.

    (srfi 21) procedure (thread-priority-boost-set! (thread thread?) (priority-boost real?)) ⟹ undefined

    Changes the priority boost of the thread to priority-boost. The priority-boost must be a non-negative real. thread-priority-boost-set! returns an unspecified value.

    (srfi 21) procedure (thread-quantum (thread thread?)) ⟹ real?

    Returns a real number which corresponds to the quantum of the thread.

    (srfi 21) procedure (thread-quantum-set! (thread thread?) (quantum real?)) ⟹ undefined

    Changes the quantum of the thread to quantum. The quantum must be a non-negative real. A value of zero selects the smallest quantum supported by the implementation. thread-quantum-set! returns an unspecified value.

    (srfi 21) procedure (thread-start! (thread thread?)) ⟹ thread?

    Makes thread runnable. The thread must be a new thread. thread-start! returns the thread.

    (srfi 21) procedure (thread-yield! (thread thread?)) ⟹ undefined

    The current thread exits the running state as if its quantum had expired. thread-yield! returns an unspecified value.

    (srfi 21) procedure (thread-sleep! (timeout integer?)) ⟹ undefined

    The current thread waits until the timeout is reached. This blocks the thread only if timeout represents a point in the future. It is an error for timeout to be #f. thread-sleep! returns an unspecified value.

    (srfi 21) procedure (thread-terminate! (thread thread?)) ⟹ undefined

    Causes an abnormal termination of the thread. If the thread is not already terminated, all mutexes owned by the thread become unlocked/abandoned and a "terminated thread exception" object is stored in the thread's end-exception field. If thread is the current thread, thread-terminate! does not return. Otherwise thread-terminate! returns an unspecified value; the termination of the thread will occur before thread-terminate! returns.

    (srfi 21) procedure (thread-join! (thread thread?)) ⟹ *

    (srfi 21) procedure (thread-join! (thread thread?) (timeout integer?)) ⟹ *

    (srfi 21) procedure (thread-join! (thread thread?) (timeout integer?) timeout-val) ⟹ *

    The current thread waits until the thread terminates (normally or not) or until the timeout is reached if timeout is supplied. If the timeout is reached, thread-join! returns timeout-val if it is supplied, otherwise a "join timeout exception" is raised. If the thread terminated normally, the content of the end-result field is returned, otherwise the content of the end-exception field is raised.

    (srfi 21) procedure (mutex? object) ⟹ boolean?

    Returns #t if obj is a mutex, otherwise returns #f.

    (srfi 21) procedure (make-mutex ) ⟹ mutex?

    (srfi 21) procedure (make-mutex name) ⟹ mutex?

    Returns a new mutex in the unlocked/not-abandoned state. The optional name is an arbitrary Scheme object which identifies the mutex (useful for debugging); it defaults to an unspecified value. The mutex's specific field is set to an unspecified value.

    (srfi 21) procedure (mutex-name (mutex mutex?)) ⟹ *

    Returns the name of the mutex.

    (srfi 21) procedure (mutex-specific (mutex mutex?)) ⟹ *

    Returns the content of the mutex's specific field.

    (srfi 21) procedure (mutex-specific-set! (mutex mutex?) obj) ⟹ undefined

    Stores obj into the mutex's specific field. mutex-specific-set! returns an unspecified value.

    (srfi 21) procedure (mutex-state (mutex mutex?)) ⟹ thread? | symbol?

    Returns information about the state of the mutex. The possible results are:

  • thread T: the mutex is in the locked/owned state and thread T is the owner of the mutex
  • symbol not-owned: the mutex is in the locked/not-owned state
  • symbol abandoned: the mutex is in the unlocked/abandoned state
  • symbol not-abandoned: the mutex is in the unlocked/not-abandoned state
  • (srfi 21) procedure (mutex-lock! (mutex mutex?)) ⟹ boolean?

    (srfi 21) procedure (mutex-lock! (mutex mutex?) (timeout integer?)) ⟹ boolean?

    (srfi 21) procedure (mutex-lock! (mutex mutex?) (timeout integer?) (thread #f | thread?)) ⟹ boolean?

    If the mutex is currently locked, the current thread waits until the mutex is unlocked, or until the timeout is reached if timeout is supplied. If the timeout is reached, mutex-lock! returns #f. Otherwise, the state of the mutex is changed as follows:

  • if thread is #f the mutex becomes locked/not-owned,
  • otherwise, let T be thread (or the current thread if thread is not supplied),
  • if T is terminated the mutex becomes unlocked/abandoned,

    otherwise mutex becomes locked/owned with T as the owner.

    After changing the state of the mutex, an "abandoned mutex exception" is raised if the mutex was unlocked/abandoned before the state change, otherwise mutex-lock! returns #t. It is not an error if the mutex is owned by the current thread (but the current thread will have to wait).

    (srfi 21) procedure (mutex-unlock! (mutex mutex?)) ⟹ boolean?

    (srfi 21) procedure (mutex-unlock! (mutex mutex?) (condition-variable condition-variable?)) ⟹ boolean?

    (srfi 21) procedure (mutex-unlock! (mutex mutex?) (condition-variable condition-variable?) (timeout integer?)) ⟹ boolean?

    Unlocks the mutex by making it unlocked/not-abandoned. It is not an error to unlock an unlocked mutex and a mutex that is owned by any thread. If condition-variable is supplied, the current thread is blocked and added to the condition-variable before unlocking mutex; the thread can unblock at any time but no later than when an appropriate call to condition-variable-signal! or condition-variable-broadcast! is performed (see below), and no later than the timeout (if timeout is supplied). If there are threads waiting to lock this mutex, the scheduler selects a thread, the mutex becomes locked/owned or locked/not-owned, and the thread is unblocked. mutex-unlock! returns #f when the timeout is reached, otherwise it returns #t.

    (srfi 21) procedure (condition-variable? object) ⟹ boolean?

    Returns #t if obj is a condition variable, otherwise returns #f.

    (srfi 21) procedure (make-condition-variable ) ⟹ condition-variable?

    (srfi 21) procedure (make-condition-variable name) ⟹ condition-variable?

    (srfi 21) procedure (make-condition-variable name) ⟹ condition-variable?

    Returns a new empty condition variable. The optional name is an arbitrary Scheme object which identifies the condition variable (useful for debugging); it defaults to an unspecified value. The condition variable's specific field is set to an unspecified value.

    (srfi 21) procedure (condition-variable-name (condition-variable condition-variable?)) ⟹ *

    Returns the name of the condition-variable.

    (srfi 21) procedure (condition-variable-specific (condition-variable condition-variable?)) ⟹ *

    Returns the content of the condition-variable's specific field.

    (srfi 21) procedure (condition-variable-specific-set! (condition-variable condition-variable?) obj) ⟹ undefined

    Stores obj into the condition-variable's specific field. condition-variable-specific-set! returns an unspecified value.

    (srfi 21) procedure (condition-variable-signal! (condition-variable condition-variable?)) ⟹ undefined

    If there are threads blocked on the condition-variable, the scheduler selects a thread and unblocks it. condition-variable-signal! returns an unspecified value.

    (srfi 21) procedure (condition-variable-broadcast! (condition-variable condition-variable?)) ⟹ undefined

    Unblocks all the threads blocked on the condition-variable. condition-variable-broadcast! returns an unspecified value.

    (srfi 21) procedure (current-time) ⟹ time?

    Returns the time object corresponding to the current time.

    (srfi 21) procedure (time? obj) ⟹ boolean?

    Returns #t if obj is a time object, otherwise returns #f.

    (srfi 21) procedure (time->seconds (time time?)) ⟹ real?

    Converts the time object time into an exact or inexact real number representing the number of seconds elapsed since some implementation dependent reference point.

    (srfi 21) procedure (seconds->time (seconds real?)) ⟹ time?

    Converts into a time object the exact or inexact real number x representing the number of seconds elapsed since some implementation dependent reference point.

    (srfi 21) procedure (current-exception-handler) ⟹ procedure?

    (return err) ⟹ *

    Returns the current exception handler.

    (srfi 21) procedure (with-exception-handler (handler procedure?) (thunk procedure?)) ⟹ *

    (handler err) ⟹ *

    (thunk) ⟹ *

    Returns the result(s) of calling thunk with no arguments. The handler, which must be a procedure, is installed as the current exception handler in the dynamic environment in effect during the call to thunk.

    (srfi 21) procedure (raise obj) ⟹ undefined

    Calls the current exception handler with obj as the single argument. obj may be any Scheme object.

    (srfi 21) procedure (join-timeout-exception? obj) ⟹ boolean?

    Returns #t if obj is a "join timeout exception" object, otherwise returns #f. A join timeout exception is raised when thread-join! is called, the timeout is reached and no timeout-val is supplied.

    (srfi 21) procedure (abandoned-mutex-exception? obj) ⟹ boolean?

    Returns #t if obj is an "abandoned mutex exception" object, otherwise returns #f. An abandoned mutex exception is raised when the current thread locks a mutex that was owned by a thread which terminated (see mutex-lock!).

    (srfi 21) procedure (terminated-thread-exception? obj) ⟹ boolean?

    Returns #t if obj is a "terminated thread exception" object, otherwise returns #f. A terminated thread exception is raised when thread-join! is called and the target thread has terminated as a result of a call to thread-terminate!.

    (srfi 21) procedure (uncaught-exception? obj) ⟹ boolean?

    Returns #t if obj is an "uncaught exception" object, otherwise returns #f. An uncaught exception is raised when thread-join! is called and the target thread has terminated because it raised an exception that called the initial exception handler of that thread.

    (srfi 21) procedure (uncaught-exception-reason (exc uncaught-exception?)) ⟹ *

    exc must be an "uncaught exception" object. uncaught-exception-reason returns the object which was passed to the initial exception handler of that thread.

    library (srfi 23) Error reporting mechanism

    A mechanism is proposed to allow Scheme code to report errors and abort execution. The proposed mechanism is already implemented in several Scheme systems and can be implemented, albeit imperfectly, in any R5RS conforming Scheme.

    See (scheme base)

    library (srfi 25) Multi-dimensional Array Primitives

    A core set of procedures for creating and manipulating heterogeneous multidimensional arrays is proposed. The design is consistent with the rest of Scheme and independent of other container data types. It provides easy sharing of parts of an array as other arrays without copying, encouraging a declarative style of programming.

    The specification is based on an original contribution by Alan Bawden in 1993.

    (srfi 25) procedure (array? obj) ⟹ boolean?

    Returns #t if obj is an array, otherwise returns #f.

    (srfi 25) procedure (make-array (shape array?)) ⟹ array?

    (srfi 25) procedure (make-array (shape array?) obj) ⟹ array?

    Returns a newly allocated array whose shape is given by shape. If obj is provided, then each element is initialized to it. Otherwise the initial contents of each element is unspecified. The array does not retain a dependence to shape.

    (srfi 25) procedure (shape (lowerbound1 integer?) (upperbound1 integer?) ...) ⟹ array?

    Returns a shape. The sequence bound ... must consist of an even number of exact integers that are pairwise not decreasing. Each pair gives the lower and upper bound of a dimension. If the shape is used to specify the dimensions of an array and bound ... is the sequence b0 e0 ... bk ek ... of n pairs of bounds, then a valid index to the array is any sequence j0 ... jk ... of n exact integers where each jk satisfies (<= bk jk) and (< jk ek).

    The shape of a d-dimensional array is a d × 2 array where the element at k 0 contains the lower bound for an index along dimension k and the element at k 1 contains the corresponding upper bound, where k satisfies (<= 0 k) and (< k d).

    (srfi 25) procedure (array (shape array?) obj ...) ⟹ array?

    Returns a new array whose shape is given by shape and the initial contents of the elements are obj ... in row major order. The array does not retain a dependence to shape.

    (srfi 25) procedure (array-rank (shape array?)) ⟹ integer?

    Returns the number of dimensions of array.

    (srfi 25) procedure (array-start (shape array?) (k integer?)) ⟹ integer?

    Returns the lower bound for the index along dimension k.

    (srfi 25) procedure (array-end (shape array?) (k integer?)) ⟹ integer?

    Returns the upper bound for the index along dimension k.

    (srfi 25) procedure (array-ref (shape array?) (k integer?) ...) ⟹ *

    (srfi 25) procedure (array-ref (shape array?) (index vector? | array?)) ⟹ *

    Returns the contents of the element of array at index k .... The sequence k ... must be a valid index to array. In the second form, index must be either a vector or a 0-based 1-dimensional array containing k ....

    (srfi 25) procedure (array-set! (shape array?) (k integer?) ... obj) ⟹ undefined

    (srfi 25) procedure (array-set! (shape array?) (index vector? | array?) obj) ⟹ undefined

    Stores obj in the element of array at index k .... Returns an unspecified value. The sequence k ... must be a valid index to array. In the second form, index must be either a vector or a 0-based 1-dimensional array containing k ....

    (srfi 25) procedure (share-array (array array?) (shape array?) (proc procedure?)) ⟹ array?

    (proc (index1 integer?) ...) ⟹ (values integer? ...)

    Returns a new array of shape shape that shares elements of array through proc. The procedure proc must implement an affine function that returns indices of array when given indices of the array returned by share-array. The array does not retain a dependence to shape.

    library (srfi 26) Notation for Specializing Parameters without Currying

    When programming in functional style, it is frequently necessary to specialize some of the parameters of a multi-parameter procedure. For example, from the binary operation cons one might want to obtain the unary operation (lambda (x) (cons 1 x)). This specialization of parameters is also known as "partial application", "operator section" or "projection".

    The mechanism proposed here allows to write this sort of specialization in a simple and compact way. The mechanism is best explained by a few examples:
    (cut cons (+ a 1) <>) is the same as (lambda (x2) (cons (+ a 1) x2))
    (cut list 1 <> 3 <> 5) is the same as (lambda (x2 x4) (list 1 x2 3 x4 5))
    (cut list) is the same as (lambda () (list))
    (cut list 1 <> 3 <...>) is the same as (lambda (x2 . xs) (apply list 1 x2 3 xs))
    (cut <> a b) is the same as (lambda (f) (f a b))

    As you see, the macro cut specializes some of the parameters of its first argument. The parameters that are to show up as formal variables of the result are indicated by the symbol <>, pronouced as "slot". In addition, the symbol <...>, pronounced as "rest-slot", matches all residual arguments of a variable argument procedure. As you can see from the last example above, the first argument can also be a slot, as one should expect in Scheme.

    In addition to cut, there is a variant called cute (a mnemonic for "cut with evaluated non-slots") which evaluates the non-slot expressions at the time the procedure is specialized, not at the time the specialized procedure is called. For example,
    (cute cons (+ a 1) <>) is the same as (let ((a1 (+ a 1))) (lambda (x2) (cons a1 x2)))

    As you see from comparing this example with the first example above, the cute-variant will evaluate (+ a 1) once, while the cut-variant will evaluate it during every invokation of the resulting procedure.

    The mechanism proposed in this SRFI allows specializing any subset of the variables of a procedure. The result can be of fixed arity or of variable arity. The mechanism does not allow permutation, omission, duplication or any other processing of the arguments; for this it is necessary to write to use a different mechanism such as lambda.

    (srfi 26) syntax (cut slot-or-expr slot-or-expr ...)⟹ return

    (srfi 26) syntax (cut slot-or-expr slot-or-expr ... <...>)⟹ return

    slot-or-expr ⟹ <> | expression

    The macro cut transforms a <cut-expression> into a <lambda expression> with as many formal variables as there are slots in the list <slot-or-expr>*. The body of the resulting <lambda expression> calls the first <slot-or-expr> with arguments from <slot-or-expr>* in the order they appear. In case there is a rest-slot symbol, the resulting procedure is also of variable arity, and the body calls the first <slot-or-expr> with all arguments provided to the actual call of the specialized procedure.

    (srfi 26) syntax (cute slot-or-expr slot-or-expr ...)⟹ return

    (srfi 26) syntax (cute slot-or-expr slot-or-expr ... <...>)⟹ return

    slot-or-expr ⟹ <> | expression

    The macro cute is similar to the macro cut, except that it first binds new variables to the result of evaluating the non-slot expressions (in an unspecific order) and then substituting the variables for the non-slot expressions. In effect, cut evaluates non-slot expressions at the time the resulting procedure is called, whereas cute evaluates the non-slot expressions at the time the procedure is constructed.

    library (srfi 27) Sources of Random Bits

    This document specifies an interface to sources of random bits, or "random sources" for brevity. In particular, there are three different ways to use the interface, with varying demands on the quality of the source and the amount of control over the production process:

    • The "no fuss" interface specifies that (random-integer n) produces the next random integer in {0, ..., n-1} and (random-real) produces the next random real number between zero and one. The details of how these random values are produced may not be very relevant, as long as they appear to be sufficiently random.
    • For simulation purposes, on the contrary, it is usually necessary to know that the numbers are produced deterministically by a pseudo random number generator of high quality and to have explicit access to its state. In addition, one might want to use several independent sources of random numbers at the same time and it can be useful to have some simple form of randomization.
    • For security applications a serious form of true randomization is essential, in the sense that it is difficult for an adversary to exploit or introduce imperfections into the distribution of random bits. Moreover, the linear complexity of the stream of random bits is more important than its statistical properties. In these applications, an entropy source (producing truely random bits at a low rate) is used to randomize a pseudo random number generator to increase the rate of available bits.

    Once random sources provide the infrastructure to obtain random bits, these can be used to construct other random deviates. Most important are floating point numbers of various distributions and random discrete structures, such as permutations or graphs. As there is an essentially unlimited number of such objects (with limited use elsewhere), we do not include them in this SRFI. In other words, this SRFI is not about making all sorts of random objects---it is about obtaining random bits in a portable, flexible, reliable, and efficient way.

    (srfi 27) procedure (random-integer (n integer?)) ⟹ integer?

    The next integer x in {0, ..., n-1} obtained from default-random-source. Subsequent results of this procedure appear to be independent uniformly distributed over the range {0, ..., n-1}. The argument n must be a positive integer, otherwise an error is signalled.

    (srfi 27) procedure (random-real) ⟹ real?

    The next number 0 < x < 1 obtained from default-random-source. Subsequent results of this procedure appear to be independent uniformly distributed. The numerical type of the results and the quantization of the output range depend on the implementation; refer to random-source-make-reals for details.

    (srfi 27) value default-random-source ⟹ random-source?

    A random source from which random-integer and random-real have been derived using random-source-make-integers and random-source-make-reals. Note that an assignment to default-random-source does not change random or random-real; it is also strongly recommended not to assign a new value.

    (srfi 27) procedure (make-random-source) ⟹ random-source?

    Creates a new random source s. Implementations may accept additional, optional arguments in order to create different types of random sources. A random source created with make-random-source represents a deterministic stream of random bits generated by some form of pseudo random number generator. Each random source obtained as (make-random-source) generates the same stream of values, unless the state is modified with one of the procedures below.

    (srfi 27) procedure (random-source? obj) ⟹ boolean?

    Tests if obj is a random source. Objects of type random source are distinct from all other types of objects.

    (srfi 27) procedure (random-source-state-ref (s random-source?)) ⟹ random-source-state

    Get the current state of a random source s. The structure of the object state depends on the implementation; the only portable use of it is as argument to random-source-state-set!. It is, however, required that a state possess an external representation.

    (srfi 27) procedure (random-source-state-set! (s random-source?) (state random-source-state)) ⟹ undefined

    Set the current state of a random source s.

    (srfi 27) procedure (random-source-randomize! (s random-source?)) ⟹ undefined

    Makes an effort to set the state of the random source s to a truly random state. The actual quality of this randomization depends on the implementation but it can at least be assumed that the procedure sets s to a different state for each subsequent run of the Scheme system.

    (srfi 27) procedure (random-source-pseudo-randomize! (s random-source?) (i integer?) (j integer?)) ⟹ undefined

    Changes the state of the random source s into the initial state of the (i, j)-th independent random source, where i and j are non-negative integers. This procedure provides a mechanism to obtain a large number of independent random sources (usually all derived from the same backbone generator), indexed by two integers. In contrast to random-source-randomize!, this procedure is entirely deterministic.

    (srfi 27) procedure (random-source-make-integers (s random-source?)) ⟹ procedure?

    (return (n integer?)) ⟹ integer?

    Obtains a procedure rand to generate random integers using the random source s. Rand takes a single argument n, which must be a positive integer, and returns the next uniformly distributed random integer from the interval {0, ..., n-1} by advancing the state of the source s.

    If an application obtains and uses several generators for the same random source s, a call to any of these generators advances the state of s. Hence, the generators do not produce the same sequence of random integers each but rather share a state. This also holds for all other types of generators derived from a fixed random sources. Implementations that support concurrency make sure that the state of a generator is properly advanced.

    (srfi 27) procedure (random-source-make-reals (s random-source?)) ⟹ procedure?

    (srfi 27) procedure (random-source-make-reals (s random-source?) (unit real?)) ⟹ procedure?

    (return) ⟹ real?

    Obtains a procedure rand to generate random real numbers 0 < x < 1 using the random source s. The procedure rand is called without arguments.

    The optional parameter unit determines the type of numbers being produced by rand and the quantization of the output. Unit must be a number such that 0 < unit < 1. The numbers created by rand are of the same numerical type as unit and the potential output values are spaced by at most unit. One can imagine rand to create numbers as x*unit where x is a random integer in {1, ..., floor(1/unit)-1}. Note, however, that this need not be the way the values are actually created and that the actual resolution of rand can be much higher than unit. In case unit is absent it defaults to a reasonably small value (related to the width of the mantissa of an efficient number format).

    library (srfi 28) Basic Format Strings

    This document specifies Format Strings, a method of interpreting a Scheme string which contains a number of escape sequences that are replaced with other string data according to the semantics of each sequence.

    (srfi 28) procedure (format (format-string string?) obj ...) ⟹ string?

    Accepts a message template (a Scheme String), and processes it, replacing any escape sequences in order with one or more characters, the characters themselves dependent on the semantics of the escape sequence encountered.

    An escape sequence is a two character sequence in the string where the first character is a tilde '~'. Each escape code's meaning is as follows:

    ~a The corresponding value is inserted into the string as if printed with display.

    ~s The corresponding value is inserted into the string as if printed with write.

    ~% A newline is inserted.

    ~~ A tilde '~' is inserted.

    ~a and ~s, when encountered, require a corresponding Scheme value to be present after the format string. The values provided as operands are used by the escape sequences in order. It is an error if fewer values are provided than escape sequences that require them.

    ~% and ~~ require no corresponding value.

    library (srfi 29) Localization

    This document specifies an interface to retrieving and displaying locale sensitive messages. A Scheme program can register one or more translations of templated messages, and then write Scheme code that can transparently retrieve the appropriate message for the locale under which the Scheme system is running.

    (srfi 29) procedure (current-language ) ⟹ symbol?

    (srfi 29) procedure (current-language (lang symbol?)) ⟹ undefined

    When given no arguments, returns the current ISO 639-1 language code as a symbol. If provided with an argument, the current language is set to that named by the symbol for the currently executing Scheme thread (or for the entire Scheme system if such a distinction is not possible).

    (srfi 29) procedure (current-country ) ⟹ symbol?

    (srfi 29) procedure (current-country (country symbol?)) ⟹ undefined

    returns the current ISO 3166-1 country code as a symbol. If provided with an argument, the current country is set to that named by the symbol for the currently executing Scheme thread (or for the entire Scheme system if such a distinction is not possible).

    (srfi 29) procedure (current-locale-details ) ⟹ list?

    (srfi 29) procedure (current-locale-details (symbols list?)) ⟹ undefined

    Returns a list of additional locale details as a list of symbols. This list may contain information about encodings or other more specific information. If provided with an argument, the current locale details are set to those given in the currently executing Scheme thread (or for the entire Scheme system if such a distinction is not possible).

    (srfi 29) procedure (declare-bundle! (bundle-specifier list?) (alist list?)) ⟹ undefined

    Declares a new bundle named by the given bundle-specifier. The contents of the bundle are defined by the provided association list. The list contains associations between Scheme symbols and the message templates (Scheme strings) they name. If a bundle already exists with the given name, it is overwritten with the newly declared bundle.

    (srfi 29) procedure (store-bundle (bundle-specifier list?)) ⟹ boolean?

    Attempts to store a bundle named by the given bundle specifier, and previously made available using declare-bundle! or load-bundle!, in an unspecified mechanism that may be persistent across Scheme system restarts. If successful, a non-false value is returned. If unsuccessful, #f is returned.

    (srfi 29) procedure (load-bundle! (bundle-specifier list?)) ⟹ boolean?

    Attempts to retrieve a bundle from an unspecified mechanism which stores bundles outside the Scheme system. If the bundle was retrieved successfully, the function returns a non-false value, and the bundle is immediately available to the Scheme system. If the bundle could not be found or loaded successfully, the function returns #f, and the Scheme system's bundle registry remains unaffected.

    (srfi 29) procedure (localized-template (package-name symbol?) (message-tpl-name symbol?)) ⟹ string? | #f

    Retrieves a localized message template for the given package name and the given message template name (both symbols). If no such message could be found, false (#f) is returned.

    library (srfi 31) A special form `rec' for recursive evaluation

    We propose the implementation of a special form called rec. This form is a generalization and combination of the forms rec and named-lambda of [Clinger1985]. It allows the simple and non-imperative construction of self-referential expressions. As an important special case, it extends the A. Church form lambda such that it allows the direct definition of recursive procedures without using further special forms like let or letrec, without using advanced constructions like the H. B. Curry combinator and, unlike define, without introducing variable bindings into the external environment.

    (srfi 31) syntax (rec (name variables ...) body ...)⟹ return

    (srfi 31) syntax (rec name expression)

    (define-syntax rec

    (syntax-rules ()

    ((rec (NAME . VARIABLES) . BODY)

    (letrec ( (NAME (lambda VARIABLES . BODY)) ) NAME))

    ((rec NAME EXPRESSION)

    (letrec ( (NAME EXPRESSION) ) NAME))))

    library (srfi 34) Exception Handling for Programs

    This SRFI defines exception-handling and exception-raising constructs for Scheme, including

    • a with-exception-handler procedure and a guard form for installing exception-handling procedures,
    • a raise procedure for invoking the current exception handler.

    This SRFI is based on (withdrawn) SRFI 12: Exception Handling by William Clinger, R. Kent Dybvig, Matthew Flatt, and Marc Feeley.

    See (scheme base)

    library (srfi 35) Conditions

    The SRFI defines constructs for creating and inspecting condition types and values. A condition value encapsulates information about an exceptional situation, or exception. This SRFI also defines a few basic condition types.

    (srfi 35) procedure (make-condition-type (id symbol?) (parent condition-type?) (field-names list?)) ⟹ condition-type?

    Make-condition-type returns a new condition type. Id must be a symbol that serves as a symbolic name for the condition type. Parent must itself be a condition type. Field-names must be a list of symbols. It identifies the fields of the conditions associated with the condition type.

    Field-names must be disjoint from the field names of parent and its ancestors.

    (srfi 35) procedure (condition-type? obj) ⟹ boolean?

    Condition-type? is a predicate for condition types: it returns #t if thing is a condition type, and #f otherwise

    (srfi 35) procedure (make-condition (type condition-type?) (field-name1 symbol?) value1 ...) ⟹ condition?

    Make-condition creates a condition value belonging condition type type. The following arguments must be, in turn, a field name and an arbitrary value. There must be such a pair for each field of type and its direct and indirect supertypes. Make-condition returns the condition value, with the argument values associated with their respective fields.

    (srfi 35) procedure (condition? obj) ⟹ boolean?

    Condition? is a predicate for conditions: it returns #t if thing is a condition type, and #f otherwise

    (srfi 35) procedure (condition-has-type? (condition condition?) (type condition-type?)) ⟹ boolean?

    Condition-has-type? tests if condition condition belongs to condition type condition-type. It returns #t if any of condition 's types includes condition-type either directly or as an ancestor and #f otherwise. It is an error if condition is not a condition, or if condition-type is not a condition type.

    (srfi 35) procedure (condition-ref (condition condition?) (field-name symbol?)) ⟹ *

    Condition must be a condition, and field-name a symbol. Moreover, condition must belong to a condition type which has a field name called field-name, or one of its (direct or indirect) supertypes must have the field. Condition-ref returns the value associated with field-name.

    It is an error to refer to a field the condition does not have.

    (srfi 35) procedure (make-compound-condition (condition1 condition?) (condition2 condition?) ...) ⟹ condition?

    Make-compound-condition returns a compound condition belonging to all condition types that the conditioni belong to.

    Condition-ref, when applied to a compound condition will return the value from the first of the conditioni that has such a field.

    (srfi 35) procedure (extract-condition (condition condition?) (type condition-type?)) ⟹ condition?

    Condition must be a condition belonging to condition-type. Extract-condition returns a condition of condition type condition-type with the field values specified by condition.

    If condition is a compound condition, extract-condition extracts the field values from the subcondition belonging to condition-type that appeared first in the call to make-compound-condition that created the the condition. The returned condition may be newly created

    (srfi 35) syntax (define-condition-type condition-type supertype predicate field-spec ...)

    field-spec ⟹ (field accessor)

    supertype ⟹ condition-type?

    This defines a new condition type. <Condition-type>, <supertypes>, and <predicate> must all be identifiers. Define-condition-type defines an identifier <condition-type> to some value describing the condition type. <supertype> must be the name of a previously defined condition type.

    Define-condition-type also defines <predicate> to a predicate that identifies conditions associated with that type, or with any of its subtypes.

    Each <field-spec> must be of the form ( <field> <accessor>) where both <field> and <accessor> must be identifiers. Define-condition-type defines each <accessor> to a procedure which extracts the value of the named field from a condition associated with this condition type.

    (srfi 35) syntax (condition type-field-binding ...)⟹ return

    type-field-binding ⟹ (condition-type field-binding)

    field-binding ⟹ (field exp)

    condition-type ⟹ condition-type?

    This creates a condition value. Each <type-field-binding> must be of the form ( <condition-type> <field-binding> ...) Each <field-binding> must be of the form ( <field> <exp>) where <field> is a field identifier from the definition of <condition-type>.

    The <exp> are evaluated in some unspecified order; their values can later be extracted from the condition object via the accessors of the associated condition types or their supertypes.

    The condition returned by condition is created by a call of form

    (make-compound-condition

    (make-condition <condition-type> '<field-name> <value>...)

    ...)

    with the condition types retaining their order from thecondition form. The field names and values are duplicated as necessary as described below.

    Each <type-field-binding> must contain field bindings for all fields of <condition-type> without duplicates. There is an exception to this rule: if a field binding is missing, and the field belongs to a supertype shared with one of the other <type-field-binding> subforms, then the value defaults to that of the first such binding in the condition form.

    (srfi 35) value &condition ⟹ condition-type?

    This is the root of the entire condition type hierarchy. It has a no fields.

    (srfi 35) value &message ⟹ condition-type?

    (srfi 35) procedure (message-condition? obj) ⟹ boolean?

    (srfi 35) procedure (condition-message (condition message-condition?)) ⟹ *

    This condition type could be defined by

    (define-condition-type &message &condition

    message-condition?

    (message condition-message))

    It carries a message further describing the nature of the condition to humans.

    (srfi 35) value &serious ⟹ condition-type?

    (srfi 35) procedure (serious-condition? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &serious &condition

    serious-condition?)

    This type describes conditions serious enough that they cannot safely be ignored. This condition type is primarily intended as a supertype of other condition types.

    (srfi 35) value &error ⟹ condition-type?

    (srfi 35) procedure (error? obj) ⟹ boolean?

    This condition type could be defined by

    (define-condition-type &error &serious

    error?)

    This condition describes errors, typically caused by something that has gone wrong in the interaction of the program with the external world or the user.

    library (srfi 36) I/O Conditions

    This SRFI specifies a set of condition types for I/O errors. The condition types are defined in terms of SRFI 35. Moreover, this SRFI requires a Scheme system implementing it to raise exceptions in the sense of SRFI 34 for errors occurring during the execution of the R5RS I/O operations.

    (srfi 36) value &i/o-error ⟹ condition-type?

    (srfi 36) procedure (i/o-error? obj) ⟹ boolean?

    (define-condition-type &i/o-error &error

    i/o-error?)

    This is a supertype for a set of more specific I/O errors.

    (srfi 36) value &i/o-port-error ⟹ condition-type?

    (srfi 36) procedure (i/o-port-error? obj) ⟹ boolean?

    (srfi 36) procedure (i/o-error-port (err i/o-port-error?)) ⟹ port?

    (define-condition-type &i/o-port-error &i/o-error

    i/o-port-error?

    (port i/o-error-port))

    This condition type specifies an I/O error that occurred during an operation on a port. Condition objects belonging to this type must specify a port in the port field.

    (srfi 36) value &i/o-read-error ⟹ condition-type?

    (srfi 36) procedure (i/o-read-error? obj) ⟹ boolean?

    (define-condition-type &i/o-read-error &i/o-port-error

    i/o-read-error?)

    This condition type specifies a read error that occurred during an operation on a port.

    (srfi 36) value &i/o-write-error ⟹ condition-type?

    (srfi 36) procedure (i/o-write-error? obj) ⟹ boolean?

    (define-condition-type &i/o-write-error &i/o-port-error

    i/o-write-error?)

    This condition type specifies a write error that occurred during an operation on a port.

    (srfi 36) value &i/o-closed-error ⟹ condition-type?

    (srfi 36) procedure (i/o-closed-error? obj) ⟹ boolean?

    (define-condition-type &i/o-closed-error &i/o-port-error

    i/o-closed-error?)

    A condition of this type specifies that an operation tried to operate on a closed port under the assumption that it is open.

    (srfi 36) value &i/o-filename-error ⟹ condition-type?

    (srfi 36) procedure (i/o-filename-error? obj) ⟹ boolean?

    (srfi 36) procedure (i/o-error-filename (err i/o-filename-error?)) ⟹ string?

    (define-condition-type &i/o-filename-error &i/o-error

    i/o-filename-error?

    (filename i/o-error-filename))

    This condition type specifies an I/O error that occurred during an operation on a named file. Condition objects belonging to this type must specify a file name in the filename field.

    (srfi 36) value &i/o-malformed-filename-error ⟹ condition-type?

    (srfi 36) procedure (i/o-malformed-filename-error? obj) ⟹ boolean?

    (define-condition-type &i/o-malformed-filename-error &i/o-filename-error

    i/o-malformed-filename-error?)

    This condition type indicates that a file name had an invalid format.

    (srfi 36) value &i/o-file-protection-error ⟹ condition-type?

    (srfi 36) procedure (i/o-file-protection-error? obj) ⟹ boolean?

    (define-condition-type &i/o-file-protection-error &i/o-filename-error

    i/o-file-protection-error?)

    A condition of this type specifies that an operation tried to operate on a named file with insufficient access rights.

    (srfi 36) value &i/o-file-is-read-only-error ⟹ condition-type?

    (srfi 36) procedure (i/o-file-is-read-only-error? obj) ⟹ boolean?

    (define-condition-type &i/o-file-is-read-only-error &i/o-file-protection-error

    i/o-file-is-read-only-error?)

    A condition of this type specifies that an operation tried to operate on a named read-only file under the assumption that it is writeable.

    (srfi 36) value &i/o-file-already-exists-error ⟹ condition-type?

    (srfi 36) procedure (i/o-file-already-exists-error? obj) ⟹ boolean?

    (define-condition-type &i/o-file-already-exists-error &i/o-filename-error

    i/o-file-already-exists-error?)

    A condition of this type specifies that an operation tried to operate on an existing named file under the assumption that it does not exist.

    (srfi 36) value &i/o-no-such-file-error ⟹ condition-type?

    (srfi 36) procedure (i/o-no-such-file-error? obj) ⟹ boolean?

    (define-condition-type &i/o-no-such-file-error &i/o-filename-error

    i/o-no-such-file-error?)

    A condition of this type specifies that an operation tried to operate on an non-existent named file under the assumption that it exists.

    (srfi 36) value &read-error ⟹ condition-type?

    (srfi 36) procedure (read-error? obj) ⟹ boolean?

    (srfi 36) procedure (read-error-line (err read-error?)) ⟹ integer? | #f

    (srfi 36) procedure (read-error-column (err read-error?)) ⟹ integer? | #f

    (srfi 36) procedure (read-error-position (err read-error?)) ⟹ integer? | #f

    (srfi 36) procedure (read-error-span (err read-error?)) ⟹ integer? | #f

    (define-condition-type &read-error &error

    read-error?

    (line read-error-line)

    (column read-error-column)

    (position read-error-position)

    (span read-error-span))

    A condition of this type specifies that a parse error happened during a read operation. The fields give more information about the nature of the error. However, a Scheme implementation is not obliged to actually provide any information in any of the fields: each field value may be #f in that case.

    The field values that are not #f must contain the following kinds of information:

  • line is the line number of the parse error, starting from the beginning of the character sequence accessed through the port of the read operation. The first line has the number 1.
  • column is the column number of the parse error. The first column has the number 0.
  • position is the character position of the beginning of the parse error, starting from the beginning of the character sequence accessed through the port of the read operation. The first position is 1.
  • span is the number of characters involved in the parse error.
  • library (srfi 37) args-fold: a program argument processor

    Many operating systems make the set of argument strings used to invoke a program available (often following the program name string in an array called argv). Most programs need to parse and process these argument strings in one way or another. This SRFI describes a set of procedures that support processing program arguments according to POSIX and GNU C Library Reference Manual guidelines.

    (srfi 37) procedure (option (names list?) (required-arg? boolean?) (optional-arg? boolean?) (option-proc procedure?)) ⟹ option

    (option-proc (option option) (name char? | string?) (arg string?) seed ...) ⟹ (values * ...)

    Return an option. NAMES is a list of short (character) and long (string) option names. REQUIRED-ARG? specifies if this options requires an option-argument (boolean). OPTIONAL-ARG? specifies if this option can accept an option-argument (boolean). OPTION-PROC is a procedure (following the option-processor prototype) used to process this option.

    (srfi 37) procedure (option-names (option option)) ⟹ list?

    (srfi 37) procedure (option-required-arg? (option option)) ⟹ boolean?

    (srfi 37) procedure (option-optional-arg? (option option)) ⟹ boolean?

    (srfi 37) procedure (option-processor (option option)) ⟹ procedure?

    (return (option option) (name char? | string?) (arg string?) seed ...) ⟹ (values * ...)

    Return the contents of corresponding fields of OPTION.

    (srfi 37) procedure (args-fold (args list?) (options list?) (unrecognized-option-proc procedure?) (operand-proc procedure?) seed ...) ⟹ (values * ...)

    (unrecognized-option-proc (option option) (name char? | string?) (arg string?) seed ...) ⟹ (values * ...)

    (operand-proc (operand string?) seed ...) ⟹ (values * ...)

    Parse argument strings left-to-right, calling the appropriate processors in-order (for the parsed known options, unknown options, and operands), passing the seed values from one processor to the next and returning the final seeds values as results. ARGS is a list of strings. OPTIONS is a list of options. UNRECOGNIZED-OPTION-PROC is a procedure (following the option-processor prototype) for unrecognized options. NOTE: args-fold will create temporary options as necessary for the UNRECOGNIZED-OPTION-PROC. OPERAND-PROC is a procedure (following the operand-processor prototype) for operands.

    library (srfi 38) External Representation for Data With Shared Structure

    This SRFI proposes (write-with-shared-structure) and (read-with-shared-structure), procedures for writing and reading external representations of data containing shared structure. These procedures implement a proposed standard external notation for data containing shared structure.

    This SRFI permits but does not require replacing the standard (write) and (read) functions. These functions may be implemented without the overhead in time and space required to detect and specify shared structure.

    An implementation conforms to this SRFI if it provides procedures named (write-with-shared-structure) and (read-with-shared-structure), which produce and read the same notation as produced by the reference implementation. It may also provide (read/ss) and (write/ss), equivalent functions with shorter names.

    (srfi 38) procedure (write-with-shared-structure obj) ⟹ undefined

    (srfi 38) procedure (write-with-shared-structure obj (port output-port?)) ⟹ undefined

    (srfi 38) procedure (write-with-shared-structure obj (port output-port?) optarg) ⟹ undefined

    Writes a written representation of obj to the given port. Strings that appear in the written representation are enclosed in doublequotes, and within those strings backslash and doublequote characters are escaped by backslashes. Character objects are written using the #\ notation.

    Objects which denote locations rather than values (cons cells, vectors, and non-zero-length strings in R5RS scheme; also mutable objects, records, or containers if provided by the implementation), if they appear at more than one point in the data being written, must be preceded by "#N=" the first time they are written and replaced by "#N#" all subsequent times they are written, where N is a natural number used to identify that particular object. If objects which denote locations occur only once in the structure, then (write-with-shared-structure) must produce the same external representation for those objects as (write).

    Write-with-shared-structure must terminate in finite time when writing finite data. Write-with-shared-structure must produce a finite representation when writing finite data.

    Write-with-shared-structure returns an unspecified value. The port argument may be omitted, in which case it defaults to the value returned by (current-output-port). The optarg argument may also be omitted. If present, its effects on the output and return value are unspecified but (write-with-shared-structure) must still write a representation that can be read by (read-with-shared-structure). Some implementations may wish to use optarg to specify formatting conventions, numeric radixes, or return values. The reference implementation ignores optarg.

    (srfi 38) procedure (read-with-shared-structure ) ⟹ *

    (srfi 38) procedure (read-with-shared-structure input-port? port) ⟹ *

    (read-with-shared-structure) converts the external representations of Scheme objects produced by (write-with-shared-structure) into scheme objects. That is, it is a parser for the nonterminal <datum> in the augmented external representation grammar defined above. (read-with-shared-structure) returns the next object parsable from the given input port, updating port to point to the first character past the end of the external representation of the object.

    If an end-of-file is encountered in the input before any characters are found that can begin an object, then an end-of-file object is returned. The port remains open, and further attempts to read it (by (read-with-shared-structure) or (read) will also return an end-of-file object. If an end of file is encountered after the beginning of an object's external representation, but the external representation is incomplete and therefore not parsable, an error is signalled.

    The port argument may be omitted, in which case it defaults to the value returned by (current-input-port). It is an error to read from a closed port.

    library (srfi 39) Parameter objects

    This SRFI defines parameter objects, the procedure make-parameter to create parameter objects and the parameterize special form to dynamically bind parameter objects. In the dynamic environment, each parameter object is bound to a cell containing the value of the parameter. When a procedure is called the called procedure inherits the dynamic environment from the caller. The parameterize special form allows the binding of a parameter object to be changed for the dynamic extent of its body.

    See (scheme base)

    library (srfi 41) Streams

    Streams, sometimes called lazy lists, are a sequential data structure containing elements computed only on demand. A stream is either null or is a pair with a stream in its cdr. Since elements of a stream are computed only when accessed, streams can be infinite. Once computed, the value of a stream element is cached in case it is needed again.

    Streams without memoization were first described by Peter Landin in 1965. Memoization became accepted as an essential feature of streams about a decade later. Today, streams are the signature data type of functional programming languages such as Haskell.

    This Scheme Request for Implementation describes two libraries for operating on streams: a canonical set of stream primitives and a set of procedures and syntax derived from those primitives that permits convenient expression of stream operations. They rely on facilities provided by R6RS, including libraries, records, and error reporting. To load both stream libraries, say:

    (import (streams))

    See (scheme stream)

    library (srfi 42) Eager Comprehensions

    This SRFI defines a modular and portable mechanism for eager comprehensions extending the algorithmic language Scheme [R5RS]. An eager comprehension is a convenient notation for one or more nested or parallel loops generating a sequence of values, and accumulating this sequence into a result.

    (srfi 42) syntax (do-ec qualifier ... command)

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    Evaluates the <command> exactly once for each binding in the sequence defined by the qualifiers. If there are no qualifiers <command> is evaluated exactly once. The expression is evaluated for its side-effects only. The result of the comprehension is unspecified.

    (srfi 42) syntax (list-ec qualifier ... expression)⟹ return

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    The list of values obtained by evaluating <expression> once for each binding in the sequence defined by the qualifiers. If there are no qualifiers the result is the list with the value of <expression>.

    (srfi 42) syntax (append-ec qualifier ... expression)⟹ return

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    expression ⟹ list?

    The list obtained by appending all values of <expression>, which must all be lists. Think of it as (apply append (list-ec <qualifier>* <expression>)).

    (srfi 42) syntax (string-ec qualifier ... expression)⟹ return

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    expression ⟹ char?

    The string of all values of <expression>. Think of it as (list->string (list-ec <qualifier>* <expression>)).

    (srfi 42) syntax (string-append-ec qualifier ... expression)⟹ return

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    expression ⟹ string?

    The string obtained by appending all values of <expression>, which must all be strings. Think of it as (apply string-append (list-ec <qualifier>* <expression>)).

    (srfi 42) syntax (vector-ec qualifier ... expression)⟹ return

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    The vector of all values of <expression>. Think of it as (list->vector (list-ec <qualifier>* <expression>)).

    (srfi 42) syntax (vector-of-length-ec k qualifier ... expression)⟹ return

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    k ⟹ integer?

    The vector of all values of <expression>, of which there must be exactly <k>. This comprehension behaves like vector-ec but can be implemented more efficiently.

    (srfi 42) syntax (sum-ec qualifier ... expression)⟹ return

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    expression ⟹ number?

    The sum of all values of <expression>. Think of it as (apply + (list-ec <qualifier>* <expression>)).

    (srfi 42) syntax (product-ec qualifier ... expression)⟹ return

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    expression ⟹ number?

    The product of all values of <expression>. Think of it as (apply * (list-ec <qualifier>* <expression>)).

    (srfi 42) syntax (min-ec qualifier ... expression)⟹ return

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    expression ⟹ number?

    The minimum of all values of <expression>.

    (srfi 42) syntax (max-ec qualifier ... expression)⟹ return

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    expression ⟹ number?

    The maximum of all values of <expression>.

    (srfi 42) syntax (any?-ec qualifier ... test)⟹ return

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    Tests whether any value of <test> in the sequence of bindings specified by the qualifiers is non-#f. If this is the case, #t is returned, otherwise #f. If there are no bindings in the sequence specified by the qualifiers at all then the result is #f. The enumeration of values stops after the first non-#f encountered.

    (srfi 42) syntax (every?-ec qualifier ... test)⟹ return

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    Tests whether all values of <test> are non-#f. If this is the case, #t is returned, otherwise #f. If the sequence is empty the result is #t. Enumeration stops after the first #f.

    (srfi 42) syntax (first-ec default qualifier ... expression)

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    The first value of <expression> in the sequence of bindings specified by the qualifiers. Before enumeration, the result is initialized with the value of <default>; so this will be the result if the sequence is empty. Enumeration is terminated in first-ec when the first value has been computed.

    (srfi 42) syntax (last-ec default qualifier ... expression)

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    The last value of <expression> in the sequence of bindings specified by the qualifiers. Before enumeration, the result is initialized with the value of <default>; so this will be the result if the sequence is empty.

    (srfi 42) syntax (fold-ec x0 qualifier ... expression f2)

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    f2 ⟹ procedure?

    Reduces the sequence x[0], x[1], ..., x[n-1] of values obtained by evaluating <expression> once for each binding as specified by <qualifier>*. The arguments <x0>, <f2>, and <f1>, all syntactically equivalent to <expression>, specify the reduction process.

    The reduction process for fold-ec is defined as follows. A reduction variable x is initialized to the value of <x0>, and for each k in {0, ..., n-1} the command (set! x (<f2> x[k] x)) is evaluated. Finally, x is returned as the value of the comprehension.

    As the order of the arguments suggests, <x0> is evaluated outside the scope of the qualifiers, whereas the reduction expressions involving <f1> and <f2> are inside the scope of the qualifiers (so they may depend on any variable introduced by the qualifiers). Note that <f2> is evaluated repeatedly, with any side-effect or overhead this might have.

    (srfi 42) syntax (fold3-ec x0 qualifier ... expression f1 f2)

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    generator ⟹ generator-macro

    f1 ⟹ procedure?

    f2 ⟹ procedure?

    Reduces the sequence x[0], x[1], ..., x[n-1] of values obtained by evaluating <expression> once for each binding as specified by <qualifier>*. The arguments <x0>, <f2>, and <f1>, all syntactically equivalent to <expression>, specify the reduction process.

    The reduction process for fold3-ec is defined as follows. If and only if n = 0, i.e. the sequence is empty, then <x0> is evaluated and returned as the value of the comprehension. Otherwise, a reduction variable x is initialized to the value of (<f1> x[0]), and for each k in {1, ..., n-1} the command (set! x (<f2> x[k] x)) is evaluated. Finally, x is returned as the value of the comprehension.

    As the order of the arguments suggests, <x0> is evaluated outside the scope of the qualifiers, whereas the reduction expressions involving <f1> and <f2> are inside the scope of the qualifiers (so they may depend on any variable introduced by the qualifiers). Note that <f2> is evaluated repeatedly, with any side-effect or overhead this might have.

    (srfi 42) syntax (: var arg1 arg2 ...)⟹ return

    (srfi 42) syntax (: var1 (index var2) arg1 arg2 ...)⟹ return

    First the expressions <arg1> <arg>* are evaluated into a[1] a[2] ... a[n] and then a global dispatch procedure is used to dispatch on the number and types of the arguments and run the resulting generator.

    Initially (after loading the SRFI), the following cases are recognized:

    :list if for all i in {1..n}: (list? a[i]).

    :string if for all i in {1..n}: (string? a[i]).

    :vector if for all i in {1..n}: (vector? a[i]).

    :range if n in {1..3} and for all i in {1..n}: (integer? a[i]) and (exact? a[i]).

    :real-range if n in {1..3} and for all i in {1..n}: (real? a[i]).

    :char-range if n = 2 and for all i in {1, 2}: (char? a[i]).

    :port if n in {1,2} and (input-port? a[1]) and (procedure? a[2]).

    (srfi 42) procedure (:-dispatch-ref) ⟹ procedure?

    The current dispatcher used by `:`.

    (srfi 42) procedure (:-dispatch-set! (d procedure?)) ⟹ undefined

    Install dispatched to be used with `:`.

    (srfi 42) procedure (make-initial-:-dispatch) ⟹ procedure?

    Get a copy of initial dispatcher for `:`.

    (srfi 42) syntax (:list var arg1 arg2 ...)⟹ return

    (srfi 42) syntax (:list var1 (index var2) arg1 arg2 ...)⟹ return

    arg1 ⟹ list?

    arg2 ⟹ list?

    Run through one or more lists. First all expressions in <arg1> <arg>* are evaluated and then all elements of the resulting values are enumerated from left to right.

    (srfi 42) syntax (:string var arg1 arg2 ...)⟹ return

    (srfi 42) syntax (:string var1 (index var2) arg1 arg2 ...)⟹ return

    arg1 ⟹ string?

    arg2 ⟹ string?

    Run through one or more strings. First all expressions in <arg1> <arg>* are evaluated and then all elements of the resulting values are enumerated from left to right.

    (srfi 42) syntax (:vector var arg1 arg2 ...)⟹ return

    (srfi 42) syntax (:vector var1 (index var2) arg1 arg2 ...)⟹ return

    arg1 ⟹ vector?

    arg2 ⟹ vector?

    Run through one or more vectors. First all expressions in <arg1> <arg>* are evaluated and then all elements of the resulting values are enumerated from left to right.

    (srfi 42) syntax (:integers var)⟹ return

    (srfi 42) syntax (:integers var1 (index var2))⟹ return

    Runs through the sequence 0, 1, 2, ... of non-negative integers. This is most useful in combination with :parallel, :while, and :until or with a non-local exit in the body of the comprehension.

    (srfi 42) syntax (:range var stop)⟹ return

    (srfi 42) syntax (:range var1 (index var2) stop)⟹ return

    (srfi 42) syntax (:range var start stop)⟹ return

    (srfi 42) syntax (:range var1 (index var2) start stop)⟹ return

    (srfi 42) syntax (:range var start stop step)⟹ return

    (srfi 42) syntax (:range var1 (index var2) start stop step)⟹ return

    start ⟹ integer?

    stop ⟹ integer?

    step ⟹ integer?

    Runs through a range of exact rational numbers.

    The form (:range <vars> <stop>) evaluates the expression <stop>, which must result in an exact integer n, and runs through the finite sequence 0, 1, 2, ..., n-1. If n is zero or negative the sequence is empty.

    The form (:range <vars> <start> <stop>) evaluates the expressions <start> and <stop>, which must result in exact integers a and b, and runs through the finite sequence a, a+1, a+2, ..., b-1. If b is less or equal a then the sequence is empty.

    The form (:range <vars> <start> <stop> <step>) first evaluates the expressions <start>, <stop>, and <step>, which must result in exact integers a, b, and s such that s is unequal to zero. Then the sequence a, a + s, a + 2 s, ..., a + (n-1) s is enumerated where n = ceil((b-a)/s). In other words, the sequence starts at a, increments by s, and stops when the next value would reach or cross b. If n is zero or negative the sequence is empty.

    (srfi 42) syntax (:real-range var stop)⟹ return

    (srfi 42) syntax (:real-range var1 (index var2) stop)⟹ return

    (srfi 42) syntax (:real-range var start stop)⟹ return

    (srfi 42) syntax (:real-range var1 (index var2) start stop)⟹ return

    (srfi 42) syntax (:real-range var start stop step)⟹ return

    (srfi 42) syntax (:real-range var1 (index var2) start stop step)⟹ return

    start ⟹ real?

    stop ⟹ real?

    step ⟹ real?

    Runs through a range of real numbers using an explicit index variable. This form of range enumeration avoids accumulation of rounding errors and is the one to use if any of the numbers defining the range is inexact, not an integer, or a bignum of large magnitude.

    Providing default value 0 for <start> and 1 for <step>, the generator first evaluates <start>, <stop>, and <step>, which must result in reals a, b, and s such that n = (b-a)/s is also representable as a real. Then the sequence 0, 1, 2, ... is enumerated while the current value i is less than n, and the variable in <vars> is bound to the value a + i s. If any of the values a, b, or s is non-exact then all values in the sequence are non-exact.

    (srfi 42) syntax (:char-range var min max)⟹ return

    (srfi 42) syntax (:char-range var1 (index var2) min max)⟹ return

    min ⟹ char?

    max ⟹ char?

    Runs through a range of characters. First <min> and <max> are evaluated, which must result in two characters a and b. Then the sequence of characters a, a+1, a+2, ..., b is enumerated in the order defined by char<=? in the sense of [R5RS, 6.3.4.]. If b is smaller than a then the sequence is empty. (Note that b is included in the sequence.)

    (srfi 42) syntax (:port var port)⟹ return

    (srfi 42) syntax (:port var1 (index var2) port)⟹ return

    (srfi 42) syntax (:port var port read-proc)⟹ return

    (srfi 42) syntax (:port var1 (index var2) port read-proc)⟹ return

    port ⟹ input-port?

    read-proc ⟹ procedure?

    Reads from the port until the eof-object is read. Providing the default read for <read-proc>, the generator first evaluates <port> and <read-proc>, which must result in an input port p and a procedure r. Then the variable is run through the sequence obtained by (r p) while the result does not satisfy eof-object?.

    (srfi 42) syntax (:dispatched var dispatch arg1 arg2 ...)⟹ return

    (srfi 42) syntax (:dispatched var1 (index var2) dispatch arg1 arg2 ...)⟹ return

    dispatch ⟹ procedure?

    Runs the variables through a sequence defined by <dispatch> and <arg1> <arg>*. The purpose of :dispatched is implementing dispatched generators, in particular the predefined dispatching generator :.

    The working of :dispatched is as follows. First <dispatch> and <arg1> <arg>* are evaluated, resulting in a procedure d (the 'dispatcher') and the values a[1] a[2] ... a[n]. Then (d (list a[1] a[2] ... a[n] )) is evaluated, resulting in a value g. If g is not a procedure then the dispatcher did not recognize the argument list and an error is raised. Otherwise the 'generator procedure' g is used to run <vars> through a sequence of values. The sequence defined by g is obtained by repeated evaluation of (g empty) until the result is empty. In other words, g indicates the end of the sequence by returning its only argument, for which the caller has provided an object distinct from anything g can produce.

    (srfi 42) syntax (:generator-proc generator-macro)⟹ return

    Constructs a generator procedure from a typed generator. Let (g var arg1 arg ...) be an instance of the <generator> syntax, for example an application-specific typed generator, with a single variable var and no index variable. Then

    (:generator-proc (g arg1 arg ...)) => g

    where the generator procedure g runs through the list (list-ec (g var arg1 arg ...) var).

    (srfi 42) procedure (dispatch-union (d1 procedure?) (d2 procedure?)) ⟹ procedure?

    The new dispatcher d recognizes the union of the cases recognized by the dispatchers d1 and d2. The new dispatcher always tries both component dispatchers and raises an error in case of conflict. The identification returned by (d) is the concatenation of the component identifications (d1) and (d2), enclosed in lists if necessary.

    (srfi 42) syntax (:do (lb ...) ne1? (ls ...))⟹ return

    (srfi 42) syntax (:do (let (ob ...) oc ...) (lb ...) ne1? (let (ib ...) ic ...) ne2? (ls ...))

    Defines a generator in terms of a named-let, optionally decorated with inner and outer lets. This generator is for defining other generators. (In fact, the reference implementation transforms any other generator into an instance of fully decorated :do.) The generator is a compromise between expressive power (more flexible loops) and fixed structure (necessary for merging and modifying generators). In the fully decorated form, the syntactic variables <ob> (outer binding), <oc> (outer command), <lb> (loop binding), <ne1?> (not-end1?), <ib> (inner binding), <ic> (inner command), <ne2?> (not-end2?), and <ls> (loop step) define the following loop skeleton:

    (let (<ob>*)

    <oc>*

    (let loop (<lb>*)

    (if <ne1?>

    (let (<ib>*)

    <ic>*

    payload

    (if <ne2?>

    (loop <ls>*)))))),

    where <oc>* and <ic>* are syntactically equivalent to <command>*, i.e. they do not begin with a <definition>. The latter requirement allows the code generator to produce more efficient code for special cases by removing empty let-expressions altogether.

    (srfi 42) syntax (:let var expression)⟹ return

    (srfi 42) syntax (:let var1 (index var2) expression)⟹ return

    Runs through the sequence consisting of the value of <expression>, only. This is the same as (:list <vars> (list <expression>)). If an index variable is specified, its value is 0. The :let-generator can be used to introduce an intermediate variable depending on outer generators.

    (srfi 42) syntax (:parallel generator ...)⟹ return

    generator ⟹ generator-macro

    Runs several generators in parallel. This means that the next binding in the sequence is obtained by advancing each generator in <generator>* by one step. The parallel generator terminates when any of its component generators terminates. The generators share a common scope for the variables they introduce. This implies that the names of the variables introduced by the various generators must be distinct.

    (srfi 42) syntax (:while generator expression)⟹ return

    generator ⟹ generator-macro

    Runs <generator> while <expression> evaluates to non-#f. The guarding expression is included in the scope of the variables introduced by the generator.

    Note the distinction between the filter if and the modified generator expressed by :while.

    (srfi 42) syntax (:until generator expression)⟹ return

    generator ⟹ generator-macro

    Runs <generator> until after <expression> has evaluated to non-#f. The guarding expression is included in the scope of the variables introduced by the generator.

    Note the distinction between :while, stopping at a certain condition, and :until, stopping after a certain condition has occurred. The latter implies that the binding that has triggered termination has been processed by the comprehension.

    library (srfi 43) Vector library

    This SRFI proposes a comprehensive and complete library of vector operations accompanied by a freely available and complete reference implementation. The reference implementation is unencumbered by copyright, and useable with no modifications on any Scheme system that is R5RS-compliant. It also provides several hooks for implementation-specific optimization as well.

    Because this SRFI is more of a library or module specification than a request for additions to readers or any other internal implementation detail, in an implementation that supports a module or structure or package or library or unit (et cetera) systems, these procedures should be contained in a module / structure / package / library / unit called vector-lib.

    (srfi 43) procedure (make-vector (k integer?)) ⟹ vector?

    (srfi 43) procedure (make-vector (k integer?) fill) ⟹ vector?

    Creates and returns a vector of size size, optionally filling it with fill. The default value of fill is unspecified.

    (srfi 43) procedure (vector x ...) ⟹ vector?

    Creates and returns a vector whose elements are x ...

    (srfi 43) procedure (vector-unfold (f procedure?) (length integer?) initial-seed ...) ⟹ vector?

    (f (index integer?) seed ...) ⟹ (values * * ...)

    The fundamental vector constructor. Creates a vector whose length is length and iterates across each index k between 0 and length, applying f at each iteration to the current index and current seeds, in that order, to receive n + 1 values: first, the element to put in the kth slot of the new vector and n new seeds for the next iteration. It is an error for the number of seeds to vary between iterations.

    (srfi 43) procedure (vector-unfold-right (f procedure?) (length integer?) initial-seed ...) ⟹ vector?

    (f (index integer?) seed ...) ⟹ (values * * ...)

    Like vector-unfold, but it uses f to generate elements from right-to-left, rather than left-to-right.

    (srfi 43) procedure (vector-copy (vec vector?)) ⟹ vector?

    (srfi 43) procedure (vector-copy (vec vector?) (start integer?)) ⟹ vector?

    (srfi 43) procedure (vector-copy (vec vector?) (start integer?) (end integer?)) ⟹ vector?

    (srfi 43) procedure (vector-copy (vec vector?) (start integer?) (end integer?) fill) ⟹ vector?

    Allocates a new vector whose length is end - start and fills it with elements from vec, taking elements from vec starting at index start and stopping at index end. start defaults to 0 and end defaults to the value of (vector-length vec). If end extends beyond the length of vec, the slots in the new vector that obviously cannot be filled by elements from vec are filled with fill, whose default value is unspecified.

    (srfi 43) procedure (vector-reverse-copy (vec vector?)) ⟹ vector?

    (srfi 43) procedure (vector-reverse-copy (vec vector?) (start integer?)) ⟹ vector?

    (srfi 43) procedure (vector-reverse-copy (vec vector?) (start integer?) (end integer?)) ⟹ vector?

    Like vector-copy, but it copies the elements in the reverse order from vec.

    (srfi 43) procedure (vector-append (vec vector?) ...) ⟹ vector?

    Returns a newly allocated vector that contains all elements in order from the subsequent locations in vec ...

    (srfi 43) procedure (vector-concatenate (list-of-vectors list?) ...) ⟹ vector?

    list-of-vectors ⟹ (list (v vector?))

    Appends each vector in list-of-vectors. This is equivalent to: (apply vector-append list-of-vectors) however, it may be implemented better.

    (srfi 43) procedure (vector? obj) ⟹ boolean?

    Disjoint type predicate for vectors: this returns #t if x is a vector, and #f if otherwise.

    (srfi 43) procedure (vector-empty? (vec vector?)) ⟹ boolean?

    Returns #t if vec is empty, i.e. its length is 0, and #f if not.

    (srfi 43) procedure (vector= (elt=? procedure?) (vec vector?) ...) ⟹ boolean?

    (elt=? a b) ⟹ boolean?

    Vector structure comparator, generalized across user-specified element comparators. Vectors a and b are considered equal by vector= iff their lengths are the same, and for each respective elements Ea and Eb, (elt=? Ea Eb) returns a true value. Elt=? is always applied to two arguments. Element comparison must be consistent with eq; that is, if (eq? Ea Eb) results in a true value, then (elt=? Ea Eb) must also result in a true value. This may be exploited to avoid unnecessary element comparisons. (The reference implementation does, but it does not consider the situation where elt=? is in fact itself eq? to avoid yet more unnecessary comparisons.)

    If there are only zero or one vector arguments, #t is automatically returned. The dynamic order in which comparisons of elements and of vectors are performed is left completely unspecified; do not rely on a particular order.

    (srfi 43) procedure (vector-ref (vec vector?) (i integer?)) ⟹ *

    Vector element dereferencing: returns the value that the location in vec at i is mapped to in the store. Indexing is based on zero. I must be within the range [0, (vector-length vec)).

    (srfi 43) procedure (vector-length (vec vector?)) ⟹ integer?

    Returns the length of vec, the number of locations reachable from vec. (The careful word 'reachable' is used to allow for 'vector slices,' whereby vec refers to a larger vector that contains more locations that are unreachable from vec. This SRFI does not define vector slices, but later SRFIs may.)

    (srfi 43) procedure (vector-fold (kons procedure?) knil (vec1 vector?) (vec2 vector?) ...) ⟹ *

    (kons (index integer?) state obj1 obj2 ...) ⟹ *

    The fundamental vector iterator. Kons is iterated over each index in all of the vectors, stopping at the end of the shortest; kons is applied as (kons i state (vector-ref vec1 i) (vector-ref vec2 i) ···) where state is the current state value — the current state value begins with knil, and becomes whatever kons returned at the respective iteration —, and i is the current index. The iteration is strictly left-to-right.

    (srfi 43) procedure (vector-fold-right (kons procedure?) knil (vec1 vector?) (vec2 vector?) ...) ⟹ *

    (kons (index integer?) state obj1 obj2 ...) ⟹ *

    Similar to vector-fold, but it iterates right to left instead of left to right.

    (srfi 43) procedure (vector-map (f procedure?) (vec1 vector?) (vec2 vector?) ...) ⟹ vector?

    (proc (index integer?) obj ...) ⟹ *

    Constructs a new vector of the shortest size of the vector arguments. Each element at index i of the new vector is mapped from the old vectors by (f i (vector-ref vec1 i) (vector-ref vec2 i) ···). The dynamic order of application of f is unspecified.

    (srfi 43) procedure (vector-map! (f procedure?) (vec1 vector?) (vec2 vector?) ...) ⟹ undefined

    (proc (index integer?) obj ...) ⟹ *

    Similar to vector-map, but rather than mapping the new elements into a new vector, the new mapped elements are destructively inserted into vec1. Again, the dynamic order of application of f unspecified, so it is dangerous for f to apply either vector-ref or vector-set! to vec1 in f.

    (srfi 43) procedure (vector-for-each (f procedure?) (vec1 vector?) (vec2 vector?) ...) ⟹ undefined

    (proc (index integer?) obj ...) ⟹ undefined

    Simple vector iterator: applies f to each index in the range [0, length), where length is the length of the smallest vector argument passed, and the respective list of parallel elements from vec1 vec2 ··· at that index. In contrast with vector-map, f is reliably applied to each subsequent elements, starting at index 0, in the vectors.

    (srfi 43) procedure (vector-count (pred? procedure?) (vec1 vector?) (vec2 vector?) ...) ⟹ integer?

    (pred? (index integer?) obj1 obj2 ...) ⟹ *

    Counts the number of parallel elements in the vectors that satisfy pred?, which is applied, for each index i in the range [0, length) — where length is the length of the smallest vector argument —, to i and each parallel element in the vectors at that index, in order.

    (srfi 43) procedure (vector-index (pred? procedure?) (vec1 vector?) (vec2 vector?) ...) ⟹ integer? | #f

    (pred? obj1 obj2 ...) ⟹ *

    Finds & returns the index of the first elements in vec1 vec2 ... that satisfy pred?. If no matching element is found by the end of the shortest vector, #f is returned.

    (srfi 43) procedure (vector-index-right (pred? procedure?) (vec1 vector?) (vec2 vector?) ...) ⟹ integer? | #f

    (pred? obj1 obj2 ...) ⟹ *

    Like vector-index, but it searches right-to-left, rather than left-to-right, and all of the vectors must have the same length.

    (srfi 43) procedure (vector-skip (pred? procedure?) (vec1 vector?) (vec2 vector?) ...) ⟹ integer? | #f

    (pred? obj1 obj2 ...) ⟹ *

    Finds & returns the index of the first elements in vec1 vec2 ... that do not satisfy pred?. If all the values in the vectors satisfy pred? until the end of the shortest vector, this returns #f.

    (srfi 43) procedure (vector-skip-right (pred? procedure?) (vec1 vector?) (vec2 vector?) ...) ⟹ integer? | #f

    (pred? obj1 obj2 ...) ⟹ *

    Like vector-skip, but it searches for a non-matching element right-to-left, rather than left-to-right, and all of the vectors must have the same length.

    (cmp a b) ⟹ integer?

    Similar to vector-index and vector-index-right, but instead of searching left to right or right to left, this performs a binary search. cmp should be a procedure of two arguments and return a negative integer, which indicates that its first argument is less than its second, zero, which indicates that they are equal, or a positive integer, which indicates that the first argument is greater than the second argument.

    (srfi 43) procedure (vector-any (pred? procedure?) (vec1 vector?) (vec2 vector?) ...) ⟹ *

    (pred? obj1 obj2 ...) ⟹ *

    Finds the first set of elements in parallel from vec1 vec2 ... for which pred? returns a true value. If such a parallel set of elements exists, vector-any returns the value that pred? returned for that set of elements. The iteration is strictly left-to-right.

    (srfi 43) procedure (vector-every (pred? procedure?) (vec1 vector?) (vec2 vector?) ...) ⟹ *

    (pred? obj1 obj2 ...) ⟹ *

    If, for every index i between 0 and the length of the shortest vector argument, the set of elements (vector-ref vec1 i) (vector-ref vec2 i) ··· satisfies pred?, vector-every returns the value that pred? returned for the last set of elements, at the last index of the shortest vector. The iteration is strictly left-to-right.

    (srfi 43) procedure (vector-set! (vector vector?) (i integer?) obj) ⟹ undefined

    Assigns the contents of the location at i in vec to value.

    (srfi 43) procedure (vector-swap! (vector vector?) (i integer?) (j integer?)) ⟹ undefined

    Swaps or exchanges the values of the locations in vec at i & j.

    (srfi 43) procedure (vector-fill! (vec vector?) fill) ⟹ undefined

    (srfi 43) procedure (vector-fill! (vec vector?) fill (start integer?)) ⟹ undefined

    (srfi 43) procedure (vector-fill! (vec vector?) fill (start integer?) (end integer?)) ⟹ undefined

    Assigns the value of every location in vec between start, which defaults to 0 and end, which defaults to the length of vec, to fill.

    (srfi 43) procedure (vector-reverse! (vec vector?)) ⟹ undefined

    (srfi 43) procedure (vector-reverse! (vec vector?) (start integer?)) ⟹ undefined

    (srfi 43) procedure (vector-reverse! (vec vector?) (start integer?) (end integer?)) ⟹ undefined

    Destructively reverses the contents of the sequence of locations in vec between start and end. Start defaults to 0 and end defaults to the length of vec. Note that this does not deeply reverse.

    (srfi 43) procedure (vector-copy! (target vector?) (tstart integer?) (source vector?)) ⟹ undefined

    (srfi 43) procedure (vector-copy! (target vector?) (tstart integer?) (source vector?) (sstart integer?)) ⟹ undefined

    (srfi 43) procedure (vector-copy! (target vector?) (tstart integer?) (source vector?) (sstart integer?) (send integer?)) ⟹ undefined

    Copies a block of elements from source to target, both of which must be vectors, starting in target at tstart and starting in source at sstart, ending when send - sstart elements have been copied. It is an error for target to have a length less than tstart + (send - sstart). Sstart defaults to 0 and send defaults to the length of source.

    (srfi 43) procedure (vector-reverse-copy! (target vector?) (tstart integer?) (source vector?)) ⟹ undefined

    (srfi 43) procedure (vector-reverse-copy! (target vector?) (tstart integer?) (source vector?) (sstart integer?)) ⟹ undefined

    (srfi 43) procedure (vector-reverse-copy! (target vector?) (tstart integer?) (source vector?) (sstart integer?) (send integer?)) ⟹ undefined

    Like vector-copy!, but this copies the elements in the reverse order. It is an error if target and source are identical vectors and the target & source ranges overlap; however, if tstart = sstart, vector-reverse-copy! behaves as (vector-reverse! target tstart send) would.

    (srfi 43) procedure (vector->list (vec vector?)) ⟹ list?

    (srfi 43) procedure (vector->list (vec vector?) (start integer?)) ⟹ list?

    (srfi 43) procedure (vector->list (vec vector?) (start integer?) (end integer?)) ⟹ list?

    Creates a list containing the elements in vec between start, which defaults to 0, and end, which defaults to the length of vec.

    (srfi 43) procedure (reverse-vector->list (vec vector?)) ⟹ list?

    (srfi 43) procedure (reverse-vector->list (vec vector?) (start integer?)) ⟹ list?

    (srfi 43) procedure (reverse-vector->list (vec vector?) (start integer?) (end integer?)) ⟹ list?

    Like vector->list, but the resulting list contains the elements in reverse between the the specified range.

    (srfi 43) procedure (list->vector (list list?)) ⟹ vector?

    Creates a vector of elements from proper-list.

    (srfi 43) procedure (reverse-list->vector (list list?)) ⟹ vector?

    Like list->vector, but the resulting list contains the elements in reverse of proper-list.

    library (srfi 45) Primitives for Expressing Iterative Lazy Algorithms

    Lazy evaluation is traditionally simulated in Scheme using delay and force. However, these primitives are not powerful enough to express a large class of lazy algorithms that are iterative. Indeed, it is folklore in the Scheme community that typical iterative lazy algorithms written using delay and force will often require unbounded memory.

    Although varous modifications of delay and force had been proposed to resolve this problem (see e.g., the SRFI-40 discussion list) they all fail some of the benchmarks provided below. To our knowledge, the current SRFI provides the first exhaustive solution to this problem.

    As motivation, we first explain how the usual laziness encoding using only delay and force will break the iterative behavior of typical algorithms that would have been properly tail-recursive in a true lazy language, causing the computation to require unbounded memory.

    The problem is then resolved by introducing a set of three operations:

        {lazy, delay, force}
    
    which allow the programmer to succinctly express lazy algorithms while retaining bounded space behavior in cases that are properly tail-recursive. A general recipe for using these primitives is provided. An additional procedure {eager} is provided for the construction of eager promises in cases where efficiency is a concern.

    Although this SRFI redefines delay and force, the extension is conservative in the sense that the semantics of the subset {delay, force} in isolation (i.e., as long as the program does not use lazy) agrees with that in R5RS. In other words, no program that uses the R5RS definitions of delay and force will break if those definition are replaced by the SRFI-45 definitions of delay and force.

    (srfi 45) syntax (delay expression)⟹ return

    Takes an expression of arbitrary type a and returns a promise of type (Promise a) which at some point in the future may be asked (by the force procedure) to evaluate the expression and deliver the resulting value.

    (srfi 45) syntax (lazy expression)⟹ return

    expression ⟹ promise?

    Takes an expression of type (Promise a) and returns a promise of type (Promise a) which at some point in the future may be asked (by the force procedure) to evaluate the expression and deliver the resulting promise.

    (srfi 45) procedure (force (expression promise?)) ⟹ *

    Takes an argument of type (Promise a) and returns a value of type a as follows: If a value of type a has been computed for the promise, this value is returned. Otherwise, the promise is first evaluated, then overwritten by the obtained promise or value, and then force is again applied (iteratively) to the promise.

    (srfi 45) procedure (eager expression) ⟹ promise?

    Takes an argument of type a and returns a value of type Promise a. As opposed to delay, the argument is evaluated eagerly.

    library (srfi 46) Basic Syntax-rules Extensions

    This SRFI proposes two extensions to the R5RS1 syntax-rules pattern language: the first allows syntax-rules macros to generate macros, where the macro-generated macros use ellipsis that is not used by the macro-generating macros; the second allows for 'tail patterns.'

    (srfi 46) syntax (syntax-rules (literal ...) syntax-rule ...)⟹ return

    (srfi 46) syntax (syntax-rules ellipsis (literal ...) syntax-rule ...)⟹ return

    syntax-rule ⟹ (pattern template)

    pattern ⟹ _ | identifier | constant | (pattern ...) | (pattern pattern ... . pattern) | (pattern ... pattern ellipsis pattern ...) | (pattern ... pattern ellipsis pattern ... . pattern) | #(pattern ...) | #(pattern ... pattern ellipsis pattern ...)

    template ⟹ identifier | constant | (element ...) | (element element ... . template) | (ellipsis template) | #(element ...)

    element ⟹ template | template ellipsis

    Syntax-rules syntax is extended so that there is an extra possible token before the literal identifier list:

    (syntax-rules [<ellipsis-identifier>] (<literal-identifier> ...)

    (<pattern> <template>)

    ...)

    Ellipsis-identifier specifies the token used for ellipsis. It defaults to the usual R5RS1 ellipsis identifier, ..., but it can be specified to be any identifier, such as :::. This identifier's specification is considered to be a binding whose scope is the rules of the transformer. The macro system implementation must make the hygienic arrangements described in R5RS's section 4.3 to preserve the lexical scope of these bindings.

    The syntax-rules pattern language is also extended to allow 'tail patterns.' The following clauses are added to <pattern>:

    (<pattern> ... <ellipsis> <pattern> ...)

    #(<pattern> ... <ellipsis> <pattern> ...)

    And the following clauses are added to the semantics of syntax-rules' pattern matching:

  • P is of the form (P1 ... Px-1 Px <ellipsis> Px+1 ... Py) where <ellipsis> is the identifier ... and F is a proper list of M forms such that M >= Y, the first X-1 of which match P1 through Px-1, respectively, the forms Fx through Fm-(y-x), where Fi is the Ith element of the proper list F, all match Px, and the forms Fm-(y-x) through Fm match the patterns Px+1 through Py.
  • P is of the form #(P1 ... Px-1 Px <ellipsis> Px+1 ... Py) where <ellipsis> is the identifier ... and F is a vector of M forms such that M >= Y, the first X-1 of which match P1 through Px-1, respectively, the forms Fx through Fm-(y-x), where Fi is the Ith element of the vector F, all match Px and the forms Fm-(y-x) through Fm all match Px+1 through Py, respectively.
  • library (srfi 47) Array

    "slib/array.scm" synthesizes array ideas from Common-Lisp and Alan Bawden with homogeneous vector ideas from SRFI-4 and SCM. The result portably integrates homogeneous and heterogeneous arrays into Scheme.

    (srfi 47) procedure (array? obj) ⟹ boolean?

    Returns #t if the obj is an array, and #f if not.

    Note: Arrays are not disjoint from other Scheme types. Strings and vectors also satisfy array?.

    (srfi 47) procedure (equal? obj1 obj2) ⟹ boolean?

    `Equal?' recursively compares the contents of pairs, vectors, strings, and arrays, applying `eqv?' on other objects such as numbers and symbols. A rule of thumb is that objects are generally `equal?' if they print the same. `Equal?' may fail to terminate if its arguments are circular data structures.

    (srfi 47) procedure (make-array (prototype array?) (k1 integer?) ...) ⟹ array?

    Creates and returns an array of type prototype with dimensions k1, k2, ... and filled with elements from prototype. prototype must be an array, vector, or string. The implementation-dependent type of the returned array will be the same as the type of prototype. except if that would be a vector or string with more than one dimension, in which case some variety of array will be returned.

    If the prototype has no elements, then the initial contents of the returned array are unspecified. Otherwise, the returned array will be filled with the element at the origin of prototype.

    (srfi 47) procedure (ac64 ) ⟹ array?

    (srfi 47) procedure (ac64 (z complex?)) ⟹ array?

    Returns a high-precision complex uniform-array prototype.

    (srfi 47) procedure (ac32 ) ⟹ array?

    (srfi 47) procedure (ac32 (z complex?)) ⟹ array?

    Returns a complex uniform-array prototype.

    (srfi 47) procedure (ar64 ) ⟹ array?

    (srfi 47) procedure (ar64 (x real?)) ⟹ array?

    Returns a high-precision real uniform-array prototype.

    (srfi 47) procedure (ar32 ) ⟹ array?

    (srfi 47) procedure (ar32 (x real?)) ⟹ array?

    Returns a real uniform-array prototype.

    (srfi 47) procedure (as64 ) ⟹ array?

    (srfi 47) procedure (as64 (n integer?)) ⟹ array?

    Returns an exact signed integer uniform-array prototype with at least 64 bits of precision.

    (srfi 47) procedure (as32 ) ⟹ array?

    (srfi 47) procedure (as32 (n integer?)) ⟹ array?

    Returns an exact signed integer uniform-array prototype with at least 32 bits of precision.

    (srfi 47) procedure (as16 ) ⟹ array?

    (srfi 47) procedure (as16 (n integer?)) ⟹ array?

    Returns an exact signed integer uniform-array prototype with at least 16 bits of precision.

    (srfi 47) procedure (as8 ) ⟹ array?

    (srfi 47) procedure (as8 (n integer?)) ⟹ array?

    Returns an exact signed integer uniform-array prototype with at least 8 bits of precision.

    (srfi 47) procedure (au64 ) ⟹ array?

    (srfi 47) procedure (au64 (n integer?)) ⟹ array?

    Returns an exact non-negative integer uniform-array prototype with at least 64 bits of precision.

    (srfi 47) procedure (au32 ) ⟹ array?

    (srfi 47) procedure (au32 (n integer?)) ⟹ array?

    Returns an exact non-negative integer uniform-array prototype with at least 32 bits of precision.

    (srfi 47) procedure (au16 ) ⟹ array?

    (srfi 47) procedure (au16 (n integer?)) ⟹ array?

    Returns an exact non-negative integer uniform-array prototype with at least 16 bits of precision.

    (srfi 47) procedure (au8 ) ⟹ array?

    (srfi 47) procedure (au8 (n integer?)) ⟹ array?

    Returns an exact non-negative integer uniform-array prototype with at least 8 bits of precision.

    (srfi 47) procedure (at1 ) ⟹ array?

    (srfi 47) procedure (at1 (b boolean?)) ⟹ array?

    Returns a boolean uniform-array prototype.

    (srfi 47) procedure (make-shared-array (array array?) (mapper procedure?) (k1 integer?) ...) ⟹ array?

    (mapper (i1 integer?) ...) ⟹ list?

    make-shared-array can be used to create shared subarrays of other arrays. The mapper is a function that translates coordinates in the new array into coordinates in the old array. A mapper must be linear, and its range must stay within the bounds of the old array, but it can be otherwise arbitrary.

    (srfi 47) procedure (array-rank obj) ⟹ integer?

    Returns the number of dimensions of obj. If obj is not an array, 0 is returned.

    (srfi 47) procedure (array-dimnesions (array array?)) ⟹ list?

    return ⟹ (list integer?)

    Returns a list of dimensions.

    (srfi 47) procedure (array-in-bounds? (array array?) (index1 integer?) ...) ⟹ boolean?

    Returns #t if its arguments would be acceptable to array-ref.

    (srfi 47) procedure (array-ref (array array?) (index1 integer?) ...) ⟹ *

    Returns the (index1, index2, ...) element of array.

    (srfi 47) procedure (array-set! (array array?) obj (index1 integer?) ...) ⟹ undefined

    Stores obj in the (index1, index2, ...) element of array. The value returned by array-set! is unspecified.

    library (srfi 48) Intermediate Format Strings

    This document specifies Format Strings, a method of interpreting a Scheme string which contains a number of format directives that are replaced with other string data according to the semantics of each directive. This SRFI extends SRFI-28 in being more generally useful but is less general than advanced format strings in that it does not allow, aside from ~F, for controlled positioning of text within fields.

    (srfi 48) procedure (format (format-string string?) obj ...) ⟹ string?

    (srfi 48) procedure (format (port #f) (format-string string?) obj ...) ⟹ string?

    (srfi 48) procedure (format (port output-port?) (format-string string?) obj ...) ⟹ undefined

    Accepts a format template (a Scheme String), and processes it, replacing any format directives in order with one or more characters, the characters themselves dependent on the semantics of the format directive encountered. Each directive may consume one obj. It is an error if fewer or more obj values are provided than format directives that require them.

    When a port is specified it must be either an output port or a boolean. If an output-port is specified, the formatted output is output into that port. If the port argument is #t, output is to the current-output-port. If the port is #f or no port is specified, the output is returned as a string. If the port is specified and is #t or an output-port, the result of the format function is unspecified.

    It is unspecified which encoding is used (e.g. ASCII, EBCDIC, UNICODE). A given implementation must specify which encoding is used. The implementation may or may not allow the encoding to be selected or changed.

    It is an error if an format directive consumes an obj argument and that argument does not confirm to a required type as noted in the table below.

    It is permissible, but highly discouraged, to implement pretty-print as (define pretty-print write).

    An format directive is a two character sequence in the string where the first character is a tilde '~'. Directive characters are case-independent, i.e. upper and lower case characters are interpreted the same. Each directive code's meaning is described in the following table:

    DIRECTIVE MNEMONIC ACTION CONSUMES?

    ~a Any (display obj) for humans yes

    ~s Slashified (write obj) for parsers yes

    ~w WriteCircular (write-with-shared-structure obj) like ~s, but handles recursive structures yes

    ~d Decimal the obj is a number which is output in decimal radix yes

    ~x heXadecimal the obj is a number which is output in hexdecimal radix yes

    ~o Octal the obj is a number which is output in octal radix yes

    ~b Binary the obj is a number which is output in binary radix yes

    ~c Character the single charater obj is output by write-char yes

    ~y Yuppify the list obj is pretty-printed to the output yes

    ~? Indirection the obj is another format-string and the following obj is a list of arguments; format is called recursively yes

    ~K Indirection the same as ~? for backward compatability with some existing implementations yes

    ~[w[,d]]F Fixed ~w,dF outputs a number with width w and d digits after the decimal; ~wF outputs a string or number with width w. yes

    ~~ Tilde output a tilde no

    ~t Tab output a tab character no

    ~% Newline output a newline character no

    ~& Freshline output a newline character if it is known that the previous output was not a newline no

    ~_ Space a single space character is output no

    ~h Help outputs one line of call synopsis, one line of comment, and one line of synopsis for each format directive, starting with the directive (e.g. "~t") no

    The ~F, fixed format, directive requires some elucidation.

    ~wF is useful for strings or numbers. Where the string (or number->string of the number) has fewer characters than the integer width w, the string is padded on the left with space characters.

    ~w,dF is typically used only on numbers. For strings, the d specifier is ignored. For numbers, the integer d specifies the number of decimal digits after the decimal place. Both w and d must be zero or positive.

    If d is specified, the number is processed as if added to 0.0, i.e. it is converted to an inexact value.

    (format "~8,2F" 1/3) => " 0.33"

    If no d is specified, the number is not coerced to inexact.

    (format "~6F" 32) => " 32"

    Digits are padded to the right with zeros

    (format "~8,2F" 32) => " 32.00"

    If the number it too large to fit in the width specified, a string longer than the width is returned

    (format "~1,2F" 4321) => "4321.00"

    If the number is complex, d is applied to both real and imaginal parts

    (format "~1,2F" (sqrt -3.9)) => "0.00+1.97i"

    For very large or very small numbers, the point where exponential notation is used is implementation defined.

    (format "~8F" 32e5) => " 3.2e6" or "3200000.0"

    library (srfi 51) Handling rest list

    This SRFI introduces the rest-values procedure which has three modes of operation:

    1. it processes a rest list after checking its elements with default values or predicate procedures,
    2. it processes a rest list with default values without checking its elements,
    3. it processes a default list whose elements are lists or pairs, after checking their elements that are default values or predicate procedures with the elements of a rest list,

    and eight macros which additionally check the rest arguments that are returned by rest-values.

    (srfi 51) procedure (rest-values (rest-list list?)) ⟹ list?

    (srfi 51) procedure (rest-values caller (rest-list list?)) ⟹ list?

    (srfi 51) procedure (rest-values (rest-list list?) args-number-limit) ⟹ list?

    (srfi 51) procedure (rest-values caller (rest-list list?) args-number-limit default ...) ⟹ list?

    1. When the <args-number-limit> is + or a positive integer, each <default> should be a list that contains default value(s), or a pair whose car is a default value and cdr is a predicate procedure.

    2. When the <args-number-limit> is - or a negative integer, each <default> is any scheme expression.

    3. When the <args-number-limit> is a boolean, each <default> is the same as 1.

    1. (first mode of operation)

    Rest-values checks whether each element of the <rest-list> is a member of the corresponding <default> list, or satisfies the predicate procedure of the corresponding <default> pair, and then returns the checked element(s). If the element doesn't pass, rest-values signals an error. when there are no more elements in the <rest-list>, then rest-values additionally returns the car values of the remaining <default>s. On the other hand, when the number of elements of the <rest-list> are more than the number of the <default>s, the supernumerary elements are additionally returned if the <args-number-limit> is +, or its value is not less than the number of elements of the <rest-list>.

    2. (second mode of operation)

    This is the same as the first except that rest-values does not check each element of the <rest-list>, and it uses - instead of +, and an absolute value instead of a simple value as the value of <args-number-limit>.

    3. (third mode of operation)

    Rest-values checks whether any element of the <default> list is a member of the <rest-list>, or any element of the <rest-list> satisfies the predicate procedure of the <default> pair, and then returns the checked element. If the <default> doesn't pass, rest-values returns the car value of the <default>. when any elements of the <rest-list> are remained after the above processing, rest-values either signals an error if the <args-number-limit> is #t, or returns the remaining elements of the <rest-list> if the <args-number-limit> is #f.

    (srfi 51) syntax (arg-and variable expr ...)⟹ return

    (srfi 51) syntax (arg-and caller variable expr ...)⟹ return

    (srfi 51) syntax (arg-ands (variable expr ...) ...)⟹ return

    (srfi 51) syntax (arg-ands (caller variable expr ...) ...)⟹ return

    (srfi 51) syntax (arg-ands common-caller (variable expr ...) ...)⟹ return

    (srfi 51) syntax (arg-ands common-caller (caller variable expr ...) ...)⟹ return

    (srfi 51) syntax (err-and caller expression ...)

    (srfi 51) syntax (err-ands (caller expression ...) ...)

    (srfi 51) syntax (arg-or variable expr ...)⟹ return

    (srfi 51) syntax (arg-or caller variable expr ...)⟹ return

    (srfi 51) syntax (arg-ors (variable expr ...) ...)⟹ return

    (srfi 51) syntax (arg-ors (caller variable expr ...) ...)⟹ return

    (srfi 51) syntax (arg-ors common-caller (variable expr ...) ...)⟹ return

    (srfi 51) syntax (arg-ors common-caller (caller variable expr ...) ...)⟹ return

    (srfi 51) syntax (err-or caller expression ...)

    (srfi 51) syntax (err-ors (caller expression ...) ...)

    Each <variable> should be an argument of a procedure.

    The <caller>, <expr>, and <expression> are any scheme expression, but the <expr> should contain the corresponding <variable>.

    Arg-and, arg-ands, err-and, and err-ands are the same as "and" except that these signal an error in case "and" returns a false value.

    Arg-or, arg-ors, err-or, and err-ors are the same as "or" except that these signal an error in case "or" returns a true value.

    library (srfi 54) Formatting

    This SRFI introduces the CAT procedure that converts any object to a string. It takes one object as the first argument and accepts a variable number of optional arguments, unlike the procedure called FORMAT.

    (srfi 54) procedure (CAT object formatting-specifier ...) ⟹ string?

    Each formatting-specifier should match one of following:

    <suffix%>: effective only for the number type of <object>.

    <suffix$>: effective for all types except the number type of <object>.

    <suffix*>: effective for all types of <object>.

    <object> is any Scheme object.

    <exactness> is a symbol: exact or inexact.

    <radix> is a symbol: binary, octal, decimal, or hexadecimal. Each radix sign except decimal is prefixed to the resulting string. The default value is decimal. If <sign> is a symbol that takes the form of 'sign, and <object> is a positive number without a positive sign, the positive sign is prefixed to the resulting string.

    <precision> is an inexact integer whose absolute value specifies the number of decimal digits after a decimal point. If <precision> is a non-negative integer, an exact sign is prefixed to the resulting string as needed.

    <separator> is a list whose first element is a character serving as a separator and second element is a positive exact integer. If the integer is n, the resulting string is separated in every n-characters of the resulting string. When the integer is omitted, the default value is 3.

    <writer> is a procedure of two arguments; <object> and a string port. It writes <object> to the string port. The default value of <writer> is varied according to the type of <object>. When <object> is a self-evaluating constant, it becomes equivalent to DISPLAY procedure, otherwise, it becomes WRITE procedure. If you want any objects to be displayed in your own way, you have to define your own <writer>. Otherwise, they are displayed simply in their evaluated forms.

    <pipe> is a list which is composed of one or more procedures. Each procedure takes at least one string argument and returns a string. One procedure connects with another as a pipe.

    <take> is a list whose elements are two exact integers; n and m, and the absolute values of n and m are N and M, respectively. First, the resulting string takes from the left n-characters, if it is non-negative, or all the characters but N-characters, if negative. Second, it takes from the right m-characters, if it is non-negative, or all the characters but M-characters, if negative. Then, it concatenates two set of characters taken. The second element can be omitted. If omitted, the default value is 0.

    <converter> is a pair whose car value is a predicate procedure that checks whether <object> satisfies it, and cdr value is a procedure that takes the <object> as an argument and returns a string. When <object> satisfies the predicate procedure, all optional arguments are ineffective except <width>, <char>, <port>, and <string>.

    <width> is an exact integer whose absolute value specifies the width of the resulting string. When the resulting string has fewer characters than the absolute value of <width>, it is placed rightmost with the rest being padded with <char>s, if <width> is positive, or it is placed leftmost with the rest being padded with <char>s, if <width> is negative. On the other hand, when the resulting string has more characters than the absolute value of <width>, the <width> is ignored. The default value is 0.

    <char> is a padding character. The default value is #\space.

    <port> is an output port or a boolean. If an output port is specified, the resulting string and <string>s are output into that port and simultaneously returned as a string. If <port> is #t, the output port is current output port. If <port> is #f, the output is only returned as a string. The default value is #f.

    <string> is a string that is appended to the resulting string.

    The order of all optional arguments does not matter. The CAT procedure processes optional arguments in the following order; <exactness>, <radix>, <precision>, <separator>, <sign> for the number type of <object>, or in the following order; <writer>, <pipe>, <take> for all other types.

    library (srfi 59) Vicinity

    A vicinity is a descriptor for a place in the file system. Vicinities hide from the programmer the concepts of host, volume, directory, and version. Vicinities express only the concept of a file environment where a file name can be resolved to a file in a system independent manner.

    All of these procedures are file-system dependent. Use of these vicinity procedures can make programs file-system independent.

    (srfi 59) procedure (program-vicinity) ⟹ vicinity

    Returns the vicinity of the currently loading Scheme code. For an interpreter this would be the directory containing source code. For a compiled system (with multiple files) this would be the directory where the object or executable files are. If no file is currently loading, then the result is undefined. Warning: program-vicinity can return incorrect values if your program escapes back into a load continuation.

    (srfi 59) procedure (library-vicinity) ⟹ vicinity

    Returns the vicinity of the shared Scheme library.

    (srfi 59) procedure (implementation-vicinity) ⟹ vicinity

    Returns the vicinity of the underlying Scheme implementation. This vicinity will likely contain startup code and messages and a compiler.

    (srfi 59) procedure (user-vicinity) ⟹ vicinity

    Returns the vicinity of the current directory of the user. On most systems this is `""' (the empty string).

    (srfi 59) procedure (home-vicinity) ⟹ vicinity

    Returns the vicinity of the user's HOME directory, the directory which typically contains files which customize a computer environment for a user. If scheme is running without a user (eg. a daemon) or if this concept is meaningless for the platform, then home-vicinity returns #f.

    (srfi 59) procedure (in-vicinity (vicinity vicinity) (filename string?)) ⟹ string?

    Returns a filename suitable for use by load, open-input-file, open-output-file, etc. The returned filename is filename in vicinity. in-vicinity should allow filename to override vicinity when filename is an absolute pathname and vicinity is equal to the value of (user-vicinity). The behavior of in-vicinity when filename is absolute and vicinity is not equal to the value of (user-vicinity) is unspecified. For most systems in-vicinity can be string-append.

    (srfi 59) procedure (sub-vicinity (vicinity vicinity) (name string?)) ⟹ vicinity

    Returns the vicinity of vicinity restricted to name. This is used for large systems where names of files in subsystems could conflict. On systems with directory structure sub-vicinity will return a pathname of the subdirectory name of vicinity.

    (srfi 59) procedure (make-vicinity (dir-path string?)) ⟹ vicinity

    Returns dirpath as a vicinity for use as first argument to in-vicinity.

    (srfi 59) procedure (pathname->vicinity (path string?)) ⟹ vicinity

    Returns the vicinity containing path.

    (srfi 59) procedure (vicinity:suffix? (chr char?)) ⟹ boolean?

    Returns the `#t' if chr is a vicinity suffix character; and #f otherwise. Typical vicinity suffixes are `/', `:', and `\'.

    library (srfi 60) Integers as Bits

    Treating integers as two's-complement strings of bits is an arcane but important domain of computer science. It is used for:

    • hashing;
    • Galois-field[2] calculations of error-detecting and error-correcting codes;
    • cryptography and ciphers;
    • pseudo-random number generation;
    • register-transfer-level modeling of digital logic designs;
    • Fast-Fourier transforms;
    • packing and unpacking numbers in persistant data structures;
    • space-filling curves with applications to dimension reduction and sparse multi-dimensional database indexes; and
    • generating approximate seed values for root-finders and transcendental function algorithms.

    (srfi 60) procedure (logand (n1 integer?) ...) ⟹ integer?

    (srfi 60) procedure (bitwise-and (n1 integer?) ...) ⟹ integer?

    Returns the integer which is the bit-wise AND of the integer arguments.

    (srfi 60) procedure (logior (n1 integer?) ...) ⟹ integer?

    (srfi 60) procedure (bitwise-ior (n1 integer?) ...) ⟹ integer?

    Returns the integer which is the bit-wise OR of the integer arguments.

    (srfi 60) procedure (logxor (n1 integer?) ...) ⟹ integer?

    (srfi 60) procedure (bitwise-xor (n1 integer?) ...) ⟹ integer?

    Returns the integer which is the bit-wise XOR of the integer arguments.

    (srfi 60) procedure (lognot (n integer?)) ⟹ integer?

    (srfi 60) procedure (bitwise-not (n integer?)) ⟹ integer?

    Returns the integer which is the one's-complement of the integer argument.

    (srfi 60) procedure (bitwise-if (mask integer?) (n0 integer?) (n1 integer?)) ⟹ integer?

    (srfi 60) procedure (bitwise-merge (mask integer?) (n0 integer?) (n1 integer?)) ⟹ integer?

    Returns an integer composed of some bits from integer n0 and some from integer n1. A bit of the result is taken from n0 if the corresponding bit of integer mask is 1 and from n1 if that bit of mask is 0.

    (srfi 60) procedure (logtest (j integer?) (k integer?)) ⟹ boolean?

    (srfi 60) procedure (any-bits-set? (j integer?) (k integer?)) ⟹ boolean?

    (logtest j k) == (not (zero? (logand j k)))

    (srfi 60) procedure (logcount (n integer?)) ⟹ integer?

    (srfi 60) procedure (bit-count (n integer?)) ⟹ integer?

    Returns the number of bits in integer n. If integer is positive, the 1-bits in its binary representation are counted. If negative, the 0-bits in its two's-complement binary representation are counted. If 0, 0 is returned.

    (srfi 60) procedure (integer-length (n integer?)) ⟹ integer?

    Returns the number of bits neccessary to represent n.

    (srfi 60) procedure (log2-binary-factors (n integer?)) ⟹ integer?

    (srfi 60) procedure (first-set-bit (n integer?)) ⟹ integer?

    Returns the number of factors of two of integer n. This value is also the bit-index of the least-significant `1' bit in n.

    (srfi 60) procedure (logbit? (index integer?) (n integer?)) ⟹ boolean?

    (srfi 60) procedure (bit-set? (index integer?) (n integer?)) ⟹ boolean?

    (logbit? index n) == (logtest (expt 2 index) n)

    (srfi 60) procedure (copy-bit (index integer?) (from integer?) (bit boolean?)) ⟹ integer?

    Returns an integer the same as from except in the indexth bit, which is 1 if bit is #t and 0 if bit is #f.

    (srfi 60) procedure (bit-field (n integer?) (start integer?) (end integer?)) ⟹ integer?

    Returns the integer composed of the start (inclusive) through end (exclusive) bits of n. The startth bit becomes the 0-th bit in the result.

    (srfi 60) procedure (copy-bit-field (to integer?) (from integer?) (start integer?) (end integer?)) ⟹ integer?

    Returns an integer the same as to except possibly in the start (inclusive) through end (exclusive) bits, which are the same as those of from. The 0-th bit of from becomes the startth bit of the result.

    (srfi 60) procedure (ash (n integer?) (count integer?)) ⟹ integer?

    (srfi 60) procedure (arithmetic-shift (n integer?) (count integer?)) ⟹ integer?

    Returns an integer equivalent to (inexact->exact (floor (* n (expt 2 count)))).

    (srfi 60) procedure (rotate-bit-field (n integer?) (count integer?) (start integer?) (end integer?)) ⟹ integer?

    Returns n with the bit-field from start to end cyclically permuted by count bits towards high-order.

    (srfi 60) procedure (reverse-bit-field (n integer?) (start integer?) (end integer?)) ⟹ integer?

    Returns n with the order of bits start to end reversed.

    (srfi 60) procedure (integer->list (k integer?)) ⟹ list?

    (srfi 60) procedure (integer->list (k integer?) (len integer?)) ⟹ list?

    integer->list returns a list of len booleans corresponding to each bit of the non-negative integer k. #t is coded for each 1; #f for 0. The len argument defaults to (integer-length k).

    (srfi 60) procedure (list->integer (list list?)) ⟹ integer?

    list->integer returns an integer formed from the booleans in the list list, which must be a list of booleans. A 1 bit is coded for each #t; a 0 bit for #f.

    (srfi 60) procedure (booleans->integer (bool1 boolean?) ...) ⟹ integer?

    Returns the integer coded by the bool1 ... arguments.

    library (srfi 61) A more general cond clause

    This SRFI proposes an extension to the cond syntax to allow a more general clause, one that allows binding the results of tests as in the => clauses and user-defined meaning of the success & failure of tests.

    (srfi 61) syntax (cond clause1 clause2 ...)

    clause ⟹ (test expression1 ...) | (test => receiver) | (test guard => receiver) | (else expression1 expression2 ...)

    guard ⟹ procedure?

    receiver ⟹ procedure?

    The <cond clause> production in the formal syntax of Scheme as written by R5RS in section 7.1.3 is extended with a new option:

    <cond clause> --->

    ...

    | (<generator> <guard> => <receiver>)

    where <generator>, <guard>, & <receiver> are all <expression>s.

    Clauses of this form have the following semantics: <generator> is evaluated. It may return arbitrarily many values. <Guard> is applied to an argument list containing the values in order that <generator> returned. If <guard> returns a true value for that argument list, <receiver> is applied with an equivalent argument list. If <guard> returns a false value, however, the clause is abandoned and the next one is tried.

    library (srfi 63) Homogeneous and Heterogeneous Arrays

    The SRFI, which is to supersede SRFI-47, "Array",

    • synthesizes array concepts from Common-Lisp and Alan Bawden's "array.scm";
    • incorporates all the uniform vector types from SFRI-4 "Homogeneous numeric vector datatypes";
    • adds a boolean uniform array type;
    • adds 16.bit and 128.bit floating-point uniform-array types;
    • adds decimal floating-point uniform-array types; and
    • adds array types of (dual) floating-point complex numbers.
    Multi-dimensional arrays subsume homogeneous vectors as the one-dimensional case, obviating the need for SRFI-4.

    SRFI-58 gives a read/write invariant syntax for the homogeneous and heterogeneous arrays described here.

    (srfi 63) procedure (array? obj) ⟹ boolean?

    Returns #t if the obj is an array, and #f if not.

    Note: Arrays are not disjoint from other Scheme types. Vectors and possibly strings also satisfy array?.

    (srfi 63) procedure (equal? obj1 obj2) ⟹ boolean?

    Returns #t if obj1 and obj2 have the same rank and dimensions and the corresponding elements of obj1 and obj2 are equal?.

    equal? recursively compares the contents of pairs, vectors, strings, and arrays, applying eqv? on other objects such as numbers and symbols. A rule of thumb is that objects are generally equal? if they print the same. equal? may fail to terminate if its arguments are circular data structures.

    (srfi 63) procedure (array-rank obj) ⟹ integer?

    Returns the number of dimensions of obj. If obj is not an array, 0 is returned.

    (srfi 63) procedure (array-dimnesions (array array?)) ⟹ list?

    return ⟹ (list integer?)

    Returns a list of dimensions.

    (srfi 63) procedure (make-array (prototype array?) (k1 integer?) ...) ⟹ array?

    Creates and returns an array of type prototype with dimensions k1, ... and filled with elements from prototype. prototype must be an array, vector, or string. The implementation-dependent type of the returned array will be the same as the type of prototype; except if that would be a vector or string with rank not equal to one, in which case some variety of array will be returned.

    If the prototype has no elements, then the initial contents of the returned array are unspecified. Otherwise, the returned array will be filled with the element at the origin of prototype.

    (srfi 63) procedure (make-shared-array (array array?) (mapper procedure?) (k1 integer?) ...) ⟹ array?

    (mapper (i1 integer?) ...) ⟹ list?

    make-shared-array can be used to create shared subarrays of other arrays. The mapper is a function that translates coordinates in the new array into coordinates in the old array. A mapper must be linear, and its range must stay within the bounds of the old array, but it can be otherwise arbitrary.

    (srfi 63) procedure (list->array (rank integer?) (proto array?) (list list?)) ⟹ array?

    list must be a rank-nested list consisting of all the elements, in row-major order, of the array to be created.

    (srfi 63) procedure (array->list (array array?)) ⟹ *

    Returns a rank-nested list consisting of all the elements, in row-major order, of array. In the case of a rank-0 array, array->list returns the single element.

    (srfi 63) procedure (vector->array (vect vector?) (proto array?) (dim1 integer?) ...) ⟹ array?

    vect must be a vector of length equal to the product of exact nonnegative integers dim1, ....

    vector->array returns an array of type proto consisting of all the elements, in row-major order, of vect. In the case of a rank-0 array, vect has a single element.

    (srfi 63) procedure (array->vector (array array?)) ⟹ vector?

    Returns a new vector consisting of all the elements of array in row-major order.

    (srfi 63) procedure (array-in-bounds? (array array?) (index1 integer?) ...) ⟹ boolean?

    Returns #t if its arguments would be acceptable to array-ref.

    (srfi 63) procedure (array-ref (array array?) (index1 integer?) ...) ⟹ *

    Returns the (k1, ...) element of array.

    (srfi 63) procedure (array-set! (array array?) obj (index1 integer?) ...) ⟹ undefined

    Stores obj in the (k1, ...) element of array. The value returned by array-set! is unspecified.

    These functions return a prototypical uniform-array enclosing the optional argument (which must be of the correct type). If the uniform-array type is supported by the implementation, then it is returned; defaulting to the next larger precision type; resorting finally to vector.

    (srfi 63) procedure (A:floC128b ) ⟹ array?

    (srfi 63) procedure (A:floC128b (z complex?)) ⟹ array?

    Returns an inexact 128.bit flonum complex uniform-array prototype.

    (srfi 63) procedure (A:floC64b ) ⟹ array?

    (srfi 63) procedure (A:floC64b (z complex?)) ⟹ array?

    Returns an inexact 64.bit flonum complex uniform-array prototype.

    (srfi 63) procedure (A:floC32b ) ⟹ array?

    (srfi 63) procedure (A:floC32b (z complex?)) ⟹ array?

    Returns an inexact 32.bit flonum complex uniform-array prototype.

    (srfi 63) procedure (A:floC16b ) ⟹ array?

    (srfi 63) procedure (A:floC16b (z complex?)) ⟹ array?

    Returns an inexact 16.bit flonum complex uniform-array prototype.

    (srfi 63) procedure (A:floR128b ) ⟹ array?

    (srfi 63) procedure (A:floR128b (z real?)) ⟹ array?

    Returns an inexact 128.bit flonum real uniform-array prototype.

    (srfi 63) procedure (A:floR64b ) ⟹ array?

    (srfi 63) procedure (A:floR64b (z real?)) ⟹ array?

    Returns an inexact 64.bit flonum real uniform-array prototype.

    (srfi 63) procedure (A:floR32b ) ⟹ array?

    (srfi 63) procedure (A:floR32b (z real?)) ⟹ array?

    Returns an inexact 32.bit flonum real uniform-array prototype.

    (srfi 63) procedure (A:floR16b ) ⟹ array?

    (srfi 63) procedure (A:floR16b (z real?)) ⟹ array?

    Returns an inexact 16.bit flonum real uniform-array prototype.

    (srfi 63) procedure (A:floQ128d ) ⟹ array?

    (srfi 63) procedure (A:floQ128d (z real?)) ⟹ array?

    Returns an exact 128.bit decimal flonum rational uniform-array prototype.

    (srfi 63) procedure (A:floQ64d ) ⟹ array?

    (srfi 63) procedure (A:floQ64d (z real?)) ⟹ array?

    Returns an exact 64.bit decimal flonum rational uniform-array prototype.

    (srfi 63) procedure (A:floQ32d ) ⟹ array?

    (srfi 63) procedure (A:floQ32d (z real?)) ⟹ array?

    Returns an exact 32.bit decimal flonum rational uniform-array prototype.

    (srfi 63) procedure (A:fixZ64b ) ⟹ array?

    (srfi 63) procedure (A:fixZ64b (z integer?)) ⟹ array?

    Returns an exact binary fixnum uniform-array prototype with at least 64 bits of precision.

    (srfi 63) procedure (A:fixZ32b ) ⟹ array?

    (srfi 63) procedure (A:fixZ32b (z integer?)) ⟹ array?

    Returns an exact binary fixnum uniform-array prototype with at least 32 bits of precision.

    (srfi 63) procedure (A:fixZ16b ) ⟹ array?

    (srfi 63) procedure (A:fixZ16b (z integer?)) ⟹ array?

    Returns an exact binary fixnum uniform-array prototype with at least 16 bits of precision.

    (srfi 63) procedure (A:fixZ8b ) ⟹ array?

    (srfi 63) procedure (A:fixZ8b (z integer?)) ⟹ array?

    Returns an exact binary fixnum uniform-array prototype with at least 8 bits of precision.

    (srfi 63) procedure (A:fixN64b ) ⟹ array?

    (srfi 63) procedure (A:fixN64b (z integer?)) ⟹ array?

    Returns an exact non-negative binary fixnum uniform-array prototype with at least 64 bits of precision.

    (srfi 63) procedure (A:fixN32b ) ⟹ array?

    (srfi 63) procedure (A:fixN32b (z integer?)) ⟹ array?

    Returns an exact non-negative binary fixnum uniform-array prototype with at least 32 bits of precision.

    (srfi 63) procedure (A:fixN16b ) ⟹ array?

    (srfi 63) procedure (A:fixN16b (z integer?)) ⟹ array?

    Returns an exact non-negative binary fixnum uniform-array prototype with at least 16 bits of precision.

    (srfi 63) procedure (A:fixN8b ) ⟹ array?

    (srfi 63) procedure (A:fixN8b (z integer?)) ⟹ array?

    Returns an exact non-negative binary fixnum uniform-array prototype with at least 8 bits of precision.

    (srfi 63) procedure (A:bool ) ⟹ array?

    (srfi 63) procedure (A:bool (b boolean?)) ⟹ array?

    Returns a boolean uniform-array prototype.

    library (srfi 64) A Scheme API for test suites

    This defines an API for writing test suites, to make it easy to portably test Scheme APIs, libraries, applications, and implementations. A test suite is a collection of test cases that execute in the context of a test-runner. This specifications also supports writing new test-runners, to allow customization of reporting and processing the result of running test suites.

    (srfi 64) syntax (test-assert expression)

    (srfi 64) syntax (test-assert test-name expression)

    test-name ⟹ string?

    This evaluates the expression. The test passes if the result is true; if the result is false, a test failure is reported. The test also fails if an exception is raised, assuming the implementation has a way to catch exceptions. How the failure is reported depends on the test runner environment. The test-name is a string that names the test case. (Though the test-name is a string literal in the examples, it is an expression. It is evaluated only once.) It is used when reporting errors, and also when skipping tests, as described below. It is an error to invoke test-assert if there is no current test runner.

    (srfi 64) syntax (test-eqv expected test-expr)

    (srfi 64) syntax (test-eqv test-name expected test-expr)

    test-name ⟹ string?

    This is equivalent to:

    (test-assert [test-name] (eqv? expected test-expr))

    (srfi 64) syntax (test-equal expected test-expr)

    (srfi 64) syntax (test-equal test-name expected test-expr)

    test-name ⟹ string?

    This is equivalent to:

    (test-assert [test-name] (equal? expected test-expr))

    (srfi 64) syntax (test-eq expected test-expr)

    (srfi 64) syntax (test-eq test-name expected test-expr)

    test-name ⟹ string?

    This is equivalent to:

    (test-assert [test-name] (eq? expected test-expr))

    (srfi 64) syntax (test-approximate expected test-expr error)

    (srfi 64) syntax (test-approximate test-name expected test-expr error)

    test-name ⟹ string?

    This is equivalent to (except that each argument is only evaluated once):

    (test-assert [test-name]

    (and (>= test-expr (- expected error))

    (<= test-expr (+ expected error))))

    (srfi 64) syntax (test-error test-expr)

    (srfi 64) syntax (test-error error-type test-expr)

    (srfi 64) syntax (test-error test-name error-type test-expr)

    test-name ⟹ string?

    Evaluating test-expr is expected to signal an error. The kind of error is indicated by error-type. If the error-type is left out, or it is #t, it means "some kind of unspecified error should be signaled". This specification leaves it implementation-defined (or for a future specification) what form test-error may take, though all implementations must allow #t. Some implementations may support SRFI-35's conditions, but these are only standardized for SRFI-36's I/O conditions, which are seldom useful in test suites.

    (srfi 64) syntax (test-read-eval-string string)

    string ⟹ string?

    This function parses string (using read) and evaluates the result. The result of evaluation is returned from test-read-eval-string. An error is signalled if there are unread characters after the read is done.

    (srfi 64) syntax (test-begin suite-name)

    (srfi 64) syntax (test-begin suite-name count)

    A test-begin enters a new test group. The suite-name becomes the current test group name, and is added to the end of the test group path. Portable test suites should use a sting literal for suite-name; the effect of expressions or other kinds of literals is unspecified.

    (srfi 64) syntax (test-end)

    (srfi 64) syntax (test-end suite-name)

    A test-end leaves the current test group. An error is reported if the suite-name does not match the current test group name.

    Additionally, if the matching test-begin installed a new test-runner, then the test-end will de-install it, after reporting the accumulated test results in an implementation-defined manner.

    (srfi 64) syntax (test-group suite-name decl-or-expr ...)

    Equivalent to:

    (if (not (test-to-skip% suite-name))

    (dynamic-wind

    (lambda () (test-begin suite-name))

    (lambda () decl-or-expr ...)

    (lambda () (test-end suite-name))))

    This is usually equivalent to executing the decl-or-exprs within the named test group. However, the entire group is skipped if it matched an active test-skip (see later). Also, the test-end is executed in case of an exception.

    (srfi 64) syntax (test-group-with-cleanup suite-name decl-or-expr ... cleanup-form)

    Execute each of the decl-or-expr forms in order (as in a <body>), and then execute the cleanup-form. The latter should be executed even if one of a decl-or-expr forms raises an exception (assuming the implementation has a way to catch exceptions).

    (srfi 64) procedure (test-match-name (name string?)) ⟹ procedure?

    (return (runner test-runner?)) ⟹ boolean?

    The resulting specifier matches if the current test name (as returned by test-runner-test-name) is equals? to name.

    (srfi 64) procedure (test-match-nth (n integer?)) ⟹ procedure?

    (srfi 64) procedure (test-match-nth (n integer?) (count integer?)) ⟹ procedure?

    (return (runner test-runner?)) ⟹ boolean?

    This evaluates to a stateful predicate: A counter keeps track of how many times it has been called. The predicate matches the n'th time it is called (where 1 is the first time), and the next (- count 1) times, where count defaults to 1.

    (srfi 64) procedure (test-match-any (specifier procedure?) ...) ⟹ procedure?

    (specifier (runner test-runner?)) ⟹ boolean?

    (return (runner test-runner?)) ⟹ boolean?

    The resulting specifier matches if any specifier matches. Each specifier is applied, in order, so side-effects from a later specifier happen even if an earlier specifier is true.

    (srfi 64) procedure (test-match-all (specifier procedure?) ...) ⟹ procedure?

    (specifier (runner test-runner?)) ⟹ boolean?

    (return (runner test-runner?)) ⟹ boolean?

    The resulting specifier matches if each specifier matches. Each specifier is applied, in order, so side-effects from a later specifier happen even if an earlier specifier is false.

    count (i.e. an integer)

    Convenience short-hand for: (test-match-nth 1 count).

    name (i.e. a string)

    Convenience short-hand for (test-match-name name).

    (srfi 64) procedure (test-skip (specifier procedure? | integer? | string?)) ⟹ undefined

    (specifier (runner test-runner?)) ⟹ boolean?

    Evaluating test-skip adds the resulting specifier to the set of currently active skip-specifiers. Before each test (or test-group) the set of active skip-specifiers are applied to the active test-runner. If any specifier matches, then the test is skipped.

    For convenience, if the specifier is a string that is syntactic sugar for (test-match-name specifier).

    (srfi 64) procedure (test-expect-fail (specifier procedure? | integer? | string?)) ⟹ undefined

    (specifier (runner test-runner?)) ⟹ boolean?

    Matching tests (where matching is defined as in test-skip) are expected to fail. This only affects test reporting, not test execution.

    (srfi 64) procedure (test-runner? obj) ⟹ boolean?

    True iff value is a test-runner object.

    (srfi 64) procedure (test-runner-current ) ⟹ test-runner?

    (srfi 64) procedure (test-runner-current (runner test-runner?)) ⟹ undefined

    Get or set the current test-runner. If an implementation supports parameter objects (as in SRFI-39), then test-runner-current can be a parameter object. Alternatively, test-runner-current may be implemented as a macro or function that uses a fluid or thread-local variable, or a plain global variable.

    (srfi 64) procedure (test-runner-get) ⟹ test-runner?

    Same as (test-runner-current), buth throws an exception if there is no current test-runner.

    (srfi 64) procedure (test-runner-simple) ⟹ test-runner?

    Creates a new simple test-runner, that prints errors and a summary on the standard output port.

    (srfi 64) procedure (test-runner-null) ⟹ test-runner?

    Creates a new test-runner, that does nothing with the test results. This is mainly meant for extending when writing a custom runner.

    Implementations may provide other test-runners, perhaps a (test-runner-gui).

    (srfi 64) procedure (test-runner-create) ⟹ test-runner?

    Create a new test-runner. Equivalent to ((test-runner-factory))

    (srfi 64) procedure (test-runner-factory ) ⟹ procedure?

    (srfi 64) procedure (test-runner-factory (factory procedure?)) ⟹ undefined

    (factory) ⟹ test-runner?

    Get or set the current test-runner factory. A factory is a zero-argument function that creates a new test-runner. The default value is test-runner-simple, but implementations may provide a way to override the default. As with test-runner-current, this may be a parameter object, or use a per-thread, fluid, or global variable.

    (srfi 64) procedure (test-apply (specifier integer? | string? | procedure?) ... procedure) ⟹ undefined

    (procedure) ⟹ *

    (specifier (runner test-runner?)) ⟹ boolean?

    Calls procedure with no arguments using the specified runner as the current test-runner. If runner is omitted, then (test-runner-current) is used. (If there is no current runner, one is created as in test-begin.) If one or more specifiers are listed then only tests matching the specifiers are executed. A specifier has the same form as one used for test-skip. A test is executed if it matches any of the specifiers in the test-apply and does not match any active test-skip specifiers.

    (srfi 64) syntax (test-with-runner runner decl-or-expr ...)

    runner ⟹ test-runner?

    Executes each decl-or-expr in order in a context where the current test-runner is runner.

    (srfi 64) procedure (test-result-kind ) ⟹ #f | symbol?

    (srfi 64) procedure (test-result-kind (runner test-runner?)) ⟹ #f | symbol?

    Return one of the following result codes from the most recent tests:

    'pass The test passed, as expected.

    'fail The test failed (and was not expected to).

    'xfail The test failed and was expected to.

    'xpass The test passed, but was expected to fail.

    'skip The test was skipped.

    Returns #f if no tests have been run yet. If we've started on a new test, but don't have a result yet, then the result kind is 'xfail is the test is expected to fail, 'skip is the test is supposed to be skipped, or #f otherwise.

    (srfi 64) procedure (test-passed? ) ⟹ boolean?

    (srfi 64) procedure (test-passed? (runner test-runner?)) ⟹ boolean?

    True if the value of (test-result-kind [runner]) is one of 'pass or 'xpass. This is a convenient shorthand that might be useful in a test suite to only run certain tests if the previous test passed.

    (srfi 64) procedure (test-result-ref (runner test-runner?) (pname symbol?)) ⟹ *

    (srfi 64) procedure (test-result-ref (runner test-runner?) (pname symbol?) default) ⟹ *

    Returns the property value associated with the pname property name. If there is no value associated with 'pname return default, or #f if default isn't specified.

    (srfi 64) procedure (test-result-set! (runner test-runner?) (pname symbol?) value) ⟹ undefined

    Sets the property value associated with the pname property name to value. Usually implementation code should call this function, but it may be useful for a custom test-runner to add extra properties.

    (srfi 64) procedure (test-result-remove (runner test-runner?) (pname symbol?)) ⟹ undefined

    Remove the property with the name 'pname.

    (srfi 64) procedure (test-result-clear (runner test-runner?)) ⟹ undefined

    Remove all result properties. The implementation automatically calls test-result-clear at the start of a test-assert and similar procedures.

    (srfi 64) procedure (test-result-alist (runner test-runner?)) ⟹ list?

    Returns an association list of the current result properties. It is unspecified if the result shares state with the test-runner. The result should not be modified, on the other hand the result may be implicitly modified by future test-result-set! or test-result-remove calls. However, a test-result-clear does not modify the returned alist. Thus you can "archive" result objects from previous runs.

    (srfi 64) procedure (test-runner-on-test-begin (runner test-runner?)) ⟹ procedure?

    (return (runner test-runner?)) ⟹ undefined

    (srfi 64) procedure (test-runner-on-test-begin! (runner test-runner?) (on-test-begin procedure?)) ⟹ undefined

    (on-test-begin (runner test-runner?)) ⟹ undefined

    The on-test-begin-function is called at the start of an individual testcase, before the test expression (and expected value) are evaluated.

    (srfi 64) procedure (test-runner-on-test-end (runner test-runner?)) ⟹ procedure?

    (return (runner test-runner?)) ⟹ undefined

    (srfi 64) procedure (test-runner-on-test-end! (runner test-runner?) (on-test-end procedure?)) ⟹ undefined

    (on-test-end (runner test-runner?)) ⟹ undefined

    The on-test-end-function is called at the end of an individual testcase, when the result of the test is available.

    (srfi 64) procedure (test-runner-on-group-begin (runner test-runner?)) ⟹ procedure?

    (return (runner test-runner?) (suite-name string?) (count integer?)) ⟹ undefined

    (srfi 64) procedure (test-runner-on-group-begin! (runner test-runner?) (on-group-begin procedure?)) ⟹ undefined

    (on-group-begin (runner test-runner?) (suite-name string?) (count integer?)) ⟹ undefined

    The on-group-begin-function is called by a test-begin, including at the start of a test-group. The suite-name is a Scheme string, and count is an integer or #f.

    (srfi 64) procedure (test-runner-on-group-end (runner test-runner?)) ⟹ procedure?

    (return (runner test-runner?)) ⟹ undefined

    (srfi 64) procedure (test-runner-on-group-end! (runner test-runner?) (on-group-end procedure?)) ⟹ undefined

    (on-group-end (runner test-runner?)) ⟹ undefined

    The on-group-end-function is called by a test-end, including at the end of a test-group.

    (srfi 64) procedure (test-runner-on-bad-count (runner test-runner?)) ⟹ procedure?

    (return (runner test-runner?) (actual-count integer?) (expected-count integer?)) ⟹ undefined

    (srfi 64) procedure (test-runner-on-bad-count! (runner test-runner?) (on-bad-count procedure?)) ⟹ undefined

    (on-bad-count (runner test-runner?) (actual-count integer?) (expected-count integer?)) ⟹ undefined

    Called from test-end (before the on-group-end-function is called) if an expected-count was specified by the matching test-begin and the expected-count does not match the actual-count of tests actually executed or skipped.

    (srfi 64) procedure (test-runner-on-bad-end-name (runner test-runner?)) ⟹ procedure?

    (return (runner test-runner?) (begin-name string?) (end-name string?)) ⟹ undefined

    (srfi 64) procedure (test-runner-on-bad-end-name! (runner test-runner?) (on-bad-end-name procedure?)) ⟹ procedure?

    (on-bad-end-name (runner test-runner?) (begin-name string?) (end-name string?)) ⟹ undefined

    Called from test-end (before the on-group-end-function is called) if a suite-name was specified, and it did not that the name in the matching test-begin.

    (srfi 64) procedure (test-runner-on-final (runner test-runner?)) ⟹ procedure?

    (return (runner test-runner?)) ⟹ undefined

    (srfi 64) procedure (test-runner-on-final! (runner test-runner?) (on-final procedure?)) ⟹ undefined

    (on-final (runner test-runner?)) ⟹ undefined

    The on-final-function takes one parameter (a test-runner) and typically displays a summary (count) of the tests. The on-final-function is called after called the on-group-end-function correspondiong to the outermost test-end. The default value is test-on-final-simple which writes to the standard output port the number of tests of the various kinds.

    (srfi 64) procedure (test-on-test-begin-simple (runner test-runner?)) ⟹ undefined

    (srfi 64) procedure (test-on-test-end-simple (runner test-runner?)) ⟹ undefined

    (srfi 64) procedure (test-on-group-begin-simple (runner test-runner?) (suite-name string?) (count integer?)) ⟹ undefined

    (srfi 64) procedure (test-on-group-end-simple (runner test-runner?)) ⟹ undefined

    (srfi 64) procedure (test-on-bad-count-simple (runner test-runner?) (actual-count integer?) (expected-count integer?)) ⟹ undefined

    (srfi 64) procedure (test-on-bad-end-name-simple (runner test-runner?) (begin-name string?) (end-name string?)) ⟹ undefined

    The callback functions used by the default test-runner returned by test-runner-simple.

    (srfi 64) procedure (test-runner-pass-count (runner test-runner?)) ⟹ integer?

    Returns the number of tests that passed, and were expected to pass.

    (srfi 64) procedure (test-runner-fail-count (runner test-runner?)) ⟹ integer?

    Returns the number of tests that failed, but were expected to pass.

    (srfi 64) procedure (test-runner-xpass-count (runner test-runner?)) ⟹ integer?

    Returns the number of tests that passed, but were expected to fail.

    (srfi 64) procedure (test-runner-xfail-count (runner test-runner?)) ⟹ integer?

    Returns the number of tests that failed, and were expected to pass.

    (srfi 64) procedure (test-runner-skip-count (runner test-runner?)) ⟹ integer?

    Returns the number of tests or test groups that were skipped.

    (srfi 64) procedure (test-runner-test-name (runner test-runner?)) ⟹ string?

    Returns the name of the current test or test group, as a string. During execution of test-begin this is the name of the test group; during the execution of an actual test, this is the name of the test-case. If no name was specified, the name is the empty string.

    (srfi 64) procedure (test-runner-group-path (runner test-runner?)) ⟹ list?

    A list of names of groups we're nested in, with the outermost group first.

    (srfi 64) procedure (test-runner-group-stack (runner test-runner?)) ⟹ list?

    A list of names of groups we're nested in, with the outermost group last. (This is more efficient than test-runner-group-path, since it doesn't require any copying.)

    (srfi 64) procedure (test-runner-aux-value (runner test-runner?)) ⟹ *

    (srfi 64) procedure (test-runner-aux-value! (runner test-runner?) on-test) ⟹ *

    Get or set the aux-value field of a test-runner. This field is not used by this API or the test-runner-simple test-runner, but may be used by custom test-runners to store extra state.

    (srfi 64) procedure (test-runner-reset (runner test-runner?)) ⟹ undefined

    Resets the state of the runner to its initial state.

    library (srfi 66) Octet Vectors

    This SRFI defines a set of procedures for creating, accessing, and manipulating uniform vectors of octets.

    (srfi 66) procedure (u8vector? obj) ⟹ boolean?

    Returns #t if obj is an octect vector, otherwise returns #f. Analogous to vector?.

    (srfi 66) procedure (make-u8vector (size integer?) (size integer?)) ⟹ u8vector?

    Returns a newly allocated octet vector of k elements. Each element is initialized to fill. Fill must be an octet. Analogous to make-vector.

    (srfi 66) procedure (u8vector (value integer?) ...) ⟹ u8vector?

    Returns a newly allocated octet vector whose elements contain the given arguments, which must all be octets. Analogous to vector.

    (srfi 66) procedure (u8vector->list (vec u8vector?)) ⟹ list?

    u8vector->listreturns a newly allocated list of the elements of u8vector in the same order.Analogous to vector->list.

    (srfi 66) procedure (list->u8vector (proper-list list?)) ⟹ u8vector?

    List->u8vector returns a newly allocated octet vector whose elements are the elements of list octets, which must all be octets. Analogous to list->vector.

    (srfi 66) procedure (u8vector-length (vec u8vector?)) ⟹ integer?

    Returns the number of elements in u8vector as an exact integer. Analogous to vector-length.

    (srfi 66) procedure (u8vector-ref (vec u8vector?) (i integer?)) ⟹ integer?

    k must be a valid index of u8vector. u8vector-ref returns the contents of element k of u8vector. Analogous to vector-ref.

    (srfi 66) procedure (u8vector-set! (vec u8vector?) (i integer?) (value integer?)) ⟹ undefined

    k must be a valid index of u8vector. u8vector-set! stores octet in element k of u8vector. The number of return values and the return values are unspecified. However, the number of return values is such that it is accepted by a continuation created by begin. Analogous to vector-set!.

    (srfi 66) procedure (u8vector=? (vec1 u8vector?) (vec2 u8vector?)) ⟹ boolean?

    Returns #t if u8vector-1 and u8vector-2 are equal---that is, if they have the same length and equal elements at all valid indices.

    (srfi 66) procedure (u8vector-compare (vec1 u8vector?) (vec2 u8vector?)) ⟹ integer?

    Compares u8vector-1 and u8vector-2 and returns a value consistent with the vector ordering specified in SRFI 67, i.e. -1 if u8vector-1 is smaller than u8vector-2, 0 if they are equal, and 1 if u8vector-1 is greater than u8vector-2. Shorter vectors are always smaller than longer ones, and vectors of equal length are compared lexicographically.

    (srfi 66) procedure (u8vector-copy! (source u8vector?) (source-start integer?) (target u8vector?) (target-start integer?) (n integer?)) ⟹ undefined

    Copies data from octet vector source to octet vector target. Source-start, target-start, and n must be non-negative exact integers that satisfy

    0 <= source-start <= source-start + n <= (u8vector-length source)

    0 <= target-start <= target-start + n <= (u8vector-length target)

    This copies the octets from source at indices [source-start, source-start + n) to consecutive indices in target starting at target-index.

    This must work even if the memory regions for the source and the target overlap, i.e., the octets at the target location after the copy must be equal to the octets at the source location before the copy.

    The number of return values and the return values are unspecified. However, the number of return values is such that it is accepted by a continuation created by begin. Analogous to vector-ref.

    (srfi 66) procedure (u8vector-copy (vec u8vector?)) ⟹ u8vector?

    Returns a newly allocated copy of octet vector u8vector.

    library (srfi 67) Compare Procedures

    This SRFI can be seen as an extension of the standard procedures =, <, char<? etc. of R5RS -- or even as a replacement. The primary design aspect in this SRFI is the separation of representing a total order and using it. For representing the order, we have chosen for truly 3-way comparisons. For using it we provide an extensive set of operations, each of which accepts a procedure used for comparison. Since these compare procedures are often optional, comparing built-in types is as convenient as R5RS , sometimes more convenient: For example, testing if the integer index i lies in the integer range {0, ..., n - 1} can be written as (<=/<? 0 i n), implicitly invoking default-compare.

    As soon as new total orders are required, the infrastructure provided by this SRFI is far more convenient and often even more efficient than building each total order from scratch.

    Moreover, in case Scheme users and implementors find this mechanism useful and adopt it, the benefit of having a uniform interface to total orders to be used in data structures will manifest itself. Most concretely, a new sorting procedure in the spirit of this SRFI would have the interface (my-sort [ compare ] xs), using default-compare if the optional compare was not provided. Then my-sort could be defined using the entire infrastructure of this SRFI: Efficient 2- and 3-way branching, testing for chains and pairwise inequality, min/max, and general order statistics.

    (srfi 67) procedure (boolean-compare (bool1 boolean?) (bool2 boolean?)) ⟹ integer?

    Compares two booleans, ordered by #f < #t.

    (srfi 67) procedure (char-compare (char1 char?) (char2 char?)) ⟹ integer?

    (srfi 67) procedure (char-compare-ci (char1 char?) (char2 char?)) ⟹ integer?

    Compare characters as char<=? and char-ci<=? respectively. The suffix -ci means "case insensitive."

    (srfi 67) procedure (string-compare (string1 string?) (string2 string?)) ⟹ integer?

    (srfi 67) procedure (string-compare-ci (string1 string?) (string2 string?)) ⟹ integer?

    Compare strings as string<= and string-ci<=?. The suffix -ci means "case insensitive."

    (srfi 67) procedure (symbol-compare (symbol1 symbol?) (symbol2 symbol?)) ⟹ integer?

    Compares symbols as string<= on the names returned by symbol->string.

    (srfi 67) procedure (integer-compare (integer1 integer?) (integer2 integer?)) ⟹ integer?

    (srfi 67) procedure (rational-compare (rational1 rational?) (rational2 rational?)) ⟹ integer?

    (srfi 67) procedure (real-compare (real1 real?) (real2 real?)) ⟹ integer?

    (srfi 67) procedure (complex-compare (complex1 complex?) (complex2 complex?)) ⟹ integer?

    (srfi 67) procedure (number-compare (number1 number?) (number2 number?)) ⟹ integer?

    Compare two numbers. It is an error if an argument is not of the type specified by the name of the procedure.

    Complex numbers are ordered lexicographically on pairs (re, im). For objects representing real numbers sign(x - y) is computed. The ordering for values satisfying real? or complex? but not representing a real or complex number should be consistent with procedures = and < of R5RS , and apart from that it is unspecified.

    Numerical compare procedures are compatible with the R5RS numerical tower in the following sense: If S is a subtype of the numerical type T and x, y can be represented both in S and in T, then compare-S and compare-T compute the same result.

    (srfi 67) procedure (vector-compare (x vector?) (y vector?)) ⟹ integer?

    (srfi 67) procedure (vector-compare (compare procedure?) (x vector?) (y vector?)) ⟹ integer?

    (srfi 67) procedure (vector-compare x y (size procedure?) (ref procedure?)) ⟹ integer?

    (srfi 67) procedure (vector-compare (compare procedure?) x y (size procedure?) (ref procedure?)) ⟹ integer?

    (compare el1 el2) ⟹ integer?

    (size seq) ⟹ integer?

    (ref seq index) ⟹ *

    (srfi 67) procedure (vector-compare-as-list (x vector?) (y vector?)) ⟹ integer?

    (srfi 67) procedure (vector-compare-as-list (compare procedure?) (x vector?) (y vector?)) ⟹ integer?

    (srfi 67) procedure (vector-compare-as-list x y (size procedure?) (ref procedure?)) ⟹ integer?

    (srfi 67) procedure (vector-compare-as-list (compare procedure?) x y (size procedure?) (ref procedure?)) ⟹ integer?

    (compare el1 el2) ⟹ integer?

    (size seq) ⟹ integer?

    (ref seq index) ⟹ *

    (srfi 67) procedure (list-compare (x list?) (y list?)) ⟹ integer?

    (srfi 67) procedure (list-compare (compare procedure?) (x list?) (y list?)) ⟹ integer?

    (srfi 67) procedure (list-compare x y (empty? procedure?) (head procedure?) (tail procedure?)) ⟹ integer?

    (srfi 67) procedure (list-compare (compare procedure?) x y (empty? procedure?) (head procedure?) (tail procedure?)) ⟹ integer?

    (compare el1 el2) ⟹ integer?

    (empty? seq) ⟹ boolean?

    (head seq) ⟹ *

    (tail seq) ⟹ *

    (srfi 67) procedure (list-compare-as-vector (x list?) (y list?)) ⟹ integer?

    (srfi 67) procedure (list-compare-as-vector (compare procedure?) (x list?) (y list?)) ⟹ integer?

    (srfi 67) procedure (list-compare-as-vector x y (empty? procedure?) (head procedure?) (tail procedure?)) ⟹ integer?

    (srfi 67) procedure (list-compare-as-vector (compare procedure?) x y (empty? procedure?) (head procedure?) (tail procedure?)) ⟹ integer?

    (compare el1 el2) ⟹ integer?

    (empty? seq) ⟹ boolean?

    (head seq) ⟹ *

    (tail seq) ⟹ *

    Compare two sequences x and y, using compare for comparing elements. The result is an exact integer in { - 1, 0, 1}. If compare is not supplied, default-compare is used.

    The procedure named access-compare-as-order accesses the objects like access and compares them with respect to the order given by order. The names type-compare are abbreviations for type-compare-as-type.

    (srfi 67) procedure (pair-compare-car (compare procedure?)) ⟹ procedure?

    (compare x y) ⟹ integer?

    (return (p1 pair?) (p2 pair?)) ⟹ integer?

    (srfi 67) procedure (pair-compare-cdr (compare procedure?)) ⟹ procedure?

    (compare x y) ⟹ integer?

    (return (p1 pair?) (p2 pair?)) ⟹ integer?

    Construct a compare procedure on pairs which only uses the car (only the cdr, respectively), and ignores the other.

    (srfi 67) procedure (pair-compare (compare-car procedure?) (compare-cdr procedure?) (pair1 pair?) (pair2 pair?)) ⟹ integer?

    (srfi 67) procedure (pair-compare obj1 obj2) ⟹ integer?

    (srfi 67) procedure (pair-compare (compare procedure?) obj1 obj2) ⟹ integer?

    (compare x y) ⟹ integer?

    The 4-ary form compares two pairs pair1 pair2 by comparing their cars using compare-car, and if the cars are equal the cdrs are compared using compare-cdr.

    The 3-ary form compares two objects by type using the ordering of types

    null < pair < neither-null-nor-pair.

    Two objects of type neither-null-nor-pair are compared using compare. Two pairs are compared by using compare on the cars, and if the cars are equal by recursing on the cdrs.

    The 2-ary form uses default-compare for compare.

    (srfi 67) procedure (default-compare obj1 obj2) ⟹ integer?

    compares its arguments by type using the ordering

    null < pair < boolean < char < string < symbol < number < vector < other

    Two objects of the same type type are compared as type-compare would, if there is such a procedure. The type null consists of the empty list '(). The effect of comparing two other objects or of comparing cyclic structures (made from lists or vectors) is unspecified. (Implementations are encouraged to add comparisons for other built-in types, e.g. records, regexps, etc.)

    (srfi 67) syntax (refine-compare compare-expression ...)⟹ return

    compare-expression ⟹ integer?

    The arguments <compare-expression> ...are evaluated from left to right until a non-zero value is found (which then is the value) or until there are no more arguments to evaluate (in which case the value is 0). It is allowed that there are no arguments at all.

    (srfi 67) syntax (select-compare x y (type? c1 ...) ...)⟹ return

    (srfi 67) syntax (select-compare x y (type? c1 ...) ... (else c1 ...))⟹ return

    c ⟹ integer?

    type? ⟹ procedure?

    Select-compare is a conditional for defining hierarchical extensions and refinements of compare procedures (refer to Section 5). It compares the values of <x1> and <x2> by trying the type tests in order, and applies an implict refine-compare on the consequences upon a match.

    In more detail, evaluation proceeds as follows: First <x1> and <x2> are evaluated in unspecified order, resulting in values x1 and x2, respectively. Then the clauses are evaluated one by one, from left to right.

    For clause (<type?> <c1> ...), first <type?> is evaluated resulting in a predicate procedure type? and then the expressions (type? x1) and (type? x2) are evaluated and interpreted as booleans. If both booleans are true then the overall value is (refine-compare <c1> ...). If only the first is true the result is -1, if only the second is true the result is 1, and if neither is true the next clause is considered. An else clause is treated as if both tests where true. If there are no clauses left, the result is 0.

    Select-compare evaluates <x1> and <x2> exactly once, even in the absence of any clauses. Moreover, each <type?> is evaluated at most once and the resulting procedure type? is called at most twice.

    (srfi 67) syntax (cond-compare x y ((t1 t2) c1 ...) ...)⟹ return

    (srfi 67) syntax (cond-compare x y ((t1 t2) c1 ...) ... (else c1 ...))⟹ return

    t ⟹ boolean?

    c ⟹ integer?

    type? ⟹ procedure?

    Cond-compare is another conditional for defining hierarchical extensions and refinements of compare procedures (refer to Section 5).

    Evaluation proceeds as follows: The clauses are evaluated one by one, from left to right. For clause ((<t1> <t2>) <c1> ...), first <t1> and <t2> are evaluated and the results are interpreted as boolean values. If both booleans are true then the overall value is (refine-compare <c1> ...). If only the first is true the result is -1, if only the second is true the result is 1, and if neither is true the next clause is considered. An else clause is treated as if both booleans where true. If there are no clauses left (or there are no clauses to begin with), the result is 0.

    Cond-compare evaluates each expression at most once.

    (srfi 67) syntax (if3 c less equal greater)

    c ⟹ integer?

    If3 is the 3-way conditional for comparisons. First <c> is evaluated, resulting in value c. The value c must be an exact integer in { - 1, 0, 1}, otherwise an error is signalled. If c = - 1 then the value of the if3-expression is obtained by evaluating <less>. If c = 0 then <equal> is evaluated. If c = 1 then <greater> is evaluated.

    (srfi 67) syntax (if=? c consequent)

    (srfi 67) syntax (if=? c consequent alternate)

    c ⟹ integer?

    (srfi 67) syntax (if<? c consequent)

    (srfi 67) syntax (if<? c consequent alternate)

    c ⟹ integer?

    (srfi 67) syntax (if>? c consequent)

    (srfi 67) syntax (if>? c consequent alternate)

    c ⟹ integer?

    (srfi 67) syntax (if<=? c consequent)

    (srfi 67) syntax (if<=? c consequent alternate)

    c ⟹ integer?

    (srfi 67) syntax (if>=? c consequent)

    (srfi 67) syntax (if>=? c consequent alternate)

    c ⟹ integer?

    (srfi 67) syntax (if-not=? c consequent)

    (srfi 67) syntax (if-not=? c consequent alternate)

    c ⟹ integer?

    These six macros are 2-way conditionals for comparisons. First <c> is evaluated, resulting in value c. The value c must be an exact integer in { - 1, 0, 1}, otherwise an error is signalled. Then, depending on the value of c and the name of the macro, either <consequence> or <alternate> is evaluated, and the resulting value is the value of the conditional expression.

    The branch is chosen according to the following table:

    <consequent> <alternate>

    if=? c = 0 c: { - 1, 1}

    if<? c = -1 c: {0, 1}

    if>? c = 1 c: { - 1, 0}

    if<=? c: { - 1, 0} c = 1

    if>=? c: {0, 1} c = -1

    if-not=? c: { - 1, 1} c = 0

    Note: The macros if<=? etc. are the preferred way of 2-way branching based on the result of a comparison.

    (srfi 67) procedure (=? ) ⟹ procedure?

    (srfi 67) procedure (=? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (=? x y) ⟹ boolean?

    (srfi 67) procedure (=? (compare procedure?) x y) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (<? ) ⟹ procedure?

    (srfi 67) procedure (<? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (<? x y) ⟹ boolean?

    (srfi 67) procedure (<? (compare procedure?) x y) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (>? ) ⟹ procedure?

    (srfi 67) procedure (>? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (>? x y) ⟹ boolean?

    (srfi 67) procedure (>? (compare procedure?) x y) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (<=? ) ⟹ procedure?

    (srfi 67) procedure (<=? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (<=? x y) ⟹ boolean?

    (srfi 67) procedure (<=? (compare procedure?) x y) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (>=? ) ⟹ procedure?

    (srfi 67) procedure (>=? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (>=? x y) ⟹ boolean?

    (srfi 67) procedure (>=? (compare procedure?) x y) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (not=? ) ⟹ procedure?

    (srfi 67) procedure (not=? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (not=? x y) ⟹ boolean?

    (srfi 67) procedure (not=? (compare procedure?) x y) ⟹ boolean?

    (compare x y) ⟹ integer?

    If the values x and y are given, test if x and y are in the relation specified by the name of the procedure rel?, with respect to compare procedure compare; otherwise construct a predicate procedure.

    In the forms (rel? [ compare ] x y), the result is a boolean (either #t or #f) depending on (compare x y) and the test rel? as specified for if<? etc. If compare is not supplied, default-compare is used.

    In the form (rel? [ compare ]), the predicate procedure (lambda (x y) (rel? compare x y)) is constructed. Again, if compare is not supplied, default-compare is used.

    (srfi 67) procedure (</<? ) ⟹ procedure?

    (srfi 67) procedure (</<? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (</<? x y z) ⟹ boolean?

    (srfi 67) procedure (</<? (compare procedure?) x y z) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (</<=? ) ⟹ procedure?

    (srfi 67) procedure (</<=? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (</<=? x y z) ⟹ boolean?

    (srfi 67) procedure (</<=? (compare procedure?) x y z) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (<=/<? ) ⟹ procedure?

    (srfi 67) procedure (<=/<? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (<=/<? x y z) ⟹ boolean?

    (srfi 67) procedure (<=/<? (compare procedure?) x y z) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (<=/<=? ) ⟹ procedure?

    (srfi 67) procedure (<=/<=? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (<=/<=? x y z) ⟹ boolean?

    (srfi 67) procedure (<=/<=? (compare procedure?) x y z) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (>/>? ) ⟹ procedure?

    (srfi 67) procedure (>/>? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (>/>? x y z) ⟹ boolean?

    (srfi 67) procedure (>/>? (compare procedure?) x y z) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (>/>=? ) ⟹ procedure?

    (srfi 67) procedure (>/>=? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (>/>=? x y z) ⟹ boolean?

    (srfi 67) procedure (>/>=? (compare procedure?) x y z) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (>=/>? ) ⟹ procedure?

    (srfi 67) procedure (>=/>? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (>=/>? x y z) ⟹ boolean?

    (srfi 67) procedure (>=/>? (compare procedure?) x y z) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (>=/>=? ) ⟹ procedure?

    (srfi 67) procedure (>=/>=? (compare procedure?)) ⟹ procedure?

    (srfi 67) procedure (>=/>=? x y z) ⟹ boolean?

    (srfi 67) procedure (>=/>=? (compare procedure?) x y z) ⟹ boolean?

    (compare x y) ⟹ integer?

    Test if x, y, and z form a chain with the two relations specified by the name of the procedure rel1/rel2?, with respect to the compare procedure compare.

    If compare is not provided, default-compare is used. If x y z are not provided, a predicate procedure of three arguments is constructed. The order in which the values are compared is unspecified, but each value is compared at least once.

    (srfi 67) procedure (chain=? (compare procedure?) x1 ...) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (chain<? (compare procedure?) x1 ...) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (chain>? (compare procedure?) x1 ...) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (chain<=? (compare procedure?) x1 ...) ⟹ boolean?

    (compare x y) ⟹ integer?

    (srfi 67) procedure (chain>=? (compare procedure?) x1 ...) ⟹ boolean?

    (compare x y) ⟹ integer?

    Test if the values x1 ...(zero or more values) form a chain with respect to the relation specified by the name of the procedure, and with respect to the compare procedure compare. The result is a boolean (either #t or #f.) The order in which the values are compared is unspecified, but each value is compared at least once (even if there is just one.)

    A sequence of values x1, ..., xn forms a chain with respect to the relation rel? if (rel? compare xi xj) for all 1 <= i < j <= n. In particular, this is the case for n: {0,1}.

    Since the relations = , <, >, <=, and >= are transitive, it is sufficient to test (rel? compare xi xi+1) for 1 < i < n.

    (srfi 67) procedure (pairwise-not=? (compare procedure?) x1 ...) ⟹ boolean?

    (compare x y) ⟹ integer?

    Tests if the values x1 ...(zero or more values) are pairwise unequal with respect to the compare procedure compare. The result is a boolean (either #t or #f). The order in which the values are compared is unspecified, but each value is compared at least once (even if there is just one).

    The values x1, ..., xn are pairwise unequal if (not=? compare xi xj) for all i != j. In particular, this is the case for n: {0,1}.

    Since compare defines a total ordering on the values, the property can be checked in time O(n log n), and implementations are required to do this. (For example by first sorting and then comparing adjacent elements).

    (srfi 67) procedure (min-compare (compare procedure?) x1 x2 ...) ⟹ *

    (compare x y) ⟹ integer?

    (srfi 67) procedure (max-compare (compare procedure?) x1 x2 ...) ⟹ *

    (compare x y) ⟹ integer?

    A minimum or maximum of the values x1 x2 ...(one or more values) with respect to the compare procedure compare.

    The result is the first value that is minimal (maximal, respectively). The order in which the values are compared is unspecified, but each value is compared at least once (even if there is just one value).

    (srfi 67) procedure (kth-largest (compare procedure?) (k integer?) x1 x2 ...) ⟹ *

    (compare x y) ⟹ integer?

    The k-th largest element of values x0 x1 ...(one or more values) with respect to the compare procedure compare.

    More precisely, (kth-largest compare k x0 ... xn-1) returns the (modulo k n)-th element of the unique sequence obtained by stably sorting (x0 ··· xn-1). (Recall that a sorting algorithm is stable if it does not permute items with equal key, i.e. equivalent w.r.t. compare).

    The argument k is an exact integer, and n >= 1. The order in which the values xi are compared is unspecified, but each value is compared at least once (even if there is just one value).

    (srfi 67) procedure (compare-by< (lt-pred procedure?)) ⟹ procedure?

    (srfi 67) procedure (compare-by< (lt-pred procedure?) x y) ⟹ integer?

    (lt-pred x y) ⟹ boolean?

    (srfi 67) procedure (compare-by> (gt-pred procedure?)) ⟹ procedure?

    (srfi 67) procedure (compare-by> (gt-pred procedure?) x y) ⟹ integer?

    (gt-pred x y) ⟹ boolean?

    (srfi 67) procedure (compare-by<= (le-pred procedure?)) ⟹ procedure?

    (srfi 67) procedure (compare-by<= (le-pred procedure?) x y) ⟹ integer?

    (le-pred x y) ⟹ boolean?

    (srfi 67) procedure (compare-by>= (ge-pred procedure?)) ⟹ procedure?

    (srfi 67) procedure (compare-by>= (ge-pred procedure?) x y) ⟹ integer?

    (ge-pred x y) ⟹ boolean?

    (srfi 67) procedure (compare-by=/< (eq-pred procedure?) (lt-pred procedure?)) ⟹ procedure?

    (srfi 67) procedure (compare-by=/< (eq-pred procedure?) (lt-pred procedure?) x y) ⟹ integer?

    (eq-pred x y) ⟹ boolean?

    (lt-pred x y) ⟹ boolean?

    (srfi 67) procedure (compare-by=/> (eq-pred procedure?) (gt-pred procedure?)) ⟹ procedure?

    (eq-pred x y) ⟹ boolean?

    (gt-pred x y) ⟹ boolean?

    (return x y) ⟹ integer?

    (srfi 67) procedure (compare-by=/< (eq-pred procedure?) (gt-pred procedure?) x y) ⟹ integer?

    (eq-pred x y) ⟹ boolean?

    (gt-pred x y) ⟹ boolean?

    If optional arguments x and y are present then these are compared with respect to the total order defined by the predicate(s) given; the result is in { -1, 0, 1 }. If x and y are not present then a procedure comparing its two arguments using the predicate(s) given is constructed and returned.

    The predicate procedures mean the following: (lt-pred x y) tests if x < y, le-pred tests for <=, gt-pred for >, ge-pred for >=, and eq-pred tests if x and y are equivalent. The result returned by a predicate procedure is interpreted as a Scheme truth value (i.e. #f is false and non-#f is true).

    The purpose of the procedures compare-bypredicate(s) is to define a compare procedure from an order predicate, and possibly an additional equivalence predicate. If an equivalence predicate eq-pred is given, it is called before the order predicate because the equivalence may be coarser than the total ordering, and it may also be cheaper.

    (srfi 67) procedure (debug-compare (compare procedure?)) ⟹ procedure?

    (compare x y) ⟹ integer?

    (return x y) ⟹ integer?

    Constructs a compare procedure equivalent to compare but with debugging code wrapped around the calls to compare. The debugging code signals an error if it detects a violation of the axioms of a compare function. For this it is assumed that compare has no side-effects.

    More specifically, (debug-compare compare) evaluates to a compare procedure compare1 which checks reflexivity, antisymmetry, and transitivity of compare based on the arguments on which compare1 is called:

    The procedure compare1 checks reflexivity on any value passed to compare, antisymmetry on any pair of values on which compare is called, and transitivity on triples where two of the arguments are from the current call to compare1 and the third is a pseudo-random selection from the two arguments of the previous call to compare1.

    library (srfi 69) Basic hash tables

    This SRFI defines basic hash tables. Hash tables are widely recognised as a fundamental data structure for a wide variety of applications. A hash table is a data structure that:

    1. provides a mapping from some set of keys to some set of values associated to those keys
    2. has no intrinsic order for the (key, value) associations it contains
    3. supports in-place modification as the primary means of setting the contents of a hash table
    4. provides key lookup and destructive update in amortised constant time, provided that a good hash function is used.

    This SRFI aims to accomplish these goals:

    1. to provide a consistent, generic and widely applicable API for hash tables
    2. to improve code portability by providing a standard hash table facility with guaranteed behaviour
    3. to help the programmer by defining utility routines that account for the most common situations of using hash tables.

    (srfi 69) procedure (make-hash-table (equality-predicate procedure?) arg ...) ⟹ hash-table?

    (srfi 69) procedure (make-hash-table (equality-predicate procedure?) (hash-function procedure?) arg ...) ⟹ hash-table?

    (equality-predicate a b) ⟹ boolean?

    (hash-function obj) ⟹ integer?

    Create a new hash table with no associations. equal? is a predicate that should accept two keys and return a boolean telling whether they denote the same key value; it defaults to equal?.

    hash is a hash function, and defaults to an appropriate hash function for the given equal? predicate (see section Hashing). However, an acceptable default is not guaranteed to be given for any equivalence predicate coarser than equal?, except for string-ci=?.[1] The function hash must be acceptable for equal?, so if you use coarser equivalence than equal? other than string-ci=?, you must always provide the function hash yourself.

    [1] An equivalence predicate c1 is coarser than a equivalence predicate c2 iff there exist values x and y such that (and (c1 x y) (not (c2 x y))).

    (srfi 69) procedure (hash-table? obj) ⟹ boolean?

    A predicate to test whether a given object obj is a hash table. The hash table type should be disjoint from all other types, if possible.

    (srfi 69) procedure (alist->hash-table (alist list?) (comparator comparator?) arg ...) ⟹ hash-table?

    alist ⟹ (alist key : value)

    Takes an "association list" alist and creates a hash table hash-table which maps the car of every element in alist to the cdr of corresponding elements in alist. equal?, hash, and args are interpreted as in make-hash-table. If some key occurs multiple times in alist, the value in the first association will take precedence over later ones. (Note: the choice of using cdr (instead of cadr) for values tries to strike balance between the two approaches: using cadr would render this procedure unusable for cdr alists, but not vice versa.)

    (srfi 69) procedure (hash-table-equivalence-function (hash-table hash-table?)) ⟹ procedure?

    (return a b) ⟹ boolean?

    Returns the equivalence predicate used for keys of hash-table.

    (srfi 69) procedure (hash-table-hash-function (hash-table hash-table?)) ⟹ procedure?

    (return obj) ⟹ integer?

    Returns the hash function used for keys of hash-table.

    (srfi 69) procedure (hash-table-ref (hash-table hash-table?) key) ⟹ *

    (srfi 69) procedure (hash-table-ref (hash-table hash-table?) key (failure procedure?)) ⟹ *

    (failure) ⟹ *

    This procedure returns the value associated to key in hash-table. If no value is associated to key and thunk is given, it is called with no arguments and its value is returned; if thunk is not given, an error is signalled. Given a good hash function, this operation should have an (amortised) complexity of O(1) with respect to the number of associations in hash-table. (Note: this rules out implementation by association lists or fixed-length hash tables.)

    (srfi 69) procedure (hash-table-ref/default (hash-table hash-table?) key default) ⟹ *

    Evaluates to the same value as (hash-table-ref hash-table key (lambda () default)). Given a good hash function, this operation should have an (amortised) complexity of O(1) with respect to the number of associations in hash-table. (Note: this rules out implementation by association lists or fixed-length hash tables.)

    (srfi 69) procedure (hash-table-set! (hash-table hash-table?) key1 value1 ...) ⟹ undefined

    This procedure sets the value associated to key in hash-table. The previous association (if any) is removed. Given a good hash function, this operation should have an (amortised) complexity of O(1) with respect to the number of associations in hash-table. (Note: this rules out implementation by association lists or fixed-length hash tables.)

    (srfi 69) procedure (hash-table-delete! (hash-table hash-table?) key ...) ⟹ undefined

    This procedure removes any association to key in hash-table. It is not an error if no association for that key exists; in this case, nothing is done. Given a good hash function, this operation should have an (amortised) complexity of O(1) with respect to the number of associations in hash-table. (Note: this rules out implementation by association lists or fixed-length hash tables.)

    (srfi 69) procedure (hash-table-exists? (hash-table hash-table?) key) ⟹ boolean?

    This predicate tells whether there is any association to key in hash-table. Given a good hash function, this operation should have an (amortised) complexity of O(1) with respect to the number of associations in hash-table. (Note: this rules out implementation by association lists or fixed-length hash tables.)

    (srfi 69) procedure (hash-table-update! (hash-table hash-table?) key (updater procedure?)) ⟹ undefined

    (srfi 69) procedure (hash-table-update! (hash-table hash-table?) key (updater procedure?) (failure procedure?)) ⟹ undefined

    (updater value) ⟹ *

    (failure) ⟹ *

    Semantically equivalent to, but may be implemented more efficiently than, the following code:

    (hash-table-set! hash-table key

    (updater (hash-table-ref hash-table key thunk)))

    (srfi 69) procedure (hash-table-update!/default (hash-table hash-table?) key (updater procedure?) default) ⟹ undefined

    (updater value) ⟹ *

    (failure) ⟹ *

    Behaves as if it evaluates to (hash-table-update! hash-table key updater (lambda () default))

    (srfi 69) procedure (hash-table-size (hash-table hash-table?)) ⟹ integer?

    Returns the number of associations in hash-table. This operation must have a complexity of O(1) with respect to the number of associations in hash-table.

    (srfi 69) procedure (hash-table-keys (hash-table hash-table?)) ⟹ list?

    Returns a list of keys in hash-table. The order of the keys is unspecified.

    (srfi 69) procedure (hash-table-values (hash-table hash-table?)) ⟹ list?

    Returns a list of values in hash-table. The order of the values is unspecified, and is not guaranteed to match the order of keys in the result of hash-table-keys.

    (srfi 69) procedure (hash-table-walk (hash-table hash-table?) (proc procedure?)) ⟹ undefined

    (proc key value) ⟹ undefined

    proc should be a function taking two arguments, a key and a value. This procedure calls proc for each association in hash-table, giving the key of the association as key and the value of the association as value. The results of proc are discarded. The order in which proc is called for the different associations is unspecified.

    (Note: in some implementations, there is a procedure called hash-table-map which does the same as this procedure. However, in other implementations, hash-table-map does something else. In no implementation that I know of, hash-table-map does a real functorial map that lifts an ordinary function to the domain of hash tables. Because of these reasons, hash-table-map is left outside this SRFI.)

    (srfi 69) procedure (hash-table-fold (hash-table hash-table?) (f procedure?) seed) ⟹ *

    (f key value state) ⟹ *

    This procedure calls f for every association in hash-table with three arguments: the key of the association key, the value of the association value, and an "accumulated value", val. val is init-value for the first invocation of f, and for subsequent invocations of f, the return value of the previous invocation of f. The value final-value returned by hash-table-fold is the return value of the last invocation of f. The order in which f is called for different associations is unspecified.

    (srfi 69) procedure (hash-table->alist (hash-table hash-table?)) ⟹ list?

    return ⟹ (alist key : value)

    Returns an association list such that the car of each element in alist is a key in hash-table and the corresponding cdr of each element in alist is the value associated to the key in hash-table. The order of the elements is unspecified.

    (srfi 69) procedure (hash-table-copy (hash-table hash-table?)) ⟹ hash-table?

    Returns a new hash table with the same equivalence predicate, hash function and mappings as in hash-table.

    (srfi 69) procedure (hash-table-merge! (hash-table1 hash-table?) (hash-table2 hash-table?)) ⟹ hash-table?

    Adds all mappings in hash-table2 into hash-table1 and returns the resulting hash table. This function may modify hash-table1 destructively.

    (srfi 69) procedure (hash obj) ⟹ integer?

    (srfi 69) procedure (hash obj arg) ⟹ integer?

    Produces a hash value for object in the range ( 0, bound (. If bound is not given, the implementation is free to choose any bound, given that the default bound is greater than the size of any imaginable hash table in a normal application. (This is so that the implementation may choose some very big value in fixnum range for the default bound.) This hash function is acceptable for equal?.

    (srfi 69) procedure (string-hash (str string?)) ⟹ integer?

    (srfi 69) procedure (string-hash (str string?) arg) ⟹ integer?

    The same as hash, except that the argument string must be a string.

    (srfi 69) procedure (string-ci-hash (str string?)) ⟹ integer?

    (srfi 69) procedure (string-ci-hash (str string?) arg) ⟹ integer?

    The same as string-hash, except that the case of characters in string does not affect the hash value produced.

    (srfi 69) procedure (hash-by-identity obj) ⟹ integer?

    (srfi 69) procedure (hash-by-identity obj arg) ⟹ integer?

    The same as hash, except that this function is only guaranteed to be acceptable for eq?. The reason for providing this function is that it might be implemented significantly more efficiently than hash. Implementations are encouraged to provide this function as a builtin.

    library (srfi 70) Numbers

    This SRFI proposes text to replace section 6.2 "Numbers" of R5RS in order to extend its capabilities, correct errors in its specification, make it more explicit about limitations of precision and magnitude, and improve portability between implementations. More specifically, this new text:

    • incorporates an inexact real positive infinity and an inexact real negative infinity,
    • extends number syntax to incorporate inexact real infinities,
    • adapts Common-Lisp semantics for `expt' and extends them to include inexact real infinities,
    • corrects the description of `sqrt',
    • sharpens the distinction between exact and inexact numbers,
    • removes a contradiction related to exactness,
    • extends `gcd' and `lcm' to exact rational numbers,
    • extends `quotient', `modulo', and `remainder' to finite real numbers,
    • clarifies the behavior of `inexact->exact' applied to an exact argument,
    • clarifies the behavior of `exact->inexact' applied to an inexact argument,
    • adds convenience procedures `exact-round', `exact-ceiling', `exact-floor', and `exact-truncate',
    • and adds examples.

    (srfi 70) procedure (exact-floor (x real?)) ⟹ integer?

    (srfi 70) procedure (exact-ceiling (x real?)) ⟹ integer?

    (srfi 70) procedure (exact-truncate (x real?)) ⟹ integer?

    (srfi 70) procedure (exact-round (x real?)) ⟹ integer?

    These procedures are the compositions of `inexact->exact' with `floor', `ceiling', `truncate', and `round'.

    library (srfi 71) Extended LET-syntax for multiple values

    This SRFI is a proposal for extending let, let*, and letrec for receiving multiple values. The syntactic extension is fully compatible with the existing syntax. It is the intention that single-value bindings, i.e. (let ((var expr)) ...), and multiple-value binding can be mixed freely and conveniently.

    The most simple form of the new syntax is best explained by an example:

    (define (quo-rem x y)
      (values (quotient x y) (remainder x y)))
    
    (define (quo x y)
      (let ((q r (quo-rem x y)))
        q))
    

    The procedure quo-rem delivers two values to its continuation. These values are received as q and r in the let-expression of the procedure quo. In other words, the syntax of let is extended such that several variables can be specified---and these variables receive the values delivered by the expression (quo-rem x y).

    The syntax of let is further extended to cases in which a rest argument receives the list of all residual values. Again by example,

    (let (((values y1 y2 . y3+) (foo x)))
       body)
    
    In this example, values is a syntactic keyword indicating the presence of multiple values to be received, and y1, y2, and y3+, resp., are variables bound to the first value, the second value, and the list of the remaining values, resp., as produced by (foo x). The syntactic keyword values allows receiving all values as in (let (((values . xs) (foo x))) body). It also allows receiving no values at all as in (let (((values) (for-each foo list))) body).

    A common application of binding multiple values is decomposing data structures into their components. This mechanism is illustrated in its most primitive form as follows: The procedure uncons (defined below) decomposes a pair x into its car and its cdr and delivers them as two values to its continuation. Then an extended let can receive these values:

    (let ((car-x cdr-x (uncons x)))
      (foo car-x cdr-x))
    

    Of course, for pairs this method is probably neither faster nor clearer than using the procedures car and cdr. However, for data structures doing substantial work upon decomposition this is different: Extracting the element of highest priority from a priority queue, while at the same time constructing the residual queue, can both be more efficient and more convenient than doing both operations independently. In fact, the quo-rem example illustrates this point already as both quotient and remainder are probably computed by a common exact division algorithm. (And often caching is used to avoid executing this algorithm twice as often as needed.)

    As the last feature of this SRFI, a mechanism is specified to store multiple values in heap-allocated data structures. For this purpose, values->list and values->vector construct a list (a vector, resp.) storing all values delivered by evaluating their argument expression. Note that these operations cannot be procedures.

    (srfi 71) syntax (let (binding-spec ...) body)

    (srfi 71) syntax (let name (binding-spec ...) body)

    binding-spec ⟹ (var1 var2 ... expression) | ((values var ...) expression) | ((values var ... . var-rest) expression)

    (srfi 71) syntax (let* (binding-spec ...) body)

    binding-spec ⟹ (var1 var2 ... expression) | ((values var ...) expression) | ((values var ... . var-rest) expression)

    (srfi 71) syntax (letrec (binding-spec ...) body)

    binding-spec ⟹ (var1 var2 ... expression) | ((values var ...) expression) | ((values var ... . var-rest) expression)

    The syntax of Scheme (R5RS, Section 7.1.3.) is extended by replacing the existing production:

    <binding spec> --> (<variable> <expression>)

    by the three new productions

    <binding spec> --> ((values <variable>*) <expression>)

    <binding spec> --> ((values <variable>* . <variable>) <expression>)

    <binding spec> --> (<variable>+ <expression>)

    The form (<variable>+ <expression>) is just an abbreviation for ((values <variable>+) <expression>), and it includes the original <binding spec> of R5RS.

    The first two forms are evaluated as follows: The variables are bound and the expression is evaluated according to the enclosing construct (either let, let*, or letrec.) However, the expression may deliver any number of values to its continuation, which stores these values into the variables specified, possibly allocating a rest list in case of the . <variable> form.

    The number of values delivered by the expression must match the number of values expected by the binding specification. Otherwise an error is raised, as call-with-values would. This implies in particular, that each binding of a named let involves exactly one value, because this binding can also be an argument to a lambda-expression.

    (srfi 71) procedure (uncons (pair pair?)) ⟹ (values * *)

    (srfi 71) procedure (uncons-2 (lst list?)) ⟹ (values * * *)

    (srfi 71) procedure (uncons-3 (lst list?)) ⟹ (values * * * *)

    (srfi 71) procedure (uncons-4 (lst list?)) ⟹ (values * * * * *)

    (srfi 71) procedure (uncons-cons (alist list?)) ⟹ (values * * *)

    (srfi 71) procedure (unlist (lst list?)) ⟹ (values * ...)

    (srfi 71) procedure (unvector (vec vector?)) ⟹ (values * ...)

    The following procedures, specified in terms of standard procedures, are added to the set of standard procedures:

    (define (uncons pair)

    (values (car pair) (cdr pair)))

    (define (uncons-2 list)

    (values (car list) (cadr list) (cddr list)))

    (define (uncons-3 list)

    (values (car list) (cadr list) (caddr list) (cdddr list)))

    (define (uncons-4 list)

    (values (car list) (cadr list) (caddr list) (cadddr list) (cddddr list)))

    (define (uncons-cons alist)

    (values (caar alist) (cdar alist) (cdr alist)))

    (define (unlist list)

    (apply values list))

    (define (unvector vector)

    (apply values (vector->list vector)))

    These procedures decompose the standard concrete data structures (pair, list, vector) and deliver the components as values. It is an error if the argument cannot be decomposed as expected. Note that the procedures are not necessarily implemented by the definition given above.

    The preferred way of decomposing a list into the first two elements and the rest list is (let ((x1 x2 x3+ (uncons-2 x))) body), and similar for three or four elements and a rest. This is not equivalent to (let (((values x1 x2 . x3+) (unlist x))) body) because the latter binds x3+ to a newly allocated copy of (cddr x).

    (srfi 71) syntax (values->list expression)⟹ return

    (srfi 71) syntax (values->vector expression)⟹ return

    These operation receive all values (if any) delivered by their argument expression and return a newly allocated list (vector, resp.) of these values. Note that values->list is not the same as list (the procedure returning the list of its arguments).

    library (srfi 74) Octet-Addressed Binary Blocks

    This SRFI defines a set of procedures for creating, accessing, and manipulating octet-addressed blocks of binary data, in short, blobs. The SRFI provides access primitives for fixed-length integers of arbitrary size, with specified endianness, and a choice of unsigned and two's complement representations.

    (srfi 74) syntax (endianness big)⟹ return

    (srfi 74) syntax (endianness little)⟹ return

    (srfi 74) syntax (endianness native)⟹ return

    (endianness big) and (endianness little) evaluate to two distinct and unique objects representing an endianness. The native endianness evaluates to the endianness of the underlying machine architecture, and must be eq? to either (endianness big) or (endianness little).

    (srfi 74) procedure (blob? obj) ⟹ boolean?

    Returns #t if obj is a blob, otherwise returns #f.

    (srfi 74) procedure (make-blob (octet-count integer?)) ⟹ blob?

    Returns a newly allocated blob of k octets, all of them 0.

    (srfi 74) procedure (blob-length (blob blob?)) ⟹ integer?

    Returns the number of octets in blob as an exact integer.

    (srfi 74) procedure (blob-u8-ref (blob blob?) (k integer?)) ⟹ integer?

    Blob-u8-ref returns the octet at index k of blob.

    (srfi 74) procedure (blob-s8-ref (blob blob?) (k integer?)) ⟹ integer?

    Blob-s8-ref returns the exact integer corresponding to the two's complement representation at index k of blob.

    (srfi 74) procedure (blob-u8-set! (blob blob?) (k integer?) (octet integer?)) ⟹ undefined

    Blob-u8-set! stores octet in element k of blob.

    (srfi 74) procedure (blob-s8-set! (blob blob?) (k integer?) (byte integer?)) ⟹ undefined

    Blob-u8-set! stores the two's complement representation of byte in element k of blob.

    (srfi 74) procedure (blob-uint-ref (size integer?) (endianness endianness) (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-sint-ref (size integer?) (endianness endianness) (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-uint-set! (size integer?) (endianness endianness) (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    (srfi 74) procedure (blob-sint-set! (size integer?) (endianness endianness) (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    Size must be a positive exact integer. K must be a valid index of blob; so must the indices {k, ..., k + size - 1}. Endianness must be an endianness object.

    Blob-uint-ref retrieves the exact integer corresponding to the unsigned representation of size size and specified by endianness at indices {k, ..., k + size - 1}.

    Blob-sint-ref retrieves the exact integer corresponding to the two's complement representation of size size and specified by endianness at indices {k, ..., k + size - 1}.

    For blob-uint-set!, n must be an exact integer in the interval [0, (256^size)-1]. Blob-uint-set! stores the unsigned representation of size size and specified by endianness into the blob at indices {k, ..., k + size - 1}.

    For blob-uint-set!, n must be an exact integer in the interval [-256^(size-1), (256^(size-1))-1]. Blob-sint-set! stores the two's complement representation of size size and specified by endianness into the blob at indices {k, ..., k + size - 1}.

    (srfi 74) procedure (blob-u16-ref (endianness endianness) (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-s16-ref (endianness endianness) (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-u16-native-ref (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-s16-native-ref (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-u16-set! (endianness endianness) (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    (srfi 74) procedure (blob-s16-set! (endianness endianness) (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    (srfi 74) procedure (blob-u16-native-set! (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    (srfi 74) procedure (blob-s16-native-set! (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    K must be a valid index of blob; so must the index k+ 1. Endianness must be an endianness object.

    These retrieve and set two-octet representations of numbers at indices k and k+1, according to the endianness specified by endianness. The procedures with u16 in their names deal with the unsigned representation, those with s16 with the two's complement representation.

    The procedures with native in their names employ the native endianness, and only work at aligned indices: k must be a multiple of 2. It is an error to use them at non-aligned indices.

    (srfi 74) procedure (blob-u32-ref (endianness endianness) (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-s32-ref (endianness endianness) (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-u32-native-ref (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-s32-native-ref (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-u32-set! (endianness endianness) (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    (srfi 74) procedure (blob-s32-set! (endianness endianness) (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    (srfi 74) procedure (blob-u32-native-set! (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    (srfi 74) procedure (blob-s32-native-set! (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    K must be a valid index of blob; so must the indices {k, ..., k+ 3}. Endianness must be an endianness object.

    These retrieve and set four-octet representations of numbers at indices {k, ..., k+ 3}, according to the endianness specified by endianness. The procedures with u32 in their names deal with the unsigned representation, those with s32 with the two's complement representation.

    The procedures with native in their names employ the native endianness, and only work at aligned indices: k must be a multiple of 4. It is an error to use them at non-aligned indices.

    (srfi 74) procedure (blob-u64-ref (endianness endianness) (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-s64-ref (endianness endianness) (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-u64-native-ref (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-s64-native-ref (blob blob?) (k integer?)) ⟹ integer?

    (srfi 74) procedure (blob-u64-set! (endianness endianness) (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    (srfi 74) procedure (blob-s64-set! (endianness endianness) (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    (srfi 74) procedure (blob-u64-native-set! (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    (srfi 74) procedure (blob-s64-native-set! (blob blob?) (k integer?) (value integer?)) ⟹ undefined

    K must be a valid index of blob; so must the indices {k, ..., k+ 7}. Endianness must be an endianness object.

    These retrieve and set eight-octet representations of numbers at indices {k, ..., k+ 7}, according to the endianness specified by endianness. The procedures with u64 in their names deal with the unsigned representation, those with s64 with the two's complement representation.

    The procedures with native in their names employ the native endianness, and only work at aligned indices: k must be a multiple of 8. It is an error to use them at non-aligned indices.

    (srfi 74) procedure (blob=? (blob1 blob?) (blob2 blob?)) ⟹ boolean?

    Returns #t if blob-1 and blob-2 are equal---that is, if they have the same length and equal octets at all valid indices.

    (srfi 74) procedure (blob-copy! (source blob?) (source-start integer?) (target blob?) (target-start integer?) (n integer?)) ⟹ boolean?

    Copies data from blob source to blob target. Source-start, target-start, and n must be non-negative exact integers that satisfy

    0 <= source-start <= source-start + n <= (blob-length source)

    0 <= target-start <= target-start + n <= (blob-length target)

    This copies the octets from source at indices [source-start, source-start + n) to consecutive indices in target starting at target-index.

    This must work even if the memory regions for the source and the target overlap, i.e., the octets at the target location after the copy must be equal to the octets at the source location before the copy.

    The return values are unspecified.

    (srfi 74) procedure (blob-copy (blob blob?)) ⟹ blob?

    Returns a newly allocated copy of blob blob.

    (srfi 74) procedure (blob->u8-list (blob blob?)) ⟹ list?

    blob->u8-list returns a newly allocated list of the octets of blob in the same order.

    (srfi 74) procedure (u8-list->blob (octets list?)) ⟹ blob?

    u8-list->blob returns a newly allocated blob whose elements are the elements of list octets, which must all be octets, in the same order. Analogous to list->vector.

    (srfi 74) procedure (blob->uint-list (size integer?) (endianness endianness) (blob blob?)) ⟹ list?

    (srfi 74) procedure (blob->sint-list (size integer?) (endianness endianness) (blob blob?)) ⟹ list?

    (srfi 74) procedure (uint-list->blob (size integer?) (endianness endianness) (list list?)) ⟹ blob?

    (srfi 74) procedure (sint-list->blob (size integer?) (endianness endianness) (list list?)) ⟹ blob?

    Size must be a positive exact integer. Endianness must be an endianness object.

    These convert between lists of integers and their consecutive representations according to size and endianness in blobs in the same way as blob->u8-list, blob->s8-list, u8-list->blob, and s8-list->blob do for one-octet representations.

    library (srfi 78) Lightweight testing

    A simple mechanism is defined for testing Scheme programs. As a most primitive example, the expression

       (check (+ 1 1) => 3)
    
    evaluates the expression (+ 1 1) and compares the result with the expected result 3 provided after the syntactic keyword =>. Then the outcome of this comparison is reported in human-readable form by printing a message of the form
       (+ 1 1) => 2 ; *** failed ***
       ; expected result: 3
    
    Moreover, the outcome of any executed check is recorded in a global state counting the number of correct and failed checks and storing the first failed check. At the end of a file, or at any other point, the user can print a summary using check-report.

    In addition to the simple test above, it is also possible to execute a parametric sequence of checks. Syntactically, this takes the form of an eager comprehension in the sense of SRFI 42 [5]. For example,

       (check-ec (:range e 100)
                 (:let x (expt 2.0 e))
                 (= (+ x 1) x) => #f (e x))
    
    This statement runs the variable e through {0..99} and for each binding defines x as (expt 2.0 e). Then it is checked if (+ x 1) is equal to x, and it is expected that this is not the case (i.e. expected value is #f). The trailing (e x) tells the reporting mechanism to print the values of both e and x in case of a failed check. The output could look like this:
       (let ((e 53) (x 9007199254740992.0)) (= (+ x 1) x)) => #t ; *** failed ***
        ; expected result: #f
    
    The specification of bindings to report, (e x) in the example, is optional but very informative. Other features of this SRFI are:
    • A way to specify a different equality predicate (default is equal?).
    • Controlling the amount of reporting being printed.
    • Switching off the execution and reporting of checks entriely.
    • Retrieving a boolean if all checks have been executed and passed.

    (srfi 78) syntax (check expr (=> equal) expected)

    (srfi 78) syntax (check expr => expected)

    equal ⟹ procedure?

    Evaluates <expr> and compares the value to the value of <expected> using the predicate <equal>, which is equal? when omitted. Then a report is printed according to the current mode setting (see below) and the outcome is recorded in a global state to be used in check-report. The precise order of evaluation is that first <equal> and <expected> are evaluated (in unspecified order) and then <expr> is evaluated.

    (srfi 78) syntax (check-ec qualifier ... expr (=> equal) expected (argument ...))

    (srfi 78) syntax (check-ec qualifier ... expr => expected (argument ...))

    (srfi 78) syntax (check-ec qualifier ... expr (=> equal) expected)

    (srfi 78) syntax (check-ec qualifier ... expr => expected)

    qualifier ⟹ generator | (if test) | (not test) | (and test ...) | (or test ...) | (begin command ... expression) | (nested qualifier ...)

    equal ⟹ procedure?

    generator ⟹ generator-macro

    An eager comprehension for executing a parametric sequence of checks.

    Enumerates the sequence of bindings specified by <qualifier>*. For each binding evaluates <equal> and <expected> in unspecified order. Then evalues <expr> and compares the value obtained to the value of <expected> using the value of <equal> as predicate, which is equal? when omitted. The comprehension stops after the first failed check, if there is any. Then a report is printed according to the current mode setting (see below) and the outcome is recorded in a global state to be used in check-report. The entire check-ec counts as a single check.

    In case the check fails <argument>* is used for constructing an informative message with the argument values. Use <argument>* to list the relevant free variables of <expr> (see examples) that you want to have printed.

    A <qualifier> is any qualifier of an eager comprehension as specified in SRFI 42

    (srfi 78) procedure (check-report) ⟹ undefined

    Prints a summary and the first failed check, if there is any, depending on the current mode settings.

    (srfi 78) procedure (check-set-mode! (mode symbol?)) ⟹ undefined

    Sets the current mode to mode, which must be a symbol in '(off summary report-failed report), default is 'report. Note that you can change the mode at any time, and that check, check-ec and check-report use the current value.

    The mode symbols have the following meaning:

    off: do not execute any of the checks,

    summary: print only summary in (check-report) and nothing else,

    report-failed: report failed checks when they happen, and in summary,

    report: report every example executed.

    (srfi 78) procedure (check-reset!) ⟹ undefined

    Resets the global state (counters of correct/failed examples) to the state immediately after loading the module for the first time, i.e. no checks have been executed.

    (srfi 78) procedure (check-passed? (expected-total-count integer?)) ⟹ boolean?

    #t if there were no failed checks and expected-total-count correct checks, #f otherwise.

    Rationale: This procedure can be used in automatized tests by terminating a test program with the statement (exit (if (check-passed? n) 0 1)).

    library (srfi 87) => in case clauses

    This SRFI proposes an extension to the case syntax to allow the => clauses as in cond.

    (srfi 87) syntax (case key clause1 clause2 ...)

    clause ⟹ ((datum1 ...) expression1 expression2 ...) | ((datum1 ...) => expression) | (else expression1 expression2 ...) | (else => expression)

    A `case' expression is evaluated as follows. <Key> is evaluated and its result is compared against each <datum>. If the result of evaluating <key> is equivalent (in the sense of `eqv?'; see section see section 6.1 Equivalence predicates) to a <datum>, then the expressions in the corresponding <clause> are evaluated from left to right and the result(s) of the last expression in the <clause> is(are) returned as the result(s) of the `case' expression. If the result of evaluating <key> is different from every <datum>, then if there is an else clause its expressions are evaluated and the result(s) of the last is(are) the result(s) of the `case' expression; otherwise the result of the `case' expression is unspecified. If the selected <clause> uses the => alternate form, then the <expression> is evaluated. Its value must be a procedure that accepts one argument; this procedure is then called on the value of <Key> and the value(s) returned by this procedure is(are) returned by the `case' expression.

    library (srfi 88) Keyword objects

    This SRFI defines keyword objects, a data type similar to Scheme symbols. Keyword objects have the same lexical syntax as symbols but they must end in a colon. Moreover keyword objects are self-evaluating. Procedures for converting between strings and keyword objects (string->keyword and keyword->string) and a type predicate (keyword?) are defined. Finally this SRFI specifies the changes to the Scheme lexical syntax required to accomodate keywords.

    (srfi 88) procedure (keyword? obj) ⟹ boolean?

    Returns #t if obj is a keyword object, otherwise returns #f.

    (srfi 88) procedure (keyword->string (keyword keyword?)) ⟹ string?

    Returns the name of keyword as a string. It is an error to apply mutation procedures like string-set! to strings returned by this procedure.

    (srfi 88) procedure (string->keyword (string string?)) ⟹ keyword?

    Returns the keyword object whose name is string.

    library (srfi 95) Sorting and Merging

    Sorting and Merging are useful operations deserving a common API.

    (srfi 95) procedure (sorted? (sequence vector?) (less? procedure?)) ⟹ boolean?

    (srfi 95) procedure (sorted? (sequence vector?) (less? procedure?) (key procedure?)) ⟹ boolean?

    (srfi 95) procedure (sorted? (sequence list?) (less? procedure?)) ⟹ boolean?

    (srfi 95) procedure (sorted? (sequence list?) (less? procedure?) (key procedure?)) ⟹ boolean?

    (srfi 95) procedure (sorted? (sequence string?) (less? procedure?)) ⟹ boolean?

    (srfi 95) procedure (sorted? (sequence string?) (less? procedure?) (key procedure?)) ⟹ boolean?

    (less? x y) ⟹ boolean?

    (key obj) ⟹ *

    Returns #t when the sequence argument is in non-decreasing order according to less? (that is, there is no adjacent pair ... x y ... for which (less? y x)).

    Returns #f when the sequence contains at least one out-of-order pair. It is an error if the sequence is not a list or array (including vectors and strings).

    (srfi 95) procedure (merge (lst1 list?) (lst2 list?) (less? procedure?)) ⟹ list?

    (srfi 95) procedure (merge (lst1 list?) (lst2 list?) (less? procedure?) (key procedure?)) ⟹ list?

    (less? x y) ⟹ boolean?

    (key obj) ⟹ *

    Merges two sorted lists, returning a freshly allocated list as its result.

    (srfi 95) procedure (merge! (lst1 list?) (lst2 list?) (less? procedure?)) ⟹ list?

    (srfi 95) procedure (merge! (lst1 list?) (lst2 list?) (less? procedure?) (key procedure?)) ⟹ list?

    (less? x y) ⟹ boolean?

    (key obj) ⟹ *

    Merges two sorted lists, re-using the pairs of list1 and list2 to build the result. The result will be either list1 or list2.

    (srfi 95) procedure (sort (sequence vector?) (less? procedure?)) ⟹ vector?

    (srfi 95) procedure (sort (sequence vector?) (less? procedure?) (key procedure?)) ⟹ vector?

    (srfi 95) procedure (sort (sequence list?) (less? procedure?)) ⟹ list?

    (srfi 95) procedure (sort (sequence list?) (less? procedure?) (key procedure?)) ⟹ list?

    (srfi 95) procedure (sort (sequence string?) (less? procedure?)) ⟹ string?

    (srfi 95) procedure (sort (sequence string?) (less? procedure?) (key procedure?)) ⟹ string?

    (less? x y) ⟹ boolean?

    (key obj) ⟹ *

    Accepts a list or array (including vectors and strings) for sequence; and returns a completely new sequence which is sorted according to less?. The returned sequence is the same type as the argument sequence.

    (srfi 95) procedure (sort! (sequence vector?) (less? procedure?)) ⟹ vector?

    (srfi 95) procedure (sort! (sequence vector?) (less? procedure?) (key procedure?)) ⟹ vector?

    (srfi 95) procedure (sort! (sequence list?) (less? procedure?)) ⟹ list?

    (srfi 95) procedure (sort! (sequence list?) (less? procedure?) (key procedure?)) ⟹ list?

    (srfi 95) procedure (sort! (sequence string?) (less? procedure?)) ⟹ string?

    (srfi 95) procedure (sort! (sequence string?) (less? procedure?) (key procedure?)) ⟹ string?

    (less? x y) ⟹ boolean?

    (key obj) ⟹ *

    Returns list, array, vector, or string sequence which has been mutated to order its elements according to less?.

    library (srfi 98) An interface to access environment variables

    This SRFI specifies the procedure get-environment-variable, which gets the value of the specified environment variable, and the procedure get-environment-variables, which gets an association list of all environment variables.

    (srfi 98) procedure (getenv (name string?)) ⟹ string? | #f

    Returns the value of the named environment variable as a string, or #f if the named environment variable is not found.

    (srfi 98) procedure (getenv) ⟹ list?

    return ⟹ (alist (key string?) : (value string?))

    Returns names and values of all the environment variables as an a-list.

    library (srfi 99) ERR5RS Records

    Many Scheme programmers have considered records to be one of the most important features missing from the R5RS. The R6RS proposed a record system, but its design has been widely criticized and it was not intended for use in R5RS programs anyway.

    This SRFI proposes a better record system for use in R5RS, ERR5RS, and R6RS programs. The syntactic layer of this SRFI's record system is an extension of SRFI 9. The procedural and inspection layers of this SRFI's record system are perfectly compatible with its syntactic layer. This entire SRFI is compatible with the procedural and inspection layers of the R6RS record system, but offers several worthwhile improvements over the R6RS system.

    (srfi 99) procedure (make-rtd (name symbol?) (fieldspecs vector?)) ⟹ rtd?

    (srfi 99) procedure (make-rtd (name symbol?) (fieldspecs vector?) (parent rtd? | #f)) ⟹ rtd?

    name is a symbol, which matters only to the rtd-name procedure of the inspection layer. fieldspecs is a vector of field specifiers, where each field specifier is one of

  • a symbol naming the (mutable) field;
  • a list of the form (mutable name), where name is a symbol naming the mutable field;
  • a list of the form (immutable name), where name is a symbol naming the immutable field.
  • The optional parent is an rtd or #f. It is an error for any of the symbols in fieldspecs to name more than one of the fields specified by fieldspecs, but the field names in fieldspecs may shadow field names in the parent record-type.

    Implementations may wish to extend this procedure to support the non-generative, sealed, and/or opaque features of the R6RS. The recommended way to support those features is to allow any combination of the following arguments to follow the optional parent argument:

  • The symbol sealed means the new rtd cannot be used as the parent of other rtds.
  • The symbol opaque means the record? predicate will not recognize instances of the new rtd.
  • The symbol uid, following by another symbol id, means the new rtd is non-generative with uid id. The semantics of this extension is the same as described by the R6RS.
  • The recommendation above is not binding on implementations of SRFI 99. There are other ways to realize sealed, opaque, or non-generative rtds.

    Returns an R6RS-compatible record-type descriptor.

    (srfi 99) procedure (rtd? obj) ⟹ boolean?

    Equivalent to the record-type-descriptor? procedure of the R6RS.

    (srfi 99) procedure (rtd-constructor (rtd rtd?)) ⟹ procedure?

    (srfi 99) procedure (rtd-constructor (rtd rtd?) (fieldspec vector?)) ⟹ procedure?

    (return fieldvalue ...) ⟹ record?

    rtd is a record-type descriptor, and fieldspecs is an optional vector of symbols.

    If no fieldspecs argument is supplied, then rtd-constructor returns a procedure that expects one argument for each field of the record-type described by rtd and returns an instance of that record-type with its fields initialized to the corresponding arguments. Arguments that correspond to the fields of the record-type's parent (if any) come first.

    If fieldspecs is supplied, then rtd-constructor returns a procedure that expects one argument for each element of fieldspecs and returns an instance of the record-type described by rtd with the named fields initialized to the corresponding arguments.

    It is an error if some symbol occurs more than once in fieldspecs. Fields of a derived record-type shadow fields of the same name in its parent; the fieldspecs argument cannot be used to initialize a shadowed field.

    (srfi 99) procedure (rtd-predicate (rtd rtd?)) ⟹ procedure?

    (return obj) ⟹ boolean?

    Equivalent to the record-predicate procedure of the R6RS.

    (srfi 99) procedure (rtd-accessor (rtd rtd?) (field symbol?)) ⟹ procedure?

    (return (rec record?)) ⟹ *

    field is a symbol that names a field of the record-type described by the record-type descriptor rtd. Returns a unary procedure that accepts instances of rtd (or any record-type that inherits from rtd) and returns the current value of the named field.

    Fields in derived record-types shadow fields of the same name in a parent record-type.

    (srfi 99) procedure (rtd-mutator (rtd rtd?) (field symbol?)) ⟹ procedure?

    (return (rec record?) value) ⟹ undefined

    field is a symbol that names a field of the record-type described by the record-type descriptor rtd. Returns a binary procedure that accepts instances of rtd (or any record-type that inherits from rtd) and a new value to be stored into the named field, performs that side effect, and returns an unspecified value.

    Fields in derived record-types shadow fields of the same name in a parent record-type.

    (srfi 99) procedure (record? obj) ⟹ boolean?

    Equivalent to its R6RS namesake.

    (srfi 99) procedure (record-rtd (rec record?)) ⟹ rtd?

    Equivalent to its R6RS namesake.

    (srfi 99) procedure (rtd-name (rtd rtd?)) ⟹ symbol?

    Equivalent to the record-type-name procedure of the R6RS.

    (srfi 99) procedure (rtd-parent (rtd rtd?)) ⟹ #f | rtd?

    Equivalent to the record-type-parent procedure of the R6RS.

    (srfi 99) procedure (rtd-field-names (rtd rtd?)) ⟹ vector?

    Equivalent to the record-type-field-names procedure of the R6RS. (That is, it returns a vector of the symbols that name the fields of the record-type represented by rtd, excluding the fields of parent record-types.)

    (srfi 99) procedure (rtd-all-field-names (rtd rtd?)) ⟹ vector?

    Returns a vector of the symbols that name the fields of the record-type represented by rtd, including the fields of its parent record-types, if any. The fields of parent record-types come before the fields of its children, with each subsequence in the same order as in the vectors that would be returned by calling rtd-field-names on rtd and on all its ancestral record-type descriptors.

    (srfi 99) procedure (rtd-field-mutable? (rtd rtd?) (field symbol?)) ⟹ boolean?

    rtd is a record-type descriptor, and field is a symbol naming a field of the record-type described by rtd. Returns #t if the named field is mutable; otherwise returns #f.

    (srfi 99) syntax (define-record-type type-spec constructor predicate field ...)

    type-spec ⟹ type-name | (type-name parent)

    constructor ⟹ #f | #t | constructor-name | (constructor-name field-name ...)

    predicate ⟹ #f | #t | predicate-name

    field ⟹ field-name | (field-name) | (field-name accessor-name) | (field-name accessor-name modifier-name)

    parent ⟹ rtd?

    The semantics of a record type definition is the same as in SRFI 9: the record type definition macro-expands into a cluster of definitions that

  • define the <type name> as the record-type descriptor for the new record-type;
  • defines a constructor for instances of the new record-type (unless the constructor spec is #f);
  • defines a predicate that recognizes instances of the new record-type and its subtypes (unless the predicate spec is #f);
  • defines an accessor for each field name;
  • defines a mutator for each mutable field name.
  • An ERR5RS record type definition extends SRFI 9 with the following additional options:

  • If a <parent> expression is specified, then it must evaluate to an rtd that serves as the parent record-type for the record-type being defined.
  • If #f is specified for the constructor or predicate, then no constructor or predicate procedure is defined. (This is useful when the record-type being defined will be used as an abstract base class.)
  • If #t is specified for the constructor or predicate, then the name of the constructor is the type name prefixed by make-, and the name of the predicate is the type name followed by a question mark (?).
  • If the constructor name is specified as #t or as an identifier, then the constructor's arguments correspond to the fields of the parent (if any) followed by the new fields added by this record-type definition.
  • If a field spec consists of a single identifier, then
  • - the field is immutable;

    - the name of its accessor is the type name followed by a hyphen (-) followed by the field name.

  • If a field spec consists of a list of one identifier, then
  • - the field is mutable;

    - the name of its accessor is the type name followed by a hyphen (-) followed by the field name;

    - the name of its mutator is the type name followed by a hyphen (-) followed by the field name followed by -set!.

    library (srfi 99 records procedural) ERR5RS Records

    Many Scheme programmers have considered records to be one of the most important features missing from the R5RS. The R6RS proposed a record system, but its design has been widely criticized and it was not intended for use in R5RS programs anyway.

    This SRFI proposes a better record system for use in R5RS, ERR5RS, and R6RS programs. The syntactic layer of this SRFI's record system is an extension of SRFI 9. The procedural and inspection layers of this SRFI's record system are perfectly compatible with its syntactic layer. This entire SRFI is compatible with the procedural and inspection layers of the R6RS record system, but offers several worthwhile improvements over the R6RS system.

    See (srfi 99)

    library (srfi 99 records inspection) ERR5RS Records

    Many Scheme programmers have considered records to be one of the most important features missing from the R5RS. The R6RS proposed a record system, but its design has been widely criticized and it was not intended for use in R5RS programs anyway.

    This SRFI proposes a better record system for use in R5RS, ERR5RS, and R6RS programs. The syntactic layer of this SRFI's record system is an extension of SRFI 9. The procedural and inspection layers of this SRFI's record system are perfectly compatible with its syntactic layer. This entire SRFI is compatible with the procedural and inspection layers of the R6RS record system, but offers several worthwhile improvements over the R6RS system.

    See (srfi 99)

    library (srfi 99 records syntactic) ERR5RS Records

    Many Scheme programmers have considered records to be one of the most important features missing from the R5RS. The R6RS proposed a record system, but its design has been widely criticized and it was not intended for use in R5RS programs anyway.

    This SRFI proposes a better record system for use in R5RS, ERR5RS, and R6RS programs. The syntactic layer of this SRFI's record system is an extension of SRFI 9. The procedural and inspection layers of this SRFI's record system are perfectly compatible with its syntactic layer. This entire SRFI is compatible with the procedural and inspection layers of the R6RS record system, but offers several worthwhile improvements over the R6RS system.

    See (srfi 99)

    library (srfi 100) define-lambda-object

    This SRFI introduces a macro, DEFINE-LAMBDA-OBJECT which defines a set of procedures, that is, a group, two constructors, and a predicate. The constructors also make a group of procedures, namely lambda objects. The macro extends DEFINE-RECORD-TYPE (SRFI 9) in being more general but much less general than DEFCLASS (CLOS). The macro has no explicit field accessors and mutators but parent groups, required fields, optional fields, automatic fields, read-write fields, read-only fields, inaccessible hidden fields, immutable virtual fields, and common sharing fields.

    (srfi 100) syntax (define-lambda-object group-spec field-spec)

    group-spec ⟹ group | (group parent-group ...)

    parent-group ⟹ group | (group)

    field-spec ⟹ required-field... optional-field... automatic-field...

    required-field ⟹ field | (field)

    optional-field ⟹ (field default) | ((field) default) | ((quote field) default)

    automatic-field ⟹ ((unquote field) default) | (((unquote field)) default) | ((quote (unquote field)) default) | ((quasiquote (unquote field)) default) | ((unquote (unquote field)) default) | (((unquote (unquote field))) default)

    This SRFI introduces a macro, DEFINE-LAMBDA-OBJECT which defines a set of procedures, that is, a group, two constructors, and a predicate. The constructors also make a group of procedures, namely lambda objects. The macro extends DEFINE-RECORD-TYPE (SRFI 9) in being more general but much less general than DEFCLASS (CLOS). The macro has no explicit field accessors and mutators but parent groups, required fields, optional fields, automatic fields, read-write fields, read-only fields, inaccessible hidden fields, immutable virtual fields, and common sharing fields.

    The name of <constructor> is generated by prefixing `make-' to the group name, or by prefixing `make-' and postfixing `-by-name' to the group name. The name of <predicate> is generated by adding a question mark (`?') to the end of the group name.

    The <group> and <field> must be identifiers.

    Each <default> is an <expression> that is evaluated in an environment that the values of all the previous <field>s are visible. There is one exception to this rule. The <default>s of <automatic common field>s are evaluated in the outer environment of the define-lambda-object form, and their values are visible as the <default>s of the other fields are evaluated.

    The define-lambda-object form is a definition and can appear anywhere any other <definition> can appear. Each time define-lambda-object form is evaluated, a new group is created with distinct <group>, <constructor>, and <predicate> procedures.

    The <group> is bound to a procedure of one argument. Like a gene, it has information on its <parent group>s, <constructor>s, <predicate>, and the number and properties of <field>s. And they are checked out whenever define-lambda-object form is evaluated. In case of inheritance, all the <field>s of <parent group>s must exist in the <field spec> of the child group, irrespectively of the order. Otherwise an error is signaled. In addition, the properties (mutability, sort of field, and default expression) of <field>s of unamendable groups must be preserved in contrast with those of amendable groups. Otherwise an error is signaled.

    The <constructor> is bound to a procedure that takes at least as many arguments as the number of <required field>s. Whenever it is called, it returns an object of the <group>, namely a procedure, which has information on its own group and all that goes with it. Its first argument must be a symbol of the same name as <field>. Otherwise an error is signaled. The object becomes an accessor procedure of each <field> in case of one argument and a mutator procedure of each <field> in case of two arguments where the second argument is a new field value.

    The names of <field>s are used to access the <field>s as symbols of the same names. So they must be distinct. Otherwise an error is signaled. The read-write fields can be modified, whereas any attempt to modify the values of the read-only fields via mutators signals an error. Note: The read-only fields are not immutable. Their values, for instance, can be modified by other fields whose values work like their mutators.

    The <required field> is initialized to the first one of the remaining arguments. If there are no more remaining arguments, an error is signaled.

    The initialization of the <optional field>s is done by two types of <constructor>s:

    1. <make-`group-name'> constructor The initialization method of <optional field>s is the same as that of <required field>s except that the field is bound to the <default> instead of signaling an error if there are no more remaining arguments.

    2. <make-`group-name'-by-name> constructor The name used at a call site for the corresponding <optional field> is a symbol of the same name as the <field>. The remaining arguments are sequentially interpreted as a series of pairs, where the first member of each pair is a field name and the second is the corresponding value. If there is no element for a particular field name, the field is initialized to the <default>.

    The <automatic common field>s are initialized to each corresponding <default> that is evaluated at the time the define-lambda-object form is evaluated, and the values are shared with all the lambda objects that are maded by the constructors of the define-lambda-object form. The other <automatic field>s except <automatic virtual field>s are initialized to each corresponding <default> that is evaluated at the time the lambda object is made by a constructor. The <hidden field> is an externally nonexistent field, that is, the field is invisible outside of the define-lambda-object form but visible inside of it. On the contrary, the <virtual field> is an internally nonexistent field whose <default> is evaluated each time when the field is accessed.

    The <predicate> is a predicate procedure that returns #t for objects constructed by <constructor> or <constructor>s for child groups and #f for everything else.

    library (srfi 101) Purely Functional Random-Access Pairs and Lists

    Random-access lists [1] are a purely functional data structure for representing lists of values. A random-access list may act as a drop in replacement for the usual linear-access pair and list data structures (pair?, cons, car, cdr), which additionally supports fast index-based addressing and updating (list-ref, list-set). The impact is a whole class of purely-functional algorithms expressed in terms of index-based list addressing become feasible compared with their linear-access list counterparts.

    This document proposes a library API for purely functional random-access lists consistent with the R6RS [2] base library and list utility standard library [3].

    (srfi 101) procedure (pair? obj) ⟹ boolean?

    Returns #t if obj is a pair, and otherwise returns #f.

    (srfi 101) procedure (cons obj1 obj2) ⟹ pair?

    Returns a newly allocated pair whose car is obj1 and whose cdr is obj2. The pair is guaranteed to be different (in the sense of eqv?) from every existing object. This operation must take O(1) time.

    (srfi 101) procedure (car (pair pair?)) ⟹ *

    Returns the contents of the car field of pair. This operation must take O(1) time.

    (srfi 101) procedure (cdr (pair pair?)) ⟹ *

    Returns the contents of the cdr field of pair. This operation must take O(1) time.

    (srfi 101) procedure (caar (pair pair?)) ⟹ *

    (srfi 101) procedure (cadr (pair pair?)) ⟹ *

    (srfi 101) procedure (cdar (pair pair?)) ⟹ *

    (srfi 101) procedure (cddr (pair pair?)) ⟹ *

    (srfi 101) procedure (caaar (pair pair?)) ⟹ *

    (srfi 101) procedure (caadr (pair pair?)) ⟹ *

    (srfi 101) procedure (cadar (pair pair?)) ⟹ *

    (srfi 101) procedure (caddr (pair pair?)) ⟹ *

    (srfi 101) procedure (cdaar (pair pair?)) ⟹ *

    (srfi 101) procedure (cdadr (pair pair?)) ⟹ *

    (srfi 101) procedure (cddar (pair pair?)) ⟹ *

    (srfi 101) procedure (cdddr (pair pair?)) ⟹ *

    (srfi 101) procedure (caaaar (pair pair?)) ⟹ *

    (srfi 101) procedure (caaadr (pair pair?)) ⟹ *

    (srfi 101) procedure (caadar (pair pair?)) ⟹ *

    (srfi 101) procedure (caaddr (pair pair?)) ⟹ *

    (srfi 101) procedure (cadaar (pair pair?)) ⟹ *

    (srfi 101) procedure (cadadr (pair pair?)) ⟹ *

    (srfi 101) procedure (caddar (pair pair?)) ⟹ *

    (srfi 101) procedure (cadddr (pair pair?)) ⟹ *

    (srfi 101) procedure (cdaaar (pair pair?)) ⟹ *

    (srfi 101) procedure (cdaadr (pair pair?)) ⟹ *

    (srfi 101) procedure (cdadar (pair pair?)) ⟹ *

    (srfi 101) procedure (cdaddr (pair pair?)) ⟹ *

    (srfi 101) procedure (cddaar (pair pair?)) ⟹ *

    (srfi 101) procedure (cddadr (pair pair?)) ⟹ *

    (srfi 101) procedure (cdddar (pair pair?)) ⟹ *

    (srfi 101) procedure (cddddr (pair pair?)) ⟹ *

    These procedures are compositions of car and cdr.

    (srfi 101) procedure (null? obj) ⟹ boolean?

    Returns #t if obj is the empty list, #f otherwise.

    (srfi 101) procedure (list? obj) ⟹ boolean?

    Returns #t if obj is a list, #f otherwise. By definition, all lists are chains of pairs that have finite length and are terminated by the empty list. This operation must take time bounded by O(log(n)), where n is the number of pairs in the chain forming the potential list.

    (srfi 101) procedure (list obj ...) ⟹ list?

    Returns a newly allocated list of its arguments. This operation must take time bounded by O(n), where n is the number of arguments to list.

    (srfi 101) procedure (make-list (k integer?)) ⟹ list?

    (srfi 101) procedure (make-list (k integer?) obj) ⟹ list?

    Returns a newly allocated list of k elements. If a second argument is given, then each element is initialized to obj. Otherwise the initial contents of each element is unspecified. This operation must take time and space bounded by O(log(k)).

    (srfi 101) procedure (length (list list?)) ⟹ integer?

    Returns the length of list. This operation must take time bounded by O(log(n)), where n is the length of the list.

    (srfi 101) procedure (length<=? obj (k integer?)) ⟹ boolean?

    Returns true if obj is a chain of at least k pairs and false otherwise. This operation must take time bounded by O(log(min(k,n))), where n is the length of the chain of pairs.

    (srfi 101) procedure (append (list list?) ...) ⟹ list?

    (srfi 101) procedure (append (list list?) ... obj) ⟹ *

    Returns a chain of pairs consisting of the elements of the first list followed by the elements of the other lists, with obj as the cdr of the final pair. An improper list results if obj is not a list. This operation must take time bounded by O(log(n)), where n is the total number of elements in the given lists.

    (srfi 101) procedure (reverse (list list?)) ⟹ list?

    Returns a newly allocated list consisting of the element of list in reverse order. This operation must take time bounded by O(n) where n is the length of the list.

    (srfi 101) procedure (list-tail (list list?) (k integer?)) ⟹ list?

    (srfi 101) procedure (list-tail obj (k integer?)) ⟹ *

    Obj should be a chain of pairs with a count of at least k. The list-tail procedure returns the object obtained by omitting the first k elements in obj. This operation must take time bounded by O(log(min(k,n))), where n is the length of the chain of pairs.

    (srfi 101) procedure (list-ref (pair pair?) (k integer?)) ⟹ *

    Pair must be a chain of pairs whose count is at least k + 1. The list-ref procedure returns the kth element of pair. This operation must take time bounded by O(min(k,log(n))), where n is the length of the chain of pairs.

    (srfi 101) procedure (list-set (pair pair?) (k integer?) obj) ⟹ pair?

    Pair must be a chain of pairs whose count is at least k + 1. The list-set procedure returns the chain of pairs obtained by replacing the kth element with obj. This operation must take time bounded by O(min(k,log(n))), where n is the length of the chain of pairs.

    (srfi 101) procedure (list-ref/update (pair pair?) (k integer?) (proc procedure?)) ⟹ (values * pair?)

    (proc obj) ⟹ *

    Returns the same results as:

    (values (list-ref pair k)

    (list-set pair k (proc (list-ref pair k))))

    but it may be implemented more efficiently.

    (srfi 101) procedure (map (proc procedure?) (list1 list?) (list2 list?) ...) ⟹ list?

    (proc obj1 obj2 ...) ⟹ *

    The lists should all have the same length. Proc should accept as many arguments as there are lists and return a single value.

    The map procedure applies proc element-wise to the elements of the lists and returns a list of the results, in order. Proc is always called in the same dynamic environment as map itself. The order in which proc is applied to the elements of the lists is unspecified.

    (srfi 101) procedure (for-each (proc procedure?) (list1 list?) (list2 list?) ...) ⟹ undefined

    (proc obj1 obj2 ...) ⟹ undefined

    The lists should all have the same length. Proc should accept as many arguments as there are lists.

    The for-each procedure applies proc element-wise to the elements of the lists for its side effects, in order from the first element to the last. Proc is always called in the same dynamic environment as for-each itself. The return values of for-each are unspecified.

    (srfi 101) procedure (random-access-list->linear-access-list (list list?)) ⟹ list?

    (srfi 101) procedure (linear-access-list->random-access-list (list list?)) ⟹ list?

    These procedures convert between (potentially) distinct representations of lists. To avoid confusion, parameters named ra-list range over lists represented with random-access lists, i.e. objects satisfying the list? predicate described above, while parameters named la-list range over lists represented with the more traditional linear-access lists, i.e. objects satisfying the list? predicate of R6RS. In systems that represent all lists as random-access lists, these conversions may simply be list identity procedures.

    library (srfi 102) Procedure Arity Inspection

    Many Scheme systems provide mechanisms for inspecting the arity of a procedural value, making it a common feature, however there is no standard interface. As a result there is no portable way to observe the arity of a procedure without actually applying it. This SRFI proposes a simple interface that is consistent with existing Scheme systems' facilities and prior proposals.

    (srfi 102) procedure (procedure-arity (proc procedure?)) ⟹ #f | integer? | arity-at-least? | list?

    Produces an arity object representing the arity of proc. If this procedure produces #f, no information is available for proc.

    (srfi 102) procedure (arity-at-least? obj) ⟹ boolean?

    Returns #t if obj is an arity-at-least object and false otherwise.

    (srfi 102) procedure (arity-at-least-value (arity-at-least arity-at-least?)) ⟹ integer?

    Returns the exact non-negative integer denoting the minimum number of arguments required by the given arity-at-least object.

    (srfi 102) procedure (procedure-arity-includes? (proc procedure?) (k integer?)) ⟹ boolean?

    Returns #t if the proc can accept k arguments and #f otherwise. If this procedure returns #f, applying proc to k arguments will result in an arity error.

    library (srfi 106) Basic socket interface

    This document specifies basic socket interfaces.

    (srfi 106) procedure (make-client-socket (node string?) (service string?)) ⟹ socket?

    (srfi 106) procedure (make-client-socket (node string?) (service string?) (ai-family address-family)) ⟹ socket?

    (srfi 106) procedure (make-client-socket (node string?) (service string?) (ai-family address-family) (ai-socktype socket-domain)) ⟹ socket?

    (srfi 106) procedure (make-client-socket (node string?) (service string?) (ai-family address-family) (ai-socktype socket-domain) (ai-flags address-info)) ⟹ socket?

    (srfi 106) procedure (make-client-socket (node string?) (service string?) (ai-family address-family) (ai-socktype socket-domain) (ai-flags address-info) (ai-protocol ip-protocol)) ⟹ socket?

    Returns a client socket connected to an Internet address. The Internet address is identified by node and service. node and service must be string. Example value of node: "localhost" "127.0.0.1" Example value of service: "http" "80". The optional parameter may specify the created socket's behaviour.

    If the optional argument(s) is omitted, then following flags should be used as default.

    ai-family

    *af-inet*

    ai-socktype

    *sock-stream*

    ai-flags

    (socket-merge-flags *ai-v4mapped* *ai-addrconfig*)

    ai-protocol

    *ipproto-ip*

    The created socket may not be closed automatically so it is users' responsibility to close it explicitly.

    (srfi 106) procedure (make-server-socket (service string?)) ⟹ socket?

    (srfi 106) procedure (make-server-socket (service string?) (ai-family address-family)) ⟹ socket?

    (srfi 106) procedure (make-server-socket (service string?) (ai-family address-family) (ai-socktype socket-domain)) ⟹ socket?

    (srfi 106) procedure (make-server-socket (service string?) (ai-family address-family) (ai-socktype socket-domain)) ⟹ socket?

    (srfi 106) procedure (make-server-socket (service string?) (ai-family address-family) (ai-socktype socket-domain) (ai-protocol ip-protocol)) ⟹ socket?

    Returns a server socket waiting for connection. The description of node argument is the same as make-client-socket. The optional parameter may specify the created socket's behaviour.

    If the optional argument(s) is omitted, then following flags should be used as default.

    ai-family

    *af-inet*

    ai-socktype

    *sock-stream*

    ai-protocol

    *ipproto-ip*

    The created socket may not be closed automatically so it is users' responsibility to close it explicitly.

    (srfi 106) procedure (socket? obj) ⟹ boolean?

    Returns #t if given object is socket object. Otherwise #f.

    (srfi 106) procedure (socket-accept (socket socket?)) ⟹ socket?

    Wait for an incoming connection request, and returns a fresh connected client socket.

    (srfi 106) procedure (socket-send (socket socket?) (bv bytevector?)) ⟹ integer?

    (srfi 106) procedure (socket-send (socket socket?) (bv bytevector?) (flags message-type)) ⟹ integer?

    Sends a binary data block to a socket and returns the sent data size. flags may specify the procedure's behaviour.

    If the flags is omitted, the default value must be the result of following form;

    (message-type none)

    (srfi 106) procedure (socket-recv (socket socket?) (size integer?)) ⟹ bytevector?

    (srfi 106) procedure (socket-recv (socket socket?) (size integer?) (flags message-type)) ⟹ bytevector?

    Receives a binary data block from a socket. If zero length bytevector is returned, it means the peer connection is closed. flags may specify the procedure's behaviour.

    If the flags is omitted, the default value must be the result of following form;

    (message-type none)

    (srfi 106) procedure (socket-shutdown (socket socket?) (how shutdown-method)) ⟹ undefined

    Shutdowns a socket.

    (srfi 106) procedure (socket-close (socket socket?)) ⟹ undefined

    Closes a socket. The procedure should not shutdown the given socket. To shutdown a socket, socket-shutdown should be called explicitly.

    (srfi 106) procedure (socket-input-port (socket socket?)) ⟹ input-port?

    (srfi 106) procedure (socket-output-port (socket socket?)) ⟹ output-port?

    Returns a fresh binary input and output port associated with a socket, respectively. The port should not close underlying socket when it's closing.

    (srfi 106) procedure (call-with-socket (socket socket?) (proc procedure?)) ⟹ *

    (proc (socket socket?)) ⟹ *

    Calls a given procedure with a given socket as an argument. If given proc returns then it returns the result of proc and socket will be automatically closed. If proc doesn't return then given socket won't be closed automatically. It's analogy of call-with-port.

    (srfi 106) syntax (address-family name)⟹ return

    Returns proper address family from given name.

    Implementation must support at least following names and must have the described behaviour.

    inet

    Returns *af-inet*

    inet6

    Returns *af-inet6*

    unspec

    Returns *af-unspec*

    Implementation may support more names such as unix or local or other names.

    (srfi 106) syntax (address-info names ...)⟹ return

    Returns merged address info flags from given names.

    Implementation must support at least following names and must have the described behaviour.

    canoname

    Returns *ai-canonname*

    numerichost

    Returns *ai-numerichost*

    v4mapped

    Returns *ai-v4mapped*

    all

    Returns *ai-all*

    addrconfig

    Returns *ai-addrconfig*

    Implementation may support more names.

    (srfi 106) syntax (socket-domain name)⟹ return

    Returns socket domain flags from given name.

    Implementation must support at least following names and must have the described behaviour.

    stream

    Returns *sock-stream*

    datagram

    Returns *sock-dgram*

    Implementation may support more names.

    (srfi 106) syntax (ip-protocol name)⟹ return

    Returns ip-protocol flag from given name.

    Implementation must support at least following names and must have the described behaviour.

    ip

    Returns *ipproto-ip*

    tcp

    Returns *ipproto-tcp*

    udp

    Returns *ipproto-udp*

    Implementation may support more names.

    (srfi 106) syntax (message-type names ...)⟹ return

    Returns message type flag from given name. The flag can be used both socket-recv and socket-send.

    Implementation must support at least following names and must have the described behaviour.

    none

    Returns no flag.

    peek

    Returns *msg-peek*

    oob

    Returns *msg-oob*

    wait-all

    Returns *msg-waitall*

    Implementation may support more names.

    (srfi 106) syntax (shutdown-method names ...)⟹ return

    Returns shutdown method flags from given names.

    Implementation must support at least following names and must have the described behaviour.

    read

    Returns *shut-rd*

    write

    Returns *shut-wr*

    If shutdown-method is given both read and write, then it must return *shut-rdwr*

    (srfi 106) procedure (socket-merge-flags (flags address-info) ...) ⟹ address-info

    (srfi 106) procedure (socket-merge-flags (flags message-type) ...) ⟹ message-type

    (srfi 106) procedure (socket-merge-flags (flags shutdown-method) ...) ⟹ shutdown-method

    Merges given flags and returns a new flag.

    (srfi 106) procedure (socket-purge-flags (base-flag address-info) (flags address-info) ...) ⟹ address-info

    (srfi 106) procedure (socket-purge-flags (base-flag message-type) (flags message-type) ...) ⟹ message-type

    (srfi 106) procedure (socket-purge-flags (base-flag shutdown-method) (flags shutdown-method) ...) ⟹ shutdown-method

    Removes flags from base-flag if exists and returns a new flag.

    (srfi 106) value *af-inet* ⟹ address-family

    Internet domain sockets for use with IPv4 addresses. This must behave the same as POSIX's AF_INET.

    (srfi 106) value *af-inet6* ⟹ address-family

    Internet domain sockets for use with IPv6 addresses. This must behave the same as POSIX's AF_INET6.

    (srfi 106) value *af-unspec* ⟹ address-family

    Unspecified. This must behave the same as POSIX's AF_UNSPEC.

    (srfi 106) value *sock-stream* ⟹ socket-domain

    Byte-stream socket. This must behave the same as POSIX's SOCK_STREAM.

    (srfi 106) value *sock-dgram* ⟹ socket-domain

    Datagram socket. This must behave the same as POSIX's SOCK_DGRAM.

    (srfi 106) value *ai-canonname* ⟹ address-info

    This must behave the same as POSIX's AI_CANONNAME.

    (srfi 106) value *ai-numerichost* ⟹ address-info

    This must behave the same as POSIX's AI_NUMERICHOST.

    (srfi 106) value *ai-v4mapped* ⟹ address-info

    This must behave the same as POSIX's AI_V4MAPPED.

    (srfi 106) value *ai-all* ⟹ address-info

    This must behave the same as POSIX's AI_ALL.

    (srfi 106) value *ai-addrconfig* ⟹ address-info

    This must behave the same as POSIX's AI_ADDRCONFIG.

    (srfi 106) value *ipproto-ip* ⟹ ip-protocol

    Internet protocol. This must behave the same as POSIX's IPPROTO_IP.

    (srfi 106) value *ipproto-tcp* ⟹ ip-protocol

    Transmission control protocol. This must behave the same as POSIX's IPPROTO_TCP.

    (srfi 106) value *ipproto-udp* ⟹ ip-protocol

    User datagram protocol. This must behave the same as POSIX's IPPROTO_UDP.

    (srfi 106) value *msg-peek* ⟹ message-type

    For socket-recv. Peeks at an incoming message. The data is treated as unread and the next socket-recv shall still return this data. This must behave the same as POSIX's MSG_PEEK.

    (srfi 106) value *msg-oob* ⟹ message-type

    For both socket-recv and socket-send. Requests/sends out-of-band data. This must behave the same as POSIX's MSG_OOB.

    (srfi 106) value *msg-waitall* ⟹ message-type

    For socket-recv. On sockets created with *sock-stream* flag, this requests the procedure block until the full amount of data ban be returned. This must behave the same as POSIX's MSG_WAITALL.

    (srfi 106) value *shut-rd* ⟹ shutdown-method

    Disables further receive operation. This must behave the same as POSIX's SHUT_RD.

    (srfi 106) value *shut-wr* ⟹ shutdown-method

    Disables further send operations. This must behave the same as POSIX's SHUT_WR.

    (srfi 106) value *shut-rdwr* ⟹ shutdown-method

    Disables further send and receive operations. This must behave the same as POSIX's SHUT_RDWR.

    library (srfi 111) Boxes

    Boxes are objects with a single mutable state. Several Schemes have them, sometimes called cells. A constructor, predicate, accessor, and mutator are provided.

    See (scheme box)

    library (srfi 112) Environment Inquiry

    This is a proposal for environment inquiry, providing human-readable information at run time about the hardware and software configuration on which a Scheme program is being executed. They are mostly based on Common Lisp, with additions from the Posix uname() system call.

    (srfi 112) procedure (implementation-name) ⟹ string? | #f

    Returns the name of the Scheme implementation. This procedure corresponds roughly to Common Lisp's lisp-implementation-type function.

    (srfi 112) procedure (implementation-version) ⟹ string? | #f

    Returns the version of the Scheme implementation. This procedure corresponds roughly to Common Lisp's lisp-implementation-version function.

    (srfi 112) procedure (cpu-architecture) ⟹ string? | #f

    Returns the CPU architecture, real or virtual, on which this implementation is executing. This procedure corresponds roughly to Common Lisp's machine-type function. On Posix systems, the result may be derived from the machine field of the utsname structure.

    (srfi 112) procedure (machine-name) ⟹ string? | #f

    Returns a name for the particular machine on which the implementation is running. Possible values are the DNS or WINS host name, the DNS full name, an IP address in string form associated with the system, or a MAC address in string form associated with the system. This procedure corresponds roughly to Common Lisp's machine-instance function. On Posix systems, the result may be derived from the nodename field of the utsname structure.

    (srfi 112) procedure (os-name) ⟹ string? | #f

    Returns a name for the operating system, platform, or equivalent on which the implementation is running. This procedure corresponds roughly to Common Lisp's software-type function. On Posix systems, the result may be derived from the sysname field of the utsname structure.

    (srfi 112) procedure (os-version) ⟹ string? | #f

    Returns the version of the operating system, platform, or equivalent on which the implementation is running. This procedure corresponds roughly to Common Lisp's software-version function. On Posix systems, the result may be derived from the release and/or version fields of the utsname structure.

    library (srfi 113) Sets and bags

    Sets and bags (also known as multisets) are unordered collections that can contain any Scheme object. Sets enforce the constraint that no two elements can be the same in the sense of the set's associated equality predicate; bags do not.

    See (scheme set)

    library (srfi 115) Scheme Regular Expressions

    This SRFI provides a library for matching strings with regular expressions described using the SRE "Scheme Regular Expression" notation first introduced by SCSH, and extended heavily by IrRegex.

    See (scheme regex)

    library (srfi 116) Immutable List Library

    Scheme currently does not provide immutable pairs corresponding to its existing mutable pairs, although most uses of pairs do not exploit their mutability. The Racket system takes the radical approach of making Scheme's pairs immutable, and providing a minimal library of mutable pairs with procedures named mpair?, mcons, mcar, mcdr, set-mcar!, set-mcdr!. This SRFI takes the opposite approach of leaving Scheme's pairs unchanged and providing a full set of routines for creating and dealing with immutable pairs. The sample implementation is portable (to systems with SRFI 9) and efficient.

    See (scheme ilist)

    library (srfi 117) Queues based on lists

    List queues are mutable ordered collections that can contain any Scheme object. Each list queue is based on an ordinary Scheme list containing the elements of the list queue by maintaining pointers to the first and last pairs of the list. It's cheap to add or remove elements from the front of the list or to add elements to the back, but not to remove elements from the back. List queues are disjoint from other types of Scheme objects.

    See (scheme list-queue)

    library (srfi 118) Simple adjustable-size strings

    Scheme specifies mutable fixed-length strings. We add two procedures string-append! and string-replace! which allow the size of the string to change. We also require that the standard Scheme procedures make-string and string-copy return variable-size strings.

    (srfi 118) procedure (string-append! (string string?) (value char? | string?) ...) ⟹ undefined

    The string must be a variable-size mutable string. The string-append! procedure extends string by appending each value (in order) to the end of string. A value can be a character or a string.

    Using a string port in this situation is probably preferable: It is more portable, and you can expect decent performance in most implementations. Using string-append! may be slighly more efficient on some implementations, due to lower overhead, but that depends on the strategy used by string-append! when the allocated buffer is too small. The string-append! function is most useful when using (reading) a string is interleaved with growing it, or when also using string-replace!.

    (srfi 118) procedure (string-replace! (dst string?) (dst-start integer?) (dst-end integer?) (src string?)) ⟹ undefined

    (srfi 118) procedure (string-replace! (dst string?) (dst-start integer?) (dst-end integer?) (src string?) (src-start integer?)) ⟹ undefined

    (srfi 118) procedure (string-replace! (dst string?) (dst-start integer?) (dst-end integer?) (src string?) (src-start integer?) (src-end integer?)) ⟹ undefined

    Replaces the characters of the variable-size string dst (between dst-start and dst-end) with the characters of the string src (between src-start and src-end). The number of characters from src may be different than the number replaced in dst, so the string may grow or contract. The special case where dst-start is equal to dst-end corresponds to insertion; the case where src-start is equal to src-end corresponds to deletion. The order in which characters are copied is unspecified, except that if the source and destination overlap, copying takes place as if the source is first copied into a temporary string and then into the destination. (This can be achieved without allocating storage by making sure to copy in the correct direction in such circumstances.)

    When value is a string then (string-append! dst value) is equivalent to (string-replace! dst (string-length dst) (string-length dst) value).

    library (srfi 120) Timer APIs

    This SRFI defines interfaces to handle timer processes.

    (srfi 120) procedure (make-timer ) ⟹ timer?

    (srfi 120) procedure (make-timer (error-handler procedure?)) ⟹ timer?

    (error-handler err) ⟹ *

    Creates and starts a timer object. The optional argument error-handler must be a procedure which accepts one argument. If it is given and when a timer task raises an error, then the handler will be invoked and timer will continue if the error-handler wouldn't raise an error. Otherwise whenever an error is raised, timer stops and preserves the error. The error is raised when timer-cancel! procedure is called.

    Two timers should run in separate context, means whenever timer A is executing a task, timer B should not be disturbed executing a task by timer A's execution.

    (srfi 120) procedure (timer? obj) ⟹ boolean?

    Returns #t if given obj is a timer object, otherwise #f.

    (srfi 120) procedure (timer-cancel! (timer timer?)) ⟹ undefined

    Stops the given timer. The procedure raises the preserved error if there is. Once a timer is stopped, it will never be able to start again.

    (srfi 120) procedure (timer-schedule! (timer timer?) (thunk procedure?) (when timer-delta? | integer?)) ⟹ timer-id

    (srfi 120) procedure (timer-schedule! (timer timer?) (thunk procedure?) (when timer-delta? | integer?) (period timer-delta? | integer?)) ⟹ timer-id

    (thunk) ⟹ *

    Schedules the given thunk as the given timer's task. The when argument specifies when the task will be started. It can be either timer delta object or non negative integer. The task is scheduled on the time when the given when passed from the procedure is called. The task is executed on the dynamic environment where the timer is created.

    If the optional argument period is given, which must be either timer delta object or an integer, then the given task is scheduled as periodical task. The next task is scheduled by adding when and period. If the period or when is an integer, then it is interpreted as milliseconds.

    The procedure returns task id, which is a readable datum such as an integer.

    The executing order of the same timing tasks are not defined.

    A task should be able to cancel or reschedule other tasks. But it should not be able to cancel or reschedule itself.

    If a task is rescheduled whenever it's executed, the timer doesn't stop its execution. It is rescheduled but the current execution will be continued.

    (srfi 120) procedure (timer-reschedule! (timer timer?) (id timer-id) (when timer-delta? | integer?)) ⟹ timer-id

    (srfi 120) procedure (timer-reschedule! (timer timer?) (id timer-id) (when timer-delta? | integer?) (period timer-delta? | integer?)) ⟹ timer-id

    Reschedules the task associated to the given id on the given timer. The when and period arguments are the same as timer-schedule!.

    Thus to cancel the periodical task, you can specify 0 as period argument.

    The procedure returns given id.

    It is an error if the given task id is not associated with the given timer or if the task is already executed and not scheduled anymore.

    (srfi 120) procedure (timer-task-remove! (timer timer?) (id timer-id)) ⟹ boolean?

    Removes the task associated to the given id on the given timer. It returns #t if a task is removed, otherwise #f.

    (srfi 120) procedure (timer-task-exists? (timer timer?) (id timer-id)) ⟹ boolean?

    Returns #t if a task associated to the given id exists, otherwise #f.

    (srfi 120) procedure (make-timer-delta (n integer?) (unit symbol?)) ⟹ timer-delta?

    Creates a timer delta object. n must be an integer and unit must be a symbol which represents the time unit. Implementations must support the following units:

    h : hour

    m : minute

    s : second

    ms : millisecond

    us : microsecond

    ns : nanosecond

    And may support other unit.

    (srfi 120) procedure (timer-delta? obj) ⟹ boolean?

    Returns #t if given obj is a timer delta object, otherwise #f.

    library (srfi 123) Generic accessor and modifier operators

    Lisp dialects including Scheme have traditionally lacked short, simple, generic syntax for accessing and modifying the fields of arbitrary "collection" objects. We fill this gap for Scheme by defining generalized accessors, and an associated SRFI-17 setter.

    (srfi 123) procedure (ref object field) ⟹ *

    (srfi 123) procedure (ref object field default) ⟹ *

    Returns the value for field in object. It is an error if object has no field identified by field. If object is of a "sparse" type, meaning its fields can be "empty" or "unassigned" (e.g. a hashtable), and the requested field is empty, then the value of default is returned. It is an error if the default argument is not provided in this case. If object is not of a sparse type, then providing the default argument is an error. Valid types for object are: bytevectors, hashtables, pairs, strings, vectors, non-opaque record types, SRFI-4 vectors, and SRFI-111 boxes. Only hashtables are a sparse type. Implementations are encouraged to expand this list of types with any further types they support.

    (srfi 123) procedure (ref* object field ...) ⟹ *

    (srfi 123) procedure (~ object field ...) ⟹ *

    ref* (and its synonym ~) is like ref but for chained access.

    library (srfi 124) Ephemerons

    An ephemeron is an object with two components called its key and its datum. It differs from an ordinary pair as follows: if the garbage collector (GC) can prove that there are no references to the key except from the ephemeron itself and possibly from the datum, then it is free to break the ephemeron, dropping its reference to both key and datum. In other words, an ephemeron can be broken when nobody else cares about its key. Ephemerons can be used to construct weak vectors or lists and (possibly in combination with finalizers) weak hash tables.

    Much of this specification is derived with thanks from the MIT Scheme Reference Manual.

    See (scheme ephemeron)

    library (srfi 125) Intermediate hash tables

    This SRFI defines an interface to hash tables, which are widely recognized as a fundamental data structure for a wide variety of applications. A hash table is a data structure that:

    • Is disjoint from all other types.
    • Provides a mapping from objects known as keys to corresponding objects known as values.
      • Keys may be any Scheme objects in some kinds of hash tables, but are restricted in other kinds.
      • Values may be any Scheme objects.
    • Has no intrinsic order for the key-value associations it contains.
    • Provides an equality predicate which defines when a proposed key is the same as an existing key. No table may contain more than one value for a given key.
    • Provides a hash function which maps a candidate key into a non-negative exact integer.
    • Supports mutation as the primary means of setting the contents of a table.
    • Provides key lookup and destructive update in (expected) amortized constant time, provided a satisfactory hash function is available.
    • Does not guarantee that whole-table operations work in the presence of concurrent mutation of the whole hash table (values may be safely mutated).

    See (scheme hash-table)

    library (srfi 126) R6RS-based hashtables

    We provide a hashtable API that takes the R6RS hashtables API as a basis and makes backwards compatible additions such as support for weak hashtables, external representation, API support for double hashing implementations, and utility procedures.

    (srfi 126) procedure (make-eq-hashtable ) ⟹ hashtable?

    (srfi 126) procedure (make-eq-hashtable (capacity integer?)) ⟹ hashtable?

    (srfi 126) procedure (make-eq-hashtable (capacity integer?) (weakness #f | symbol?)) ⟹ hashtable?

    Returns a newly allocated mutable hashtable that accepts arbitrary objects as keys, and compares those keys with eq?. If the capacity argument is provided and not #f, it must be an exact non-negative integer and the initial capacity of the hashtable is set to approximately capacity elements. The weakness argument, if provided, must be one of: #f, weak-key, weak-value, weak-key-and-value, ephemeral-key, ephemeral-value, and ephemeral-key-and-value, and determines the weakness or ephemeral status for the keys and values in the hashtable. All values other than #f are optional to support; the implementation should signal the user in an implementation-defined manner when an unsupported value is used.

    (srfi 126) procedure (make-eqv-hashtable ) ⟹ hashtable?

    (srfi 126) procedure (make-eqv-hashtable (k integer?)) ⟹ hashtable?

    (srfi 126) procedure (make-eqv-hashtable (capacity integer?) (weakness #f | symbol?)) ⟹ hashtable?

    Returns a newly allocated mutable hashtable that accepts arbitrary objects as keys, and compares those keys with eqv?. The semantics of the optional arguments are as in make-eq-hashtable.

    (srfi 126) procedure (make-hashtable (hash procedure?) (equiv procedure?)) ⟹ hashtable?

    (srfi 126) procedure (make-hashtable (hash procedure?) (equiv procedure?) (capacity integer?)) ⟹ hashtable?

    (srfi 126) procedure (make-hashtable (hash procedure?) (equiv procedure?) (capacity integer?) (weakness #f | symbol?)) ⟹ hashtable?

    (hash key) ⟹ integer?

    (equiv a b) ⟹ boolean?

    If hash is #f and equiv is the eq? procedure, the semantics of make-eq-hashtable apply to the rest of the arguments. If hash is #f and equiv is the eqv? procedure, the semantics of make-eqv-hashtable apply to the rest of the arguments.

    Otherwise, hash must be a pair of hash functions or a hash function, and and equiv must be a procedure. Equiv should accept two keys as arguments and return a single value. None of the procedures should mutate the hashtable returned by make-hashtable. The make-hashtable procedure returns a newly allocated mutable hashtable using the function(s) specified by hash as its hash function(s), and equiv as the equivalence function used to compare keys. The semantics of the remaining arguments are as in make-eq-hashtable and make-eqv-hashtable.

    Implementations using a hashing strategy that involves a single hash function should ignore one of the functions in the pair when given a pair of hash functions. Implementations preferring a hashing strategy involving a pair of hash functions may automatically derive a pair of hash functions from a given single hash function.

    The hash functions and equiv should behave like pure functions on the domain of keys. For example, the string-hash and string=? procedures are permissible only if all keys are strings and the contents of those strings are never changed so long as any of them continues to serve as a key in the hashtable. Furthermore, any pair of keys for which equiv returns true should be hashed to the same exact integer objects by the given hash function(s).

    Note: Hashtables are allowed to cache the results of calling a hash function and equivalence function, so programs cannot rely on a hash function being called for every lookup or update. Furthermore any hashtable operation may call a hash function more than once.

    (srfi 126) procedure (hashtable? obj) ⟹ boolean?

    Returns #t if obj is a hashtable, #f otherwise.

    (srfi 126) procedure (hashtable-size (hashtable hashtable?)) ⟹ integer?

    Returns the number of keys contained in hashtable as an exact integer object.

    (srfi 126) procedure (hashtable-ref (hashtable hashtable?) key) ⟹ *

    (srfi 126) procedure (hashtable-ref (hashtable hashtable?) key default) ⟹ *

    Returns the value in hashtable associated with key. If hashtable does not contain an association for key, default is returned. If hashtable does not contain an association for key and the default argument is not provided, an error should be signaled.

    (srfi 126) procedure (hashtable-set! (hashtable hashtable?) key obj) ⟹ undefined

    Changes hashtable to associate key with obj, adding a new association or replacing any existing association for key, and returns an unspecified value.

    (srfi 126) procedure (hashtable-delete! (hashtable hashtable?) key) ⟹ undefined

    Removes any association for key within hashtable and returns an unspecified value.

    (srfi 126) procedure (hashtable-contains? (hashtable hashtable?) key) ⟹ boolean?

    Returns #t if hashtable contains an association for key, #f otherwise.

    (srfi 126) procedure (hashtable-lookup (hashtable hashtable?) key) ⟹ (values * boolean?)

    Returns two values: the value in hashtable associated with key or an unspecified value if there is none, and a Boolean indicating whether an association was found.

    (srfi 126) procedure (hashtable-update! (hashtable hashtable?) key (proc procedure?)) ⟹ boolean?

    (srfi 126) procedure (hashtable-update! (hashtable hashtable?) key (proc procedure?) default) ⟹ boolean?

    (proc value) ⟹ *

    Proc should accept one argument, should return a single value, and should not mutate hashtable. The hashtable-update! procedure applies proc to the value in hashtable associated with key, or to default if hashtable does not contain an association for key. The hashtable is then changed to associate key with the value returned by proc. If hashtable does not contain an association for key and the default argument is not provided, an error should be signaled. Hashtable-update! returns the value of the new association for key in hashtable.

    (srfi 126) procedure (hashtable-intern! (hashtable hashtable?) key (default-proc procedure?)) ⟹ *

    (default-proc) ⟹ *

    Default-proc should accept zero arguments, should return a single value, and should not mutate hashtable. The hashtable-intern! procedure returns the association for key in hashtable if there is one, otherwise it calls default-proc with zero arguments, associates its return value with key in hashtable, and returns that value.

    (srfi 126) procedure (hashtable-copy (hashtable hashtable?)) ⟹ hashtable?

    (srfi 126) procedure (hashtable-copy (hashtable hashtable?) (mutable boolean?)) ⟹ hashtable?

    (srfi 126) procedure (hashtable-copy (hashtable hashtable?) (mutable boolean?) (weakness #f | symbol?)) ⟹ hashtable?

    Returns a copy of hashtable. If the mutable argument is provided and is true, the returned hashtable is mutable; otherwise it is immutable. If the optional weakness argument is provided, it determines the weakness of the copy, otherwise the weakness attribute of hashtable is used.

    (srfi 126) procedure (hashtable-clear! (hashtable hashtable?)) ⟹ undefined

    (srfi 126) procedure (hashtable-clear! (hashtable hashtable?) (capacity integer?)) ⟹ undefined

    Removes all associations from hashtable and returns an unspecified value. If capacity is provided and not #f, it must be an exact non-negative integer and the current capacity of the hashtable is reset to approximately capacity elements.

    (srfi 126) procedure (hashtable-empty-copy (hashtable hashtable?)) ⟹ hashtable?

    (srfi 126) procedure (hashtable-empty-copy (hashtable hashtable?) (capacity integer?)) ⟹ hashtable?

    Returns a newly allocated mutable hashtable that has the same hash and equivalence functions and weakness attribute as hashtable. The capacity argument may be #t to set the initial capacity of the copy to approximately (hashtable-size hashtable) elements; otherwise the semantics of make-eq-hashtable apply to the capacity argument.

    (srfi 126) procedure (hashtable-keys (hashtable hashtable?)) ⟹ vector?

    Returns a vector of all keys in hashtable. The order of the vector is unspecified.

    (srfi 126) procedure (hashtable-values (hashtable hashtable?)) ⟹ vector?

    Returns a vector of all values in hashtable. The order of the vector is unspecified, and is not guaranteed to match the order of keys in the result of hashtable-keys.

    (srfi 126) procedure (hashtable-entries (hashtable hashtable?)) ⟹ (values vector? vector?)

    Returns two values, a vector of the keys in hashtable, and a vector of the corresponding values.

    (srfi 126) procedure (hashtable-key-list (hashtable hashtable?)) ⟹ list?

    Returns a list of all keys in hashtable. The order of the list is unspecified.

    (srfi 126) procedure (hashtable-value-list (hashtable hashtable?)) ⟹ list?

    Returns a list of all values in hashtable. The order of the list is unspecified, and is not guaranteed to match the order of keys in the result of hashtable-key-list.

    (srfi 126) procedure (hashtable-entry-list (hashtable hashtable?)) ⟹ (values list? list?)

    Returns two values, a list of the keys in hashtable, and a list of the corresponding values.

    (srfi 126) procedure (hashtable-walk (hashtable hashtable?) (proc procedure?)) ⟹ undefined

    (proc key value) ⟹ undefined

    Proc should accept two arguments, and should not mutate hashtable. The hashtable-walk procedure applies proc once for every association in hashtable, passing it the key and value as arguments. The order in which proc is applied to the associations is unspecified. Return values of proc are ignored. Hashtable-walk returns an unspecified value.

    (srfi 126) procedure (hashtable-update-all! (hashtable hashtable?) (proc procedure?)) ⟹ undefined

    (proc key value) ⟹ *

    Proc should accept two arguments, should return a single value, and should not mutate hashtable. The hashtable-update-all! procedure applies proc once for every association in hashtable, passing it the key and value as arguments, and changes the value of the association to the return value of proc. The order in which proc is applied to the associations is unspecified. Hashtable-update-all! returns an unspecified value.

    (srfi 126) procedure (hashtable-prune! (hashtable hashtable?) (proc procedure?)) ⟹ undefined

    (proc key value) ⟹ boolean?

    Proc should accept two arguments, should return a single value, and should not mutate hashtable. The hashtable-prune! procedure applies proc once for every association in hashtable, passing it the key and value as arguments, and deletes the association if proc returns a true value. The order in which proc is applied to the associations is unspecified. Hashtable-prune! returns an unspecified value.

    (srfi 126) procedure (hashtable-merge! (hashtable-dest hashtable?) (hashtable-source hashtable?)) ⟹ hashtable?

    Effectively equivalent to:

    (begin

    (hashtable-walk hashtable-source

    (lambda (key value)

    (hashtable-set! hashtable-dest key value)))

    hashtable-dest)

    (srfi 126) procedure (hashtable-sum (hashtable hashtable?) init (proc procedure?)) ⟹ *

    (proc key value state) ⟹ *

    Proc should accept three arguments, should return a single value, and should not mutate hashtable. The hashtable-sum procedure accumulates a result by applying proc once for every association in hashtable, passing it as arguments: the key, the value, and the result of the previous application or init at the first application. The order in which proc is applied to the associations is unspecified.

    (srfi 126) procedure (hashtable-map->lset (hashtable hashtable?) (proc procedure?)) ⟹ list?

    (proc key value) ⟹ *

    Proc should accept two arguments, should return a single value, and should not mutate hashtable. The hashtable-map->lset procedure applies proc once for every association in hashtable, passing it the key and value as arguments, and accumulates the returned values into a list. The order in which proc is applied to the associations, and the order of the results in the returned list, are unspecified.

    (srfi 126) procedure (hashtable-find (hashtable hashtable?) (proc procedure?)) ⟹ (values * * boolean?)

    (proc key value) ⟹ boolean?

    Proc should accept two arguments, should return a single value, and should not mutate hashtable. The hashtable-find procedure applies proc to associations in hashtable in an unspecified order until one of the applications returns a true value or the associations are exhausted. Three values are returned: the key and value of the matching association or two unspecified values if none matched, and a Boolean indicating whether any association matched.

    (srfi 126) procedure (hashtable-empty? (hashtable hashtable?)) ⟹ boolean?

    Effectively equivalent to:

    (zero? (hashtable-size hashtable))

    (srfi 126) procedure (hashtable-pop! (hashtable hashtable?)) ⟹ *

    Effectively equivalent to:

    (let-values (((key value found?)

    (hashtable-find hashtable (lambda (k v) #t))))

    (when (not found?)

    (error))

    (hashtable-delete! hashtable key)

    (values key value))

    (srfi 126) procedure (hashtable-inc! (hashtable hashtable?) key) ⟹ boolean?

    (srfi 126) procedure (hashtable-inc! (hashtable hashtable?) key (number number?)) ⟹ boolean?

    Effectively equivalent to:

    (hashtable-update! hashtable key (lambda (v) (+ v number)) 0)

    where number is 1 when not provided.

    (srfi 126) procedure (hashtable-dec! (hashtable hashtable?) key) ⟹ boolean?

    (srfi 126) procedure (hashtable-dec! (hashtable hashtable?) key (number number?)) ⟹ boolean?

    Effectively equivalent to:

    (hashtable-update! hashtable key (lambda (v) (- v number)) 0)

    where number is 1 when not provided.

    (srfi 126) procedure (hashtable-equivalence-function (hashtable hashtable?)) ⟹ procedure?

    (return a b) ⟹ boolean?

    Returns the equivalence function used by hashtable to compare keys. For hashtables created with make-eq-hashtable and make-eqv-hashtable, returns eq? and eqv? respectively.

    (srfi 126) procedure (hashtable-hash-function (hashtable hashtable?)) ⟹ procedure?

    (return key) ⟹ integer?

    Returns the hash function(s) used by hashtable, that is, either a procedure, or a pair of procedures. For hashtables created by make-eq-hashtable or make-eqv-hashtable, #f is returned.

    (srfi 126) procedure (hashtable-weakness (hashtable hashtable?)) ⟹ #f | sybmol?

    Returns the weakness attribute of hashtable. The same values that are accepted as the weakness argument in the constructor procedures are returned. This procedure may expose the fact that weak-key and weak-value hashtables are implemented as ephemeral-key and ephemeral-value hashtables, returning symbols indicating the latter even when the former were used to construct the hashtable.

    (srfi 126) procedure (hashtable-mutable? (hashtable hashtable?)) ⟹ boolean?

    Returns #t if hashtable is mutable, otherwise #f.

    (srfi 126) syntax (hash-salt)⟹ return

    Expands to a form evaluating to an exact non-negative integer that lies within the fixnum range of the implementation. The value the expanded form evaluates to remains constant throughout the execution of the program. It is random for every run of the program, except when the environment variable SRFI_126_HASH_SEED is set to a non-empty string before program startup, in which case it is derived from the value of that environment variable in a deterministic manner.

    (srfi 126) procedure (equal-hash obj) ⟹ integer?

    Returns an integer hash value for obj, based on its structure and current contents. This hash function is suitable for use with equal? as an equivalence function.

    (srfi 126) procedure (string-hash (string string?)) ⟹ integer?

    Returns an integer hash value for string, based on its current contents. This hash function is suitable for use with string=? as an equivalence function.

    (srfi 126) procedure (string-ci-hash (string string?)) ⟹ integer?

    Returns an integer hash value for string based on its current contents, ignoring case. This hash function is suitable for use with string-ci=? as an equivalence function.

    (srfi 126) procedure (symbol-hash (symbol symbol?)) ⟹ integer?

    Returns an integer hash value for symbol.

    library (srfi 127) Lazy Sequences

    Lazy sequences (or lseqs, pronounced "ell-seeks") are a generalization of lists. In particular, an lseq is either a proper list or a dotted list whose last cdr is a SRFI 121 generator. A generator is a procedure that can be invoked with no arguments in order to lazily supply additional elements of the lseq. When a generator has no more elements to return, it returns an end-of-file object. Consequently, lazy sequences cannot reliably contain end-of-file objects.

    This SRFI provides a set of procedures suitable for operating on lazy sequences based on SRFI 1.

    See (scheme lseq)

    library (srfi 128) Comparators (reduced)

    This SRFI provides comparators, which bundle a type test predicate, an equality predicate, an ordering predicate, and a hash function (the last two are optional) into a single Scheme object. By packaging these procedures together, they can be treated as a single item for use in the implementation of data structures.

    See (scheme comparator)

    library (srfi 129) Titlecase procedures

    This SRFI defines R7RS-style char-title-case?, char-titlecase, and string-titlecase procedures.

    (srfi 129) procedure (char-title-case? (char char?)) ⟹ boolean?

    Returns #t if char is a character belonging to the Unicode category Lt, and #f otherwise. (The same as the R6RS equivalent.)

    (srfi 129) procedure (char-titlecase (char char?)) ⟹ char?

    Returns the titlecase equivalent of char, if that character exists in the implementation, and char otherwise. The titlecase equivalent of a character is typically not a titlecase character; for most characters it is the same as the uppercase equivalent or else the character itself. Note that language-sensitive mappings are not used. (The same as the R6RS equivalent.)

    (srfi 129) procedure (string-titlecase (string string?)) ⟹ string?

    This procedure applies the Unicode full string lowercasing algorithm to its argument. However, any character preceded by a non-cased character, or which is the first character of string, is processed by a different algorithm. If such a character has a multi-character titlecase mapping specified by Unicode, and all the characters of the mapping are supported by the implementation, then it is replaced by that mapping. Otherwise, it is replaced by its single-character titlecase mapping as if by char-titlecase. The result of the application of these algorithms is returned.

    In certain cases, the result differs in length from the argument. If the result is equal to the argument in the sense of string=?, the argument may be returned. Note that language-sensitive mappings are not used. (The R6RS version does not make use of multi-character mappings.)

    library (srfi 130) Cursor-based string library

    R5RS Scheme has an impoverished set of string-processing utilities, which is a problem for authors of portable code. Although R7RS provides some extensions and improvements, it is still very incomplete. This SRFI proposes a coherent and comprehensive set of string-processing procedures; it is accompanied by a portable sample implementation of the spec.

    This SRFI is derived from SRFI 13. The biggest difference is that it allows subsequences of strings to be specified by cursors as well as the traditional string indexes. In addition, it omits the comparison, case-mapping, and mutation operations of SRFI 13, as well as all procedures already present in R7RS.

    (srfi 130) procedure (string-cursor? obj) ⟹ boolean?

    Returns #t if obj can be a string cursor, and #f otherwise. In implementations where cursors and indexes are the same thing, #t is returned on any cursor or index; where they are disjoint, #t is returned on cursors, #f on indexes. If obj is neither a cursor nor an index, string-cursor? will always return #f.

    (srfi 130) procedure (string-cursor-start (s string?)) ⟹ string-cursor?

    (srfi 130) procedure (string-cursor-end (s string?)) ⟹ string-cursor?

    Returns the start/post-end cursor of s respectively.

    (srfi 130) procedure (string-cursor-next (s string?) (cursor integer? | string-cursor?)) ⟹ string-cursor?

    (srfi 130) procedure (string-cursor-prev (s string?) (cursor integer? | string-cursor?)) ⟹ string-cursor?

    Returns the cursor into s following/preceding cursor. If cursor is an index, returns one more/less than cursor. It is an error if cursor is the post-end/start cursor of s.

    (srfi 130) procedure (string-cursor-forward (s string?) (cursor integer? | string-cursor?) (nchars integer?)) ⟹ string-cursor?

    (srfi 130) procedure (string-cursor-back (s string?) (cursor integer? | string-cursor?) (nchars integer?)) ⟹ string-cursor?

    Returns the cursor into s which follows/precedes cursor by nchars characters. If cursor is an index, returns nchars more/less than cursor. It is an error if the result would be an invalid cursor or index.

    (srfi 130) procedure (string-cursor=? (cursor1 integer? | string-cursor?) (cursor2 integer? | string-cursor?)) ⟹ boolean?

    (srfi 130) procedure (string-cursor<? (cursor1 integer? | string-cursor?) (cursor2 integer? | string-cursor?)) ⟹ boolean?

    (srfi 130) procedure (string-cursor>? (cursor1 integer? | string-cursor?) (cursor2 integer? | string-cursor?)) ⟹ boolean?

    (srfi 130) procedure (string-cursor<=? (cursor1 integer? | string-cursor?) (cursor2 integer? | string-cursor?)) ⟹ boolean?

    (srfi 130) procedure (string-cursor>=? (cursor1 integer? | string-cursor?) (cursor2 integer? | string-cursor?)) ⟹ boolean?

    Compares two cursors or two indexes pointing into the same string.

    (srfi 130) procedure (string-cursor-diff (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ integer?

    Returns the number of characters between start and end in string s. Note that the result is always non-negative if start and end are a valid start-end pair.

    (srfi 130) procedure (string-cursor->index (s string?) (cursor string-cursor?)) ⟹ integer?

    (srfi 130) procedure (string-index->cursor (s string?) (index integer?)) ⟹ string-cursor?

    Converts a cursor/index into s into the corresponding index/cursor. If the argument is already an index/cursor, it is returned unchanged.

    (srfi 130) procedure (string-null? (s string?)) ⟹ boolean?

    Is s the empty string?

    (srfi 130) procedure (string-every (pred predicate) (s string?)) ⟹ *

    (srfi 130) procedure (string-every (pred predicate) (s string?) (start integer? | string-cursor?)) ⟹ *

    (srfi 130) procedure (string-every (pred predicate) (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ *

    (srfi 130) procedure (string-any (pred predicate) (s string?)) ⟹ *

    (srfi 130) procedure (string-any (pred predicate) (s string?) (start integer? | string-cursor?)) ⟹ *

    (srfi 130) procedure (string-any (pred predicate) (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ *

    Checks to see if every/any character in s satisfies pred proceeding from left (index start) to right (index end). The predicate is "witness-generating":

  • If string-any returns true, the returned true value is the one produced by the application of the predicate.
  • If string-every returns true, the returned true value is the one produced by the final application of the predicate to s[end-1]. If string-every is applied to an empty sequence of characters, it simply returns #t.
  • The names of these procedures do not end with a question mark — this is to indicate that they do not return a simple boolean (#t or #f), but a general value.

    (srfi 130) procedure (string-tabulate (proc procedure?) (len integer?)) ⟹ string?

    (srfi 130) procedure (string-tabulate (proc procedure?) (len integer?)) ⟹ string?

    (proc (index integer?)) ⟹ char?

    Proc is an integer → char procedure. Construct a string of size len by applying proc to each value from 0 (inclusive) to len (exclusive) to produce the corresponding string element. The order in which proc is applied to the indexes is not specified.

    Note that the order of arguments is not the same as SRFI 1's list-tabulate, but is the same as tabulation functions in other SRFIs. When this discrepancy was discovered in SRFI 13, it was too late to change SRFI 1.

    (srfi 130) procedure (string-unfold (stop? predicate) (mapper procedure?) seed) ⟹ string?

    (srfi 130) procedure (string-unfold (stop? predicate) (mapper procedure?) seed (base string?)) ⟹ string?

    (srfi 130) procedure (string-unfold (stop? predicate) (mapper procedure?) seed (base string?) (make-final procedure?)) ⟹ string?

    (mapper seed) ⟹ char?

    (make-final seed) ⟹ string?

    This is a fundamental constructor for strings.

  • Successor is used to generate a series of "seed" values from the initial seed: seed, (successor seed), (successor2 seed), (successor3 seed), ...
  • Stop? tells us when to stop — when it returns true when applied to one of these seed values.
  • Mapper maps each seed value to the corresponding character in the result string. These chars are assembled into the string in a left-to-right order.
  • Base is the optional initial/leftmost portion of the constructed string; it defaults to the empty string "".
  • Make-final is applied to the terminal seed value (on which stop? returns true) to produce the final/rightmost portion of the constructed string. It defaults to (lambda (x) "").
  • string-unfold is a fairly powerful string constructor — you can use it to convert a list to a string, read a port into a string, reverse a string, copy a string, and so forth.

    (srfi 130) procedure (string-unfold-right (stop? predicate) (mapper procedure?) seed) ⟹ string?

    (srfi 130) procedure (string-unfold-right (stop? predicate) (mapper procedure?) seed (base string?)) ⟹ string?

    (srfi 130) procedure (string-unfold-right (stop? predicate) (mapper procedure?) seed (base string?) (make-final procedure?)) ⟹ string?

    (mapper seed) ⟹ char?

    (make-final seed) ⟹ string?

    This is a fundamental constructor for strings. It is equivalent to string-unfold, except that the results of mapper are assembled into the string in a right-to-left order, base is the optional rightmost portion of the constructed string, and make-final produces the leftmost portion of the constructed string.

    (srfi 130) procedure (string->list/cursors (s string?)) ⟹ list?

    (srfi 130) procedure (string->list/cursors (s string?) (start integer? | string-cursor?)) ⟹ list?

    (srfi 130) procedure (string->list/cursors (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ list?

    return ⟹ (list (c char?))

    (srfi 130) procedure (string->vector/cursors (s string?)) ⟹ vector?

    (srfi 130) procedure (string->vector/cursors (s string?) (start integer? | string-cursor?)) ⟹ vector?

    (srfi 130) procedure (string->vector/cursors (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ vector?

    return ⟹ (vector (c char?))

    string->list/cursors and string->vector/cursors return a newly allocated list or vector of the characters that make up the given string. They differ from the R7RS procedures string->list and string->vector by accepting either cursors or indexes.

    (srfi 130) procedure (reverse-list->string (char-list list?)) ⟹ string?

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

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

    This is a common idiom in the epilog of string-processing loops that accumulate an answer in a reverse-order list. (See also string-concatenate-reverse for the "chunked" variant.)

    (srfi 130) procedure (string-join (string-list list?)) ⟹ string?

    (srfi 130) procedure (string-join (string-list list?) (delimiter string?)) ⟹ string?

    (srfi 130) procedure (string-join (string-list list?) (delimiter string?) (grammar symbol?)) ⟹ string?

    This procedure is a simple unparser —- it pastes strings together using the delimiter string.

    The grammar argument is a symbol that determines how the delimiter is used, and defaults to 'infix.

    'infix means an infix or separator grammar: insert the delimiter between list elements. An empty list will produce an empty string — note, however, that parsing an empty string with an infix or separator grammar is ambiguous. Is it an empty list, or a list of one element, the empty string?

    'strict-infix means the same as 'infix, but will signal an error if given an empty list.

    'suffix means a suffix or terminator grammar: insert the delimiter after every list element. This grammar has no ambiguities.

    'prefix means a prefix grammar: insert the delimiter before every list element. This grammar has no ambiguities.

    The delimiter is the string used to delimit elements; it defaults to a single space " ".

    (srfi 130) procedure (string-ref/cursor (s string?) (cursor integer? | string-cursor?)) ⟹ char?

    Returns character s[i] using a valid cursor or index of s. It differs from the R7RS procedure string-ref by accepting either a cursor or an index.

    (srfi 130) procedure (substring/cursors (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-copy/cursors (s string?)) ⟹ string?

    (srfi 130) procedure (string-copy/cursors (s string?) (start integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-copy/cursors (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string?

    These procedures return a string whose contents are the characters of s beginning with index start (inclusive) and ending with index end (exclusive). If substring/cursors produces the entire string, it may return either s or a copy of s; in some implementations, proper substrings may share memory with s. However, string-copy/cursors always returns a newly allocated string. They differ from the R7RS procedures substring and string-copy by accepting either cursors or indexes.

    (srfi 130) procedure (string-take (s string?) (nchars integer?)) ⟹ string?

    (srfi 130) procedure (string-drop (s string?) (nchars integer?)) ⟹ string?

    (srfi 130) procedure (string-take-right (s string?) (nchars integer?)) ⟹ string?

    (srfi 130) procedure (string-drop-right (s string?) (nchars integer?)) ⟹ string?

    string-take returns the first nchars of s; string-drop returns all but the first nchars of s. string-take-right returns the last nchars of s; string-drop-right returns all but the last nchars of s. If these procedures produce the entire string, they may return either s or a copy of s; in some implementations, proper substrings may share memory with s.

    (srfi 130) procedure (string-pad (s string?) (len integer?)) ⟹ string?

    (srfi 130) procedure (string-pad (s string?) (len integer?) (char char?)) ⟹ string?

    (srfi 130) procedure (string-pad (s string?) (len integer?) (char char?) (start integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-pad (s string?) (len integer?) (char char?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-pad-right (s string?) (len integer?)) ⟹ string?

    (srfi 130) procedure (string-pad-right (s string?) (len integer?) (char char?)) ⟹ string?

    (srfi 130) procedure (string-pad-right (s string?) (len integer?) (char char?) (start integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-pad-right (s string?) (len integer?) (char char?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string?

    Build a string of length len comprised of s padded on the left (right) by as many occurrences of the character char as needed. If s has more than len chars, it is truncated on the left (right) to length len. Char defaults to #\space.

    If len <= end-start, the returned value is allowed to share storage with s, or be exactly s (if len = end-start).

    (srfi 130) procedure (string-trim (s string?)) ⟹ string?

    (srfi 130) procedure (string-trim (s string?) (pred predicate)) ⟹ string?

    (srfi 130) procedure (string-trim (s string?) (pred predicate) (start integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-trim (s string?) (pred predicate) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-trim-right (s string?)) ⟹ string?

    (srfi 130) procedure (string-trim-right (s string?) (pred predicate)) ⟹ string?

    (srfi 130) procedure (string-trim-right (s string?) (pred predicate) (start integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-trim-right (s string?) (pred predicate) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-trim-both (s string?)) ⟹ string?

    (srfi 130) procedure (string-trim-both (s string?) (pred predicate)) ⟹ string?

    (srfi 130) procedure (string-trim-both (s string?) (pred predicate) (start integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-trim-both (s string?) (pred predicate) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string?

    Trim s by skipping over all characters on the left / on the right / on both sides that satisfy the second parameter pred: pred defaults to char-whitespace?.

    If no trimming occurs, these functions may return either s or a copy of s; in some implementations, proper substrings may share memory with s.

    (srfi 130) procedure (string-prefix-length (s1 string?) (s2 string?)) ⟹ integer?

    (srfi 130) procedure (string-prefix-length (s1 string?) (s2 string?) (start1 integer? | string-cursor?)) ⟹ integer?

    (srfi 130) procedure (string-prefix-length (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?)) ⟹ integer?

    (srfi 130) procedure (string-prefix-length (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?)) ⟹ integer?

    (srfi 130) procedure (string-prefix-length (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?) (end2 integer? | string-cursor?)) ⟹ integer?

    (srfi 130) procedure (string-suffix-length (s1 string?) (s2 string?)) ⟹ integer?

    (srfi 130) procedure (string-suffix-length (s1 string?) (s2 string?) (start1 integer? | string-cursor?)) ⟹ integer?

    (srfi 130) procedure (string-suffix-length (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?)) ⟹ integer?

    (srfi 130) procedure (string-suffix-length (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?)) ⟹ integer?

    (srfi 130) procedure (string-suffix-length (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?) (end2 integer? | string-cursor?)) ⟹ integer?

    Return the length of the longest common prefix/suffix of the two strings. For prefixes, this is equivalent to the "mismatch index" for the strings (modulo the start cursors).

    The optional start/end cursors or indexes restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 130) procedure (string-prefix? (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 130) procedure (string-prefix? (s1 string?) (s2 string?) (start1 integer? | string-cursor?)) ⟹ boolean?

    (srfi 130) procedure (string-prefix? (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?)) ⟹ boolean?

    (srfi 130) procedure (string-prefix? (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?)) ⟹ boolean?

    (srfi 130) procedure (string-prefix? (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?) (end2 integer? | string-cursor?)) ⟹ boolean?

    (srfi 130) procedure (string-suffix? (s1 string?) (s2 string?)) ⟹ boolean?

    (srfi 130) procedure (string-suffix? (s1 string?) (s2 string?) (start1 integer? | string-cursor?)) ⟹ boolean?

    (srfi 130) procedure (string-suffix? (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?)) ⟹ boolean?

    (srfi 130) procedure (string-suffix? (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?)) ⟹ boolean?

    (srfi 130) procedure (string-suffix? (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?) (end2 integer? | string-cursor?)) ⟹ boolean?

    Is s1 a prefix/suffix of s2?

    The optional start/end cursors or indexes restrict the comparison to the indicated substrings of s1 and s2.

    (srfi 130) procedure (string-index (s string?) (pred predicate)) ⟹ string-cursor?

    (srfi 130) procedure (string-index (s string?) (pred predicate) (start integer? | string-cursor?)) ⟹ string-cursor?

    (srfi 130) procedure (string-index (s string?) (pred predicate) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string-cursor?

    (srfi 130) procedure (string-index-right (s string?) (pred predicate)) ⟹ string-cursor?

    (srfi 130) procedure (string-index-right (s string?) (pred predicate) (start integer? | string-cursor?)) ⟹ string-cursor?

    (srfi 130) procedure (string-index-right (s string?) (pred predicate) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string-cursor?

    (srfi 130) procedure (string-skip (s string?) (pred predicate)) ⟹ string-cursor?

    (srfi 130) procedure (string-skip (s string?) (pred predicate) (start integer? | string-cursor?)) ⟹ string-cursor?

    (srfi 130) procedure (string-skip (s string?) (pred predicate) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string-cursor?

    (srfi 130) procedure (string-skip-right (s string?) (pred predicate)) ⟹ string-cursor?

    (srfi 130) procedure (string-skip-right (s string?) (pred predicate) (start integer? | string-cursor?)) ⟹ string-cursor?

    (srfi 130) procedure (string-skip-right (s string?) (pred predicate) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string-cursor?

    string-index searches through s from the left, returning the cursor of the first occurrence of a character which satisfies the predicate pred. If no match is found, it returns end. string-index-right searches through s from the right, returning the cursor of the successor of the first occurrence of a character which satisfies the predicate pred. If no match is found, it returns start.

    The start and end parameters specify the beginning and end cursors or indexes of the search; the search includes the start, but not the end. Be careful of "fencepost" considerations: when searching right-to-left, the first position considered is (string-cursor-prev end), whereas when searching left-to-right, the first index considered is start. That is, the start/end indexes describe the same half-open interval [start,end) in these procedures that they do in all the other SRFI 130 procedures.

    The skip functions are similar, but use the complement of the criteria: they search for the first char that doesn't satisfy pred. E.g., to skip over initial whitespace, say

    (substring/cursors s (string-skip s char-whitespace?))

    Note that the result is always a cursor, even when start and end are indexes. Use string-cursor->index to convert the result to an index. Therefore, these four functions are not entirely compatible with their SRFI 13 counterparts, which return #f on failure.

    These functions can be trivially composed with string-take and string-drop to produce take-while, drop-while, span, and break procedures without loss of efficiency.

    (srfi 130) procedure (string-contains (s1 string?) (s2 string?)) ⟹ #f | string-cursor?

    (srfi 130) procedure (string-contains (s1 string?) (s2 string?) (start1 integer? | string-cursor?)) ⟹ #f | string-cursor?

    (srfi 130) procedure (string-contains (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?)) ⟹ #f | string-cursor?

    (srfi 130) procedure (string-contains (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?)) ⟹ #f | string-cursor?

    (srfi 130) procedure (string-contains (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?) (end2 integer? | string-cursor?)) ⟹ #f | string-cursor?

    (srfi 130) procedure (string-contains-right (s1 string?) (s2 string?)) ⟹ #f | string-cursor?

    (srfi 130) procedure (string-contains-right (s1 string?) (s2 string?) (start1 integer? | string-cursor?)) ⟹ #f | string-cursor?

    (srfi 130) procedure (string-contains-right (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?)) ⟹ #f | string-cursor?

    (srfi 130) procedure (string-contains-right (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?)) ⟹ #f | string-cursor?

    (srfi 130) procedure (string-contains-right (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?) (end2 integer? | string-cursor?)) ⟹ #f | string-cursor?

    Does string s1 contain string s2?

    Returns the cursor in s1 referring to the first character of the first/last instance of s2 as a substring, or #f if there is no match. The optional start/end indexes restrict the operation to the indicated substrings.

    The returned cursor is in the range [start1,end1). A successful match must lie entirely in the [start1,end1) range of s1.

    Note that the result is always a cursor, even when start1 and end1 are indexes.

    Use string-cursor->index to convert a cursor result to an index.

    (string-contains "eek -- what a geek." "ee"

    12 18) ; Searches "a geek"

    => {Cursor 15}

    The name of this procedure does not end with a question mark — this is to indicate that it does not return a simple boolean (#t or #f). Rather, it returns either false (#f) or a cursor.

    (srfi 130) procedure (string-reverse (s string?)) ⟹ string?

    (srfi 130) procedure (string-reverse (s string?) (start integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-reverse (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string?

    Reverse the string.

    (srfi 130) procedure (string-concatenate (string-list list?)) ⟹ string?

    Append the elements of string-list together into a single string. Guaranteed to return a freshly allocated string.

    Note that the (apply string-append string-list) idiom is not robust for long lists of strings, as some Scheme implementations limit the number of arguments that may be passed to an n-ary procedure.

    (srfi 130) procedure (string-concatenate-reverse (string-list list?)) ⟹ string?

    (srfi 130) procedure (string-concatenate-reverse (string-list list?) (final-string string?)) ⟹ string?

    (srfi 130) procedure (string-concatenate-reverse (string-list list?) (final-string string?) (end integer? | string-cursor?)) ⟹ string?

    With no optional arguments, this function is equivalent to

    (string-concatenate (reverse string-list))

    If the optional argument final-string is specified, it is consed onto the beginning of string-list before performing the list-reverse and string-concatenate operations.

    If the optional argument end is given, only the characters up to but not including end in final-string are added to the result.

    (srfi 130) procedure (string-fold (kons procedure?) knil (s string?)) ⟹ *

    (srfi 130) procedure (string-fold (kons procedure?) knil (s string?) (start integer? | string-cursor?)) ⟹ *

    (srfi 130) procedure (string-fold (kons procedure?) knil (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ *

    (kons (c char?) state) ⟹ *

    The left-fold operator maps the kons procedure across the string from left to right

    (... (kons s[2] (kons s[1] (kons s[0] knil))))

    (srfi 130) procedure (string-fold-right (kons procedure?) knil (s string?)) ⟹ *

    (srfi 130) procedure (string-fold-right (kons procedure?) knil (s string?) (start integer? | string-cursor?)) ⟹ *

    (srfi 130) procedure (string-fold-right (kons procedure?) knil (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ *

    (kons (c char?) state) ⟹ *

    The right-fold operator maps the kons procedure across the string from right to left

    (kons s[0] (... (kons s[end-3] (kons s[end-2] (kons s[end-1] knil)))))

    (srfi 130) procedure (string-for-each-cursor (proc procedure?) (s string?)) ⟹ undefined

    (srfi 130) procedure (string-for-each-cursor (proc procedure?) (s string?) (start integer? | string-cursor?)) ⟹ undefined

    (srfi 130) procedure (string-for-each-cursor (proc procedure?) (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ undefined

    (proc (cursor string-cursor?)) ⟹ undefined

    Apply proc to each cursor of s, in order, excluding the post-end cursor. The optional start/end pairs restrict the endpoints of the loop. This is simply a method of looping over a string that is guaranteed to be safe and correct.

    (srfi 130) procedure (string-replicate (s string?) (from integer?) (to integer?)) ⟹ string?

    (srfi 130) procedure (string-replicate (s string?) (from integer?) (to integer?) (start integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-replicate (s string?) (from integer?) (to integer?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string?

    This is an "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 (i.e., the whole string). Replicate this substring up and down index space, in both the positive and negative directions.

    string-replicate returns the substring of this string beginning at index from, and ending at to. Note that these arguments cannot be cursors. It is an error if from is greater than to.

    Note that

  • The from/to indexes give a half-open range — the characters from index from up to, but not including, index to.
  • The from/to indexes are not in terms of the index space for string s. They are in terms of the replicated index space of the substring defined by s, start, and end.
  • It is an error if start=end — although this is allowed by special dispensation when from=to.

    (srfi 130) procedure (string-count (s string?) (pred predicate)) ⟹ integer?

    (srfi 130) procedure (string-count (s string?) (pred predicate) (start integer? | string-cursor?)) ⟹ integer?

    (srfi 130) procedure (string-count (s string?) (pred predicate) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ integer?

    Return a count of the number of characters in s that satisfy the pred argument.

    (srfi 130) procedure (string-replace (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-replace (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-replace (s1 string?) (s2 string?) (start1 integer? | string-cursor?) (end1 integer? | string-cursor?) (start2 integer? | string-cursor?) (end2 integer? | string-cursor?)) ⟹ string?

    The segment of characters in s1 from start1 to end1 is replaced by the segment of characters in s2 from start2 to end2. If start1=end1, this simply splices the s2 characters into s1 at the specified index.

    (srfi 130) procedure (string-split (s string?) (delimiter string?)) ⟹ list?

    (srfi 130) procedure (string-split (s string?) (delimiter string?) (grammar symbol?)) ⟹ list?

    (srfi 130) procedure (string-split (s string?) (delimiter string?) (grammar symbol?) (limit integer? | #f)) ⟹ list?

    (srfi 130) procedure (string-split (s string?) (delimiter string?) (grammar symbol?) (limit integer? | #f) (start integer? | string-cursor?)) ⟹ list?

    (srfi 130) procedure (string-split (s string?) (delimiter string?) (grammar symbol?) (limit integer? | #f) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ list?

    Returns a list of the words contained in the substring of string from start (inclusive) to end (exclusive). Delimiter specifies a string that is to be used as the word separator. This will often be a single character, but multiple characters are allowed for cases like splitting on "\r\n". The returned list will then have one more item than the number of non-overlapping occurrences of the delimiter in the string. If delimiter is an empty string, then the returned list contains a list of strings, each of which contains a single character.

    Grammar is a symbol with the same meaning as in the string-join procedure. If it is infix, which is the default, processing is done as described above, except that an empty s produces the empty list; if it is strict-infix, an empty s signals an error. The values prefix and suffix cause a leading/trailing empty string in the result to be suppressed.

    If limit is a non-negative exact integer, at most that many splits occur, and the remainder of string is returned as the final element of the list (thus, the result will have at most limit+1 elements). If limit is not specified or is #f, then as many splits as possible are made. It is an error if limit is any other value.

    Use SRFI 115's regexp-split to split on a regular expression rather than a simple string.

    (srfi 130) procedure (string-filter (pred predicate) (s string?)) ⟹ string?

    (srfi 130) procedure (string-filter (pred predicate) (s string?) (start integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-filter (pred predicate) (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-remove (pred predicate) (s string?)) ⟹ string?

    (srfi 130) procedure (string-remove (pred predicate) (s string?) (start integer? | string-cursor?)) ⟹ string?

    (srfi 130) procedure (string-remove (pred predicate) (s string?) (start integer? | string-cursor?) (end integer? | string-cursor?)) ⟹ string?

    Filter the string s, retaining only those characters that satisfy / do not satisfy pred.

    If the string is unaltered by the filtering operation, these functions may return either s or a copy of s.

    Compatibility note: string-remove is identical to the string-delete procedure of SRFI 13, but the name string-delete is inconsistent with the conventions of SRFI 1 and other SRFIs.

    library (srfi 131) ERR5RS Record Syntax (reduced)

    This SRFI is a reduced version of the SRFI 99 syntactic layer that can be implemented with syntax-rules without requiring low-level macros. Like SRFI-99's syntax layer, it is backward compatible with the define-record-type macro from SRFI 9 or R7RS-small. It is forward compatible with SRFI 99.

    See (srfi 99)

    library (srfi 131 records procedural) ERR5RS Record Syntax (reduced)

    This SRFI is a reduced version of the SRFI 99 syntactic layer that can be implemented with syntax-rules without requiring low-level macros. Like SRFI-99's syntax layer, it is backward compatible with the define-record-type macro from SRFI 9 or R7RS-small. It is forward compatible with SRFI 99.

    See (srfi 99)

    library (srfi 131 records inspection) ERR5RS Record Syntax (reduced)

    This SRFI is a reduced version of the SRFI 99 syntactic layer that can be implemented with syntax-rules without requiring low-level macros. Like SRFI-99's syntax layer, it is backward compatible with the define-record-type macro from SRFI 9 or R7RS-small. It is forward compatible with SRFI 99.

    See (srfi 99)

    library (srfi 131 records syntactic) ERR5RS Record Syntax (reduced)

    This SRFI is a reduced version of the SRFI 99 syntactic layer that can be implemented with syntax-rules without requiring low-level macros. Like SRFI-99's syntax layer, it is backward compatible with the define-record-type macro from SRFI 9 or R7RS-small. It is forward compatible with SRFI 99.

    See (srfi 131)

    library (srfi 132) Sort Libraries

    This SRFI describes the API for a full-featured sort toolkit.

    See (scheme sort)

    library (srfi 133) Vector Library (R7RS-compatible)

    This SRFI proposes a comprehensive library of vector operations accompanied by a freely available and complete reference implementation. The reference implementation is unencumbered by copyright, and useable with no modifications on any Scheme system that is R5RS-compliant. It also provides several hooks for implementation-specific optimization as well.

    See (scheme vector)

    library (srfi 134) Immutable Deques

    This SRFI defines immutable deques. A deque is a double-ended queue, a sequence which allows elements to be added or removed efficiently from either end. A structure is immutable when all its operations leave the structure unchanged. Note that none of the procedures specified here ends with an exclamation point.

    See (scheme ideque)

    library (srfi 135) Immutable Texts

    In Scheme, strings are a mutable data type. Although it "is an error" (R5RS and R7RS) to use string-set! on literal strings or on strings returned by symbol->string, and any attempt to do so "should raise an exception" (R6RS), all other strings are mutable.

    Although many mutable strings are never actually mutated, the mere possibility of mutation complicates specifications of libraries that use strings, encourages precautionary copying of strings, and precludes structure sharing that could otherwise be used to make procedures such as substring and string-append faster and more space-efficient.

    This SRFI specifies a new data type of immutable texts. It comes with efficient and portable sample implementations that guarantee O(1) indexing for both sequential and random access, even in systems whose string-ref procedure takes linear time.

    The operations of this new data type include analogues for all of the non-mutating operations on strings specified by the R7RS and most of those specified by SRFI 130, but the immutability of texts and uniformity of character-based indexing simplify the specification of those operations while avoiding several inefficiencies associated with the mutability of Scheme's strings.

    See (scheme text)

    library (srfi 137) Minimal Unique Types

    This SRFI is intended to standardize a primitive run-time mechanism to create disjoint types.

    (srfi 137) procedure (make-type type-payload) ⟹ (values procedure? procedure? procedure? procedure? procedure?)

    (make-type type-payload) → type-accessor constructor predicate accessor make-subtype

    Calling make-type on type-payload, which can be any Scheme object, returns five values, all of which are procedures. They are distinct (in the sense of eqv?) from each other and from any other procedures returned by other calls to make-type. In brief, the five functions:

    return type-payload

    return newly allocated objects of a disjoint type known as instances, each associated with an instance payload

    return #t iff an object is an instance of this type

    return the instance payload

    return five more procedures associated with a subtype of this type

    The type payload might contain metadata (such as field names or class variables) associated with the type as a whole.

    For the purposes of this section, we will suppose that

    (define-values (reia-metadata make-reia reia? reia-ref make-reia-subtype) (make-type 'reia))

    has been evaluated, and document each of the five variables that it binds. "Reia" is an acronym for "remarkably 'evil' in appearance", and has no particular significance. Fnord!

    (reia-metadata) → object

    Returns the symbol reia.

    (make-reia instance-payload)→ reia

    Returns a newly allocated instance associated with instance-payload. This association is single and immutable, but it is possible to make use of an appropriate container payload in order to effectively associate the instance with more than one value. To make the association effectively mutable, use a mutable payload such as a box, list or vector. Instances belong to a type that is disjoint from any existing Scheme type, including types created by other calls to make-type.

    (reia? object)→ boolean

    Returns #t iff object was returned by a call to make-reia or any constructor created as part of a direct or indirect subtype of the reia type.

    (reia-ref reia)→ object

    Returns the instance payload of reia. It is an error if reia does not satisfy reia?.

    (make-reia-subtype type-payload)→ type-accessor constructor predicate accessor make-subtype

    Returns five new procedures with the same semantics as make-type, such that the objects returned by constructor satisfy reia? and their payload can be accessed using reia-ref.

    library (srfi 139) Syntax parameters

    Syntax parameters are to the expansion process of a Scheme program what parameters are to the evaluation process of a Scheme program. They allow hygienic implementation of syntactic forms that would otherwise introduce implicit identifiers unhygienically.

    (srfi 139) syntax (define-syntax-parameter keyword transformer-spec)

    Binds <keyword> to the transformer obtained by evaluating <transformer spec>. The transformer provides the default expansion for the syntax parameter, and in the absence of syntax-parameterize, is functionally equivalent to define-syntax.

    (srfi 139) syntax (syntax-parameterize ((keyword transformer-spec) ...) body)

    Adjusts the <keyword>s to use the transformer obtained by evaluating the corresponding <transformer>s in the expansion of the <body>. Each keyword must be bound to a syntax parameter. syntax-parameterize differs from let-syntax in that the binding is not shadowed, but adjusted, and so uses of the keyword in the expansion of <body> use the new transformers. This is somewhat similar to how parameterize adjusts the values of regular parameters, rather than creating new bindings.

    library (srfi 140) Immutable Strings

    This attempts to solve the same issues with R7RS strings raised by SRFI-135, but with better integration with the Scheme language.

    We propose to retain the name string as the type of sequences of Unicode characters (scalar values). There are two standard subtypes of string:

    • Immutable strings, also called istrings, cannot be modified after they have been created. Calling string-set! on an istring throws an error. On the other hand, the core operations string-ref and string-length are guaranteed to be O(1).
    • Mutable strings can be modified in-place using string-set! and other operations. However, string-ref, string-set!, or string-length have no performance guarantees. On many implementation they may take time proportional to the length of the string.

    An implementation may support other kinds of strings. For example on the Java platform it may be reasonable to consider any instance of java.lang.CharSequence to be a string.

    The main part of the proposal specifies the default bindings of various procedure names, as might be pre-defined in a REPL. Specifically, some procedures that traditionally return mutable strings are changed to return istrings. We later discuss compatibility and other library issues.

    This combines SRFI-13, SRFI-135, and SRFI-118.

    (srfi 140) procedure (string? obj) ⟹ boolean?

    Is obj a string? Must return true if istring? returns true. Must execute in O(1) time.

    (srfi 140) procedure (istring? obj) ⟹ boolean?

    Is obj an immutable string, with guaranteed O(1) performance for string-ref and string-length? Must execute in O(1) time.

    (srfi 140) procedure (string-null? (string string?)) ⟹ boolean?

    Is string the empty string? Same result as (= (string-length string) 0) but must execute in O(1) time.

    (srfi 140) procedure (string-every (pred predicate) (string string?)) ⟹ *

    (srfi 140) procedure (string-every (pred predicate) (string string?) (start integer?)) ⟹ *

    (srfi 140) procedure (string-every (pred predicate) (string string?) (start integer?) (end integer?)) ⟹ *

    (srfi 140) procedure (string-any (pred predicate) (string string?)) ⟹ *

    (srfi 140) procedure (string-any (pred predicate) (string string?) (start integer?)) ⟹ *

    (srfi 140) procedure (string-any (pred predicate) (string string?) (start integer?) (end integer?)) ⟹ *

    Checks to see if every/any character in string satisfies pred, proceeding from left (index start) to right (index end). These procedures are short-circuiting: if pred returns false, string-every does not call pred on subsequent characters; if pred returns true, string-any does not call pred on subsequent characters. Both procedures are "witness-generating":

  • If string-every is given an empty interval (with start = end), it returns #t.
  • If string-every returns true for a non-empty interval (with start < end), the returned true value is the one returned by the final call to the predicate on (string-ref string (- end 1)).
  • If string-any returns true, the returned true value is the one returned by the predicate.
  • Note: The names of these procedures do not end with a question mark. This indicates a general value is returned instead of a simple boolean (#t or #f).

    (srfi 140) procedure (string->vector (string string?)) ⟹ vector?

    (srfi 140) procedure (string->vector (string string?) (start integer?)) ⟹ vector?

    (srfi 140) procedure (string->vector (string string?) (start integer?) (end integer?)) ⟹ vector?

    return ⟹ (vector (char char?))

    (srfi 140) procedure (string->list (string string?)) ⟹ list?

    (srfi 140) procedure (string->list (string string?) (start integer?)) ⟹ list?

    (srfi 140) procedure (string->list (string string?) (start integer?) (end integer?)) ⟹ list?

    return ⟹ (list (char char?))

    string->vector, and string->list return a newly allocated (unless empty) vector, or list of the characters that make up the given substring.

    (srfi 140) procedure (vector->string (char-vector vector?)) ⟹ istring?

    (srfi 140) procedure (vector->string (char-vector vector?) (start integer?)) ⟹ istring?

    (srfi 140) procedure (vector->string (char-vector vector?) (start integer?) (end integer?)) ⟹ istring?

    char-vector ⟹ (vector (char char?))

    (srfi 140) procedure (list->string (char-list list?)) ⟹ istring?

    (srfi 140) procedure (list->string (char-list list?) (start integer?)) ⟹ istring?

    (srfi 140) procedure (list->string (char-list list?) (start integer?) (end integer?)) ⟹ istring?

    char-list ⟹ (list (char char?))

    These procedures return an istring containing the characters of the given subvector or sublist. The behavior of the result will not be affected by subsequent mutation of the vector or list.

    (srfi 140) procedure (reverse-list->string (char-list list?)) ⟹ istring?

    char-list ⟹ (list (char char?))

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

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

    This is a common idiom in the epilogue of string-processing loops that accumulate their result using a list in reverse order. (See also string-concatenate-reverse for the "chunked" variant.)

    (srfi 140) procedure (string->utf8 (string string?)) ⟹ bytevector?

    (srfi 140) procedure (string->utf8 (string string?) (start integer?)) ⟹ bytevector?

    (srfi 140) procedure (string->utf8 (string string?) (start integer?) (end integer?)) ⟹ bytevector?

    (srfi 140) procedure (string->utf16 (string string?)) ⟹ bytevector?

    (srfi 140) procedure (string->utf16 (string string?) (start integer?)) ⟹ bytevector?

    (srfi 140) procedure (string->utf16 (string string?) (start integer?) (end integer?)) ⟹ bytevector?

    (srfi 140) procedure (string->utf16be (string string?)) ⟹ bytevector?

    (srfi 140) procedure (string->utf16be (string string?) (start integer?)) ⟹ bytevector?

    (srfi 140) procedure (string->utf16be (string string?) (start integer?) (end integer?)) ⟹ bytevector?

    (srfi 140) procedure (string->utf16le (string string?)) ⟹ bytevector?

    (srfi 140) procedure (string->utf16le (string string?) (start integer?)) ⟹ bytevector?

    (srfi 140) procedure (string->utf16le (string string?) (start integer?) (end integer?)) ⟹ bytevector?

    These procedures return a newly allocated (unless empty) bytevector containing a UTF-8 or UTF-16 encoding of the given substring.

    The bytevectors returned by string->utf8, string->utf16be, and string->utf16le do not contain a byte-order mark (BOM). string->utf16be returns a big-endian encoding, while string->utf16le returns a little-endian encoding.

    The bytevectors returned by string->utf16 begin with a BOM that declares an implementation-dependent endianness. The latter should match the big-endian or little-endian identifier returned by the R7RS features procedure. The bytevector elements following that BOM encode the given substring using that endianness.

    Rationale: These procedures are consistent with the Unicode standard. Unicode suggests UTF-16 should default to big-endian, but Microsoft prefers little-endian.

    (srfi 140) procedure (utf8->string (bytevector bytevector?)) ⟹ istring?

    (srfi 140) procedure (utf8->string (bytevector bytevector?) (start integer?)) ⟹ istring?

    (srfi 140) procedure (utf8->string (bytevector bytevector?) (start integer?) (end integer?)) ⟹ istring?

    (srfi 140) procedure (utf16->string (bytevector bytevector?)) ⟹ istring?

    (srfi 140) procedure (utf16->string (bytevector bytevector?) (start integer?)) ⟹ istring?

    (srfi 140) procedure (utf16->string (bytevector bytevector?) (start integer?) (end integer?)) ⟹ istring?

    (srfi 140) procedure (utf16be->string (bytevector bytevector?)) ⟹ istring?

    (srfi 140) procedure (utf16be->string (bytevector bytevector?) (start integer?)) ⟹ istring?

    (srfi 140) procedure (utf16be->string (bytevector bytevector?) (start integer?) (end integer?)) ⟹ istring?

    (srfi 140) procedure (utf16le->string (bytevector bytevector?)) ⟹ istring?

    (srfi 140) procedure (utf16le->string (bytevector bytevector?) (start integer?)) ⟹ istring?

    (srfi 140) procedure (utf16le->string (bytevector bytevector?) (start integer?) (end integer?)) ⟹ istring?

    These procedures interpret their bytevector argument as a UTF-8 or UTF-16 encoding of a sequence of characters, and return a string containing that sequence.

    The bytevector subrange given to utf16->string may begin with a byte order mark (BOM); if so, that BOM determines whether the rest of the subrange is to be interpreted as big-endian or little-endian; in either case, the BOM will not become a character in the returned string. If the subrange does not begin with a BOM, it is decoded using the same implementation-dependent endianness used by string->utf16.

    The utf16be->string and utf16le->string procedures interpret their inputs as big-endian or little-endian, respectively. If a BOM is present, it is treated as a normal character and will become part of the result.

    It is an error if the bytevector subrange given to utf8->string contains invalid UTF-8 byte sequences. For the other three procedures, it is an error if (- end start) is odd, or if the bytevector subrange contains invalid UTF-16 byte sequences.

    (srfi 140) procedure (string (char char?) ...) ⟹ istring?

    Returns a string consisting of the given characters.

    (srfi 140) procedure (string-tabulate (proc procedure?) (len integer?)) ⟹ istring?

    (proc (index integer?)) ⟹ char?

    Proc is a procedure that accepts an exact integer as its argument and returns a character. Constructs a string of size len by calling proc on each value from 0 (inclusive) to len (exclusive) to produce the corresponding element of the string. The order in which proc is called on those indexes is not specified.

    Rationale: Although string-unfold is more general, string-tabulate is likely to run faster for the common special case it implements.

    (srfi 140) procedure (string-unfold (stop? predicate) (mapper procedure?) (successor procedure?) seed) ⟹ istring?

    (srfi 140) procedure (string-unfold (stop? predicate) (mapper procedure?) (successor procedure?) seed (base char? | string?)) ⟹ istring?

    (srfi 140) procedure (string-unfold (stop? predicate) (mapper procedure?) (successor procedure?) seed (base char? | string?) (make-final procedure?)) ⟹ istring?

    (mapper seed) ⟹ char? | string?

    (successor seed) ⟹ *

    (make-final seed) ⟹ char? | string?

    (srfi 140) procedure (string-unfold-right (stop? predicate) (mapper procedure?) (successor procedure?) seed) ⟹ istring?

    (srfi 140) procedure (string-unfold-right (stop? predicate) (mapper procedure?) (successor procedure?) seed (base char? | string?)) ⟹ istring?

    (srfi 140) procedure (string-unfold-right (stop? predicate) (mapper procedure?) (successor procedure?) seed (base char? | string?) (make-final procedure?)) ⟹ istring?

    (mapper seed) ⟹ char? | string?

    (successor seed) ⟹ *

    (make-final seed) ⟹ char? | string?

    This is a fundamental constructor for strings.

  • successor is used to generate a series of "seed" values from the initial seed:
  • seed, (successor seed), (successor2 seed), (successor3 seed), ...
  • stop? tells us when to stop — when it returns true when applied to one of these seed values.
  • mapper maps each seed value to the corresponding character(s) in the result string, which are assembled into that string in left-to-right order. It is an error for mapper to return anything other than a character or string.
  • base is the optional initial/leftmost portion of the constructed string, which defaults to the empty string "". It is an error if base is anything other than a character or string.
  • make-final is applied to the terminal seed value (on which stop? returns true) to produce the final/rightmost portion of the constructed string. It defaults to (lambda (x) (string)). It is an error for make-final to return anything other than a character or string.
  • string-unfold-right is the same as string-unfold except the results of mapper are assembled into the string in right-to-left order, base is the optional rightmost portion of the constructed string, and make-final produces the leftmost portion of the constructed string. If mapper returns a string, the string is prepended to the constructed string (without reversal).

    (srfi 140) procedure (string-length (string string?)) ⟹ integer?

    Returns the number of characters in the given string. If the string is an istring, must execute in constant time.

    (srfi 140) procedure (string-ref (string string?) (k integer?)) ⟹ char?

    It is an error if k is not a valid index of string. The string-ref procedure returns character k of string using zero-origin indexing. If the string is an istring, must execute in constant time.

    (srfi 140) procedure (substring (string string?) (start integer?) (end integer?)) ⟹ istring?

    This procedure returns a istring containing the characters of string starting with index start (inclusive) and ending with index end (exclusive).

    If string is a mutable string, then that string does not share any storage with the result, so subsequent mutation of that string will not affect the result returned by substring. When the first argument is an istring, implementations are encouraged to return a result that shares storage with that istring, to whatever extent sharing is possible while maintaining some small fixed bound on the ratio of storage used by the shared representation divided by the storage that would be used by an unshared representation. In particular, these procedures should just return their first argument when that argument is an istring, start is 0, and end is the length of that string.

    For the functionality of substring with guaranteed no sharing use xsubstring for an immutable result, or string-copy for a mutable result.

    (srfi 140) procedure (string-take (string string?) (nchars integer?)) ⟹ istring?

    (srfi 140) procedure (string-drop (string string?) (nchars integer?)) ⟹ istring?

    (srfi 140) procedure (string-take-right (string string?) (nchars integer?)) ⟹ istring?

    (srfi 140) procedure (string-drop-right (string string?) (nchars integer?)) ⟹ istring?

    string-take returns an immutable string containing the first nchars of string; string-drop returns a string containing all but the first nchars of string. string-take-right returns a string containing the last nchars of string; string-drop-right returns a string containing all but the last nchars of string.

    Subsequent mutation of the argument string will not affect the istring returned by these procedures. If string is an istring, implementations are encouraged to return a result that shares storage with that string (which is easily accomplished by using substring to create the result).

    (srfi 140) procedure (string-pad (string string?) (len integer?)) ⟹ istring?

    (srfi 140) procedure (string-pad (string string?) (len integer?) (char char?)) ⟹ istring?

    (srfi 140) procedure (string-pad (string string?) (len integer?) (char char?) (start integer?)) ⟹ istring?

    (srfi 140) procedure (string-pad (string string?) (len integer?) (char char?) (start integer?) (end integer?)) ⟹ istring?

    (srfi 140) procedure (string-pad-right (string string?) (len integer?)) ⟹ istring?

    (srfi 140) procedure (string-pad-right (string string?) (len integer?) (char char?)) ⟹ istring?

    (srfi 140) procedure (string-pad-right (string string?) (len integer?) (char char?) (start integer?)) ⟹ istring?

    (srfi 140) procedure (string-pad-right (string string?) (len integer?) (char char?) (start integer?) (end integer?)) ⟹ istring?

    Returns an istring of length len comprised of the characters drawn from the given subrange of string. The result is padded on the left (right) by as many occurrences of the character char (which defaults to #\space) as needed. If string has more than len chars, it is truncated on the left (right) to length len.

    (srfi 140) procedure (string-trim (string string?)) ⟹ istring?

    (srfi 140) procedure (string-trim (string string?) (pred predicate)) ⟹ istring?

    (srfi 140) procedure (string-trim (string string?) (pred predicate) (start integer?)) ⟹ istring?

    (srfi 140) procedure (string-trim (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ istring?

    (srfi 140) procedure (string-trim-right (string string?)) ⟹ istring?

    (srfi 140) procedure (string-trim-right (string string?) (pred predicate)) ⟹ istring?

    (srfi 140) procedure (string-trim-right (string string?) (pred predicate) (start integer?)) ⟹ istring?

    (srfi 140) procedure (string-trim-right (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ istring?

    (srfi 140) procedure (string-trim-both (string string?)) ⟹ istring?

    (srfi 140) procedure (string-trim-both (string string?) (pred predicate)) ⟹ istring?

    (srfi 140) procedure (string-trim-both (string string?) (pred predicate) (start integer?)) ⟹ istring?

    (srfi 140) procedure (string-trim-both (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ istring?

    Returns a string obtained from the given subrange of string by skipping over all characters on the left / on the right / on both sides that satisfy the second argument pred: pred defaults to char-whitespace?.

    (srfi 140) procedure (string-replace (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ istring?

    (srfi 140) procedure (string-replace (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ istring?

    (srfi 140) procedure (string-replace (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ istring?

    Returns

    (string-append (substring string1 0 start1)

    (substring string2 start2 end2)

    (substring string1 end1 (string-length string1)))

    That is, the segment of characters in string1 from start1 to end1 is replaced by the segment of characters in string2 from start2 to end2. If start1=end1, this simply splices the characters drawn from string2 into string1 at that position.

    (srfi 140) procedure (string=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 140) procedure (string<? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 140) procedure (string>? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 140) procedure (string<=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 140) procedure (string>=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 140) procedure (string-ci=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 140) procedure (string-ci<? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 140) procedure (string-ci>? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 140) procedure (string-ci<=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 140) procedure (string-ci>=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    As in R7RS

    (srfi 140) procedure (string-prefix-length (string1 string?) (string2 string?)) ⟹ integer?

    (srfi 140) procedure (string-prefix-length (string1 string?) (string2 string?) (start1 integer?)) ⟹ integer?

    (srfi 140) procedure (string-prefix-length (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ integer?

    (srfi 140) procedure (string-prefix-length (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ integer?

    (srfi 140) procedure (string-prefix-length (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ integer?

    (srfi 140) procedure (string-suffix-length (string1 string?) (string2 string?)) ⟹ integer?

    (srfi 140) procedure (string-suffix-length (string1 string?) (string2 string?) (start1 integer?)) ⟹ integer?

    (srfi 140) procedure (string-suffix-length (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ integer?

    (srfi 140) procedure (string-suffix-length (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ integer?

    (srfi 140) procedure (string-suffix-length (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ integer?

    Return the length of the longest common prefix/suffix of string1 and string2. For prefixes, this is equivalent to their "mismatch index" (relative to the start indexes).

    The optional start/end indexes restrict the comparison to the indicated substrings of string1 and string2.

    (srfi 140) procedure (string-prefix? (string1 string?) (string2 string?)) ⟹ boolean?

    (srfi 140) procedure (string-prefix? (string1 string?) (string2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 140) procedure (string-prefix? (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 140) procedure (string-prefix? (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 140) procedure (string-prefix? (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    (srfi 140) procedure (string-suffix? (string1 string?) (string2 string?)) ⟹ boolean?

    (srfi 140) procedure (string-suffix? (string1 string?) (string2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 140) procedure (string-suffix? (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 140) procedure (string-suffix? (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 140) procedure (string-suffix? (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Is string1 a prefix/suffix of string2?

    The optional start/end indexes restrict the comparison to the indicated substrings of string1 and string2.

    (srfi 140) procedure (string-index (string string?) (pred predicate)) ⟹ integer? | #f

    (srfi 140) procedure (string-index (string string?) (pred predicate) (start integer?)) ⟹ integer? | #f

    (srfi 140) procedure (string-index (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ integer? | #f

    (srfi 140) procedure (string-index-right (string string?) (pred predicate)) ⟹ integer? | #f

    (srfi 140) procedure (string-index-right (string string?) (pred predicate) (start integer?)) ⟹ integer? | #f

    (srfi 140) procedure (string-index-right (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ integer? | #f

    (srfi 140) procedure (string-skip (string string?) (pred predicate)) ⟹ integer? | #f

    (srfi 140) procedure (string-skip (string string?) (pred predicate) (start integer?)) ⟹ integer? | #f

    (srfi 140) procedure (string-skip (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ integer? | #f

    (srfi 140) procedure (string-skip-right (string string?) (pred predicate)) ⟹ integer? | #f

    (srfi 140) procedure (string-skip-right (string string?) (pred predicate) (start integer?)) ⟹ integer? | #f

    (srfi 140) procedure (string-skip-right (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ integer? | #f

    string-index searches through the given substring from the left, returning the index of the leftmost character satisfying the predicate pred. string-index-right searches from the right, returning the index of the rightmost character satisfying the predicate pred. If no match is found, these procedures return #f.

    Rationale: The SRFI 130 analogues of these procedures return cursors, even when no match is found, and SRFI 130's string-index-right returns the successor of the cursor for the first character that satisfies the predicate. As there are no cursors in this SRFI, it seems best to follow the more intuitive and long-standing precedent set by SRFI 13.

    The start and end arguments specify the beginning and end of the search; the valid indexes relevant to the search include start but exclude end. Beware of "fencepost" errors: when searching right-to-left, the first index considered is (- end 1), whereas when searching left-to-right, the first index considered is start. That is, the start/end indexes describe the same half-open interval [start,end) in these procedures that they do in all other procedures specified by this SRFI.

    The skip functions are similar, but use the complement of the criterion: they search for the first char that doesn't satisfy pred. To skip over initial whitespace, for example, say

    (substring string

    (or (string-skip string char-whitespace?)

    (string-length string))

    (string-length string))

    These functions can be trivially composed with string-take and string-drop to produce take-while, drop-while, span, and break procedures without loss of efficiency.

    (srfi 140) procedure (string-contains (string1 string?) (string2 string?)) ⟹ integer? | #f

    (srfi 140) procedure (string-contains (string1 string?) (string2 string?) (start1 integer?)) ⟹ integer? | #f

    (srfi 140) procedure (string-contains (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ integer? | #f

    (srfi 140) procedure (string-contains (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ integer? | #f

    (srfi 140) procedure (string-contains-right (string1 string?) (string2 string?)) ⟹ integer? | #f

    (srfi 140) procedure (string-contains-right (string1 string?) (string2 string?) (start1 integer?)) ⟹ integer? | #f

    (srfi 140) procedure (string-contains-right (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ integer? | #f

    (srfi 140) procedure (string-contains-right (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ integer? | #f

    Does the substring of string1 specified by start1 and end1 contain the sequence of characters given by the substring of string2 specified by start2 and end2?

    Returns #f if there is no match. If start2 = end2, string-contains returns start1 but string-contains-right returns end1. Otherwise returns the index in string1 for the first character of the first/last match; that index lies within the half-open interval [start1,end1), and the match lies entirely within the [start1,end1) range of string1.

    (srfi 140) procedure (string-upcase (string string?)) ⟹ istring?

    (srfi 140) procedure (string-downcase (string string?)) ⟹ istring?

    (srfi 140) procedure (string-foldcase (string string?)) ⟹ istring?

    (srfi 140) procedure (string-titlecase (string string?)) ⟹ istring?

    These procedures return the string obtained by applying Unicode's full uppercasing, lowercasing, case-folding, or title-casing algorithms to their argument. In some cases, the length of the result may be different from the length of the argument. If the result is equal to the argument in the sense of string=?, and the argument is immutable, then that argument may be returned. Note that language-sensitive mappings and foldings are not used.

    The results are the same as the R7RS procedures, but as immutable strings.

    (srfi 140) procedure (string-append (string string?) ...) ⟹ istring?

    Returns a string whose sequence of characters is the concatenation of the sequences of characters in the given arguments.

    (srfi 140) procedure (string-concatenate (string-list list?)) ⟹ istring?

    string-list ⟹ (list (string string?))

    Concatenates the elements of string-list together into a single string.

    If any elements of string-list are mutable strings, then those strings do not share any storage with the result, so subsequent mutation of those string will not affect the string returned by this procedure. Implementations are encouraged to return a result that shares storage with some of the strings in the list if that sharing would be space-efficient.

    Rationale: Some implementations of Scheme limit the number of arguments that may be passed to an n-ary procedure, so the (apply string-append string-list) idiom, which is otherwise equivalent to using this procedure, is not as portable.

    (srfi 140) procedure (string-concatenate-reverse (string-list list?)) ⟹ istring?

    (srfi 140) procedure (string-concatenate-reverse (string-list list?) (final-string string?)) ⟹ istring?

    (srfi 140) procedure (string-concatenate-reverse (string-list list?) (final-string string?) (end integer?)) ⟹ istring?

    string-list ⟹ (list (string string?))

    With no optional arguments, calling this procedure is equivalent to

    (string-concatenate (reverse string-list))

    If the optional argument final-string is specified, it is effectively consed onto the beginning of string-list before performing the list-reverse and string-concatenate operations.

    If the optional argument end is given, only the characters up to but not including end in final-string are added to the result, thus producing

    (string-concatenate

    (reverse (cons (substring final-string 0 end)

    string-list)))

    (srfi 140) procedure (string-join (string-list list?)) ⟹ istring?

    (srfi 140) procedure (string-join (string-list list?) (delimiter string?)) ⟹ istring?

    (srfi 140) procedure (string-join (string-list list?) (delimiter string?) (grammar symbol?)) ⟹ istring?

    This procedure is a simple unparser; it pastes strings together using the delimiter string.

    The string-list is a list of strings. The delimiter is the string used to delimit elements; it defaults to a single space " ". The grammar argument is a symbol that determines how the delimiter is used, and defaults to 'infix. It is an error for grammar to be any symbol other than these four:

  • 'infix means an infix or separator grammar: insert the delimiter between list elements. An empty list will produce an empty string.
  • 'strict-infix means the same as 'infix if the string-list is non-empty, but will signal an error if given an empty list. (This avoids an ambiguity shown in the examples below.)
  • 'suffix means a suffix or terminator grammar: insert the delimiter after every list element.
  • 'prefix means a prefix grammar: insert the delimiter before every list element.
  • (srfi 140) procedure (string-fold (kons procedure?) knil (string string?)) ⟹ *

    (srfi 140) procedure (string-fold (kons procedure?) knil (string string?) (start integer?)) ⟹ *

    (srfi 140) procedure (string-fold (kons procedure?) knil (string string?) (start integer?) (end integer?)) ⟹ *

    (kons (char char?) value) ⟹ *

    (srfi 140) procedure (string-fold-right (kons procedure?) knil (string string?)) ⟹ *

    (srfi 140) procedure (string-fold-right (kons procedure?) knil (string string?) (start integer?)) ⟹ *

    (srfi 140) procedure (string-fold-right (kons procedure?) knil (string string?) (start integer?) (end integer?)) ⟹ *

    (kons (char char?) value) ⟹ *

    These are the fundamental iterators for strings.

    The string-fold procedure maps the kons procedure across the given string from left to right:

    (... (kons string[2] (kons string[1] (kons string[0] knil))))

    The string-fold-right procedure maps kons across the given string or string from right to left:

    (kons string[0]

    (... (kons string[end-3]

    (kons string[end-2]

    (kons string[end-1]

    knil)))))

    (srfi 140) procedure (string-map (proc procedure?) (string1 string?) (string2 string?) ...) ⟹ istring?

    (proc (char1 char?) ...) ⟹ char? | string?

    As in R7RS, except the result is an immutable string. As an extension, the result from proc may be a string (not just a character).

    (srfi 140) procedure (string-for-each (proc procedure?) (string1 string?) (string2 string?) ...) ⟹ undefined

    (proc (char1 char?) ...) ⟹ undefined

    As in R7RS.

    (srfi 140) procedure (string-map-index (proc procedure?) (string string?)) ⟹ istring?

    (srfi 140) procedure (string-map-index (proc procedure?) (string string?) (start integer?)) ⟹ istring?

    (srfi 140) procedure (string-map-index (proc procedure?) (string string?) (start integer?) (end integer?)) ⟹ istring?

    (proc (index integer?)) ⟹ string? | char?

    Calls proc on each valid index of the specified substring, converts the results of those calls into strings, and returns the concatenation of those strings. It is an error for proc to return anything other than a character or string. The dynamic order in which proc is called on the indexes is unspecified, as is the dynamic order in which the coercions are performed. If any strings returned by proc are mutated after they have been returned and before the call to string-map-index has returned, then string-map-index returns a string with unspecified contents; the string-map-index procedure itself does not mutate those strings.

    (srfi 140) procedure (string-for-each-index (proc procedure?) (string string?)) ⟹ undefined

    (srfi 140) procedure (string-for-each-index (proc procedure?) (string string?) (start integer?)) ⟹ undefined

    (srfi 140) procedure (string-for-each-index (proc procedure?) (string string?) (start integer?) (end integer?)) ⟹ undefined

    (proc (index integer?)) ⟹ undefined

    Calls proc on each valid index of the specified substring, in increasing order, discarding the results of those calls. This is simply a safe and correct way to loop over a substring.

    (srfi 140) procedure (string-count (string string?) (pred predicate)) ⟹ integer?

    (srfi 140) procedure (string-count (string string?) (pred predicate) (start integer?)) ⟹ integer?

    (srfi 140) procedure (string-count (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ integer?

    Returns a count of the number of characters in the specified substring of string that satisfy the given predicate.

    (srfi 140) procedure (string-filter (pred predicate) (string string?)) ⟹ istring?

    (srfi 140) procedure (string-filter (pred predicate) (string string?) (start integer?)) ⟹ istring?

    (srfi 140) procedure (string-filter (pred predicate) (string string?) (start integer?) (end integer?)) ⟹ istring?

    (srfi 140) procedure (string-remove (pred predicate) (string string?)) ⟹ istring?

    (srfi 140) procedure (string-remove (pred predicate) (string string?) (start integer?)) ⟹ istring?

    (srfi 140) procedure (string-remove (pred predicate) (string string?) (start integer?) (end integer?)) ⟹ istring?

    Filter the given substring of string, retaining only those characters that satisfy / do not satisfy pred.

    If string is a mutable string, then that string does not share any storage with the result, so subsequent mutation of that string will not affect the string returned by these procedures. If string is an immutable string, implementations are encouraged to return a result that shares storage with that string whenever sharing would be space-efficient.

    (srfi 140) procedure (string-repeat (string-or-char string? | char?) (len integer?)) ⟹ istring?

    Create a string by repeating the first argument len times. If the first argument is a character, it is as if it were wrapped with the string constructor.

    (srfi 140) procedure (xsubstring (string string?)) ⟹ istring?

    (srfi 140) procedure (xsubstring (string string?) (from integer?)) ⟹ istring?

    (srfi 140) procedure (xsubstring (string string?) (from integer?) (to integer?)) ⟹ istring?

    (srfi 140) procedure (xsubstring (string string?) (from integer?) (to integer?) (start integer?)) ⟹ istring?

    (srfi 140) procedure (xsubstring (string string?) (from integer?) (to integer?) (start integer?) (end integer?)) ⟹ istring?

    This is an "extended substring" procedure that implements replicated copying of a substring.

    string is a string; start and end are optional arguments that specify a substring of string, defaulting to 0 and the length of string. This substring is conceptually replicated both up and down the index space, in both the positive and negative directions.

    xsubstring returns the substring of this string beginning at index from, and ending at to. It is an error if from is greater than to.

    If from and to are missing they default to 0 and from+(end-start), respectively. This variant is a generalization of using substring, but unlike substring never shares substructures that would retain characters or sequences of characters that are substructures of its first argument or previously allocated objects. (Hence it is equivalent to SRFI-135's string-copy.)

    Note that

  • The from/to arguments give a half-open range containing the characters from index from up to, but not including, index to.
  • The from/to indexes are not expressed in the index space of string. They refer instead to the replicated index space of the substring defined by string, start, and end.
  • It is an error if start=end, unless from=to, which is allowed as a special case.

    (srfi 140) procedure (string-split (string string?) (delimiter string?)) ⟹ list?

    (srfi 140) procedure (string-split (string string?) (delimiter string?) (grammar symbol?)) ⟹ list?

    (srfi 140) procedure (string-split (string string?) (delimiter string?) (grammar symbol?) (limit integer?)) ⟹ list?

    (srfi 140) procedure (string-split (string string?) (delimiter string?) (grammar symbol?) (limit integer?) (start integer?)) ⟹ list?

    (srfi 140) procedure (string-split (string string?) (delimiter string?) (grammar symbol?) (limit integer?) (start integer?) (end integer?)) ⟹ list?

    return ⟹ (list (str istring?))

    Returns a list of strings representing the words contained in the substring of string from start (inclusive) to end (exclusive). The delimiter is a string to be used as the word separator. This will often be a single character, but multiple characters are allowed for use cases such as splitting on "\r\n". The returned list will have one more item than the number of non-overlapping occurrences of the delimiter in the string. If delimiter is an empty string, then the returned list contains a list of strings, each of which contains a single character.

    The grammar is a symbol with the same meaning as in the string-join procedure. If it is infix, which is the default, processing is done as described above, except an empty string produces the empty list; if grammar is strict-infix, then an empty string signals an error. The values prefix and suffix cause a leading/trailing empty string in the result to be suppressed.

    If limit is a non-negative exact integer, at most that many splits occur, and the remainder of string is returned as the final element of the list (so the result will have at most limit+1 elements). If limit is not specified or is #f, then as many splits as possible are made. It is an error if limit is any other value.

    (srfi 140) procedure (make-string ) ⟹ string?

    (srfi 140) procedure (make-string (k integer?)) ⟹ string?

    (srfi 140) procedure (make-string (k integer?) (char char?)) ⟹ string?

    Return a new allocated mutable string of length k, where k defaults to 0. If char is given, then all the characters of the string are initialized to char, otherwise the contents of the string are unspecified. The 1-argument version is deprecated as poor style, except when k is 0.

    To return an immutable string that repeats k times a character char use string-repeat.

    This is as R7RS, except the result is variable-size and we allow leaving out k when it is zero.

    (srfi 140) procedure (string-copy (string string?)) ⟹ string?

    (srfi 140) procedure (string-copy (string string?) (start integer?)) ⟹ string?

    (srfi 140) procedure (string-copy (string string?) (start integer?) (end integer?)) ⟹ string?

    Returns a newly allocated copy of the part of the given string between start and end.

    (srfi 140) procedure (string-set! (string string?) (k integer?) (char char?)) ⟹ undefined

    It is an error if k is not a valid index of string. The string-set! procedure stores char in element k of string. There is no requirement for this procedure to execute in constant time.

    (srfi 140) procedure (string-fill! (string string?) (fill char?)) ⟹ undefined

    (srfi 140) procedure (string-fill! (string string?) (fill char?) (start integer?)) ⟹ undefined

    (srfi 140) procedure (string-fill! (string string?) (fill char?) (start integer?) (end integer?)) ⟹ undefined

    It is an error if fill is not a character. The string-fill! procedure stores fill in the elements of string between start and end.

    (srfi 140) procedure (string-copy! (to string?) (at integer?) (from string?)) ⟹ undefined

    (srfi 140) procedure (string-copy! (to string?) (at integer?) (from string?) (start integer?)) ⟹ undefined

    (srfi 140) procedure (string-copy! (to string?) (at integer?) (from string?) (start integer?) (end integer?)) ⟹ undefined

    It is an error if at is less than zero or greater than the length of to. It is also an error if (- (string-length to) at) is less than (- end start).

    Copies the characters of string from between start and end to string to, starting at at. The order in which characters are copied is unspecified, except that if the source and destination overlap, copying takes place as if the source is first copied into a temporary string and then into the destination. This can be achieved without allocating storage by making sure to copy in the correct direction in such circumstances.

    (srfi 140) procedure (string-append! (string string?) (value char? | string?) ...) ⟹ undefined

    The string must be a variable-size mutable string. The string-append! procedure extends string by appending each value (in order) to the end of string. A value can be a character or a string.

    Using a string port in this situation is probably preferable: It is more portable, and you can expect decent performance in most implementations. Using string-append! may be slighly more efficient on some implementations, due to lower overhead, but that depends on the strategy used by string-append! when the allocated buffer is too small. The string-append! function is most useful when using (reading) a string is interleaved with growing it, or when also using string-replace!.

    (srfi 140) procedure (string-replace! (dst string?) (dst-start integer?) (dst-end integer?) (src string?)) ⟹ undefined

    (srfi 140) procedure (string-replace! (dst string?) (dst-start integer?) (dst-end integer?) (src string?) (src-start integer?)) ⟹ undefined

    (srfi 140) procedure (string-replace! (dst string?) (dst-start integer?) (dst-end integer?) (src string?) (src-start integer?) (src-end integer?)) ⟹ undefined

    Replaces the characters of the variable-size string dst (between dst-start and dst-end) with the characters of the string src (between src-start and src-end). The number of characters from src may be different than the number replaced in dst, so the string may grow or contract. The special case where dst-start is equal to dst-end corresponds to insertion; the case where src-start is equal to src-end corresponds to deletion. The order in which characters are copied is unspecified, except that if the source and destination overlap, copying takes place as if the source is first copied into a temporary string and then into the destination. (This can be achieved without allocating storage by making sure to copy in the correct direction in such circumstances.)

    When value is a string then (string-append! dst value) is equivalent to (string-replace! dst (string-length dst) (string-length dst) value).

    library (srfi 141) Integer division

    This SRFI provides a fairly complete set of integral division and remainder operators.

    See (scheme division)

    library (srfi 143) Fixnums

    This SRFI describes arithmetic procedures applicable to a limited range of exact integers only. These procedures are semantically similar to the corresponding generic-arithmetic procedures, but allow more efficient implementations.

    See (scheme fixnum)

    library (srfi 144) Flonums

    This SRFI describes numeric procedures applicable to flonums, a subset of the inexact real numbers provided by a Scheme implementation. In most Schemes, the flonums and the inexact reals are the same. These procedures are semantically equivalent to the corresponding generic procedures, but allow more efficient implementations.

    See (scheme flonum)

    library (srfi 145) Assumptions

    A means to denote the invalidity of certain code paths in a Scheme program is proposed. It allows Scheme code to turn the evaluation into a user-defined error that need not be signalled by the implementation. Optimizing compilers may use these denotations to produce better code and to issue better warnings about dead code.

    (srfi 145) syntax (assume obj message)⟹ return

    This special form is an expression that evaluates to the value of obj if obj evaluates to a true value. It is an error if obj evaluates to a false value. In this case, implementations are encouraged to report this error together with the messages to the user, at least when the implementation is in debug or non-optimizing mode. In case of reporting the error, an implementation is also encouraged to report the source location of the source of the error.

    library (srfi 146) Mappings

    Mappings are finite sets of associations, where each association is a pair consisting of a key and an arbitrary Scheme value. The keys are elements of a suitable domain. Each mapping holds no more than one association with the same key. The fundamental mapping operation is retrieving the value of an association stored in the mapping when the key is given.

    See (scheme mapping)

    library (srfi 146 hash) Mappings

    Mappings are finite sets of associations, where each association is a pair consisting of a key and an arbitrary Scheme value. The keys are elements of a suitable domain. Each mapping holds no more than one association with the same key. The fundamental mapping operation is retrieving the value of an association stored in the mapping when the key is given.

    See (scheme hashmap)

    library (srfi 151) Bitwise Operations

    This SRFI proposes a coherent and comprehensive set of procedures for performing bitwise logical operations on integers; it is accompanied by a reference implementation of the spec in terms of a set of seven core operators. The sample implementation is portable, as efficient as practical with pure Scheme arithmetic (it is much more efficient to replace the core operators with C or assembly language if possible), and open source.

    The precise semantics of these operators is almost never an issue. A consistent, portable set of names and parameter conventions, however, is. Hence this SRFI, which is based mainly on SRFI 33, with some changes and additions from Olin's late revisions to SRFI 33 (which were never consummated). SRFI 60 (based on SLIB) is smaller but has a few procedures of its own; some of its procedures have both native (often Common Lisp) and SRFI 33 names. They have been incorporated into this SRFI. R6RS is a subset of SRFI 60, except that all procedure names begin with a bitwise- prefix. A few procedures have been added from the general vector SRFI 133.

    Among the applications of bitwise operations are: hashing, Galois-field calculations of error-detecting and error-correcting codes, cryptography and ciphers, pseudo-random number generation, register-transfer-level modeling of digital logic designs, Fast-Fourier transforms, packing and unpacking numbers in persistent data structures, space-filling curves with applications to dimension reduction and sparse multi-dimensional database indexes, and generating approximate seed values for root-finders and transcendental function algorithms.

    This SRFI differs from SRFI 142 in only two ways:

    1. The bitwise-if function has the argument ordering of SLIB, SRFI 60, and R6RS rather than the ordering of SRFI 33.

    2. The order in which bits are processed by the procedures listed in the "Bits conversion" section has been clarified and some of the procedures' names have been changed. See "Bit processing order" for details.

    See (scheme bitwise)

    library (srfi 152) String Library (reduced)

    Scheme has an impoverished set of string-processing utilities, which is a problem for authors of portable code. This SRFI proposes a coherent and comprehensive set of string-processing procedures. It is a reduced version of SRFI 13 that has been aligned with SRFI 135, Immutable Texts. Unlike SRFI 13, it has been made consistent with the R5RS, R6RS, and R7RS-small string procedures.

    (srfi 152) procedure (string? obj) ⟹ boolean?

    (srfi 152) procedure (string? obj) ⟹ boolean?

    Is obj a string?

    (srfi 152) procedure (string-null? (string string?)) ⟹ boolean?

    Is string the empty string?

    (srfi 152) procedure (string-every (pred predicate) (string string?)) ⟹ *

    (srfi 152) procedure (string-every (pred predicate) (string string?) (start integer?)) ⟹ *

    (srfi 152) procedure (string-every (pred predicate) (string string?) (start integer?) (end integer?)) ⟹ *

    (srfi 152) procedure (string-any (pred predicate) (string string?)) ⟹ *

    (srfi 152) procedure (string-any (pred predicate) (string string?) (start integer?)) ⟹ *

    (srfi 152) procedure (string-any (pred predicate) (string string?) (start integer?) (end integer?)) ⟹ *

    Checks to see if every/any character in string satisfies pred, proceeding from left (index start) to right (index end). These procedures are short-circuiting: if pred returns false, string-every does not call pred on subsequent characters; if pred returns true, string-any does not call pred on subsequent characters; Both procedures are "witness-generating":

  • If string-every is given an empty interval (with start = end), it returns #t.
  • If string-every returns true for a non-empty interval (with start < end), the returned true value is the one returned by the final call to the predicate on (string-ref (string-copy string) (- end 1)).
  • If string-any returns true, the returned true value is the one returned by the predicate.
  • (srfi 152) procedure (make-string (len integer?) (char char?)) ⟹ string?

    Returns a string of the given length filled with the given character.

    (srfi 152) procedure (string (char char?) ...) ⟹ string?

    Returns a string consisting of the given characters.

    (srfi 152) procedure (string-tabulate (proc procedure?) (len integer?)) ⟹ string?

    (proc (k integer?)) ⟹ char?

    Proc is a procedure that accepts an exact integer as its argument and returns a character. Constructs a string of size len by calling proc on each value from 0 (inclusive) to len (exclusive) to produce the corresponding element of the string. The order in which proc is called on those indexes is not specified.

    (srfi 152) procedure (string-unfold (stop? predicate) (mapper procedure?) (successor procedure?) seed) ⟹ string?

    (srfi 152) procedure (string-unfold (stop? predicate) (mapper procedure?) (successor procedure?) seed (base string?)) ⟹ string?

    (srfi 152) procedure (string-unfold (stop? predicate) (mapper procedure?) (successor procedure?) seed (base string?) (make-final procedure?)) ⟹ string?

    (mapper seed) ⟹ char? | string?

    (success seed) ⟹ *

    (make-final seed) ⟹ char? | string?

    This is a fundamental constructor for strings.

  • successor is used to generate a series of "seed" values from the initial seed:
  • seed, (successor seed), (successor2 seed), (successor3 seed), ...
  • stop? tells us when to stop — when it returns true when applied to one of these seed values.
  • mapper maps each seed value to the corresponding character(s) in the result string, which are assembled into that string in left-to-right order. It is an error for mapper to return anything other than a character or string.
  • base is the optional initial/leftmost portion of the constructed string, which defaults to the empty string "". It is an error if base is anything other than a character or string.
  • make-final is applied to the terminal seed value (on which stop? returns true) to produce the final/rightmost portion of the constructed string. It defaults to (lambda (x) ""). It is an error for make-final to return anything other than a character or string.
  • (srfi 152) procedure (string-unfold-right (stop? predicate) (mapper procedure?) (successor procedure?) seed) ⟹ string?

    (srfi 152) procedure (string-unfold-right (stop? predicate) (mapper procedure?) (successor procedure?) seed (base string?)) ⟹ string?

    (srfi 152) procedure (string-unfold-right (stop? predicate) (mapper procedure?) (successor procedure?) seed (base string?) (make-final procedure?)) ⟹ string?

    (mapper seed) ⟹ char? | string?

    (success seed) ⟹ *

    (make-final seed) ⟹ char? | string?

    This is a fundamental constructor for strings. It is the same as string-unfold except the results of mapper are assembled into the string in right-to-left order, base is the optional rightmost portion of the constructed string, and make-final produces the leftmost portion of the constructed string. If mapper returns a string, the string is prepended to the constructed string (without reversal).

    (srfi 152) procedure (string->vector (string string?)) ⟹ vector?

    (srfi 152) procedure (string->vector (string string?) (start integer?)) ⟹ vector?

    (srfi 152) procedure (string->vector (string string?) (start integer?) (end integer?)) ⟹ vector?

    return ⟹ (vector char?)

    (srfi 152) procedure (string->list (string string?)) ⟹ list?

    (srfi 152) procedure (string->list (string string?) (start integer?)) ⟹ list?

    (srfi 152) procedure (string->list (string string?) (start integer?) (end integer?)) ⟹ list?

    return ⟹ (list char?)

    These procedures return a newly allocated (unless empty) vector or list of the characters that make up the given substring.

    (srfi 152) procedure (vector->string (vector vector?)) ⟹ string?

    (srfi 152) procedure (vector->string (vector vector?) (start integer?)) ⟹ string?

    (srfi 152) procedure (vector->string (vector vector?) (start integer?) (end integer?)) ⟹ string?

    vector ⟹ (vector char?)

    (srfi 152) procedure (list->string (list list?)) ⟹ string?

    list ⟹ (list char?)

    These procedures return a string containing the characters of the given (sub)vector or list. The behavior of the string will not be affected by subsequent mutation of the given vector or list.

    (srfi 152) procedure (reverse-list->string (char-list list?)) ⟹ string?

    char-list ⟹ (list char?)

    Semantically equivalent to (compose list->string reverse):

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

    This is a common idiom in the epilogue of string-processing loops that accumulate their result using a list in reverse order. (See also string-concatenate-reverse for the "chunked" variant.)

    (srfi 152) procedure (string-length (string string?)) ⟹ integer?

    Returns the number of characters within the given string.

    (srfi 152) procedure (string-ref (string string?) (idx integer?)) ⟹ char?

    Returns character string[idx], using 0-origin indexing.

    (srfi 152) procedure (substring (string string?) (start integer?) (end integer?)) ⟹ string?

    (srfi 152) procedure (string-copy (string string?)) ⟹ string?

    (srfi 152) procedure (string-copy (string string?) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-copy (string string?) (start integer?) (end integer?)) ⟹ string?

    These procedures return a string containing the characters of string beginning with index start (inclusive) and ending with index end (exclusive). The only difference is that substring requires all three arguments, whereas string-copy requires only one.

    (srfi 152) procedure (string-take (string string?) (nchars integer?)) ⟹ string?

    (srfi 152) procedure (string-drop (string string?) (nchars integer?)) ⟹ string?

    (srfi 152) procedure (string-take-right (string string?) (nchars integer?)) ⟹ string?

    (srfi 152) procedure (string-drop-right (string string?) (nchars integer?)) ⟹ string?

    string-take returns a string containing the first nchars of string; string-drop returns a string containing all but the first nchars of string. string-take-right returns a string containing the last nchars of string; string-drop-right returns a string containing all but the last nchars of string.

    (srfi 152) procedure (string-pad (string string?) (len integer?)) ⟹ string?

    (srfi 152) procedure (string-pad (string string?) (len integer?) (char char?)) ⟹ string?

    (srfi 152) procedure (string-pad (string string?) (len integer?) (char char?) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-pad (string string?) (len integer?) (char char?) (start integer?) (end integer?)) ⟹ string?

    (srfi 152) procedure (string-pad-right (string string?) (len integer?)) ⟹ string?

    (srfi 152) procedure (string-pad-right (string string?) (len integer?) (char char?)) ⟹ string?

    (srfi 152) procedure (string-pad-right (string string?) (len integer?) (char char?) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-pad-right (string string?) (len integer?) (char char?) (start integer?) (end integer?)) ⟹ string?

    Returns a string of length len comprised of the characters drawn from the given subrange of string, padded on the left (right) by as many occurrences of the character char as needed. If string has more than len chars, it is truncated on the left (right) to length len. char defaults to #\space.

    (srfi 152) procedure (string-trim (string string?)) ⟹ string?

    (srfi 152) procedure (string-trim (string string?) (pred predicate)) ⟹ string?

    (srfi 152) procedure (string-trim (string string?) (pred predicate) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-trim (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ string?

    (srfi 152) procedure (string-trim-right (string string?)) ⟹ string?

    (srfi 152) procedure (string-trim-right (string string?) (pred predicate)) ⟹ string?

    (srfi 152) procedure (string-trim-right (string string?) (pred predicate) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-trim-right (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ string?

    (srfi 152) procedure (string-trim-both (string string?)) ⟹ string?

    (srfi 152) procedure (string-trim-both (string string?) (pred predicate)) ⟹ string?

    (srfi 152) procedure (string-trim-both (string string?) (pred predicate) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-trim-both (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ string?

    Returns a string obtained from the given subrange of string by skipping over all characters on the left side / on the right side / on both sides that satisfy the second argument pred: pred defaults to char-whitespace?.

    (srfi 152) procedure (string-replace (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ string?

    (srfi 152) procedure (string-replace (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ string?

    (srfi 152) procedure (string-replace (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ string?

    Returns

    (string-append (substring string1 0 start1)

    (substring string2 start2 end2)

    (substring string1 end1 (string-length string1)))

    That is, the segment of characters in string1 from start1 to end1 is replaced by the segment of characters in string2 from start2 to end2. If start1=end1, this simply splices the characters drawn from string2 into string1 at that position.

    (srfi 152) procedure (string=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    Returns #t if all the strings have the same length and contain exactly the same characters in the same positions; otherwise returns #f.

    (srfi 152) procedure (string<? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 152) procedure (string>? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 152) procedure (string<=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 152) procedure (string>=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    These procedures return #t if their arguments are (respectively): monotonically increasing, monotonically decreasing, monotonically non-decreasing, or monotonically non-increasing.

    These comparison predicates are required to be transitive.

    These procedures compare strings in an implementation-defined way. One approach is to make them the lexicographic extensions to strings of the corresponding orderings on characters. In that case, string<? would be the lexicographic ordering on strings induced by the ordering char<? on characters, and if two strings differ in length but are the same up to the length of the shorter string, the shorter string would be considered to be lexicographically less than the longer string. However, implementations are also allowed to use more sophisticated locale-specific orderings.

    In all cases, a pair of strings must satisfy exactly one of string<?, string=?, and string>?, must satisfy string<=? if and only if they do not satisfy string>?, and must satisfy string>=? if and only if they do not satisfy string<?.

    (srfi 152) procedure (string-ci=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    Returns #t if, after calling string-foldcase on each of the arguments, all of the case-folded strings would have the same length and contain the same characters in the same positions; otherwise returns #f.

    (srfi 152) procedure (string-ci<? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 152) procedure (string-ci>? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 152) procedure (string-ci<=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    (srfi 152) procedure (string-ci>=? (string1 string?) (string2 string?) (string3 string?) ...) ⟹ boolean?

    These procedures behave as though they had called string-foldcase on their arguments before applying the corresponding procedures without "-ci".

    (srfi 152) procedure (string-prefix-length (string1 string?) (string2 string?)) ⟹ integer?

    (srfi 152) procedure (string-prefix-length (string1 string?) (string2 string?) (start1 integer?)) ⟹ integer?

    (srfi 152) procedure (string-prefix-length (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ integer?

    (srfi 152) procedure (string-prefix-length (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ integer?

    (srfi 152) procedure (string-prefix-length (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ integer?

    (srfi 152) procedure (string-suffix-length (string1 string?) (string2 string?)) ⟹ integer?

    (srfi 152) procedure (string-suffix-length (string1 string?) (string2 string?) (start1 integer?)) ⟹ integer?

    (srfi 152) procedure (string-suffix-length (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ integer?

    (srfi 152) procedure (string-suffix-length (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ integer?

    (srfi 152) procedure (string-suffix-length (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ integer?

    Return the length of the longest common prefix/suffix of string1 and string2. For prefixes, this is equivalent to their "mismatch index" (relative to the start indexes).

    The optional start/end indexes restrict the comparison to the indicated substrings of string1 and string2.

    (srfi 152) procedure (string-prefix? (string1 string?) (string2 string?)) ⟹ boolean?

    (srfi 152) procedure (string-prefix? (string1 string?) (string2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 152) procedure (string-prefix? (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 152) procedure (string-prefix? (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 152) procedure (string-prefix? (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    (srfi 152) procedure (string-suffix? (string1 string?) (string2 string?)) ⟹ boolean?

    (srfi 152) procedure (string-suffix? (string1 string?) (string2 string?) (start1 integer?)) ⟹ boolean?

    (srfi 152) procedure (string-suffix? (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ boolean?

    (srfi 152) procedure (string-suffix? (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ boolean?

    (srfi 152) procedure (string-suffix? (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ boolean?

    Is string1 a prefix/suffix of string2?

    The optional start/end indexes restrict the comparison to the indicated substrings of string1 and string2.

    (srfi 152) procedure (string-index (string string?) (pred predicate)) ⟹ #f | integer?

    (srfi 152) procedure (string-index (string string?) (pred predicate) (start integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-index (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-index-right (string string?) (pred predicate)) ⟹ #f | integer?

    (srfi 152) procedure (string-index-right (string string?) (pred predicate) (start integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-index-right (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-skip (string string?) (pred predicate)) ⟹ #f | integer?

    (srfi 152) procedure (string-skip (string string?) (pred predicate) (start integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-skip (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-skip-right (string string?) (pred predicate)) ⟹ #f | integer?

    (srfi 152) procedure (string-skip-right (string string?) (pred predicate) (start integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-skip-right (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ #f | integer?

    string-index searches through the given substring from the left, returning the index of the leftmost character satisfying the predicate pred. string-index-right searches from the right, returning the index of the rightmost character satisfying the predicate pred. If no match is found, these procedures return #f.

    The start and end arguments specify the beginning and end of the search; the valid indexes relevant to the search include start but exclude end. Beware of "fencepost" errors: when searching right-to-left, the first index considered is (- end 1), whereas when searching left-to-right, the first index considered is start. That is, the start/end indexes describe the same half-open interval [start,end) in these procedures that they do in all other procedures specified by this SRFI.

    The skip functions are similar, but use the complement of the criterion: they search for the first char that doesn't satisfy pred.

    (srfi 152) procedure (string-contains (string1 string?) (string2 string?)) ⟹ #f | integer?

    (srfi 152) procedure (string-contains (string1 string?) (string2 string?) (start1 integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-contains (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-contains (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-contains (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-contains-right (string1 string?) (string2 string?)) ⟹ #f | integer?

    (srfi 152) procedure (string-contains-right (string1 string?) (string2 string?) (start1 integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-contains-right (string1 string?) (string2 string?) (start1 integer?) (end1 integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-contains-right (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?)) ⟹ #f | integer?

    (srfi 152) procedure (string-contains-right (string1 string?) (string2 string?) (start1 integer?) (end1 integer?) (start2 integer?) (end2 integer?)) ⟹ #f | integer?

    Does the substring of string1 specified by start1 and end1 contain the sequence of characters given by the substring of string2 specified by start2 and end2?

    Returns #f if there is no match. If start2 = end2, string-contains returns start1 but string-contains-right returns end1. Otherwise returns the index in string1 for the first character of the first/last match; that index lies within the half-open interval [start1,end1), and the match lies entirely within the [start1,end1) range of string1.

    (srfi 152) procedure (string-take-while (string string?) (pred predicate)) ⟹ string?

    (srfi 152) procedure (string-take-while (string string?) (pred predicate) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-take-while (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ string?

    (srfi 152) procedure (string-take-while-right (string string?) (pred predicate)) ⟹ string?

    (srfi 152) procedure (string-take-while-right (string string?) (pred predicate) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-take-while-right (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ string?

    Returns the longest initial prefix/suffix of the substring of string specified by start and end whose elements all satisfy the predicate pred. (Not SRFI 13 procedures.)

    (srfi 152) procedure (string-drop-while (string string?) (pred predicate)) ⟹ string?

    (srfi 152) procedure (string-drop-while (string string?) (pred predicate) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-drop-while (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ string?

    (srfi 152) procedure (string-drop-while-right (string string?) (pred predicate)) ⟹ string?

    (srfi 152) procedure (string-drop-while-right (string string?) (pred predicate) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-drop-while-right (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ string?

    Drops the longest initial prefix/suffix of the substring of string specified by start and end whose elements all satisfy the predicate pred, and returns the rest of the string.

    These are the same as string-trim and string-trim-right, but with a different order of arguments. (Not SRFI 13 procedures.)

    (srfi 152) procedure (string-span (string string?) (pred predicate)) ⟹ (values string? string?)

    (srfi 152) procedure (string-span (string string?) (pred predicate) (start integer?)) ⟹ (values string? string?)

    (srfi 152) procedure (string-span (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ (values string? string?)

    (srfi 152) procedure (string-break (string string?) (pred predicate)) ⟹ (values string? string?)

    (srfi 152) procedure (string-break (string string?) (pred predicate) (start integer?)) ⟹ (values string? string?)

    (srfi 152) procedure (string-break (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ (values string? string?)

    String-span splits the substring of string specified by start and end into the longest initial prefix whose elements all satisfy pred, and the remaining tail. String-break inverts the sense of the predicate: the tail commences with the first element of the input string that satisfies the predicate. (Not SRFI 13 procedures.)

    In other words: span finds the initial span of elements satisfying pred, and break breaks the string at the first element satisfying pred.

    (srfi 152) procedure (string-append (string string?) ...) ⟹ string?

    Returns a string whose sequence of characters is the concatenation of the sequences of characters in the given arguments.

    (srfi 152) procedure (string-concatenate (string-list list?)) ⟹ string?

    Concatenates the elements of string-list together into a single string.

    (srfi 152) procedure (string-concatenate-reverse (string-list list?)) ⟹ string?

    (srfi 152) procedure (string-concatenate-reverse (string-list list?) (final-string string?)) ⟹ string?

    (srfi 152) procedure (string-concatenate-reverse (string-list list?) (final-string string?) (end integer?)) ⟹ string?

    With no optional arguments, calling this procedure is equivalent to

    (string-concatenate (reverse string-list))

    If the optional argument final-string is specified, it is effectively consed onto the beginning of string-list before performing the list-reverse and string-concatenate operations.

    If the optional argument end is given, only the characters up to but not including end in final-string are added to the result, thus producing

    (string-concatenate

    (reverse (cons (substring final-string 0 end)

    string-list)))

    (srfi 152) procedure (string-join (string-list list?)) ⟹ string?

    (srfi 152) procedure (string-join (string-list list?) (delimiter string?)) ⟹ string?

    (srfi 152) procedure (string-join (string-list list?) (delimiter string?) (grammar symbol?)) ⟹ string?

    This procedure is a simple unparser; it pastes strings together using the delimiter string.

    string-list is a list of strings. delimiter is a string. The grammar argument is a symbol that determines how the delimiter is used, and defaults to 'infix. It is an error for grammar to be any symbol other than these four:

    'infix means an infix or separator grammar: insert the delimiter between list elements. An empty list will produce an empty string.

    'strict-infix means the same as 'infix if the string-list is non-empty, but will signal an error if given an empty list. (This avoids an ambiguity shown in the examples below.)

    'suffix means a suffix or terminator grammar: insert the delimiter after every list element.

    'prefix means a prefix grammar: insert the delimiter before every list element.

    The delimiter is the string used to delimit elements; it defaults to a single space " ".

    (srfi 152) procedure (string-fold (kons procedure?) knil (string string?)) ⟹ *

    (srfi 152) procedure (string-fold (kons procedure?) knil (string string?) (start integer?)) ⟹ *

    (srfi 152) procedure (string-fold (kons procedure?) knil (string string?) (start integer?) (end integer?)) ⟹ *

    (kons (char char?) state) ⟹ *

    (srfi 152) procedure (string-fold-right (kons procedure?) knil (string string?)) ⟹ *

    (srfi 152) procedure (string-fold-right (kons procedure?) knil (string string?) (start integer?)) ⟹ *

    (srfi 152) procedure (string-fold-right (kons procedure?) knil (string string?) (start integer?) (end integer?)) ⟹ *

    (kons (char char?) state) ⟹ *

    These are the fundamental iterators for strings.

    The string-fold procedure maps the kons procedure across the given string from left to right:

    (... (kons string[2] (kons string[1] (kons string[0] knil))))

    In other words, string-fold obeys the (tail) recursion

    (string-fold kons knil string start end)

    = (string-fold kons (kons string[start] knil) start+1 end)

    The string-fold-right procedure maps kons across the given string from right to left:

    (kons string[0]

    (... (kons string[end-3]

    (kons string[end-2]

    (kons string[end-1]

    knil)))))

    obeying the (tail) recursion

    (string-fold-right kons knil string start end)

    = (string-fold-right kons (kons string[end-1] knil) start end-1)

    (srfi 152) procedure (string-map (proc procedure?) (string1 string?) (string2 string?) ...) ⟹ string?

    (proc (char1 char?) (char2 char?) ...) ⟹ string? | char?

    It is an error if proc does not accept as many arguments as the number of string arguments passed to string-map, does not accept characters as arguments, or returns a value that is not a character or string.

    The string-map procedure applies proc element-wise to the characters of the string arguments, converts each value returned by proc to a string, and returns the concatenation of those strings. If more than one string argument is given and not all have the same length, then string-map terminates when the shortest string argument runs out. The dynamic order in which proc is called on the characters of the string arguments is unspecified, as is the dynamic order in which the coercions are performed. If any strings returned by proc are mutated after they have been returned and before the call to string-map has returned, then string-map returns a string with unspecified contents; the string-map procedure itself does not mutate those strings.

    (srfi 152) procedure (string-for-each (proc procedure?) (string1 string?) (string2 string?) ...) ⟹ undefined

    (proc (char1 char?) (char2 char?) ...) ⟹ undefined

    It is an error if proc does not accept as many arguments as the number of string arguments passed to string-map or does not accept characters as arguments.

    The string-for-each procedure applies proc element-wise to the characters of the string arguments, going from left to right. If more than one string argument is given and not all have the same length, then string-for-each terminates when the shortest string argument runs out.

    (srfi 152) procedure (string-count (string string?) (pred predicate)) ⟹ integer?

    (srfi 152) procedure (string-count (string string?) (pred predicate) (start integer?)) ⟹ integer?

    (srfi 152) procedure (string-count (string string?) (pred predicate) (start integer?) (end integer?)) ⟹ integer?

    Returns a count of the number of characters in the specified substring of string that satisfy the given predicate.

    (srfi 152) procedure (string-filter (pred predicate) (string string?)) ⟹ string?

    (srfi 152) procedure (string-filter (pred predicate) (string string?) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-filter (pred predicate) (string string?) (start integer?) (end integer?)) ⟹ string?

    (srfi 152) procedure (string-remove (pred predicate) (string string?)) ⟹ string?

    (srfi 152) procedure (string-remove (pred predicate) (string string?) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-remove (pred predicate) (string string?) (start integer?) (end integer?)) ⟹ string?

    Filter the given substring of string, retaining only those characters that satisfy / do not satisfy pred.

    Compatibility note: In SRFI 13, string-remove is called string-delete. This is inconsistent with SRFI 1 and other SRFIs.

    (srfi 152) procedure (string-replicate (string string?) (from integer?) (to integer?)) ⟹ string?

    (srfi 152) procedure (string-replicate (string string?) (from integer?) (to integer?) (start integer?)) ⟹ string?

    (srfi 152) procedure (string-replicate (string string?) (from integer?) (to integer?) (start integer?) (end integer?)) ⟹ string?

    This is an "extended substring" procedure that implements replicated copying of a substring.

    string is a string; start and end are optional arguments that specify a substring of string, defaulting to 0 and the length of string. This substring is conceptually replicated both up and down the index space, in both the positive and negative directions. For example, if string is "abcdefg", start is 3, and end is 6, then we have the conceptual bidirectionally-infinite string

    ... d e f d e f d e f d e f d e f d e f d ...

    -9 -8 -7 -6 -5 -4 -3 -2 -1 0 +1 +2 +3 +4 +5 +6 +7 +8 +9

    string-replicate returns the substring of this string beginning at index from, and ending at to. It is an error if from is greater than to.

    It is an error if start=end, unless from=to, which is allowed as a special case.

    (srfi 152) procedure (string-segment (string string?) (k integer?)) ⟹ list?

    Returns a list of strings representing the consecutive substrings of length k. The last string may be shorter than k. (Not a SRFI 13 procedure.)

    (srfi 152) procedure (string-split (string string?) (delimiter string?)) ⟹ list?

    (srfi 152) procedure (string-split (string string?) (delimiter string?) (grammar symbol?)) ⟹ list?

    (srfi 152) procedure (string-split (string string?) (delimiter string?) (grammar symbol?) (limit #f | integer?)) ⟹ list?

    (srfi 152) procedure (string-split (string string?) (delimiter string?) (grammar symbol?) (limit #f | integer?) (start integer?)) ⟹ list?

    (srfi 152) procedure (string-split (string string?) (delimiter string?) (grammar symbol?) (limit #f | integer?) (start integer?) (end integer?)) ⟹ list?

    Returns a list of strings representing the words contained in the substring of string from start (inclusive) to end (exclusive). The delimiter is a string to be used as the word separator. This will often be a single character, but multiple characters are allowed for use cases such as splitting on "

    ". The returned list will have one more item than the number of non-overlapping occurrences of the delimiter in the string. If delimiter is an empty string, then the returned list contains a list of strings, each of which contains a single character. (Not a SRFI 13 procedure; replaces string-tokenize).

    The grammar is a symbol with the same meaning as in the string-join procedure. If it is infix, which is the default, processing is done as described above, except an empty string produces the empty list; if grammar is strict-infix, then an empty string signals an error. The values prefix and suffix cause a leading/trailing empty string in the result to be suppressed.

    If limit is a non-negative exact integer, at most that many splits occur, and the remainder of string is returned as the final element of the list (so the result will have at most limit+1 elements). If limit is not specified or is #f, then as many splits as possible are made. It is an error if limit is any other value.

    To split on a regular expression, use SRFI 115's regexp-split procedure.

    (srfi 152) procedure (read-string (k integer?)) ⟹ eof-object? | string?

    (srfi 152) procedure (read-string (k integer?) (port input-port?)) ⟹ eof-object? | string?

    Reads the next k characters, or as many as are available before the end of file, from the textual input port into a newly allocated string in left-to-right order and returns the string. If no characters are available before the end of file, an end-of-file object is returned. The default port is the value of (current-input-port).

    (srfi 152) procedure (write-string (string string?)) ⟹ undefined

    (srfi 152) procedure (write-string (string string?) (port output-port?)) ⟹ undefined

    (srfi 152) procedure (write-string (string string?) (port output-port?) (start integer?)) ⟹ undefined

    (srfi 152) procedure (write-string (string string?) (port output-port?) (start integer?) (end integer?)) ⟹ undefined

    Writes the characters of string from index start to index end onto textual output port port. The default port is the value of (current-output-port).

    (srfi 152) procedure (string-set! (string string?) (k integer?) (char char?)) ⟹ undefined

    The string-set! procedure stores char in element k of string.

    (srfi 152) procedure (string-fill! (string string?) (fill char?)) ⟹ undefined

    (srfi 152) procedure (string-fill! (string string?) (fill char?) (start integer?)) ⟹ undefined

    (srfi 152) procedure (string-fill! (string string?) (fill char?) (start integer?) (end integer?)) ⟹ undefined

    The string-fill! procedure stores fill in elements start through end of string.

    (srfi 152) procedure (string-copy! (to string?) (at integer?) (from string?)) ⟹ undefined

    (srfi 152) procedure (string-copy! (to string?) (at integer?) (from string?) (start integer?)) ⟹ undefined

    (srfi 152) procedure (string-copy! (to string?) (at integer?) (from string?) (start integer?) (end integer?)) ⟹ undefined

    Copies the characters of string from between start and end to string to, starting at at. The order in which characters are copied is unspecified, except that if the source and destination overlap, copying takes place as if the source is first copied into a temporary string and then into the destination. This can be achieved without allocating storage by making sure to copy in the correct direction in such circumstances.

    library (srfi 154) First-class dynamic extents

    Scheme has the notion of the dynamic extent of a procedure call. A number of standard Scheme procedures and syntaxes like dynamic-wind, call-with-current-continuation, and parameterize deal with the dynamic extent indirectly. The same holds true for the procedures and syntaxes dealing with continuation marks as defined by SRFI 157.

    This SRFI reifies the dynamic extent into a first-class value together with a well-defined procedural interface and a syntax to create procedures that remember not only their environment at creation time but also their dynamic extent, which includes their dynamic environment.

    (srfi 154) procedure (dynamic-extent? obj) ⟹ boolean?

    The dynamic-extent? procedure returns #t if its argument is a dynamic extent, and #f otherwise. Note that dynamic extents are not necessarily disjoint from other Scheme types such as procedures.

    (srfi 154) procedure (current-dynamic-extent) ⟹ dynamic-extent?

    The current-dynamic-extent procedure returns the current dynamic extent by capturing the dynamic extent of the call to current-dynamic-extent, which can be reinstated by the procedure with-dynamic-extent.

    (srfi 154) procedure (with-dynamic-extent (dynamic-extent dynamic-extent?) (thunk procedure?)) ⟹ *

    (thunk) ⟹ *

    The with-dynamic-extent procedure calls the thunk and returns the values yielded by thunk. The call to thunk happens in the dynamic extent captured by the dynamic-extent.

    (srfi 154) syntax (dynamic-lambda formals body)⟹ return

    formals ⟹ (variable1 ...) | variable | (variable1 ... variable_n . variable_n+1)

    A dynamic-lambda expression is equivalent to lambda expression except that not only the environment but also the dynamic extent in effect when the dynamic-lambda expression was evaluated is remembered. In other words, the expression (dynamic-lambda <formals> <body>) closes also over the dynamic extent.

    library (srfi 156) Syntactic combiners for binary predicates

    Recognizing binary predicates as a specific area in which the use of prefix operators is an impediment, we propose a thin layer of "syntactic stevia" for in-fixing such predicates. It can be implemented using regular Scheme macros. We suggest that the code (is x < y) should be transformed to (< x y), and (is x < y <= z) -- to (let ((y* y)) (and (< x y*) (<= y* z))). In addition, we suggest special meaning to the _ symbol: (is _ < y) and (is x < _) should be transformed to (lambda (_) (< _ y)) and (lambda (_) (< x _)), respectively. This SRFI document also describes some other uses of the is macro and its limitations.

    (srfi 156) syntax (is val1 predicate-or-comparator val2 ...)⟹ return

    val ⟹ _ | obj

    predicate-or-comparator ⟹ procedure?

    (srfi 156) syntax (isnt val1 predicate-or-comparator val2 ...)⟹ return

    val ⟹ _ | obj

    predicate-or-comparator ⟹ procedure?

    Infix relations

    This document proposes to augment Scheme with a new syntactic form, is, so that, for example, the expression (is John taller-than? Tom) is expanded to (taller-than? John Tom).

    In addition to improved code readability, the introduction of the is form gives an occasion to provide some convenient special behaviour in some particular cases. While some Schemers may find the lack of regularity and predictability of the is form repulsive, we believe that it actually allows us to express some common operations more succinctly.

    Short-hand lambda expressions

    For example, we decided to treat the _ (underscore) symbol differently than other symbols. (is _ taller-than? John) is expanded to (lambda (_) (taller-than? _ John)), thereby making the functionality of the is form partially overlap with the cut special form defined in the SRFI 26 document.

    We chose the underscore symbol, although the cut macro uses the <> symbol, because it has been used as a special non-bindable symbol in various pattern matchers for Scheme (as well as in the Prolog language). It has also traditionally been used to name values that are meant to be ignored, so we believe that our choice should not be in conflict with existing practices.

    However, the _ symbol should not be bound to a new transformer, but instead it should be imported from (scheme base) and re-exported, so that it can be renamed by the users who prefer to stick with the <> symbol from SRFI-26.

    Multiple instances of underscore

    If more than one instance of the underscore symbol appears in the argument position of the is and isnt macros, each occurrence counts as a separate argument (increasing the arity of the resulting lambda accordingly). For example, (is _ < _) is equivalent to (lambda (_1 _2) (< _1 _2)).

    Negation

    In addition to the is form, this SRFI provides an implementation of the isnt form, which negates the behavior of is. Although we didn't find that form particularly useful, we are certain that it may find its use, and if it were absent from the language, Schemers would come up with their own implementations. As a matter of fact, in our experiments with parroting the English language, we initially used the isn't symbol, which failed to work on some implementations.

    Handling fewer arguments

    The is and isnt macros could technically be passed fewer than three arguments. In particular, we interpret (isnt x prime?) as (not (prime? x)), and (isnt _ prime?) as (lambda (_) (not (prime? _))). For consistency, we interpret the usages of the is macro similarly, although it may not seem particularly useful. It is illegal to use the is and isnt macros with fewer than two arguments, and such attempts should raise a syntax error.

    library (srfi 157) Continuation marks

    Continuation marks are a programming language feature that allows one to attach information to and retrieve information from continuations, generalizing stack inspection. Conceptually, a continuation consists of a number of frames where each frame stands for an active procedure call that is not a tail call. A continuation mark is then a key-value pair associated with a frame, with keys compared using eq?. At most one mark for a given key can be attached to a single frame.

    Besides stack inspection, continuation marks can be used to implement dynamic scope, delimited continuations, or delayed evaluation that is able to handle iterative lazy algorithms.

    This SRFI proposes to add continuation marks to the Scheme programming language. The interface defined here is modelled after Racket's continuation marks. It does not include all forms and procedures provided by Racket but provides a compatible subset.

    (srfi 157) syntax (with-continuation-mark key value expression)

    The <key> expression is evaluated to obtain a key, the <value> expression is evaluated to obtain a value, the key is mapped to the value as a continuation mark in the current continuation's initial continuation (if the frame already has a mark for the key, the mark is replaced), and, finally, the <expression> is evaluated. The continuation for evaluating <expression> is the continuation of the with-continuation-mark expression (so the result of the <expression> is the result of the with-continuation-mark expression, and the <expression> is in tail context if the with-continuation-mark expression is).

    (srfi 157) procedure (current-continuation-marks) ⟹ continuation-marks?

    Returns an object called a set of continuations marks, which at some point in the future can be asked (by the continuation-mark-set->list, continuation-mark-set->list* and continuation-mark-set-first procedures) to deliver the set of continuation marks of the continuation of the call to current-continuation-marks for a given key.

    (srfi 157) procedure (continuation-marks? obj) ⟹ boolean?

    Returns #t if obj is a set of continuation marks, and #f otherwise. Note that sets of continuation marks are not necessarily disjoint from other Scheme types such as lists.

    (srfi 157) procedure (continuation-mark-set->list (marks continuation-marks?)) ⟹ list?

    Returns a newly allocated list containing the marks for the key in the continuation mark set marks.

    (srfi 157) procedure (continuation-mark-set->list* (marks continuation-marks?) list) ⟹ list?

    (srfi 157) procedure (continuation-mark-set->list* (marks continuation-marks?) list default) ⟹ list?

    return ⟹ (list vector?)

    Returns a newly allocated list containing vectors of marks in the continuation mark set marks. The length of each vector in the result list is the same as the length of the key list, and a value in a particular vector position is the value for the corresponding key in list. Values for multiple keys appear in a single vector only when the marks are for the same continuation frame in the continuation mark set marks. The object default is used for vector elements to indicate the lack of a value.

    (srfi 157) procedure (continuation-mark-set-first (marks continuation-marks?) key) ⟹ *

    (srfi 157) procedure (continuation-mark-set-first (marks continuation-marks?) key default) ⟹ *

    Returns the first element of the list that would be returned by (continuation-mark-set->list marks key), or default if the result would be the empty list.

    Semantically equivalent to, but may be more efficient than:

    (let ((lst (continuation-mark-set->list marks key))

    (if (not (null? lst))

    (car lst)

    default)))

    (srfi 157) procedure (call-with-immediate-continuation-mark key (proc procedure?)) ⟹ *

    (srfi 157) procedure (call-with-immediate-continuation-mark key (proc procedure?) default) ⟹ *

    (proc mark-value) ⟹ *

    Tail-calls proc with the value associated with key in the first frame of the current continuation (i.e., a value that would be replaced in the set of current continuation marks if the call to call-with-immediate-continuation-mark were replaced with a with-continuation-mark form using key as the key expression). If no such value exists in the first frame, default is passed to proc.

    Semantically equivalent to, but may be more efficient than:

    (let ((secret-key (vector #f)))

    (with-continuation-mark secret-key #f

    (let ((marks

    (continuation-mark-set->list* (current-continuation-marks)

    (list key secret-key)

    default))

    (proc (vector-ref (car marks) 0)))))

    library (srfi 158) Generators and Accumulators

    This SRFI defines utility procedures that create, transform, and consume generators. A generator is simply a procedure with no arguments that works as a source of values. Every time it is called, it yields a value. Generators may be finite or infinite; a finite generator returns an end-of-file object to indicate that it is exhausted. For example, read-char, read-line, and read are generators that generate characters, lines, and objects from the current input port. Generators provide lightweight laziness.

    This SRFI also defines procedures that return accumulators. An accumulator is the inverse of a generator: it is a procedure of one argument that works as a sink of values.

    See (scheme generator)

    library (srfi 159) Combinator Formatting

    A library of procedures for formatting Scheme objects to text in various ways, and for easily concatenating, composing and extending these formatters efficiently without resorting to capturing and manipulating intermediate strings.

    See (scheme show)

    library (srfi 160 base) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector base)

    library (srfi 160 u8) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector u8)

    library (srfi 160 s8) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector s8)

    library (srfi 160 u16) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector u16)

    library (srfi 160 s16) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector s16)

    library (srfi 160 u32) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector u32)

    library (srfi 160 s32) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector s32)

    library (srfi 160 u64) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector u64)

    library (srfi 160 s64) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector s64)

    library (srfi 160 f32) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector f32)

    library (srfi 160 f64) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector f64)

    library (srfi 160 c64) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector c64)

    library (srfi 160 c128) Homogeneous numeric vector libraries

    This SRFI describes a set of operations on SRFI 4 homogeneous vector types (plus a few additional types) that are closely analogous to the vector operations library, SRFI 133. An external representation is specified which may be supported by the read and write procedures and by the program parser so that programs can contain references to literal homogeneous vectors.

    See (scheme vector c128)

    library (srfi 161) Unifiable Boxes

    Unifiable boxes are, like the boxes of SRFI 111, objects with a single mutable state. A constructor, predicate, accessor, and mutator are provided.

    In addition to this, an equality predicate and union operations (link, union, unify) are provided. Applying a union operation to two unifiable boxes makes the two boxes equal (in the sense of the equality predicate). As a consequence, their state will also become identical. In the case of link and union, it will be the state of one of the two unioned boxes. In the case of unify, the state is determined by a supplied unification procedure.

    Unifiable boxes are also known under the names disjoint-set data structure, union–find data structure or merge–find set.

    (srfi 161) procedure (ubox value) ⟹ ubox?

    Constructor. Returns a newly allocated unifiable box initialized to value. The new unifiable box is not equal to any previously constructed unifiable box.

    (srfi 161) procedure (ubox? object) ⟹ boolean?

    Predicate. Returns #t if object is a unifiable box, and #f otherwise.

    (srfi 161) procedure (ubox-ref (ubox ubox?)) ⟹ *

    Accessor. Returns the current value of the unifiable box ubox.

    (srfi 161) procedure (ubox-set! (ubox ubox?) value) ⟹ undefined

    Mutator. Changes the unifiable box ubox to hold value. The return value is unspecified.

    (srfi 161) procedure (ubox=? (ubox1 ubox?) (ubox2 ubox?)) ⟹ boolean?

    Equality predicate. Returns #t if ubox1 and ubox2 are equal unifiable boxes, and #f otherwise.

    (srfi 161) procedure (ubox-unify! (proc procedure?) (ubox1 ubox?) (ubox2 ubox?)) ⟹ undefined

    (proc value1 value2) ⟹ *

    Union operation. Invokes proc on the values of ubox1 and ubox2, makes ubox1 and ubox2 equal, and updates their value to the result of the invocation of proc. The return value is unspecified.

    (srfi 161) procedure (ubox-union! (ubox1 ubox?) (ubox2 ubox?)) ⟹ undefined

    Union operation. Makes the unifiable boxes ubox1 and ubox2 equal. The value of the unified box is the value of either ubox1 or ubox2 before the unification. The return value is unspecified.

    (srfi 161) procedure (ubox-link! (ubox1 ubox?) (ubox2 ubox?)) ⟹ undefined

    Union operation. Makes the unifiable boxes ubox1 and ubox2 equal. The value of the unified box is the value of ubox2 before the unification. The return value is unspecified.

    library (srfi 162) Comparators sublibrary

    This SRFI provides a few extra procedures and comparators to go with SRFI 128, Comparators. Implementers are urged to add them to their SRFI 128 libraries, for which reason they are not packaged as a separate library.

    (srfi 162) procedure (comparator-max (comarator comparator?) obj1 obj2 ...) ⟹ *

    (srfi 162) procedure (comparator-min (comarator comparator?) obj1 obj2 ...) ⟹ *

    (srfi 162) procedure (comparator-max-in-list (comarator comparator?) (list list?)) ⟹ *

    (srfi 162) procedure (comparator-min-in-list (comarator comparator?) (list list?)) ⟹ *

    These procedures are analogous to min and max respectively, but may be applied to any orderable objects, not just to real numbers. They apply the ordering procedure of comparator to the objects to find and return a minimal (or maximal) object. The order in which the values are compared is unspecified. If two objects are equal in the sense of the comparator, either may be returned.

    The -in-list versions accept a single list argument.

    (srfi 162) value default-comparator ⟹ comparator?

    A pre-created default comparator. It should behave exactly like a comparator returned by SRFI 128 make-default-comparator.

    (srfi 162) value boolean-comparator ⟹ comparator?

    A comparator for booleans such that #f compares before #t.

    (srfi 162) value real-comparator ⟹ comparator?

    A comparator for real numbers such that smaller numbers compare before larger numbers.

    (srfi 162) value char-comparator ⟹ comparator?

    A comparator for characters using Unicode codepoint order.

    (srfi 162) value char-ci-comparator ⟹ comparator?

    A comparator for characters using char-ci<?.

    (srfi 162) value string-comparator ⟹ comparator?

    A comparator for strings using the implementation-specific definition of string<?.

    (srfi 162) value string-ci-comparator ⟹ comparator?

    A comparator for strings using the implementation-specific definition of string-ci<?.

    (srfi 162) value pair-comparator ⟹ comparator?

    Compares pairs as if by the application of make-pair-comparator to pairs with default-comparator as the car and cdr comparators.

    (srfi 162) value list-comparator ⟹ comparator?

    Compares lists as if by the application of make-list-comparator to lists with default-comparator as the element comparator.

    (srfi 162) value vector-comparator ⟹ comparator?

    Compares vectors as if by the application of make-vector-comparator to vectors with default-comparator as the element comparator.

    (srfi 162) value eq-comparator ⟹ comparator?

    (srfi 162) value eqv-comparator ⟹ comparator?

    (srfi 162) value equal-comparator ⟹ comparator?

    comparators whose functions behave as follows:

  • The type test returns #t in all cases.
  • The equality functions are eq?, eqv?, and equal? respectively.
  • The ordering function is implementation-defined, except that it must conform to the rules for ordering functions. It may signal an error instead.
  • The hash function is default-hash.
  • These comparators accept circular structure (in the case of equal-comparator, provided the implementation's equal? predicate does so) and NaNs.

    library (srfi 165) The Environment Monad

    Monads model computations. The environment monad models computations that depend on values from a shared environment. These computations can read values from the environment, pass values to subsequent computations, execute sub-computations in an extended environment, and modify the environment for future computations.

    (srfi 165) procedure (make-computation-environment-variable (name string? | symbol?) default (immutable? boolean?)) ⟹ computation-env-variable

    Returns a Scheme object that can be used as an environment variable, whose default value is default and which is immutable if immutable? is not #f. The symbol or string name is solely for debugging purposes. The type of the returned object is unspecified. Each invocation returns an environment variable different to any previously returned environment variable.

    (srfi 165) procedure (make-computation-environment) ⟹ computation-env

    Returns a new environment, in which environment variables can be bound to values. The type of the returned object is unspecified.

    (srfi 165) procedure (computation-environment-ref (env computation-env) (var computation-env-variable)) ⟹ *

    If the variable var is bound to a value in the environment env, returns that value, and the environment variable's default value otherwise.

    (srfi 165) procedure (computation-environment-update (env computation-env) (var1 computation-env-variable) val1 ...) ⟹ computation-env

    The arguments arg... alternate between environment variables var and values val. Returns a new environment that extends the environment env by binding each environment variable var to the respective value val.

    (srfi 165) procedure (computation-environment-update! (env computation-env) (var computation-env-variable) val) ⟹ undefined

    Updates the environment env in place by binding the environment variable var to val, and returns an unspecified value.

    (srfi 165) procedure (computation-environment-copy (env computation-env)) ⟹ computation-env

    Returns a fresh copy of the environment env.

    (srfi 165) procedure (make-computation (proc procedure?)) ⟹ computation

    (proc (compute procedure?)) ⟹ *

    (compute (computation computation)) ⟹ *

    Takes a procedure proc, which takes one argument, and returns a computation. The Scheme type of a computation is disjoint from any type, as if created by define-record-type, except possibly procedures.

    When the computation is later executed on an environment, the procedure proc is called with an argument compute, which is a procedure taking one argument. Whenever compute is invoked on another computation, the other computation is executed on the environment and its results are returned. The results yielded by the execution are the results of the invocation of proc.

    (srfi 165) procedure (computation-run (computation computation)) ⟹ *

    Executes the computation computation and returns the results it yields.

    (srfi 165) procedure (computation-ask) ⟹ computation

    Returns a computation that, when executed on an environment, yields that environment.

    (srfi 165) procedure (computation-local (updater procedure?) (computation computation)) ⟹ computation

    (updater (env computation-env)) ⟹ computation-env

    Returns a computation that, when executed on an environment env, invokes the procedure updater on env, executes the computation computation on the result of the invocation of updater, which must be an environment, and yields its results.

    (srfi 165) procedure (computation-pure obj1 ...) ⟹ computation

    Returns a computation that, when executed, yields the values obj1...

    (srfi 165) procedure (computation-each (computation1 computation) ...) ⟹ computation

    Returns a computation that, when executed, sequentially executes the computations computation1, …, computationn and yields the results yielded by the last computation.

    (srfi 165) procedure (computation-each-in-list (list list?)) ⟹ computation

    list ⟹ (list computation)

    Equivalent to (computation-each computation1 ... computationn) if list is a list whose elements are computation1, ..., computationn.

    (srfi 165) procedure (computation-bind (computation computation) (proc1 procedure?) ...) ⟹ computation

    (proc obj) ⟹ computation

    (computation-bind computation) is equivalent to computation. (computation-bind computation proc1 proc2 ...) is equivalent to (computation-bind (computation-bind computation proc1) proc2 ...).

    The invocation of (computation-bind computation proc) returns a computation that, when executed, executes the computation computation, on which results the procedure proc is then invoked, resulting in a computation that is then executed and whose results are yielded.

    (srfi 165) procedure (computation-sequence (list list?)) ⟹ computation

    list ⟹ (list computation)

    When invoked on a list list of computations, returns a computation that, when executed, executes the computations in sequence and yields a list whose elements are the results yielded by the computations.

    (srfi 165) procedure (computation-forked (computation1 computation) ...) ⟹ computation

    Returns a computation that, when executed on an environment, executes each of the computations computation1, ... on fresh copies of the environment, and finally executes computation_n on the original environment and yields its results.

    (srfi 165) procedure (computation-bind/forked (computation computation) (proc1 procedure?) ...) ⟹ computation

    (proc obj) ⟹ computation

    As (computation-bind computation proc1 ...), but executes computation on a fresh copy of the environment.

    (srfi 165) syntax (computation-fn ((variable1 init1) ...) body)⟹ return

    Evaluates the expressions init1... to environment variables var1... in an unspecified order and returns a computation that, when executed, lexically binds the variables variable1... to the values to which the environment variables var1, ... are bound, and evaluates the body in the resulting lexical environment. The value of the last expression in body has to be a computation, which is then executed and its results yielded.

    A clause of the form (variable variable) (i.e. the expression init is the variable reference variable) can be abbreviated by variable.

    An unbound environment variable behaves as if it were bound to its default value.

    (srfi 165) syntax (computation-with ((variable1 init1) ...) expr1 ... expr_n)⟹ return

    Evaluates the expressions expr1...expr_n to computations computation1, ..., computation_n, the expressions variable1... to environment variables var1... and the expressions init1... to values val1... in an unspecified order, and returns a computation that, when executed on an environment, extends that environment non-destructively by binding var1,... to val1..., sequentially executes the computations computation1, ... computation_n on that extended environment, and then yields the results of the last computation.

    (srfi 165) syntax (computation-with! (variable1 init1) ...)⟹ return

    Evaluates the expressions variable1... to mutable environment variables var1... and the expressions init1... to values val1... in an unspecified order, and returns a computation that, when executed on an environment, modifies this environment in place by binding var1,... to val1... and which yields an unspecified value.

    (srfi 165) value default-computation ⟹ computation-env-variable

    This SRFI exports the identifier default-computation, which is bound to a location holding a mutable environment variable (as if created by (make-computation-environment-variable)) in the sense of this SRFI. In each fresh computation environment, default-computation is initially unbound. Whenever a computation computation is to be executed on an environment and is neither a computation nor a procedure, the value to which default-computation is bound in the environment has to be a procedure, which is then invoked on computation to return a computation, which is then executed on the environment.

    (srfi 165) syntax (define-computation-type make-environment run clause ...)

    clause ⟹ (variable default) | (variable default "immutable") | variable

    This syntax may appear wherever other definitions may appear. Each clause is of the form (variable default), (variable default "immutable"), or variable. The latter form is equivalent to (variable #f). make-environment, run, and each variable are identifiers.

    An instance of define-computation-type is equivalent to the following definitions:

  • make-environment is bound to a procedure that takes no arguments. Invoking the procedure is equivalent to invoking make-computation-environment except that the environment variables defined below can be used with the resulting environment.
  • run is bound to a procedure that takes one argument. Invoking the procedure is equivalent to invoking computation-run except for that the initial environment is created by invoking the procedure bound to make-environment.
  • Each variable is bound to an environment variable, which can only be used with an environment created by invoking the procedure bound to make-environment. Its default value is the result of evaluating default. The environment variable is immutable if the (variable default "immutable") form is used.
  • library (srfi 180) JSON

    This library describes a JavaScript Object Notation (JSON) parser and printer. It supports JSON that may be bigger than memory.

    (srfi 180) procedure (json-write obj) ⟹ undefined

    (srfi 180) procedure (json-write obj (port-or-accumulator port? | procedure?)) ⟹ undefined

    JSON writer procedure. PORT-OR-ACCUMULATOR must be a textual output port, or an accumulator that accepts characters and strings. The default value of PORT-OR-ACCUMULATOR is the value returned by the procedure current-output-port. The value returned by json-write is unspecified.

    json-write will validate that OBJ can be serialized into JSON before writing to PORT. An error that satisfies json-error? is raised in the case where OBJ is not an object or a composition of the following types:

  • symbol 'null
  • boolean
  • number. Must be integers or inexact rationals. (That is, they must not be complex, infinite, NaN, or exact rationals that are not integers.)
  • string
  • vector
  • association list with keys as symbols
  • (srfi 180) procedure (json-accumulator (port-or-accumulator port? | procedure?)) ⟹ procedure?

    Streaming event-based JSON writer. PORT-OR-ACCUMULATOR must be a textual output port or an accumulator that accepts characters and strings. It returns an accumulator procedure that accepts Scheme objects as its first and only argument and that follows the same protocol as described in json-generator. Any deviation from the protocol must raise an error that satisfies json-error?. In particular, objects and arrays must be properly nested.

    Mind the fact that most JSON parsers have a nesting limit that is not documented by the standard. Even if you can produce arbitrarily nested JSON with this library, you might not be able to read it with another library.

    (srfi 180) procedure (json-sequence-read ) ⟹ procedure?

    (srfi 180) procedure (json-sequence-read (port-or-generator port? | procedure?)) ⟹ procedure?

    JSON reader of JSON Text Sequences (RFC 7464). As its first and only argument, it takes a generator of characters or a textual input port whose default value is the value returned by current-input-port. It will return a generator of Scheme objects as specified in json-read.

    (srfi 180) procedure (json-lines-read ) ⟹ procedure?

    (srfi 180) procedure (json-lines-read (port-or-generator port? | generator?)) ⟹ procedure?

    JSON reader of jsonlines or ndjson. As its first and only argument, it takes a generator of characters or a textual input port whose default value is the value returned by current-input-port. It will return a generator of Scheme objects as specified in json-read.

    (srfi 180) procedure (json-read ) ⟹ *

    (srfi 180) procedure (json-read (port-or-generator port? | procedure?)) ⟹ *

    JSON reader procedure. PORT-OR-GENERATOR must be a textual input port or a generator of characters. The default value of PORT-OR-GENERATOR is the value returned by the procedure current-input-port. The returned value is a Scheme object. json-read must return only the first toplevel JSON value or structure. When there are multiple toplevel values or structures in PORT-OR-GENERATOR, the user should call json-read several times to read all of it.

    The mapping between JSON types and Scheme objects is the following:

  • null -> the symbol 'null
  • true -> #t
  • false -> #f
  • number -> number
  • string -> string
  • array -> vector
  • object -> association list with keys that are symbols
  • In the case where nesting of arrays or objects reaches the value returned by the parameter json-nesting-depth-limit, json-read must raise an object that satisfies the predicate json-error?

    (srfi 180) procedure (json-fold (proc procedure?) (array-start procedure?) (array-end procedure?) (object-start procedure?) (object-end procedure?) seed) ⟹ *

    (srfi 180) procedure (json-fold (proc procedure?) (array-start procedure?) (array-end procedure?) (object-start procedure?) (object-end procedure?) seed (port-or-generator port? | procedure?)) ⟹ *

    (proc obj seed) ⟹ *

    (array-start obj seed) ⟹ *

    (array-end obj seed) ⟹ *

    (object-start obj seed) ⟹ *

    (object-end obj seed) ⟹ *

    Fundamental JSON iterator.

    json-fold will read the JSON text from PORT-OR-GENERATOR, which has (current-input-port) as its default value. json-fold will call the procedures passed as argument:

  • (PROC obj seed) is called when a JSON value is generated or a complete JSON structure is read. PROC should return the new seed that will be used to iterate over the rest of the generator. Termination is described below.
  • (OBJECT-START seed) is called with a seed and should return a seed that will be used as the seed of the iteration over the key and values of that object.
  • (OBJECT-END seed) is called with a seed and should return a new seed that is the result of the iteration over a JSON object.
  • ARRAY-START and ARRAY-END take the same arguments, and have similar behavior, but are called for iterating on JSON arrays.

    json-fold must return the seed when:

  • PORT-OR-GENERATOR yields an object that satisfies the predicate eof-object?
  • All structures, array or object, that were started have ended. The returned object is (PROC obj SEED) where obj is the object returned by ARRAY-END or OBJECT-END
  • (srfi 180) procedure (json-generator ) ⟹ procedure?

    (srfi 180) procedure (json-generator (port-or-generator port? | procedure?)) ⟹ procedure?

    Streaming event-based JSON reader. PORT-OR-GENERATOR default value is the value returned by current-input-port. It must be a textual input port or a generator of characters. json-generator returns a generator of Scheme objects, each of which must be one of:

  • 'array-start symbol denoting that an array should be constructed.
  • 'array-end symbol denoting that the construction of the array for which the last 'array-start was generated and not closed is finished.
  • 'object-start symbol denoting that an object should be constructed. The object's key-value pairs are emitted in sequence like those in a property list (plist) where keys are strings. That is, the generation of a key is always followed by the generation of a value. Otherwise, the JSON would be invalid and json-generator would raise an error.
  • 'object-end symbol denoting that the construction of the object for which the last object-start was generated and not closed is finished.
  • the symbol 'null
  • boolean
  • number
  • string
  • In the case where nesting of arrays or objects reaches the value returned by the parameter json-nesting-depth-limit, the generator must raise an object that satisfies the predicate json-error?

    In cases where the JSON is invalid, the generator returned by json-generator should raise an object that satisfies the predicate json-error?.

    Otherwise, if PORT-OR-GENERATOR contains valid JSON text, the generator returned by json-generator must yield an end-of-file object in two situations:

  • The first time the generator returned by json-generator is called, it returns an object that is a boolean, a number, a string or the symbol 'null.
  • The first time the generator returned by json-generator is called, it returns a symbol that is not the symbol 'null. When the underlying JSON text is valid, it should be the symbol starting a structure: 'object-start or 'array-start. The end-of-file object is generated when that structure is finished.
  • In other words, the generator returned by json-generator will parse at most one JSON value or one top-level structure. If PORT is not finished, as in the case of JSON lines, the user should call json-generator again with the same PORT-OR-GENERATOR.

    (srfi 180) procedure (json-number-of-character-limit) ⟹ procedure?

    Parameter holding a number that represents the maximum number of characters for a given JSON text that can be read by json-generator, json-fold, and json-read. If the value returned by this parameter is reached, the implementation must raise an error that satisfies json-error?.

    The default value of json-number-of-character-limit is +inf.0.

    A proper value should be set on a per-application basis to mitigate the risks of denial-of-service attacks.

    (srfi 180) procedure (json-nesting-depth-limit) ⟹ procedure?

    Parameter holding a number that represents the maximum nesting depth of JSON text that can be read by json-generator, json-fold, and json-read. If the value returned by this parameter is reached, the implementation must raise an error that satisfies json-error?.

    The default value of json-nesting-depth-limit is +inf.0.

    A proper value should be set on a per-application basis to mitigate the risks of denial-of-service attacks.

    (srfi 180) procedure (json-null? obj) ⟹ boolean?

    Return #t if OBJ is the Scheme symbol 'null, which represents the JSON null in Scheme. In all other cases, return #f.

    (srfi 180) procedure (json-error-reason (err json-error?)) ⟹ string?

    Return a string explaining the reason for the error. This should be human-readable.

    (srfi 180) procedure (json-error? obj) ⟹ boolean?

    Returns #t if OBJ is an error object that is specific to this library.

    library (srfi 185) Linear adjustable-length strings

    Scheme specifies mutable fixed-length strings. SRFI 118 adds two procedures, string-append! and string-replace!, which allow the length of the string to change. This SRFI provides two linear-update versions of these procedures: that is, the implementation may change the string length or return a new string instead. In addition, two convenience macros are provided that make the procedures somewhat easier to use.

    (srfi 185) procedure (string-append-linear! (dst string?) (string-or-char string? | char?) ...) ⟹ string?

    This procedure returns a string which extends dst by appending each additional string-or-char (in order) to the end of dst. A character argument and a string argument of length 1 are treated exactly the same way. The result can either be dst itself or a newly allocated string.

    There is no requirement that this procedure execute in constant time, even amortised (i.e. average) constant time.

    (srfi 185) procedure (string-replace-linear! (dst string?) (dst-start integer?) (dst-end integer?) (src string?)) ⟹ string?

    (srfi 185) procedure (string-replace-linear! (dst string?) (dst-start integer?) (dst-end integer?) (src string?) (src-start integer?)) ⟹ string?

    (srfi 185) procedure (string-replace-linear! (dst string?) (dst-start integer?) (dst-end integer?) (src string?) (src-start integer?) (src-end integer?)) ⟹ string?

    Returns a string which has the same characters as dst, except that the characters between dst-start and dst-end have been replaced with the characters of the string src between src-start and src-end. The result can either be dst itself or a newly allocated string.

    The number of characters from src may be different than the number replaced in dst, so the result may be larger or smaller than the previous length of dst. The special case where dst-start is equal to dst-end corresponds to insertion; the case where src-start is equal to src-end corresponds to deletion. The order in which characters are copied is unspecified, except that if the source and destination overlap, copying takes place as if the source is first copied into a temporary string and then into the destination. (This can be achieved without allocating storage by making sure to copy in the correct direction in such circumstances.)

    When src is a string then (string-append-linear! dst src) is equivalent to (string-replace-linear! dst (string-length dst) (string-length dst) src).

    (srfi 185) syntax (string-append! place string-or-char ...)

    string-or-char ⟹ string?

    string-or-char ⟹ char?

    This macro sets place to the result of invoking (string-append-linear! place string-or-char ...). It returns an unspecified value.

    (srfi 185) syntax (string-replace! dst-place dst-start dst-end src)

    (srfi 185) syntax (string-replace! dst-place dst-start dst-end src src-start)

    (srfi 185) syntax (string-replace! dst-place dst-start dst-end src src-start src-end)

    dst-start ⟹ integer?

    dst-end ⟹ integer?

    src ⟹ string?

    src-start ⟹ integer?

    src-end ⟹ integer?

    This macro sets dst-place to the result of applying string-replace-linear! to its arguments. The result is an unspecified value.

    library (srfi 190) Coroutine Generators

    This SRFI defines syntax to create SRFI 121/158 coroutine generators conveniently and in the flavor of Python generator functions.

    (srfi 190) syntax (coroutine-generator body)⟹ return

    Creates a generator from a coroutine. When evaluated, immediately returns a generator g. When g is called, the definitions and expressions in <body> are evaluated until the yielding procedure of the coroutine generator is called. Calling the yielding procedure of the coroutine generator causes the evaluation of <body> to be suspended, and g returns the value passed to yield.

    Whether this generator is finite or infinite depends on the behavior of <body>. If the last expression in body> returns, it is the end of the sequence — g returns an end-of-file object from then on.

    (srfi 190) procedure (yield) ⟹ procedure?

    (return value) ⟹ undefined

    Evaluates to the yielding procedure in the (expansion of the) <body> of a coroutine generator. It is an error to evaluate yield outside the body of a coroutine generator.

    (srfi 190) syntax (define-coroutine-generator name body)

    (srfi 190) syntax (define-coroutine-generator (name . formals) body)

    Expands into

    (define <name> (coroutine-generator <body>))

    and

    (define (<name> . <formals>) (coroutine-generator <body>))

    respectively.

    library (srfi 191) Procedure Arity Inspection

    Many Scheme systems provide mechanisms for inspecting the arity of a procedural value, making it a common feature, however there is no standard interface. As a result there is no portable way to observe the arity of a procedure without actually applying it. This SRFI proposes a simple interface that is consistent with existing Scheme systems' facilities and prior proposals.

    (srfi 191) procedure (procedure-arity-mask (proc procedure?)) ⟹ integer?

    Returns an exact integer n such that if the implementation can prove that proc definitely cannot be called with k arguments, then the kth bit of n is 0. Otherwise, the kth bit is 1. The 0th bit of k is the least significant bit; positive integers are left extended with zeros and negative integers with ones.

    library (srfi 193) Command line

    R6RS and R7RS define a command-line procedure. While a useful baseline, the specification is not detailed enough to cover all practical situations. This SRFI clarifies the definition of command-line and adds a few related procedures. Scheme scripts, standalone executables, compilation and REPL use are accounted for. Option parsing is out of scope.

    (srfi 193) procedure (command-line) ⟹ list?

    return ⟹ (list string?)

    This procedure is equivalent to the R6RS and R7RS command-line procedure, but specified in more detail.

    R6RS definition: "Returns a nonempty list of strings. The first element is an implementation-specific name for the running top-level program. The remaining elements are command-line arguments according to the operating system’s conventions."

    R7RS definition: "Returns the command line passed to the process as a list of strings. The first string corresponds to the command name, and is implementation-dependent. It is an error to mutate any of these strings."

    Additional stipulations by this SRFI:

  • If the calling program is not a command in this SRFI’s terminology, a list equal to ("") is returned.
  • If the calling program is a standalone executable, the command line is equal to the command line of the operating system process, except that arguments belonging to the Scheme runtime system are omitted. (Such arguments start with -: in Gambit and Chicken.)
  • If the calling program is a script as well as a command, the command name is equal to the filename given to load, on the command line, in an environment variable, etc. The command args are the args (if any) that belong to the script.
  • Otherwise, if the command name comes from a filename, the filename is preserved as given to the implementation.
  • It is an error to mutate a (command-line) list returned by the implementation, or any of the strings in it.
  • Implementations are encouraged to have command-line as a parameter object. In that case, the implementation binds the value of the parameter as above for the duration of the command. The program may freely rebind command-line to any other string list containing at least one element, either temporarily with parameterize or permanently.
  • If a program rebinds the command-line parameter, the new binding may share structure with the old binding.
  • (srfi 193) procedure (command-name) ⟹ string? | #f

    return ⟹ (list string?)

    Returns a friendly version of (car (command-line)) evaluated in the current lexical environment.

    If (car (command-line)) is a zero-length string, #f is returned to indicate "not a command".

    Otherwise a friendly command name is typically derived from a filename as follows:

  • The directory part (if any) is removed.
  • Filename extensions known to belong to executable files or Scheme scripts on the underlying operating system are removed at the discretion of the implementation. For example, .exe or .scm.
  • Other changes may also be made according to local conventions.
  • For example, both the Windows filename C:\Program Files\Fantastic Scheme\fantastic-scheme-1.0.EXE and the Unix filename /usr/local/bin/fantastic-scheme-1.0 would be typically shortened to fantastic-scheme-1.0.

    (srfi 193) procedure (command-args) ⟹ list?

    return ⟹ (list string?)

    Returns (cdr (command-line)) evaluated in the current lexical environment.

    (srfi 193) procedure (script-file) ⟹ string? | #f

    Returns an absolute pathname pointing to the calling script. Symbolic links are not resolved.

    (The script may or may not be a command; use command-name to find out.)

    If the calling program is not a script, #f is returned.

    Implementations must resolve the absolute pathname of a script before running that script. The script may change the working directory, thereby changing the interpretation of relative pathnames.

    (srfi 193) procedure (script-directory) ⟹ string? | #f

    Returns only the non-filename part of script-file as a string. As with script-file, this is an absolute pathname.

    The string should end with a directory separator (a forward slash on Unix; a backslash on Windows; an appropriate character on other operating systems) so that string-append can be easily used to build pathnames based on it: for example, (string-append (script-directory) "my-data-file"). However, if appending such a separator would make the pathname invalid on the underlying operating system, the separator is not added.

    If the calling program is not a script, #f is returned.

    library (srfi 196) Range Objects

    Ranges are collections somewhat similar to vectors, except that they are immutable and have algorithmic representations instead of the uniform per-element data structure of vectors. The storage required is usually less than the size of the same collection stored in a vector and the time needed to reference a particular element is typically less for a range than for the same collection stored in a list. This SRFI defines a large subset of the sequence operations defined on lists, vectors, strings, and other collections. If necessary, a range can be converted to a list, vector, or string of its elements or a generator that will lazily produce each element in the range.

    (srfi 196) procedure (range (length integer?) (indexer procedure?)) ⟹ range?

    (indexer (index integer?)) ⟹ *

    Returns a range whose length (number of elements) is length. The indexer procedure returns the nth element (where 0 ≤ n < length) of the range, given n. This procedure must run in O(1) time. The range returned is compact, although indexer may close over arbitrarily large data structures. The average accessing time of the resulting range is the average time needed to run indexer.

    (srfi 196) procedure (numeric-range (start number?) (end number?)) ⟹ range?

    (srfi 196) procedure (numeric-range (start number?) (end number?) (step number?)) ⟹ range?

    Returns a numeric range, a special case of a range specified by an inclusive lower bound start, an exclusive upper bound end, and a step value (default 1), all of which can be exact or inexact real numbers. This constructor produces the sequence

    start, (+ start step), (+ start (* 2 step)), …, (+ start (* n step)),

    where n is the greatest integer such that (+ start (* n step)) < end if step is positive, or such that (+ start (* n step)) > end if step is negative. It is is an error if an n satisfying this condition cannot be determined, or if step is numerically zero. This procedure must run in O(1) time. The average accessing time of the resulting range must be O(1).

    Note that an effect of this definition is that the elements of a range over inexact numbers are enumerated by multiplying the index by the step value rather than by adding the step value to itself repeatedly. This reduces the likelihood of roundoff errors.

    (srfi 196) procedure (iota-range (length integer?)) ⟹ range?

    (srfi 196) procedure (iota-range (length integer?) (start number?)) ⟹ range?

    (srfi 196) procedure (iota-range (length integer?) (start number?) (step number?)) ⟹ range?

    Returns an iota-numeric range, a special case of a range specified by a length (a non-negative exact integer) as well as an inclusive lower bound start (default 0) and a step value (default 1), both of which can be exact or inexact real numbers. This constructor produces the sequence

    start, (+ start step), (+ start (* 2 step)), …, (+ start (* (- length 1) step)),

    This procedure must run in O(1) time. The average accessing time of the resulting range must be O(1).

    Note that an effect of this definition is that the elements of a range over inexact numbers are enumerated by multiplying the index by the step value rather than by adding the step value to itself repeatedly. This reduces the likelihood of roundoff errors.

    (srfi 196) procedure (vector-range (vector vector?)) ⟹ range?

    Returns a range whose elements are those of vector. The procedure must run in O(1) time. The average accessing time of the resulting range must be O(1). It is an error to mutate vector.

    (srfi 196) procedure (string-range (string string?)) ⟹ range?

    Returns a range whose elements are those of string. It is an error to mutate string. This procedure must run in O(n) time, where n is the length of string. The average accessing time of the resulting range must be O(1).

    In a Scheme that guarantees O(1) random access to strings, range-ref on a range created by string-range can simply call string-ref, and the resulting range is compact. But if only O(n) access is available, this procedure may have to copy the string's characters into a vector, resulting in an expanded range.

    (srfi 196) procedure (range-append (range range?) ...) ⟹ range?

    Returns a range whose elements are the elements of the ranges in order. This procedure must run in O(n) + O(k) time, where n is the total number of elements in all the ranges and k is the number of ranges. The result is usually expanded but may be compact. The average accessing time of the resulting range is asymptotically bounded by maximum of the average accessing times of the ranges.

    (srfi 196) procedure (range-reverse (range range?)) ⟹ range?

    Returns a range whose elements are the elements of the range but in reverse order. This procedure must run in O(s) time, where s is the total accessing time of range. The resulting range may be expanded, and should have O(1) average accessing time.

    (srfi 196) procedure (range? obj) ⟹ boolean?

    Returns #t if obj is a range and #f otherwise. This procedure must run in O(1) time.

    (srfi 196) procedure (range=? (equal procedure?) (range1 range?) (range2 range?) ...) ⟹ boolean?

    (equal el1 el2) ⟹ boolean?

    Returns #t if all the ranges are of the same length and if their corresponding values are the same in the sense of equal, and #f otherwise. The runtime of this procedure is O(s) + O(k), where s is the sum of the total accessing times of the ranges and k is the number of ranges.

    (srfi 196) procedure (range-length (range range?)) ⟹ integer?

    Returns the length (number of elements) of range. This procedure must run in O(1) time.

    (srfi 196) procedure (range-ref (range range?) (n integer?)) ⟹ *

    Returns the nth element of range. It is an error if n is less than 0 or greater than or equal to the length of range. The running time of this procedure must be asymptotically equal to the average accessing time of range.

    (srfi 196) procedure (range-first (range range?)) ⟹ *

    Equivalent (in running time as well) to (range-ref range 0).

    (srfi 196) procedure (range-last (range range?)) ⟹ *

    Equivalent (in running time as well) to (range-ref range (- (range-length range) 1)).

    (srfi 196) procedure (range-split-at (range range?) (index integer?)) ⟹ (values range? range?)

    Returns two values: (range-take range index) and (range-drop range index). It is an error if index is not an exact integer between 0 and the length of range, both inclusive. This procedure must run in O(1) time.

    (srfi 196) procedure (subrange (range range?) (start integer?) (end integer?)) ⟹ range?

    Returns a range which contains the elements of range from index start, inclusive, through index end, exclusive. This procedure must run in O(1) time. The average accessing time of the resulting range is asymptotically bounded by the average accessing time of range.

    (srfi 196) procedure (range-segment (range range?) (length integer?)) ⟹ list?

    return ⟹ (list (range range?))

    Returns a list of ranges representing the consecutive subranges of length length. The last range is allowed to be shorter than length. The procedure must run in O(k) time, where k is the number of ranges returned. The average accessing time of the ranges is asymptotically bounded by the average accessing time of range.

    (srfi 196) procedure (range-take (range range?) (count integer?)) ⟹ range?

    (srfi 196) procedure (range-take-right (range range?) (count integer?)) ⟹ range?

    Returns a range which contains the first/last count elements of range. The average accessing time of the resulting ranges is asymptotically bounded by the average accessing time of range.

    (srfi 196) procedure (range-drop (range range?) (count integer?)) ⟹ range?

    (srfi 196) procedure (range-drop-right (range range?) (count integer?)) ⟹ range?

    Returns a range which contains all except the first/last count elements of range. These procedures must run in O(1) time. The average accessing time of the resulting ranges is asymptotically bounded by the average accessing time respectively of range.

    (srfi 196) procedure (range-count (pred predicate) (range1 range?) (range2 range?) ...) ⟹ integer?

    Applies pred element-wise to the elements of ranges and returns the number of applications which returned true values. If more than one range is given and not all ranges have the same length, range-count terminates when the shortest range is exhausted. The runtime of this procedure is O(s) where s is the sum of the total accessing times of the ranges.

    (srfi 196) procedure (range-any (pred predicate) (range1 range?) (range2 range?) ...) ⟹ *

    Invokes pred element-wise to the elements of the ranges until one call returns a true value, and then returns that value. Otherwise, #f is returned. If more than one range is given and not all ranges have the same length, range-any terminates when the shortest range is exhausted. The runtime of this procedure is O(s) where s is the sum of the total accessing times of the ranges.

    (srfi 196) procedure (range-every (pred predicate) (range1 range?) (range2 range?) ...) ⟹ *

    Applies pred element-wise to the elements of the ranges and returns true if pred returns true on every application. Specifically it returns the last value returned by pred, or #t if pred was never invoked. Otherwise, #f is returned. If more than one range is given and not all ranges have the same length, range-every terminates when the shortest range is exhausted. The runtime of this procedure is O(s) + O(k), where s is the sum of the total accessing times of the ranges and k is the number of ranges.

    (srfi 196) procedure (range-map (proc procedure?) (range1 range?) (range2 range?) ...) ⟹ range?

    (proc el1 el2 ...) ⟹ *

    (srfi 196) procedure (range-map->list (proc procedure?) (range1 range?) (range2 range?) ...) ⟹ list?

    (proc el1 el2 ...) ⟹ *

    (srfi 196) procedure (range-map->vector (proc procedure?) (range1 range?) (range2 range?) ...) ⟹ vector?

    (proc el1 el2 ...) ⟹ *

    Applies proc element-wise to the elements of the ranges and returns a range/list/vector of the results, in order. If more than one range is given and not all ranges have the same length, these procedures terminate when the shortest range is exhausted. The dynamic order in which proc is actually applied to the elements is unspecified. The runtime of these procedures is O(s) where s is the sum of the total accessing times of the ranges. The range-map procedure eagerly computes its result and returns an expanded range. Its average accessing time is O(1).

    (srfi 196) procedure (range-for-each (proc procedure?) (range1 range?) (range2 range?) ...) ⟹ undefined

    (proc el1 el2 ...) ⟹ undefined

    Applies proc element-wise to the elements of the ranges in order. Returns an unspecified result. If more than one range is given and not all ranges have the same length, range-for-each terminates when the shortest range is exhausted. The runtime of this procedure is O(s) where s is the sum of the total accessing times of the ranges.

    (srfi 196) procedure (range-filter-map (proc procedure?) (range1 range?) (range2 range?) ...) ⟹ range?

    (proc el1 el2 ...) ⟹ *

    (srfi 196) procedure (range-filter-map->list (proc procedure?) (range1 range?) (range2 range?) ...) ⟹ list?

    (proc el1 el2 ...) ⟹ *

    Applies proc element-wise to the elements of the ranges and returns a range/list of the true values returned by proc. If more than one range is given and not all ranges have the same length, these procedures terminate when the shortest range is exhausted. The dynamic order in which proc is actually applied to the elements is unspecified. The range-filter-map procedure eagerly computes its result and returns an expanded range. The runtime of these procedures is O(n) where n is the sum of the total accessing times of the ranges.

    (srfi 196) procedure (range-filter (proc procedure?) (range range?)) ⟹ range?

    (proc el) ⟹ boolean?

    (srfi 196) procedure (range-filter->list (proc procedure?) (range range?)) ⟹ list?

    (proc el) ⟹ boolean?

    (srfi 196) procedure (range-remove (proc procedure?) (range range?)) ⟹ range?

    (proc el) ⟹ boolean?

    (srfi 196) procedure (range-remove->list (proc procedure?) (range range?)) ⟹ list?

    (proc el) ⟹ boolean?

    Returns a range/list containing the elements of range that satisfy / do not satisfy pred. The runtime of these procedures is O(s) where s is the sum of the total accessing times of the ranges.

    The range-filter and range-remove procedures eagerly compute their results and return expanded ranges. Their average accessing time is O(1).

    (srfi 196) procedure (range-fold (kons procedure?) nil (range1 range?) (range2 range?) ...) ⟹ *

    (kons state el1 el2 ...) ⟹ *

    (srfi 196) procedure (range-fold-right (kons procedure?) nil (range1 range?) (range2 range?) ...) ⟹ *

    (kons state el1 el2 ...) ⟹ *

    Folds kons over the elements of ranges in order / reverse order. kons is applied as (kons state (range-ref range1 i) (range-ref range2 i) …) where state is the result of the previous invocation and i is the current index. For the first invocation, nil is used as the first argument. Returns the result of the last invocation, or nil if there was no invocation. If more than one range is given and not all ranges have the same length, these procedures terminate when the shortest range is exhausted. The runtime of these procedures must be O(s) where s is the sum of the total accessing times of the ranges.

    (srfi 196) procedure (range-index (pred procedure?) (range1 range?) (range2 range?) ...) ⟹ #f | integer?

    (pred el1 el2 ...) ⟹ boolean?

    (srfi 196) procedure (range-index-right (pred procedure?) (range1 range?) (range2 range?) ...) ⟹ #f | integer?

    (pred el1 el2 ...) ⟹ boolean?

    Applies pred element-wise to the elements of ranges and returns the index of the first/last element at which pred returns true. Otherwise, returns #f. If more than one range is given and not all ranges have the same length, range-index terminates when the shortest range is exhausted. It is an error if the ranges passed to range-index-right do not all have the same lengths. The runtime of these procedures must be O(s) where s is the sum of the total accessing times of the ranges.

    (srfi 196) procedure (range-take-while (pred predicate) (range range?)) ⟹ range?

    (srfi 196) procedure (range-take-while-right (pred predicate) (range range?)) ⟹ range?

    Returns a range containing the leading/trailing elements of range that satisfy pred up to the first/last one that does not. The runtime of these procedures is asymptotically bounded by the total accessing time of the range. The average accessing time of the resulting range is O(1).

    (srfi 196) procedure (range-drop-while (pred predicate) (range range?)) ⟹ range?

    (srfi 196) procedure (range-drop-while-right (pred predicate) (range range?)) ⟹ range?

    Returns a range that omits leading/trailing elements of range that satisfy pred until the first/last one that does not. The runtime of these procedures is asymptotically bounded by the total accessing time of the range. The average accessing time of the resulting range is O(1).

    (srfi 196) procedure (range->list (range range?)) ⟹ list?

    (srfi 196) procedure (range->vector (range range?)) ⟹ vector?

    (srfi 196) procedure (range->string (range range?)) ⟹ string?

    Returns a list/vector/string containing the elements of range in order. It is an error to modify the result of range->vector or of range->string. In the case of range->string, it is an error if any element of range is not a character. The running times of these procedures is O(s) where s is the total accessing time for range.

    (srfi 196) procedure (vector->range (vector vector?)) ⟹ range?

    Returns an expanded range whose elements are those of vector. Note that, unlike vector-range, it is not an error to mutate vector; future mutations of vector are guaranteed not to affect the range returned by vector->range. This procedure must run in O(n) where n is the length of vector. Otherwise, this procedure is equivalent to vector-range.

    (srfi 196) procedure (range->generator (range range?)) ⟹ procedure?

    (return) ⟹ *

    Returns a SRFI 158 generator that generates the elements of range in order. This procedure must run in O(1) time, and the running time of each call of the generator is asymptotically bounded by the average accessing time of range.

    library (srfi 197) Pipeline Operators

    Many functional languages provide pipeline operators, like Clojure's -> or OCaml's |>. Pipelines are a simple, terse, and readable way to write deeply-nested expressions. This SRFI defines a family of chain and nest pipeline operators, which can rewrite nested expressions like (a b (c d (e f g))) as a sequence of operations: (chain g (e f _) (c d _) (a b _)).

    (srfi 197) syntax (chain initial-value step ...)

    (srfi 197) syntax (chain initial-value placeholder step ...)

    (srfi 197) syntax (chain initial-value placeholder ellipsis step ...)

    step ⟹ (datum ...)

    Syntax: <initial-value> is an expression.

    <placeholder> and <ellipsis> are literal symbols; these are the placeholder symbol and ellipsis symbol. If <placeholder> or <ellipsis> are not present, they default to _ and ..., respectively.

    The syntax of <step> is (<datum> ...), where each <datum> is either the placeholder symbol, the ellipsis symbol, or an expression. A <step> must contain at least one <datum>. The ellipsis symbol is only allowed at the end of a <step>, and it must immediately follow a placeholder symbol.

    Semantics: chain evaluates each <step> in order from left to right, passing the result of each step to the next.

    Each <step> is evaluated as an application, and the return value(s) of that application are passed to the next step as its pipeline values. <initial-value> is the pipeline value of the first step. The return value(s) of chain are the return value(s) of the last step.

    The placeholder symbols in each <step> are replaced with that step's pipeline values, in the order they appear. It is an error if the number of placeholders for a step does not equal the number of pipeline values for that step, unless the step contains no placeholders, in which case it will ignore its pipeline values.

    (srfi 197) syntax (chain-and initial-value step ...)

    (srfi 197) syntax (chain-and initial-value placeholder step ...)

    step ⟹ (datum ...)

    Syntax: <initial-value> is an expression. <placeholder> is a literal symbol; this is the placeholder symbol. If <placeholder> is not present, the placeholder symbol is _. The syntax of <step> is (<datum> ... [<_> <datum> ...]), where <_> is the placeholder symbol.

    Semantics: A variant of chain that short-circuits and returns #f if any step returns #f. chain-and is to chain as SRFI 2 and-let* is to let*.

    Each <step> is evaluated as an application. If the step evaluates to #f, the remaining steps are not evaluated, and chain-and returns #f. Otherwise, the return value of the step is passed to the next step as its pipeline value. <initial-value> is the pipeline value of the first step. If no step evaluates to #f, the return value of chain-and is the return value of the last step.

    The <_> placeholder in each <step> is replaced with that step's pipeline value. If a <step> does not contain <_>, it will ignore its pipeline value, but chain-and will still check whether that pipeline value is #f.

    Because chain-and checks the return value of each step, it does not support steps with multiple return values. It is an error if a step returns more than one value.

    (srfi 197) syntax (chain-when initial-value (guard step) ...)

    (srfi 197) syntax (chain-when initial-value placeholder (guard step) ...)

    (srfi 197) syntax (chain-when initial-value (step) ...)

    (srfi 197) syntax (chain-when initial-value placeholder (step) ...)

    step ⟹ (datum ...)

    Syntax: <initial-value> and <guard> are expressions. <placeholder> is a literal symbol; this is the placeholder symbol. If <placeholder> is not present, the placeholder symbol is _. The syntax of <step> is (<datum> ... [<_> <datum> ...]), where <_> is the placeholder symbol.

    Semantics: A variant of chain in which each step has a guard expression and will be skipped if the guard expression evaluates to #f.

    Each <step> is evaluated as an application. The return value of the step is passed to the next step as its pipeline value. <initial-value> is the pipeline value of the first step.

    The <_> placeholder in each <step> is replaced with that step's pipeline value. If a <step> does not contain <_>, it will ignore its pipeline value

    If a step's <guard> is present and evaluates to #f, that step will be skipped, and its pipeline value will be reused as the pipeline value of the next step. The return value of chain-when is the return value of the last non-skipped step, or <initial-value> if all steps are skipped.

    Because chain-when may skip steps, it does not support steps with multiple return values. It is an error if a step returns more than one value.

    (srfi 197) syntax (chain-lambda initial-value step ...)⟹ return

    (srfi 197) syntax (chain-lambda initial-value placeholder step ...)⟹ return

    (srfi 197) syntax (chain-lambda initial-value placeholder ellipsis step ...)⟹ return

    step ⟹ (datum ...)

    Syntax: <placeholder> and <ellipsis> are literal symbols; these are the placeholder symbol and ellipsis symbol. If <placeholder> or <ellipsis> are not present, they default to _ and ..., respectively.

    The syntax of <step> is (<datum> ...), where each <datum> is either the placeholder symbol, the ellipsis symbol, or an expression. A <step> must contain at least one <datum>. The ellipsis symbol is only allowed at the end of a <step>, and it must immediately follow a placeholder symbol.

    Semantics: Creates a procedure from a sequence of chain steps. When called, a chain-lambda procedure evaluates each <step> in order from left to right, passing the result of each step to the next.

    Each <step> is evaluated as an application, and the return value(s) of that application are passed to the next step as its pipeline values. The procedure's arguments are the pipeline values of the first step. The return value(s) of the procedure are the return value(s) of the last step.

    The placeholder symbols in each <step> are replaced with that step's pipeline values, in the order they appear. It is an error if the number of placeholders for a step does not equal the number of pipeline values for that step, unless the step contains no placeholders, in which case it will ignore its pipeline values.

    If a <step> ends with a placeholder symbol followed by an ellipsis symbol, that placeholder sequence is replaced with all remaining pipeline values that do not have a matching placeholder.

    The number of placeholders in the first <step> determines the arity of the procedure. If the first step ends with an ellipsis symbol, the procedure is variadic.

    (srfi 197) syntax (nest step ... initial-value)

    (srfi 197) syntax (nest placeholder step ... initial-value)

    step ⟹ (datum ...)

    Syntax: <placeholder> is a literal symbol; this is the placeholder symbol. If <placeholder> is not present, the placeholder symbol is _. The syntax of <step> is (<datum> ... <_> <datum> ...), where <_> is the placeholder symbol. <initial-value> is expression.

    Semantics: nest is similar to chain, but sequences its steps in the opposite order. Unlike chain, nest literally nests expressions; as a result, it does not provide the same strict evaluation order guarantees as chain.

    A nest expression is evaluated by lexically replacing the <_> in the last <step> with <initial-value>, then replacing the <_> in the next-to-last <step> with that replacement, and so on until the <_> in the first <step> has been replaced. It is an error if the resulting final replacement is not an expression, which is then evaluated and its values are returned.

    Because it produces an actual nested form, nest can build expressions that chain cannot. For example, nest can build a quoted data structure:

    nest can also safely include special forms like if, let, lambda, or parameterize in a pipeline.

    (srfi 197) syntax (nest-reverse initial-value step ...)

    (srfi 197) syntax (nest-reverse initial-value placeholder step ...)

    step ⟹ (datum ...)

    Syntax: <initial-value> is an expression. <placeholder> is a literal symbol; this is the placeholder symbol. If <placeholder> is not present, the placeholder symbol is _. The syntax of <step> is (<datum> ... <_> <datum> ...), where <_> is the placeholder symbol.

    Semantics: nest-reverse is variant of nest that nests in reverse order, which is the same order as chain.

    A nest-reverse expression is evaluated by lexically replacing the <_> in the first <step> with <initial-value>, then replacing the <_> in the second <step> with that replacement, and so on until the <_> in the last <step> has been replaced. It is an error if the resulting final replacement is not an expression, which is then evaluated and its values are returned.

    library (srfi 219) Define higher-order lambda

    This SRFI codifies the following shorthand syntax, which some Scheme implementations have had for a long time.

    (define ((outer-name outer-args ...) inner-args ...)
      inner-body ...)

    (srfi 219) syntax (define variable expression)

    (srfi 219) syntax (define (variable parameter1 ...) body)

    (srfi 219) syntax (define (variable parameter1 ... . parameter) body)

    (srfi 219) syntax (define ((variable inner-param1 ...) outter-param1 ...) body)

    (srfi 219) syntax (define ((variable inner-param1 ...) outter-param1 ... . outter-rest) body)

    (srfi 219) syntax (define ((variable inner-param1 ... . inner-rest) outter-param1 ...) body)

    (srfi 219) syntax (define ((variable inner-param1 ... . inner-rest) outter-param1 ... . outter-rest) body)

    The shorthand version of define behaves as follows:

    (define symbol expr)

    defines symbol with the value expr

    (define (symbol . args) expr ...)

    defines symbol with the value (lambda args expr ...)

    (define ((symbol . args1) . args) expr ...)

    defines symbol with the value (lambda args1 (lambda args expr ...))

    (define (((symbol . args2) . args1) . args) expr ...)

    defines symbol with the value (lambda args2 (lambda args1 (lambda args expr ...)))

    and so on.

    library (srfi 235) Combinators

    This SRFI contains various procedures that accept and return procedures, as well as a few others, drawn from an earlier version of Chicken. Common Lisp has a few of them too, and more come from the Standard Prelude from Programming Praxis. Using these procedures helps to keep code terse and reduce the need for ad hoc lambdas.

    (srfi 235) procedure (constantly obj ...) ⟹ procedure?

    (return arg ...) ⟹ (values * ...)

    Returns the objs as its values, ignoring args.

    (srfi 235) procedure (complement (proc predicate)) ⟹ predicate

    Returns #t when (proc obj) returns #f, and #f otherwise.

    (srfi 235) procedure (flip (proc procedure?)) ⟹ procedure?

    (proc objs ...) ⟹ *

    (return obj ...) ⟹ *

    Returns what (apply proc (reverse objs)) returns.

    (srfi 235) procedure (swap (proc procedure?)) ⟹ procedure?

    (proc x y rest ...) ⟹ *

    (return y x rest ...) ⟹ *

    Returns (apply proc obj₂ obj₁ objs).

    (srfi 235) procedure (on-left (proc procedure?)) ⟹ procedure?

    (proc x) ⟹ *

    (return obj1 obj2) ⟹ *

    Returns (proc obj₁).

    (srfi 235) procedure (on-right (proc procedure?)) ⟹ procedure?

    (proc x) ⟹ *

    (return obj1 obj2) ⟹ *

    Returns (proc obj₂).

    (srfi 235) procedure (conjoin (proc predicate) ...) ⟹ predicate

    The predicates are applied in turn to the args as follows: If a call to a predicate returns false, no more predicates are applied and #f is returned. If all predicates return true, then the last value is returned. If there are no predicates, #t is returned.

    (srfi 235) procedure (disjoin (proc predicate) ...) ⟹ predicate

    The predicates are applied in turn to the args as follows: If a call to a predicate returns true, no more predicates are applied and its value is returned. If all predicates return false, then the last value is returned. If there are no predicates, #f is returned.

    (srfi 235) procedure (each-of (proc procedure?) ...) ⟹ procedure?

    (proc arg ...) ⟹ *

    (return arg ...) ⟹ undefined

    Applies each of the procs in turn to args, discarding the results and returning an unspecified value.

    (srfi 235) procedure (all-of (proc procedure?)) ⟹ procedure?

    (proc arg) ⟹ *

    (return (lst list?)) ⟹ boolean?

    Applies predicate to each element of list in turn, and immediately returns #f if predicate is not satisfied by that element. If every element satisfies predicate, returns the result of the last call to predicate. If list is empty, returns #t.

    (srfi 235) procedure (any-of (proc procedure?)) ⟹ procedure?

    (proc arg) ⟹ *

    (return (lst list?)) ⟹ boolean?

    Applies predicate to each element of list in turn, and if predicate is satisfied by that element, immediately returns the result of calling predicate. If no element satisfies predicate returns #f. If list is empty, returns #f.

    (srfi 235) procedure (on (reducer procedure?) (mapper procedure?)) ⟹ procedure?

    (reducer a b) ⟹ *

    (mapper x) ⟹ *

    (return arg ...) ⟹ *

    Applies mapper to each obj in any order and then applies reducer to all of the results in left to right order.

    (srfi 235) procedure (left-section (proc procedure?) arg ...) ⟹ procedure?

    (proc obj ...) ⟹ *

    (return obj ...) ⟹ *

    Applies proc to args concatenated with objs.

    (srfi 235) procedure (right-section (proc procedure?) arg ...) ⟹ procedure?

    (proc obj ...) ⟹ *

    (return obj ...) ⟹ *

    Applies proc to objs concatenated with the value of (reverse args).

    (srfi 235) procedure (apply-chain (proc procedure?) ...) ⟹ procedure?

    (proc obj ...) ⟹ *

    (return obj ...) ⟹ *

    Applies the last proc to args returning zero or more values, then applies the previous proc to the values, returning more values, until the first proc has been invoked; its values are returned. For example, (apply-chain car cdr) returns a procedure that behaves like cadr:

    (srfi 235) procedure (arguments-drop (proc procedure?) (n integer?)) ⟹ procedure?

    (proc obj ...) ⟹ *

    (return obj ...) ⟹ *

    (srfi 235) procedure (arguments-drop-right (proc procedure?) (n integer?)) ⟹ procedure?

    (proc obj ...) ⟹ *

    (return obj ...) ⟹ *

    (srfi 235) procedure (arguments-take (proc procedure?) (n integer?)) ⟹ procedure?

    (proc obj ...) ⟹ *

    (return obj ...) ⟹ *

    (srfi 235) procedure (arguments-take-right (proc procedure?) (n integer?)) ⟹ procedure?

    (proc obj ...) ⟹ *

    (return obj ...) ⟹ *

    Apply proc to the args after taking/dropping n arguments from args.

    (srfi 235) procedure (group-by (key-proc procedure?)) ⟹ procedure?

    (srfi 235) procedure (group-by (key-proc procedure?) (= procedure?)) ⟹ procedure?

    (key-proc obj) ⟹ *

    (= a b) ⟹ boolean?

    (return (lst list?)) ⟹ list?

    Takes the elements of list and applies key-proc to each of them to get their keys. Elements whose keys are the same (in the sense of =, which defaults to equal?) are grouped into newly allocated lists, and a list of these lists is returned. Within each list, the elements appear in the same order as they do in list; in addition, the first elements of each list also appear in the same order as they do in list. If list is the empty list, it is returned.

    (srfi 235) procedure (begin-procedure (thunk procedure?) ...) ⟹ *

    (thunk) ⟹ *

    Invokes thunks in order, and returns what the last thunk returns, or an unspecified value if there are no thunks.

    (srfi 235) procedure (if-procedure value (then-thunk procedure?) (else-thunk procedure?)) ⟹ *

    (then-thunk) ⟹ *

    (else-thunk) ⟹ *

    If value is true, invokes then-thunk and returns what it returns. Otherwise, invokes else-thunk and returns what it returns.

    (srfi 235) procedure (when-procedure value (thunk procedure?) ...) ⟹ undefined

    (thunk) ⟹ *

    (srfi 235) procedure (unless-procedure value (thunk procedure?) ...) ⟹ undefined

    (thunk) ⟹ *

    If value is false/true, immediately returns. Otherwise, invokes each thunk in turn and then returns. In all cases an unspecified value is returned.

    (srfi 235) procedure (value-procedure value (then-thunk procedure?) (else-thunk procedure?)) ⟹ *

    (then-thunk value) ⟹ *

    (else-thunk) ⟹ *

    If value is true, invokes then-thunk and returns what it returns. Otherwise, invokes else-thunk and returns what it returns.

    (srfi 235) procedure (case-procedure value (thunk-alist list?)) ⟹ undefined

    (srfi 235) procedure (case-procedure value (thunk-alist list?) (else-thunk procedure?)) ⟹ undefined

    thunk-alist ⟹ (alist * : procedure?)

    (else-thunk) ⟹ *

    Searches thunk-alist for value (as if by assv). If there is a matching entry in thunk-alist, its cdr is invoked as a thunk, and case-procedure returns what the thunk returns. If there is no such entry in thunk-alist, invokes else-thunk (if present) and returns what it returns. If else-thunk is not present, the result is undefined.

    (srfi 235) procedure (and-procedure (thunk procedure?) ...) ⟹ *

    (thunk) ⟹ *

    The thunks are invoked from left to right, and if any thunk returns false, then #f is returned. Any remaining thunks are not invoked. If all the thunks return true values, the values of the last thunk are returned. If there are no thunks, then #t is returned.

    (srfi 235) procedure (eager-and-procedure (thunk procedure?) ...) ⟹ *

    (thunk) ⟹ *

    All the thunks are invoked from left to right. If any thunk returns false, then #f is returned. If all the thunks return true values, the value of the last thunk is returned. If there are no thunks, then #t is returned.

    (srfi 235) procedure (or-procedure (thunk procedure?) ...) ⟹ *

    (thunk) ⟹ *

    The thunks are invoked from left to right, and the first true value is returned. Any remaining thunks are not invoked. If all thunks return #f or if there are no thunks, then #f is returned.

    (srfi 235) procedure (eager-or-procedure (thunk procedure?) ...) ⟹ *

    (thunk) ⟹ *

    All the thunks are invoked from left to right, and then the first true value is returned. If all thunks return #f or if there are no thunks, then #f is returned.

    (srfi 235) procedure (funcall-procedure (thunk procedure?)) ⟹ *

    (thunk) ⟹ *

    Invokes thunk once, and returns what it returns.

    (srfi 235) procedure (loop-procedure (thunk procedure?)) ⟹ *

    (thunk) ⟹ *

    Invokes thunk repeatedly. Does not return unless via call/cc.

    (srfi 235) procedure (while-procedure (thunk procedure?)) ⟹ *

    (thunk) ⟹ *

    Invokes thunk repeatedly until it returns false. Returns an unspecified value.

    (srfi 235) procedure (until-procedure (thunk procedure?)) ⟹ *

    (thunk) ⟹ *

    Invokes thunk repeatedly until it returns true. Returns an unspecified value.

    (srfi 235) procedure (always arg ...) ⟹ boolean?

    Ignores its arguments and always returns #t.

    (srfi 235) procedure (never arg ...) ⟹ #f

    Ignores its arguments and always returns #f.

    (srfi 235) procedure (boolean obj) ⟹ boolean?

    If obj is true, returns #t; otherwise returns #f.

    library (srfi 236) Evaluating expressions in an unspecified order

    This SRFI defines the independently syntax, which can be used to combine side effects into one expression without specifying their relative order.

    (srfi 236) syntax (independently expression ...)

    Evaluates the ⟨expressions⟩s in an unspecified order and discards their return values. The result of the independently expression is unspecified.

    Note: Although the order of evaluation is otherwise unspecified, the effect of any concurrent evaluation of the ⟨expressions⟩ is constrained to be consistent with some sequential order of evaluation. The order of evaluation may be chosen differently for each evaluation of the independently form.

    library (srfi 239) Destructuring Lists

    This SRFI provides the list-case, the syntactic fundamental list destructor.

    (srfi 239) syntax (list-case expression list-case-clause ...)⟹ return

    list-case-clause ⟹ ((variable . variable) body) | (() body) | (variable body)

    A list-case expression is evaluated as follows: The ⟨expression⟩ is evaluated. The further evaluation then depends on the type of the result:

    If the result is a pair and a clause of the form [(⟨variable1⟩ . ⟨variable2⟩) ⟨body⟩] is present, the ⟨variables⟩ are bound to locations holding the car and the cdr of the pair, the ⟨body⟩ is evaluated and its results returned.

    If the result is () and clause of the form [() ⟨body⟩] is present, the ⟨body⟩ is evaluated and its results returned.

    If the result is neither a pair nor () and a clause of the form [⟨variable⟩ ⟨body⟩] is present, the ⟨variable⟩ is bound to a location holding the result, the ⟨body⟩ is evaluated and its results returned.

    If no corresponding clause is present, an exception of type &assertion-violation is raised.

    The region of the bindings consists of the corresponding ⟨body⟩. If _ appears in place of a ⟨variable⟩, the corresponding location is not bound to any variable.

    If the list-case expression is in tail context, the ⟨bodies⟩ are in tail context as well.

    library (srfi 253) Data (Type-)Checking

    Data validation and type checking (supposedly) make for more correct code. And faster code too, sometimes. And, in rare cases, code that's easier to follow than un-checked code. Unfortunately, Scheme does not have many (type-)checking primitives out of the box. This SRFI provides some, with the aim of allowing more performant and correct code with minimum effort on the user side. Both (manual) argument checking/validation (check-arg) and return value(s) (values-checked) checking/coercion are provided. Syntax sugar like define-checked and define-record-type-checked is added on top.

    (srfi 253) syntax (check-arg predicate arg caller)

    (srfi 253) syntax (check-arg predicate arg)

    (predicate obj) ⟹ *

    Guarantees that the arg (evaluated) conforms to the predicate (evaluated). Implementations can enforce the predicate check in all the code that follows, but are not required to. It is an error if predicate returns #f when called on arg. Otherwise, return value is unspecified. Implementations may use optional caller (evaluated) argument as the error who/origin if/when signaling a checking error.

    (srfi 253) syntax (values-checked (predicate ...) value ...)⟹ return

    (predicate obj) ⟹ *

    Guarantees that the values (evaluated) abide by the given predicates (the number of values and predicates should match) and returns them as multiple values. It is an error if any of the predicates returns false. Implementations may choose to coerce the values when the types are compatible (e.g. integer -> inexact).

    (srfi 253) syntax (check-case key (predicate expression ...) ...)

    (srfi 253) syntax (check-case key (predicate expression ...) ... (else expression ...))

    (predicate obj) ⟹ *

    check-case checks whether the value satisfies one of the predicates. If any of the predicates is satisfied, it evaluates the body corresponding to the first one that is satisfied. If none of the predicates is satisfied and there’s an else clause, it evaluates to the body of that clause; and if there’s it is an error if there’s no else clause and no other clause is satisfied.

    (srfi 253) syntax (lambda-checked (arg ...) body ...)⟹ return

    arg ⟹ name | (name predicate)

    (predicate obj) ⟹ *

    A regular lambda, but with any argument (except the rest argument) optionally having the form (name predicate) (as compared to default single-symbol form). Arguments of this extended form are guaranteed to satisfy the respective (evaluated) predicate. At least on procedure application time. This guarantee might be extended for all the procedure body, including for any modification and shadowing, at implementors' will. It is an error if either of the arguments does not satisfy the predicate.

    (srfi 253) syntax (case-lambda-checked clause ...)⟹ return

    clause ⟹ ((arg ...) body ...) | ((arg arg ... . args) body ...) | (args body ...)

    arg ⟹ name | (name predicate)

    (predicate obj) ⟹ *

    Same as case-lambda, but with any argument taking a form of (name predicate) to be checked. See lambda-checked for other details.

    (srfi 253) syntax (define-checked (proc-name arg ...) body ...)⟹ return

    (srfi 253) syntax (define-checked name predicate value)

    arg ⟹ name | (name predicate)

    (predicate obj) ⟹ *

    Defines a procedure or variable satisfying the given predicates. For procedures, effectively equal to define+lambda-checked. For variables, checks the value (and, if implementation supports that, all the subsequent modifications) for the predicate match.

    (srfi 253) syntax (define-record-type-checked type-name (constructor arg-name ...) predicate-name field ...)

    field ⟹ (name predicate accessor) | (name predicate accessor modifier)

    (predicate obj) ⟹ *

    Defines a record type with checked constructor and field accessors/modifiers. type-name, constructor, and predicate are the same as R7RS define-record-type's (note especially the constructor—checks are not allowed in it, only arg-name symbols!) Fields are either of the form (field-name predicate accessor-name) or (field-name predicate accessor-name modifier-name). These ensure that accessor and modifier return checked data and check new data respectively. It is an error if any of the checks are not successful.

    library (srfi 273) Extensions to Data (Type-)Checking

    The original SRFI 253 established a basis for type-checked (or otherwise checked) data handling. But it lacked some quality-of-life features. This SRFI extends SRFI 253 to match existing implementation practice and common sense. Provided extensions are: check aliasing with define-check; pre- and post-declaration of type / check with declare-checked; return value checks in lambda-checked, case-lambda-checked, and define-checked; and some optimizable, supported, and explicitly unsupported patterns suggested to implementors.

    (srfi 273) syntax (define-check name predicate)

    (predicate obj) ⟹ *

    Defines a new name-d checking predicate based on the provided predicate (possibly evaluated)

    (srfi 273) syntax (define-values-checked (name ...) (predicate ...) form)

    (predicate obj) ⟹ *

    Same as define-values, but makes sure the values returned by form abide by checks. Further symbol value modifications may be checked too.

    (srfi 273) syntax (declare-checked (proc-name arg ...))

    (srfi 273) syntax (declare-checked (proc-name arg ...) => (predicate ...))

    (srfi 273) syntax (declare-checked name predicate)

    arg ⟹ name | (name predicate)

    (predicate obj) ⟹ *

    This syntax declares checks for a given value (in the first form) before / after the value itself was bound to a name. Or argument / return checks for a procedure defined separately. In the case of the procedure check declaration, argument checks are specified as either (arg pred?) (list of 2 elements) or arg (a single symbol,) like in define-checked. Return value type checks, introduced by => symbol, are syntactically optional. They specify the checks for procedure return value(s) when provided.

    library (srfi 277) Cyclic ports

    Cyclic ports are like infinite string and bytevector input ports: they produce the elements of a given sequence repeatedly, forever. While their intended use is as reusable seeds for SRFI 271 random ports, they are also useful whenever a repeating sequence of one or more bytes or characters is needed.

    (srfi 277) procedure (open-cyclic-input-string (string string?)) ⟹ input-port?

    Returns a new textual cyclic input port that delivers characters from string. An error is signaled if string is empty. If string is modified after open-cyclic-input-string has been called, the behavior is undefined.

    (srfi 277) procedure (open-cyclic-input-bytevector (string bytevector?)) ⟹ input-port?

    Returns a new binary cyclic port that delivers bytes from bytevector. An error is signaled if bytevector is empty. If bytevector is modified after open-cyclic-input-bytevector has been called, the behavior is undefined.