r7rs-small-texinfo

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit d743997938d6490c32bcdfe4fc3b8d5046c4ca0c
parent 33b9ea42aa3e55f10a331f77519ea826b45c6e6e
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Mon, 29 Jan 2024 18:28:31 +0200

Add several @example and @end example, put some procedures in a single line, and add some @code.

Diffstat:
Mdoc/r7rs-small/r7rs-small.texinfo | 874++++++++++++++++++++++++++++---------------------------------------------------
1 file changed, 309 insertions(+), 565 deletions(-)

diff --git a/doc/r7rs-small/r7rs-small.texinfo b/doc/r7rs-small/r7rs-small.texinfo @@ -410,11 +410,7 @@ template for a call to the procedure. Argument names in the template are italicized. Thus the header line -procedure: (vector-ref - -vector - -k) +procedure: (vector-ref vector k) indicates that the procedure bound to the vector-ref variable takes two arguments, a @@ -424,16 +420,10 @@ vector and an exact non-negative integer k (see below). The header lines -procedure: (make-vector - -k) - - -procedure: (make-vector +procedure: (make-vector k) -k -fill) +procedure: (make-vector k fill) indicate that the make-vector procedure must be defined to take either one or two @@ -1983,17 +1973,13 @@ are supported in some implementations: @end example -lazy library procedure: (promise? - -obj) +lazy library procedure: (promise? obj) The promise? procedure returns #t if its argument is a promise, and #f otherwise. Note that promises are not necessarily disjoint from other Scheme types such as procedures. -lazy library procedure: (make-promise - -obj) +lazy library procedure: (make-promise obj) The make-promise procedure returns a promise which, when forced, will return @@ -2522,8 +2508,9 @@ they are hygienic (as required) and the following is not an error. @end example The macro transformer for cond recognizes @code{=>} as a local -variable, and hence an expression, and not as the base identifier =>, which the macro -transformer treats as a syntactic keyword. Thus the example expands into +variable, and hence an expression, and not as the base identifier +@code{=>}, which the macro transformer treats as a syntactic +keyword. Thus the example expands into @example @@ -2675,15 +2662,25 @@ them. The simplest kind of variable definition takes one of the following forms: more variables followed by a space-delimited period and another variable (as in a lambda expression). This form is equivalent to - (define <variable> +@example + +(define <variable> (lambda (<formals>) <body>)). + +@end example + + * (define (<variable> .​ ​<formal>) <body>) <Formal> is a single variable. This form is equivalent to - (define <variable> +@example + +(define <variable> (lambda <formal> <body>)). +@end example + @menu * Top level definitions:: * Internal definitions:: @@ -2722,17 +2719,29 @@ definitions described above. The variables defined by internal definitions are l <body>. That is, <variable> is bound rather than assigned, and the region of the binding is the entire <body>. For example, +@example + (let ((x 5)) (define foo (lambda (y) (bar x y))) (define bar (lambda (a b) (+ (* a b) a))) - (foo (+ x 3))) ⟹ 45 An expanded <body> containing internal definitions can always + (foo (+ x 3))) ⟹ 45 + +@end example + +An expanded <body> containing internal definitions can always be converted into a completely equivalent letrec* expression. For example, the let expression in the above example is equivalent to +@example + (let ((x 5)) (letrec* ((foo (lambda (y) (bar x y))) (bar (lambda (a b) (+ (* a b) a)))) - (foo (+ x 3)))) Just as for the equivalent letrec* expression, it is an error if it is not + (foo (+ x 3)))) + +@end example + +Just as for the equivalent letrec* expression, it is an error if it is not possible to evaluate each <expression> of every internal definition in a <body> without assigning or referring to the value of the corresponding <variable> or the <variable> of any of the definitions that follow it in <body>. @@ -2757,6 +2766,8 @@ Semantics: <Expression> is evaluated, and the <formals> are bound to the return the same way that the <formals> in a lambda expression are matched to the arguments in a procedure call. +@example + (define-values (x y) (exact-integer-sqrt 17)) (list x y) ⟹ (4 1) @@ -2764,6 +2775,8 @@ a procedure call. (define-values (x y) (values 1 2)) (+ x y)) ⟹ 3 +@end example + @node Syntax definitions @section Syntax definitions @@ -2782,6 +2795,8 @@ internal syntax definition, and is local to the <body> in which it is defined. A syntax keyword before its corresponding definition is an error. In particular, a use that precedes an inner definition will not apply an outer definition. +@example + (let ((x 1) (y 2)) (define-syntax swap! (syntax-rules () @@ -2792,6 +2807,8 @@ precedes an inner definition will not apply an outer definition. (swap! x y) (list x y)) ⟹ (2 1) +@end example + Macros can expand into definitions in any context that permits them. However, it is an error for a definition to define an identifier whose binding has to be known in order to determine the meaning of the definition itself, or of any preceding definition that belongs @@ -2800,6 +2817,8 @@ to define an identifier whose binding has to be known in order to determine the boundary between the internal definitions and the expressions of the body it belongs to. For example, the following are errors: +@example + (define define 3) (begin (define begin list)) @@ -2815,6 +2834,8 @@ For example, the following are errors: (define foo x) (plus foo x))) +@end example + @node Record-type definitions @section Record-type definitions @@ -2866,14 +2887,21 @@ An instance of define-record-type is equivalent to the following definitions: For instance, the following record-type definition +@example + (define-record-type <pare> (kons x y) pare? (x kar set-kar!) (y kdr)) + +@end example + defines kons to be a constructor, kar and kdr to be accessors, set-kar! to be a modifier, and pare? to be a predicate for instances of <pare>. +@example + (pare? (kons 1 2)) ⟹ #t (pare? (cons 1 2)) ⟹ #f (kar (kons 1 2)) ⟹ 1 @@ -2882,6 +2910,8 @@ and pare? to be a predicate for instances of <pare>. (set-kar! k 3) (kar k)) ⟹ 3 +@end example + @node Libraries @section Libraries @@ -2986,6 +3016,8 @@ The following example shows how a program can be divided into libraries plus a r small main program [16]. If the main program is entered into a REPL, it is not necessary to import the base library. +@example + (define-library (example grid) (export make rows cols ref each (rename put! set!)) @@ -3041,10 +3073,10 @@ import the base library. (define (life-print grid) (display "\x1B;[1H\x1B;[J") ; clear vt100 (each grid - (lambda (i j v) - (display (if v "*" " ")) - (when (= j (- (cols grid) 1)) - (newline))))) + (lambda (i j v) + (display (if v "*" " ")) + (when (= j (- (cols grid) 1)) + (newline))))) (define (life grid iterations) (do ((i 0 (+ i 1)) (grid0 grid grid1) @@ -3052,9 +3084,9 @@ import the base library. grid0)) ((= i iterations)) (each grid0 - (lambda (j k v) - (let ((a (life-alive? grid0 j k))) - (set! grid1 j k a)))) + (lambda (j k v) + (let ((a (life-alive? grid0 j k))) + (set! grid1 j k a)))) (life-print grid1))))) ;; Main program. @@ -3074,6 +3106,8 @@ import the base library. ;; Run for 80 iterations. (life grid 80) +@end example + @node The REPL @section The REPL @@ -3140,19 +3174,12 @@ symmetric, reflexive, and transitive. Of the equivalence predicates described in section, eq?​ ​is the finest or most discriminating, equal?​ ​is the coarsest, and eqv?​ ​is slightly less discriminating than eq?. -procedure: (eqv? - -obj1 - -obj2) - +procedure: (eqv? obj1 obj2) The eqv? procedure defines a useful equivalence relation on objects. Briefly, it returns #t if -obj1 and - -obj2 are normally regarded as the same object. This relation is left slightly open to +obj1 and obj2 are normally regarded as the same object. This relation is left slightly open to interpretation, but the following partial specification of eqv? holds for all implementations of Scheme. @@ -3254,6 +3281,8 @@ The eqv? procedure returns #f if: obj2 are procedures that would behave differently (return different values or have different side effects) for some arguments. +@example + (eqv? 'a 'a) ⟹ #t (eqv? 'a 'b) ⟹ #f (eqv? 2 2) ⟹ #t @@ -3266,10 +3295,16 @@ The eqv? procedure returns #f if: (lambda () 2)) ⟹ #f (let ((p (lambda (x) x))) (eqv? p p)) ⟹ #t -(eqv? #f 'nil) ⟹ #f The following examples illustrate cases in which the above rules +(eqv? #f 'nil) ⟹ #f + +@end example + +The following examples illustrate cases in which the above rules do not fully specify the behavior of eqv?. All that can be said about such cases is that the value returned by eqv? must be a boolean. +@example + (eqv? "" "") ⟹ unspecified (eqv? '#() '#()) ⟹ unspecified (eqv? (lambda (x) x) @@ -3277,7 +3312,11 @@ value returned by eqv? must be a boolean. (eqv? (lambda (x) x) (lambda (y) y)) ⟹ unspecified (eqv? 1.0e0 1.0f0) ⟹ unspecified -(eqv? +nan.0 +nan.0) ⟹ unspecified Note that (eqv? 0.0 -0.0) will return #f if negative zero +(eqv? +nan.0 +nan.0) ⟹ unspecified + +@end example + +Note that (eqv? 0.0 -0.0) will return #f if negative zero is distinguished, and #t if negative zero is not distinguished. The next set of examples shows the use of eqv?​ ​with procedures that have local state. The @@ -3287,6 +3326,8 @@ operationally equivalent procedures each time, since the local state does not af value or side effects of the procedures. However, eqv? may or may not detect this equivalence. +@example + (define gen-counter (lambda () (let ((n 0)) @@ -3312,16 +3353,26 @@ equivalence. (letrec ((f (lambda () (if (eqv? f g) 'f 'both))) (g (lambda () (if (eqv? f g) 'g 'both)))) (eqv? f g)) - ⟹ #f Since it is an error to modify constant objects (those returned by literal + ⟹ #f + +@end example + +Since it is an error to modify constant objects (those returned by literal expressions), implementations may share structure between constants where appropriate. Thus the value of eqv? on constants is sometimes implementation-dependent. +@example + (eqv? '(a) '(a)) ⟹ unspecified (eqv? "a" "a") ⟹ unspecified (eqv? '(b) (cdr '(a b))) ⟹ unspecified (let ((x '(a))) - (eqv? x x)) ⟹ #t The above definition of eqv? allows implementations latitude in + (eqv? x x)) ⟹ #t + +@end example + +The above definition of eqv? allows implementations latitude in their treatment of procedures and literals: implementations may either detect or fail to detect that two procedures or two literals are equivalent to each other, and can decide whether or not to merge representations of equivalent objects by using the same pointer @@ -3331,11 +3382,7 @@ or bit pattern to represent both. an implementation of eqv? that simply compares equal-sized inexact numbers for bitwise equality is correct by the above definition. -procedure: (eq? - -obj1 - -obj2) +procedure: (eq? obj1 obj2) The eq?​ ​procedure is similar to eqv?​ ​except that in some cases it is capable of discerning @@ -3349,6 +3396,8 @@ and characters, eq?’s behavior is implementation-dependent, but it will always either true or false. On empty strings, empty vectors, and empty bytevectors, eq? may also behave differently from eqv?. +@example + (eq? 'a 'a) ⟹ #t (eq? '(a) '(a)) ⟹ unspecified (eq? (list 'a) (list 'a)) ⟹ #f @@ -3367,18 +3416,15 @@ behave differently from eqv?. (let ((p (lambda (x) x))) (eq? p p)) ⟹ #t - Rationale: It will usually be possible to implement eq?​ ​much more efficiently than +@end example + +Rationale: It will usually be possible to implement eq?​ ​much more efficiently than eqv?, for example, as a simple pointer comparison instead of as some more complicated operation. One reason is that it is not always possible to compute eqv?​ ​of two numbers in constant time, whereas eq?​ ​implemented as pointer comparison will always finish in constant time. -procedure: (equal? - -obj1 - -obj2) - +procedure: (equal? obj1 obj2) The equal? procedure, when applied to pairs, vectors, strings and bytevectors, recursively compares them, returning #t when the unfoldings of its arguments into (possibly infinite) @@ -3388,6 +3434,8 @@ procedures, and the empty list. If two objects are eqv?, they must be equal? as other cases, equal? may return either #t or #f. Even if its arguments are circular data structures, equal?​ ​must always terminate. +@example + (equal? 'a 'a) ⟹ #t (equal? '(a) '(a)) ⟹ #t (equal? '(a (b) c) @@ -3401,7 +3449,9 @@ structures, equal?​ ​must always terminate. (equal? (lambda (x) x) (lambda (y) y)) ⟹ unspecified - Note: A rule of thumb is that objects are generally equal? if they print the same. +@end example + +Note: A rule of thumb is that objects are generally equal? if they print the same. @node Numbers @section Numbers @@ -3719,6 +3769,8 @@ x)). The numbers +inf.0, -inf.0, and +nan.0 are real but not rational. +@example + (complex? 3+4i) ⟹ #t (complex? 3) ⟹ #t (real? 3) ⟹ #t @@ -3735,7 +3787,9 @@ The numbers +inf.0, -inf.0, and +nan.0 are real but not rational. (integer? 3.0) ⟹ #t (integer? 8/4) ⟹ #t - Note: The behavior of these type predicates on inexact numbers is unreliable, since +@end example + +Note: The behavior of these type predicates on inexact numbers is unreliable, since any inaccuracy might affect the result. Note: In many implementations the complex? procedure will be the same as @@ -3743,118 +3797,96 @@ The numbers +inf.0, -inf.0, and +nan.0 are real but not rational. exactly or may extend the number system to support some kind of non-complex numbers. -procedure: (exact? - -z) - +procedure: (exact? z) -procedure: (inexact? -z) +procedure: (inexact? z) These numerical predicates provide tests for the exactness of a quantity. For any Scheme number, precisely one of these predicates is true. +@example + (exact? 3.0) ⟹ #f (exact? #e3.0) ⟹ #t (inexact? 3.) ⟹ #t -procedure: (exact-integer? +@end example -z) +procedure: (exact-integer? z) Returns #t if z is both exact and an integer; otherwise returns #f. +@example + (exact-integer? 32) ⟹ #t (exact-integer? 32.0) ⟹ #f (exact-integer? 32/5) ⟹ #f -inexact library procedure: (finite? +@end example -z) +inexact library procedure: (finite? z) The finite? procedure returns #t on all real numbers except +inf.0, -inf.0, and +nan.0, and on complex numbers if their real and imaginary parts are both finite. Otherwise it returns #f. +@example + (finite? 3) ⟹ #t (finite? +inf.0) ⟹ #f (finite? 3.0+inf.0i) ⟹ #f -inexact library procedure: (infinite? +@end example -z) +inexact library procedure: (infinite? z) The infinite? procedure returns #t on the real numbers +inf.0 and -inf.0, and on complex numbers if their real or imaginary parts or both are infinite. Otherwise it returns #f. +@example + (infinite? 3) ⟹ #f (infinite? +inf.0) ⟹ #t (infinite? +nan.0) ⟹ #f (infinite? 3.0+inf.0i) ⟹ #t -inexact library procedure: (nan? +@end example -z) +inexact library procedure: (nan? z) The nan? procedure returns #t on +nan.0, and on complex numbers if their real or imaginary parts or both are +nan.0. Otherwise it returns #f. +@example + (nan? +nan.0) ⟹ #t (nan? 32) ⟹ #f (nan? +nan.0+5.0i) ⟹ #t (nan? 1+2i) ⟹ #f -procedure: (= - -z1 - -z2 - -z3 …) - - -procedure: (< - -x1 - -x2 - -x3 …) - - -procedure: (> - -x1 - -x2 - -x3 …) - +@end example -procedure: (<= +procedure: (= z1 z2 z3 …) -x1 -x2 +procedure: (< x1 x2 x3 …) -x3 …) +procedure: (> x1 x2 x3 …) -procedure: (>= -x1 +procedure: (<= x1 x2 x3 …) -x2 -x3 …) +procedure: (>= x1 x2 x3 …) These procedures return #t if their arguments are (respectively): equal, monotonically @@ -3877,100 +3909,74 @@ These predicates are required to be transitive. results are unreliable because a small inaccuracy can affect the result; this is especially true of = and zero?. When in doubt, consult a numerical analyst. -procedure: (zero? - -z) +procedure: (zero? z) -procedure: (positive? +procedure: (positive? x) -x) +procedure: (negative? x) -procedure: (negative? -x) +procedure: (odd? n) -procedure: (odd? - -n) - - -procedure: (even? - -n) +procedure: (even? n) These numerical predicates test a number for a particular property, returning #t or #f. See note above. -procedure: (max - -x1 - -x2 …) +procedure: (max x1 x2 …) -procedure: (min - -x1 - -x2 …) +procedure: (min x1 x2 …) These procedures return the maximum or minimum of their arguments. +@example + (max 3 4) ⟹ 4 ; exact (max 3.9 4) ⟹ 4.0 ; inexact - Note: If any argument is inexact, then the result will also be inexact (unless the +@end example + +Note: If any argument is inexact, then the result will also be inexact (unless the procedure can prove that the inaccuracy is not large enough to affect the result, which is possible only in unusual implementations). If min or max is used to compare numbers of mixed exactness, and the numerical value of the result cannot be represented as an inexact number without loss of accuracy, then the procedure may report a violation of an implementation restriction. -procedure: (+ - -z1 …) - +procedure: (+ z1 …) -procedure: (* -z1 …) +procedure: (* z1 …) These procedures return the sum or product of their arguments. +@example + (+ 3 4) ⟹ 7 (+ 3) ⟹ 3 (+) ⟹ 0 (* 4) ⟹ 4 (*) ⟹ 1 -procedure: (- - -z) - - -procedure: (- - -z1 - -z2 …) +@end example +procedure: (- z) -procedure: (/ -z) +procedure: (- z1 z2 …) -procedure: (/ +procedure: (/ z) -z1 -z2 …) +procedure: (/ z1 z2 …) With two or more arguments, these procedures return the difference or quotient of their @@ -3981,58 +3987,42 @@ It is an error if any argument of / other than the first is an exact zero. If th argument is an exact zero, an implementation may return an exact zero unless one of the other arguments is a NaN. +@example + (- 3 4) ⟹ -1 (- 3 4 5) ⟹ -6 (- 3) ⟹ -3 (/ 3 4 5) ⟹ 3/20 (/ 3) ⟹ 1/3 +@end example + procedure: (abs x) The abs procedure returns the absolute value of its argument. -(abs -7) ⟹ 7 - -procedure: (floor/ - -n1 - -n2) - - -procedure: (floor-quotient - -n1 - -n2) - - -procedure: (floor-remainder - -n1 +@example -n2) +(abs -7) ⟹ 7 +@end example -procedure: (truncate/ +procedure: (floor/ n1 n2) -n1 -n2) +procedure: (floor-quotient n1 n2) -procedure: (truncate-quotient +procedure: (floor-remainder n1 n2) -n1 -n2) +procedure: (truncate/ n1 n2) -procedure: (truncate-remainder +procedure: (truncate-quotient n1 n2) -n1 -n2) +procedure: (truncate-remainder n1 n2) These procedures implement number-theoretic (integer) division. It is an error if @@ -4131,6 +4121,8 @@ provided all numbers involved in that computation are exact. Examples: +@example + (floor/ 5 2) ⟹ 2 1 (floor/ -5 2) ⟹ -3 1 (floor/ 5 -2) ⟹ -3 -1 @@ -4141,25 +4133,15 @@ Examples: (truncate/ -5 -2) ⟹ 2 -1 (truncate/ -5.0 -2) ⟹ 2.0 -1.0 -procedure: (quotient - -n1 - -n2) - - -procedure: (remainder - -n1 +@end example -n2) +procedure: (quotient n1 n2) -procedure: (modulo +procedure: (remainder n1 n2) -n1 -n2) +procedure: (modulo n1 n2) The quotient and remainder procedures are equivalent to truncate-quotient and @@ -4168,44 +4150,44 @@ truncate-remainder, respectively, and modulo is equivalent to floor-remainder. Note: These procedures are provided for backward compatibility with earlier versions of this report. -procedure: (gcd +procedure: (gcd n1 …) -n1 …) - -procedure: (lcm - -n1 …) +procedure: (lcm n1 …) These procedures return the greatest common divisor or least common multiple of their arguments. The result is always non-negative. +@example + (gcd 32 -36) ⟹ 4 (gcd) ⟹ 0 (lcm 32 -36) ⟹ 288 (lcm 32.0 -36) ⟹ 288.0 ; inexact (lcm) ⟹ 1 -procedure: (numerator - -q) +@end example +procedure: (numerator q) -procedure: (denominator -q) +procedure: (denominator q) 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. +@example + (numerator (/ 6 4)) ⟹ 3 (denominator (/ 6 4)) ⟹ 2 (denominator (inexact (/ 6 4))) ⟹ 2.0 +@end example + procedure: (floor x) procedure: (ceiling x) procedure: (truncate x) @@ -4233,6 +4215,8 @@ x is halfway between two integers. be inexact. If an exact value is needed, the result can be passed to the exact procedure. If the argument is infinite or a NaN, then it is returned. +@example + (floor -4.3) ⟹ -5.0 (ceiling -4.3) ⟹ -4.0 (truncate -4.3) ⟹ -4.0 @@ -4246,6 +4230,8 @@ x is halfway between two integers. (round 7/2) ⟹ 4 ; exact (round 7) ⟹ 7 +@end example + procedure: (rationalize x y) The rationalize procedure returns the simplest rational number differing from @@ -4259,62 +4245,42 @@ interval contains a rational number that is simpler than every other rational nu that interval (the simpler 2/5 lies between 2/7 and 3/5). Note that 0 = 0/1 is the simplest rational of all. +@example + (rationalize (exact .3) 1/10) ⟹ 1/3 ; exact (rationalize .3 1/10) ⟹ #i1/3 ; inexact -inexact library procedure: (exp - -z) - - -inexact library procedure: (log - -z) - - -inexact library procedure: (log - -z1 - -z2) - - -inexact library procedure: (sin - -z) +@example +inexact library procedure: (exp z) -inexact library procedure: (cos -z) +inexact library procedure: (log z) -inexact library procedure: (tan +inexact library procedure: (log z1 z2) -z) +inexact library procedure: (sin z) -inexact library procedure: (asin -z) +inexact library procedure: (cos z) -inexact library procedure: (acos +inexact library procedure: (tan z) -z) +inexact library procedure: (asin z) -inexact library procedure: (atan -z) +inexact library procedure: (acos z) -inexact library procedure: (atan +inexact library procedure: (atan z) -y -x) +inexact library procedure: (atan y x) These procedures compute the usual transcendental functions. The log procedure @@ -4381,25 +4347,19 @@ more detailed discussion of branch cuts, boundary conditions, and implementation these functions. When it is possible, these procedures produce a real result from a real argument. -procedure: (square - -z) +procedure: (square z) -Returns the square of +Returns the square of z. This is equivalent to @code{(* z z)}. -z. This is equivalent to (* - -z - -z). +@example (square 42) ⟹ 1764 (square 2.0) ⟹ 4.0 -inexact library procedure: (sqrt +@end example -z) +inexact library procedure: (sqrt z) Returns the principal square root of @@ -4407,9 +4367,13 @@ Returns the principal square root of z. The result will have either a positive real part, or a zero real part and a non-negative imaginary part. +@example + (sqrt 9) ⟹ 3 (sqrt -1) ⟹ +i +@end example + procedure: (exact-integer-sqrt k) Returns two non-negative exact integers s and r where @@ -4418,14 +4382,14 @@ k = s2 + r and k < (s + 1)2. +@example + (exact-integer-sqrt 4) ⟹ 2 0 (exact-integer-sqrt 5) ⟹ 2 1 -procedure: (expt - -z1 +@end example -z2) +procedure: (expt z1 z2) Returns @@ -4441,38 +4405,22 @@ z1, this is The value of 0z is 1 if (zero? z), 0 if (real-part z) is positive, and an error otherwise. Similarly for 0.0z, with inexact results. -complex library procedure: (make-rectangular - -x1 - -x2) - - -complex library procedure: (make-polar - -x3 +complex library procedure: (make-rectangular x1 x2) -x4) +complex library procedure: (make-polar x3 x4) -complex library procedure: (real-part -z) +complex library procedure: (real-part z) -complex library procedure: (imag-part +complex library procedure: (imag-part z) -z) +complex library procedure: (magnitude z) -complex library procedure: (magnitude -z) - - -complex library procedure: (angle - -z) +complex library procedure: (angle z) Let @@ -4493,38 +4441,16 @@ z be a complex number such that Then all of -(make-rectangular - -x1 - -x2) ⟹ - -z -(make-polar - -x3 - -x4) ⟹ - -z -(real-part - -z) ⟹ - -x1 -(imag-part - -z) ⟹ - -x2 -(magnitude - -z) ⟹ | +@example -x3| -(angle +(make-rectangular x1 x2) ⟹ z +(make-polar x3 x4) ⟹ z +(real-part z) ⟹ x1 +(imag-part z) ⟹ x2 +(magnitude z) ⟹ |x3| +(angle z) ⟹ xangle -z) ⟹ xangle +@end example are true, where −π≤xangle ≤π with xangle = @@ -4538,14 +4464,10 @@ make-rectangular was exact. Rationale: The magnitude procedure is the same as abs for a real argument, but abs is in the base library, whereas magnitude is in the optional complex library. -procedure: (inexact - -z) - +procedure: (inexact z) -procedure: (exact -z) +procedure: (exact z) The procedure inexact returns an inexact representation of @@ -4588,17 +4510,17 @@ radix is not one of 2, 8, 10, or 16. The procedure number->string takes a number and a radix and returns as a string an external representation of the given number in the given radix such that -(let ((number - -number) - (radix +@example -radix)) +(let ((number number) + (radix radix)) (eqv? number (string->number (number->string number radix) radix))) +@end example + is true. It is an error if no possible result makes this expression true. If omitted, radix defaults to 10. @@ -4648,11 +4570,15 @@ signaled due to the content of string. +@example + (string->number "100") ⟹ 100 (string->number "100" 16) ⟹ 256 (string->number "1e2") ⟹ 100.0 - Note: The domain of string->number may be restricted by implementations in the +@end example + +Note: The domain of string->number may be restricted by implementations in the following ways. If all numbers supported by an implementation are real, then string->number is permitted to return #f whenever @@ -4688,16 +4614,22 @@ Scheme values, including #t, count as true. Boolean constants evaluate to themselves, so they do not need to be quoted in programs. +@example + #t ⟹ #t #f ⟹ #f '#f ⟹ #f +@end example + procedure: (not obj) The not procedure returns #t if obj is false, and returns #f otherwise. +@example + (not #t) ⟹ #f (not 3) ⟹ #f (not (list 3)) ⟹ #f @@ -4706,23 +4638,23 @@ obj is false, and returns #f otherwise. (not (list)) ⟹ #f (not 'nil) ⟹ #f +@end example + procedure: (boolean? obj) The boolean? predicate returns #t if obj is either #t or #f and returns #f otherwise. +@example + (boolean? #f) ⟹ #t (boolean? 0) ⟹ #f (boolean? '()) ⟹ #f -procedure: (boolean=? - -boolean1 - -boolean2 +@end example -boolean3 …) +procedure: (boolean=? boolean1 boolean2 boolean3 …) Returns #t if all the arguments are #t or all are #f. @@ -4829,11 +4761,7 @@ obj is a pair, and otherwise returns #f. (pair? '()) ⟹ #f (pair? '#(a b)) ⟹ #f -procedure: (cons - -obj1 - -obj2) +procedure: (cons obj1 obj2) Returns a newly allocated pair whose car is @@ -4946,9 +4874,7 @@ fill. Otherwise the initial contents of each element is unspecified. (make-list 2 3) ⟹ (3 3) -procedure: (list - -obj …) +procedure: (list obj …) Returns a newly allocated list of its arguments. @@ -4996,9 +4922,7 @@ list in reverse order. (reverse '(a (b c) d (e (f)))) ⟹ ((e (f)) d (b c) a) -procedure: (list-tail list - -k) +procedure: (list-tail list k) It is an error if @@ -5019,9 +4943,7 @@ k elements. The list-tail procedure could be defined by x (list-tail (cdr x) (- k 1))))) -procedure: (list-ref list - -k) +procedure: (list-ref list k) The @@ -5213,13 +5135,7 @@ obj is a symbol, otherwise returns #f. (symbol? '()) ⟹ #f (symbol? #f) ⟹ #f -procedure: (symbol=? - -symbol1 - -symbol2 - -symbol3 …) +procedure: (symbol=? symbol1 symbol2 symbol3 …) Returns #t if all the arguments all have the same names in the sense of string=?. @@ -5339,49 +5255,19 @@ Returns #t if obj is a character, otherwise returns #f. -procedure: (char=? - -char1 - -char2 - -char3 …) - - -procedure: (char<? - -char1 - -char2 - -char3 …) - - -procedure: (char>? - -char1 +procedure: (char=? char1 char2 char3 …) -char2 -char3 …) +procedure: (char<? char1 char2 char3 …) -procedure: (char<=? +procedure: (char>? char1 char2 char3 …) -char1 -char2 +procedure: (char<=? char1 char2 char3 …) -char3 …) - -procedure: (char>=? - -char1 - -char2 - -char3 …) +procedure: (char>=? char1 char2 char3 …) These procedures return #t if the results of passing their arguments to char->integer @@ -5390,49 +5276,19 @@ monotonically non-decreasing, or monotonically non-increasing. These predicates are required to be transitive. -char library procedure: (char-ci=? - -char1 - -char2 - -char3 …) - - -char library procedure: (char-ci<? - -char1 - -char2 - -char3 …) +char library procedure: (char-ci=? char1 char2 char3 …) -char library procedure: (char-ci>? +char library procedure: (char-ci<? char1 char2 char3 …) -char1 -char2 +char library procedure: (char-ci>? char1 char2 char3 …) -char3 …) +char library procedure: (char-ci<=? char1 char2 char3 …) -char library procedure: (char-ci<=? -char1 - -char2 - -char3 …) - - -char library procedure: (char-ci>=? - -char1 - -char2 - -char3 …) +char library procedure: (char-ci>=? char1 char2 char3 …) These procedures are similar to char=?​ ​et cetera, but they treat upper case and lower @@ -5465,9 +5321,7 @@ This procedure returns the numeric value (0 to 9) of its argument if it is a num (digit-value #\x0EA6) ⟹ #f procedure: (char->integer char) -procedure: (integer->char - -n) +procedure: (integer->char n) Given a Unicode character, char->integer returns an exact integer between 0 and #xD7FF @@ -5571,14 +5425,10 @@ Returns #t if obj is a string, otherwise returns #f. -procedure: (make-string - -k) +procedure: (make-string k) -procedure: (make-string - -k char) +procedure: (make-string k char) The make-string procedure returns a newly allocated string of length @@ -5599,9 +5449,7 @@ Returns the number of characters in the given string. -procedure: (string-ref string - -k) +procedure: (string-ref string k) It is an error if @@ -5642,101 +5490,41 @@ string. There is no requirement for this procedure to execute in constant time. 0 #\?) ⟹ error -procedure: (string=? - -string1 - -string2 - -string3 …) +procedure: (string=? string1 string2 string3 …) Returns #t if all the strings are the same length and contain exactly the same characters in the same positions, otherwise returns #f. -char library procedure: (string-ci=? - -string1 - -string2 - -string3 …) +char library procedure: (string-ci=? string1 string2 string3 …) Returns #t if, after case-folding, all the strings are the same length and contain the same characters in the same positions, otherwise returns #f. Specifically, these procedures behave as if string-foldcase were applied to their arguments before comparing them. -procedure: (string<? - -string1 - -string2 - -string3 …) - - -char library procedure: (string-ci<? - -string1 +procedure: (string<? string1 string2 string3 …) -string2 -string3 …) +char library procedure: (string-ci<? string1 string2 string3 …) -procedure: (string>? +procedure: (string>? string1 string2 string3 …) -string1 -string2 +char library procedure: (string-ci>? string1 string2 string3 …) -string3 …) +procedure: (string<=? string1 string2 string3 …) -char library procedure: (string-ci>? -string1 +char library procedure: (string-ci<=? string1 string2 string3 …) -string2 -string3 …) +procedure: (string>=? string1 string2 string3 …) -procedure: (string<=? - -string1 - -string2 - -string3 …) - - -char library procedure: (string-ci<=? - -string1 - -string2 - -string3 …) - - -procedure: (string>=? - -string1 - -string2 - -string3 …) - - -char library procedure: (string-ci>=? - -string1 - -string2 - -string3 …) +char library procedure: (string-ci>=? string1 string2 string3 …) These procedures return #t if their arguments are (respectively): monotonically @@ -5786,9 +5574,7 @@ start and ending with index end. This is equivalent to calling string-copy with the same arguments, but is provided for backward compatibility and stylistic flexibility. -procedure: (string-append - -string …) +procedure: (string-append string …) Returns a newly allocated string whose characters are the concatenation of the @@ -6098,9 +5884,7 @@ making sure to copy in the correct direction in such circumstances. (vector-copy! b 1 a 0 2) b ⟹ #(10 1 2 40 50) -procedure: (vector-append - -vector …) +procedure: (vector-append vector …) Returns a newly allocated vector whose elements are the concatenation of the elements @@ -6167,9 +5951,7 @@ byte, otherwise the contents of each element are unspecified. (make-bytevector 2 12) ⟹ #u8(12 12) -procedure: (bytevector - -byte …) +procedure: (bytevector byte …) Returns a newly allocated bytevector containing its arguments. @@ -6278,9 +6060,7 @@ b ⟹ #u8(10 1 2 40 50) Note: This procedure appears in R6RS, but places the source before the destination, contrary to other such procedures in Scheme. -procedure: (bytevector-append - -bytevector …) +procedure: (bytevector-append bytevector …) Returns a newly allocated bytevector whose elements are the concatenation of the @@ -6339,18 +6119,14 @@ obj is a procedure, otherwise returns #f. (call-with-current-continuation procedure?) ⟹ #t -procedure: (apply proc - -arg1 … args) +procedure: (apply proc arg1 … args) The apply procedure calls -proc with the elements of the list (append (list +proc with the elements of the list @code{(append (list arg1 …) args)} as the actual arguments. -arg1 …) - -args) as the actual arguments. +@example (apply + (list 3 4)) ⟹ 7 @@ -6361,11 +6137,9 @@ args) as the actual arguments. ((compose sqrt *) 12 75) ⟹ 30 -procedure: (map proc - -list1 +@end example -list2 …) +procedure: (map proc list1 list2 …) It is an error if @@ -6407,11 +6181,7 @@ returns are not mutated. or (2 1) -procedure: (string-map proc - -string1 - -string2 …) +procedure: (string-map proc string1 string2 …) It is an error if @@ -6450,11 +6220,7 @@ earlier returns are not mutated. "ululululul") ⟹ "StUdLyCaPs" -procedure: (vector-map proc - -vector1 - -vector2 …) +procedure: (vector-map proc vector1 vector2 …) It is an error if @@ -6494,11 +6260,7 @@ earlier returns are not mutated. or #(2 1) -procedure: (for-each proc - -list1 - -list2 …) +procedure: (for-each proc list1 list2 …) It is an error if @@ -6530,11 +6292,7 @@ proc to mutate any of the lists. '(0 1 2 3 4)) v) ⟹ #(0 1 4 9 16) -procedure: (string-for-each proc - -string1 - -string2 …) +procedure: (string-for-each proc string1 string2 …) It is an error if @@ -6563,11 +6321,7 @@ proc to mutate any of the strings. "abcde") v) ⟹ (101 100 99 98 97) -procedure: (vector-for-each proc - -vector1 - -vector2 …) +procedure: (vector-for-each proc vector1 vector2 …) It is an error if @@ -6810,11 +6564,7 @@ object encapsulating information about the exception. Any procedure accepting on argument can serve as an exception handler and any object can be used to represent an exception. -procedure: (with-exception-handler - -handler - -thunk) +procedure: (with-exception-handler handler thunk) It is an error if @@ -6853,9 +6603,7 @@ thunk. prints something went wrong After printing, the second example then raises another exception. -procedure: (raise - -obj) +procedure: (raise obj) Raises an exception by invoking the current exception handler on @@ -6867,9 +6615,7 @@ same dynamic environment as the handler. The relationship between obj and the object raised by the secondary exception is unspecified. -procedure: (raise-continuable - -obj) +procedure: (raise-continuable obj) Raises an exception by invoking the current exception handler on @@ -6880,6 +6626,8 @@ place when the handler being called was installed, and (2) if the handler being 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. +@example + (with-exception-handler (lambda (con) (cond @@ -6894,11 +6642,9 @@ the values it returns become the values returned by the call to raise-continuabl prints: should be a number ⟹ 65 -procedure: (error - -message +@end example -obj …) +procedure: (error message obj …) Message should be a string. @@ -6949,9 +6695,7 @@ output port on a file, respectively. Otherwise, it returns #f. @node Environments and evaluation @section Environments and evaluation -eval library procedure: (environment - -list1 …) +eval library procedure: (environment list1 …) This procedure returns a specifier for the environment that results by starting with an