Go to the previous, next section.

Standards Support

With-File

(require 'with-file)

Function: with-input-from-file file thunk

Function: with-output-to-file file thunk

Description found in R4RS.

Transcripts

(require 'transcript)

Function: transcript-on filename

Function: transcript-off filename

Redefines read-char, read, write-char, write, display, and newline.

Rev2 Procedures

(require 'rev2-procedures)

The procedures below were specified in the Revised^2 Report on Scheme. N.B.: The symbols 1+ and -1+ are not R4RS syntax. Scheme->C, for instance, barfs on this module.

Procedure: substring-move-left! string1 start1 end1 string2 start2

Procedure: substring-move-right! string1 start1 end1 string2 start2

string1 and string2 must be a strings, and start1, start2 and end1 must be exact integers satisfying

0 <= start1 <= end1 <= (string-length string1)
0 <= start2 <= end1 - start1 + start2 <= (string-length string2)

substring-move-left! and substring-move-right! store characters of string1 beginning with index start1 (inclusive) and ending with index end1 (exclusive) into string2 beginning with index start2 (inclusive).

substring-move-left! stores characters in time order of increasing indices. substring-move-right! stores characters in time order of increasing indeces.

Procedure: substring-fill! string start end char

Fills the elements start--end of string with the character char.

Function: string-null? str

== (= 0 (string-length str))

Procedure: append! . pairs

Destructively appends its arguments. Equivalent to nconc.

Function: 1+ n

Adds 1 to n.

Function: -1+ n

Subtracts 1 from n.

Function: <?

Function: <=?

Function: =?

Function: >?

Function: >=?

These are equivalent to the procedures of the same name but without the trailing `?'.

Rev3 Procedures

(require 'rev3-procedures)

The procedures below were specified in the Revised^3 Report on Scheme.

Function: last-pair l

Returns the last pair in the list l. Example:

(last-pair (cons 1 2))
   => (1 . 2)
(last-pair '(1 2))
   => (2)
    == (cons 2 '())

Variable: t

Derfined as #t.

Variable: nil

Defined as #f.

Rev4 Optional Procedures

(require 'rev4-optional-procedures)

See R4RS for the specification of these optional procedures.

Function: list-tail l p

Function: string->list s

Function: list->string l

Function: string-copy

Procedure: string-fill! s obj

Function: list->vector l

Function: vector->list s

Procedure: vector-fill! s obj

Multi-argument / and -

(require 'mutliarg/and-)

See R4RS for the specification of these optional forms. The two-arg:* forms are only defined if the implementation does not support the many-argument forms.

Function: two-arg:/ n1 n2

The original two-argument version of /.

Function: / divident . divisors

Function: two-arg:- n1 n2

The original two-argument version of -.

Function: - minuend . subtrahends

Multi-argument Apply

See R4RS for the specification of this optional form. (require 'multiarg-apply)

Function: two-arg:apply proc l

The implementation's native apply. Only defined for implementations which don't support the many-argument version.

Function: apply proc . args

Rationalize

(require 'rationalize)

The procedure rationalize is interesting because most programming languages do not provide anything analogous to it. For simplicity, we present an algorithm which computes the correct result for exact arguments (provided the implementation supports exact rational numbers of unlimited precision), and produces a reasonable answer for inexact arguments when inexact arithmetic is implemented using floating-point. We thank Alan Bawden for contributing this algorithm.

Function: rationalize x e

Promises

(require 'promise)

Function: make-promise proc

Change occurrences of (delay expression) to (make-promise (lambda () expression)) and (define force promise:force) to implement promises if your implementation doesn't support them (see R4RS).

Dynamic-Wind

(require 'dynamic-wind)

This facility is a generalization of Common LISP unwind-protect, designed to take into account the fact that continuations produced by call-with-current-continuation may be reentered.

Procedure: dynamic-wind thunk1 thunk2 thunk3

The arguments thunk1, thunk2, and thunk3 must all be procedures of no arguments (thunks).

dynamic-wind calls thunk1, thunk2, and then thunk3. The value returned by thunk2 is returned as the result of dynamic-wind. thunk3 is also called just before control leaves the dynamic context of thunk2 by calling a continuation created outside that context. Furthermore, thunk1 is called before reentering the dynamic context of thunk2 by calling a continuation created inside that context. (Control is inside the context of thunk2 if thunk2 is on the current return stack).

Warning: There is no provision for dealing with errors or interrupts. If an error or interrupt occurs while using dynamic-wind, the dynamic environment will be that in effect at the time of the error or interrupt.

Values

(require 'values)

Function: values obj ...

values takes any number of arguments, and passes (returns) them to its continuation.

Function: call-with-values thunk proc

thunk must be a procedure of no arguments, and proc must be a procedure. call-with-values calls thunk with a continuation that, when passed some values, calls proc with those values as arguments.

Except for continuations created by the call-with-values procedure, all continuations take exactly one value, as now; the effect of passing no value or more than one value to continuations that were not created by the call-with-values procedure is unspecified.

Time

The procedures current-time, difftime, and offset-time are supported by all implementations (SLIB provides them if feature ('current-time) is missing. current-time returns a calendar time (caltime) which can be a number or other type.

time: current-time

Returns the time since 00:00:00 GMT, January 1, 1970, measured in seconds. Note that the reference time is different from the reference time for get-universal-time in section CLTime. On implementations which cannot support actual times, current-time will increment a counter and return its value when called.

difftime: caltime1 caltime0

Returns the difference (number of seconds) between twe calendar times: caltime1 - caltime0. caltime0 can also be a number.

offset-time: caltime offset

Returns the calendar time of caltime offset by offset number of seconds (+ caltime offset).

(require 'posix-time)

These procedures are intended to be compatible with Posix time conversion functions.

Variable: *timezone*

contains the difference, in seconds, between UTC and local standard time (for example, in the U.S. Eastern time zone (EST), timezone is 5*60*60). *timezone* is initialized by tzset.

time: tzset

initializes the *timezone* variable from the TZ environment variable. This function is automatically called by the other time conversion functions that depend on the time zone.

time: gmtime caltime

converts the calendar time caltime to a vector of integers representing the time expressed as Coordinated Universal Time (UTC).

time: localtime caltime

converts the calendar time caltime to a vector of integers expressed relative to the user's time zone. localtime sets the variable *timezone* with the difference between Coordinated Universal Time (UTC) and local standard time in seconds by calling tzset. The elements of the returned vector are as follows:

  1. seconds (0 - 61)
  2. minutes (0 - 59)
  3. hours since midnight
  4. day of month
  5. month (0 - 11). Note difference from decode-universal-time.
  6. year (A.D.)
  7. day of week (0 - 6)
  8. day of year (0 - 365)
  9. 1 for daylight savings, 0 for regular time

time: mktime univtime

Converts a vector of integers in Coordinated Universal Time (UTC) format to calendar time (caltime) format.

time: asctime univtime

Converts the vector of integers caltime in Coordinated Universal Time (UTC) format into a string of the form "Wed Jun 30 21:49:08 1993".

time: ctime caltime

Equivalent to (time:asctime (time:localtime caltime)).

CLTime

Function: get-decoded-time

Equivalent to (decode-universal-time (get-universal-time)).

Function: get-universal-time

Returns the current time as Universal Time, number of seconds since 00:00:00 Jan 1, 1900 GMT. Note that the reference time is different from current-time.

Function: decode-universal-time univtime

Converts univtime to Decoded Time format. Nine values are returned:

  1. seconds (0 - 61)
  2. minutes (0 - 59)
  3. hours since midnight
  4. day of month
  5. month (1 - 12). Note difference from gmtime and localtime.
  6. year (A.D.)
  7. day of week (0 - 6)
  8. #t for daylight savings, #f otherwise
  9. hours west of GMT (-24 - +24)

Notice that the values returned by decode-universal-time do not match the arguments to encode-universal-time.

Function: encode-universal-time second minute hour date month year

Function: encode-universal-time second minute hour date month year time-zone

Converts the arguments in Decoded Time format to Universal Time format. If time-zone is not specified, the returned time is adjusted for daylight saving time. Otherwise, no adjustment is performed.

Notice that the values returned by decode-universal-time do not match the arguments to encode-universal-time.

Go to the previous, next section.