The features described in this chapter are exported from the (rnrs r5rs (6))library and provide some functionality of the preceding revision of this report [6] that was omitted from the main part of the current report.
These are the same as the inexact and exact procedures; see report section on “Generic conversions”.
These procedures implement number-theoretic (integer) division. n2 must be non-zero. All three procedures return integers. If n1/n2 is an integer:
(quotient n1 n2) ⇒ n1/n2If n1/n2 is not an integer:
(quotient n1 n2) ⇒ nqwhere nq is n1/n2 rounded towards zero, 0 < |nr| < |n2|, 0 < |nm| < |n2|, nr and nm differ from n1 by a multiple of n2, nr has the same sign as n1, and nm has the same sign as n2.
Consequently, for integers n1 and n2 with n2 not equal to 0,
(= n1 (+ (* n2 (quotient n1 n2))provided all numbers involved in that computation are exact.
(modulo 13 4) ⇒ 1
Note: These procedures could be defined in terms of div and mod (see report section on “Arithmetic operations”) as follows (without checking of the argument types): (define (sign n)
(cond
((negative? n) -1)
((positive? n) 1)
(else 0)))
(define (quotient n1 n2)
(* (sign n1) (sign n2) (div (abs n1) (abs n2))))
(define (remainder n1 n2)
(* (sign n1) (mod (abs n1) (abs n2))))
(define (modulo n1 n2)
(* (sign n2) (mod (* (sign n2) n1) (abs n2))))
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.
Promise must be a promise.
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.
(force (delay (+ 1 2))) ⇒ 3
Promises are mainly intended for programs written in functional style. The following examples should not be considered to illustrate good programming style, but they illustrate the property that only one value is computed for a promise, no matter how many times it is forced.
(define count 0)
Here is a possible implementation of delay and force. Promises are implemented here as procedures of no arguments, and force simply calls its argument:
(define force
The expression
(delay <expression>)
has the same meaning as the procedure call
(make-promise (lambda () <expression>))
as follows
(define-syntax delay
where make-promise is defined as follows:
(define make-promise
Rationale: A promise may refer to its own value, as in the last example above. Forcing such a promise may cause the promise to be forced a second time before the value of the first force has been computed. This complicates the definition of make-promise.
N must be the exact integer 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 syntactic keywords described in the previous revision of this report [6].
N must be the exact integer 5. The scheme-report-environment procedure returns an environment specifier for an environment that is empty except for the bindings for the standard procedures described in the previous revision of this report [6], omitting load, transcript-on, transcript-off, and char-ready?. The bindings have as values the procedures of the same names described in this report.