commit ef70253f504ffa6a7020909d6454a30266c63640
parent 321cb6a38ca9d5e6f457b293607a89155ecfd17a
Author: Wolfgang Corcoran-Mathe <wcm@sigwinch.xyz>
Date: Wed, 31 Jan 2024 21:16:00 -0500
Don't put padding newlines inside @example blocks.
Diffstat:
1 file changed, 0 insertions(+), 341 deletions(-)
diff --git a/doc/r7rs-small/r7rs-small.texinfo b/doc/r7rs-small/r7rs-small.texinfo
@@ -632,7 +632,6 @@ that @code{||} is a valid identifier that is different from any other identifier
Here are some examples of identifiers:
@example
-
... +
+soup+ <=?
->string a34kTMNs
@@ -640,7 +639,6 @@ lambda list->vector
q V17a
|two words| |two\x20;words|
the-word-recursion-has-many-meanings
-
@end example
See section 7.1.1 for the formal syntax of
@@ -670,10 +668,8 @@ sentence.
The following directives give explicit control over case folding.
@example
-
#!fold-case
#!no-fold-case
-
@end example
These directives can appear anywhere comments are permitted (see section 2.2) but
@@ -706,7 +702,6 @@ useful for ``commenting out'' sections of code.
Block comments are indicated with properly nested @code{#|} and @code{|#} pairs.
@example
-
#|
The FACT procedure computes the factorial
of a non-negative integer.
@@ -717,7 +712,6 @@ Block comments are indicated with properly nested @code{#|} and @code{|#} pairs.
#;(= n 1)
1 ;Base case: return 1
(* n (fact (- n 1))))))
-
@end example
@node Other notations
@@ -800,11 +794,9 @@ result is the same object as the @code{#}<n>@code{=} (see section 6.1). Together
the notation of structures with shared or circular substructure.
@example
-
(let ((x (list 'a 'b 'c)))
(set-cdr! (cddr x) x)
x) @result{} #0=(a b c . #0#)
-
@end example
The scope of a datum label is the portion of the outermost datum in which it appears that
@@ -817,9 +809,7 @@ It is an error for a <program> or <library> to include circular references excep
In particular, it is an error for quasiquote (section 4.2.8) to contain them.
@example
-
#1=(begin (display #\x) #1#) @result{} @error{}
-
@end example
@end deffn
@@ -1065,12 +1055,10 @@ expression> below, occurs in a tail context. The same is true of all the
bodies of @code{case-lambda} expressions.
@example
-
(lambda @svar{formals}
@svar{definition}* @svar{expression}* @svar{tail expression})
(case-lambda (@svar{formals} @svar{tail body})*)
-
@end example
@item
@@ -1152,13 +1140,11 @@ the calls to @code{g} or @code{h} are tail calls. The reference to @code{x}
is in a tail context, but it is not a call and thus is not a tail call.
@example
-
(lambda ()
(if (g)
(let ((x (h)))
x)
(and (g) (f))))
-
@end example
@subheading Note
@@ -1215,10 +1201,8 @@ location to which the variable is bound. It is an error to reference an
unboundvariable.
@example
-
(define x 28)
x @result{} 28
-
@end example
@node Literal expressions
@@ -1234,25 +1218,21 @@ external representation of a Scheme object
literal constants in Scheme code.
@example
-
(quote a) @result{} a
(quote #(a b c)) @result{} #(a b c)
(quote (+ 1 2)) @result{} (+ 1 2)
-
@end example
@code{(quote} @svar{datum}@code{)} can be abbreviated as @code{'}@svar{datum}. The two
notations are equivalent in all respects.
@example
-
'a @result{} a
'#(a b c) @result{} #(a b c)
'() @result{} ()
'(+ 1 2) @result{} (+ 1 2)
'(quote a) @result{} (quote a)
''a @result{} (quote a)
-
@end example
Numerical constants, string constants, character constants, vector
@@ -1260,7 +1240,6 @@ constants, bytevector constants, and boolean constants evaluate to
themselves; they need not be quoted.
@example
-
'145932 @result{} 145932
145932 @result{} 145932
'"abc" @result{} "abc"
@@ -1273,7 +1252,6 @@ themselves; they need not be quoted.
#u8(64 65) @result{} #u8(64 65)
'#t @result{} #t
#t @result{} #t
-
@end example
As noted in @ref{Storage model}, it is an error to attempt to alter a
@@ -1292,10 +1270,8 @@ unspecified order) and the resulting procedure is passed the resulting
arguments.
@example
-
(+ 3 4) @result{} 7
((if #f + *) 3 4) @result{} 12
-
@end example
The procedures in this document are available as the values of variables
@@ -1358,7 +1334,6 @@ of the procedure call.
(let ((x 4))
(lambda (y) (+ x y))))
(add4 6) @result{} 10
-
@end example
@svar{Formals} have one of the following forms:
@@ -1390,11 +1365,9 @@ formal arguments.
It is an error for a @svar{variable} to appear more than once in @svar{formals}.
@example
-
((lambda x x) 3 4 5 6) @result{} (3 4 5 6)
((lambda (x y . z) z)
3 4 5 6) @result{} (5 6)
-
@end example
Each procedure created as the result of evaluating a @code{lambda}
@@ -1420,13 +1393,11 @@ of the expression is unspecified.
@end deffn
@example
-
(if (> 3 2) 'yes 'no) @result{} yes
(if (> 2 3) 'yes 'no) @result{} no
(if (> 3 2)
(- 3 2)
(+ 3 2)) @result{} 1
-
@end example
@node Assignments
@@ -1442,12 +1413,10 @@ unspecified.
@end deffn
@example
-
(define x 2)
(+ x 1) @result{} 3
(set! x 4) @result{} @r{unspecified}
(+ x 1) @result{} 5
-
@end example
@node Inclusion
@@ -1538,7 +1507,6 @@ of the last one are returned.
@end deffn
@example
-
(cond ((> 3 2) 'greater)
((< 3 2) 'less)) @result{} greater
@@ -1548,7 +1516,6 @@ of the last one are returned.
(cond ((assv 'b '((a 1) (b 2))) => cadr)
(else #f)) @result{} 2
-
@end example
@deffn syntax case @svar{key} @svar{clause@sub{1}} @svar{clause@sub{2}}@dots{}
@@ -1600,7 +1567,6 @@ returned by the @code{case} expression.
@end deffn
@example
-
(case (* 2 3)
((2 3 5 7) 'prime)
((1 4 6 8 9) 'composite)) @result{} composite
@@ -1611,7 +1577,6 @@ returned by the @code{case} expression.
((a e i o u) 'vowel)
((w y) 'semivowel)
(else => (lambda (x) x))) @result{} c
-
@end example
@deffn syntax and @svar{test@sub{1}}@dots{}
@@ -1624,12 +1589,10 @@ returned. If there are no expressions, then @code{#t} is returned.
@end deffn
@example
-
(and (= 2 2) (> 2 1)) @result{} #t
(and (= 2 2) (< 2 1)) @result{} #f
(and 1 2 'c '(f g)) @result{} (f g)
(and) @result{} #t
-
@end example
@deffn syntax or @svar{test@sub{1}}@dots{}
@@ -1642,13 +1605,11 @@ then @code{#f} is returned.
@end deffn
@example
-
(or (= 2 2) (> 2 1)) @result{} #t
(or (= 2 2) (< 2 1)) @result{} #t
(or #f #f #f) @result{} #f
(or (memq 'b '(a b c))
(/ 3 0)) @result{} (b c)
-
@end example
@deffn syntax when @svar{test} @svar{expression@sub{1}} @svar{expression@sub{2}}@dots{}
@@ -1661,12 +1622,10 @@ is unspecified.
@end deffn
@example
-
(when (= 1 1.0)
(display "1")
(display "2")) @result{} @r{unspecified}
@print{} 12
-
@end example
@deffn syntax unless @svar{test} @svar{expression@sub{1}} @svar{expression@sub{2}}@dots{}
@@ -1783,7 +1742,6 @@ environment, and the values of the last expression of @svar{body} are
returned. Each binding of a @svar{variable} has @svar{body} as its region.
@example
-
(let ((x 2) (y 3))
(* x y)) @result{} 6
@@ -1791,7 +1749,6 @@ returned. Each binding of a @svar{variable} has @svar{body} as its region.
(let ((x 7)
(z (+ x y)))
(* z x))) @result{} 35
-
@end example
See also ``named @code{let},'' @ref{Iteration}.
@@ -1816,12 +1773,10 @@ the second binding is done in an environment in which the first binding is
visible, and so on. The @svar{variable}s need not be distinct.
@example
-
(let ((x 2) (y 3))
(let* ((x 7)
(z (+ x y)))
(* z x))) @result{} 70
-
@end example
@end deffn
@@ -1848,7 +1803,6 @@ letrec expression as its region, making it possible to define mutually
recursive procedures.
@example
-
(letrec ((even?
(lambda (n)
(if (zero? n)
@@ -1861,7 +1815,6 @@ recursive procedures.
(even? (- n 1))))))
(even? 88))
@result{} #t
-
@end example
One restriction on @code{letrec} is very important: if it is not possible to
@@ -1902,7 +1855,6 @@ is an error. Another restriction is that it is an error to invoke the
continuation of an @svar{init} more than once.
@example
-
;; Returns the arithmetic, geometric, and
;; harmonic means of a nested list of numbers
(define (means ton)
@@ -1922,7 +1874,6 @@ continuation of an @svar{init} more than once.
(values (mean values values)
(mean exp log)
(mean / /))))
-
@end example
Evaluating @code{(means '(3 (1 4)))} returns three values: 8/3,
@@ -1957,10 +1908,8 @@ It is an error if the @svar{formals} do not match the number of values
returned by the corresponding @svar{init}.
@example
-
(let-values (((root rem) (exact-integer-sqrt 32)))
(* root rem)) @result{} 35
-
@end example
@end deffn
@@ -1984,12 +1933,10 @@ right, with the region of the bindings of each @svar{formals} including the
bindings is visible and initialized, and so on.
@example
-
(let ((a 'a) (b 'b) (x 'x) (y 'y))
(let*-values (((a b) (values x y))
((x y) (values a b)))
(list a b x y))) @result{} (x y x y)
-
@end example
@end deffn
@@ -2018,7 +1965,6 @@ returned. This expression type is used to sequence side effects such as assignme
input and output.
@example
-
(define x 0)
(and (= x 0)
@@ -2029,7 +1975,6 @@ input and output.
(display (+ 4 1)))
@result{}
unspecified and prints 4 plus 1 equals 5
-
@end example
Note that there is a third form of begin used as a library declaration: see section 5.6.1.
@@ -2072,7 +2017,6 @@ A @svar{step} can be omitted, in which case the effect is the same as if (@svar{
@svar{variable}) had been written instead of (@svar{variable} @svar{init}).
@example
-
(do ((vec (make-vector 5))
(i 0 (+ i 1)))
((= i 5) vec)
@@ -2082,7 +2026,6 @@ A @svar{step} can be omitted, in which case the effect is the same as if (@svar{
(do ((x x (cdr x))
(sum 0 (+ sum (car x))))
((null? x) sum))) @result{} 25
-
@end example
syntax: (let @svar{variable} @svar{bindings} @svar{body})
@@ -2095,7 +2038,6 @@ Thus the execution of @svar{body} can be repeated by invoking the procedure name
@svar{variable}.
@example
-
(let loop ((numbers '(3 -2 1 6 -5))
(nonneg '())
(neg '()))
@@ -2109,7 +2051,6 @@ Thus the execution of @svar{body} can be repeated by invoking the procedure name
nonneg
(cons (car numbers) neg)))))
@result{} ((6 1 3) (-5 -2))
-
@end example
@node Delayed evaluation
@@ -2151,7 +2092,6 @@ values and exception handler of the call to force which first requested its valu
promise is not a promise, it may be returned unchanged.
@example
-
(force (delay (+ 1 2))) @result{} 3
(let ((p (delay (+ 1 2))))
(list (force p) (force p)))
@@ -2169,7 +2109,6 @@ promise is not a promise, it may be returned unchanged.
(head (tail (tail integers)))
@result{} 2
-
@end example
The following example is a mechanical transformation of a lazy
@@ -2180,7 +2119,6 @@ ever-growing sequence of pending promises does not exhaust available storage, be
force will in effect force such sequences iteratively.
@example
-
(define (stream-filter p? s)
(delay-force
(if (null? (force s))
@@ -2193,7 +2131,6 @@ force will in effect force such sequences iteratively.
(head (tail (tail (stream-filter odd? integers))))
@result{} 5
-
@end example
The following examples are not intended to illustrate good
@@ -2202,7 +2139,6 @@ written in the functional style. However, they do illustrate the property that o
is computed for a promise, no matter how many times it is forced.
@example
-
(define count 0)
(define p
(delay (begin (set! count (+ count 1))
@@ -2215,7 +2151,6 @@ p @result{} a promise
p @result{} a promise, still
(begin (set! x 10)
(force p)) @result{} 6
-
@end example
Various extensions to this semantics of delay, force and delay-force
@@ -2235,11 +2170,9 @@ are supported in some implementations:
force them.
@example
-
(+ (delay (* 3 7)) 13) @result{} unspecified
(car
(list (delay (* 3 7)) 13)) @result{} a promise
-
@end example
@end deffn
@@ -2312,7 +2245,6 @@ Parameter objects can be used to specify configurable settings for a computation
without the need to pass the value to every procedure in the call chain explicitly.
@example
-
(define radix
(make-parameter
10
@@ -2332,7 +2264,6 @@ without the need to pass the value to every procedure in the call chain explicit
(parameterize ((radix 0))
(f 12)) @result{} error
-
@end example
@node Exception handling
@@ -2356,7 +2287,6 @@ of the guard expression.
See section 6.11 for a more complete discussion of exceptions.
@example
-
(guard (condition
((assq 'a condition) => cdr)
((assq 'b condition)))
@@ -2368,7 +2298,6 @@ See section 6.11 for a more complete discussion of exceptions.
((assq 'b condition)))
(raise (list (cons 'b 23))))
@result{} (b . 23)
-
@end example
@node Quasiquotation
@@ -2398,7 +2327,6 @@ an explicit unquote or to put whitespace after the comma, to avoid colliding wit
comma at-sign sequence.
@example
-
`(list ,(+ 1 2) 4) @result{} (list 3 4)
(let ((name 'a)) `(list ,name ',name))
@result{} (list a (quote a))
@@ -2411,7 +2339,6 @@ comma at-sign sequence.
(let ((foo '(foo bar)) (@@baz 'baz))
`(list ,@@foo , @@baz))
@result{} (list foo bar baz)
-
@end example
Quasiquote expressions can be nested. Substitutions are made only
@@ -2420,14 +2347,12 @@ quasiquote. The nesting level increases by one inside each successive quasiquota
decreases by one inside each unquotation.
@example
-
`(a `(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f)
@result{} (a `(b ,(+ 1 2) ,(foo 4 d) e) f)
(let ((name1 'x)
(name2 'y))
`(a `(b ,,name1 ,',name2 d) e))
@result{} (a `(b ,x ,'y d) e)
-
@end example
A quasiquote expression may return either newly allocated, mutable
@@ -2437,21 +2362,17 @@ Thus, @code{(let ((a 3)) `((1 2) ,a ,4 ,'five 6))} may be treated as equivalent
expressions:
@example
-
`((1 2) 3 4 five 6)
(let ((a 3))
(cons '(1 2)
(cons a (cons 4 (cons 'five '(6))))))
-
@end example
However, it is not equivalent to this expression:
@example
-
(let ((a 3)) (list (list 1 2) a 4 'five 6))
-
@end example
The two notations `@svar{qq template} and (quasiquote <qq
@@ -2460,13 +2381,11 @@ template>) are identical in all respects. ,@svar{expression} is identical to (un
write procedure may output either format.
@example
-
(quasiquote (list (unquote (+ 1 2)) 4))
@result{} (list 3 4)
'(quasiquote (list (unquote (+ 1 2)) 4))
@result{} `(list ,(+ 1 2) 4)
i.e., (quasiquote (list (unquote (+ 1 2)) 4))
-
@end example
It is an error if any of the identifiers quasiquote, unquote, or unquote-splicing appear in
@@ -2492,7 +2411,6 @@ results of the procedure call.
It is an error for the arguments not to agree with the @svar{formals} of any @svar{clause}.
@example
-
(define range
(case-lambda
((e) (range 0 e))
@@ -2502,7 +2420,6 @@ It is an error for the arguments not to agree with the @svar{formals} of any @sv
(range 3) @result{} (0 1 2)
(range 3 5) @result{} (3 4)
-
@end example
@node Macros
@@ -2574,7 +2491,6 @@ the @svar{keyword}s, bound to the specified transformers. Each binding of a @sva
@svar{body} as its region.
@example
-
(let-syntax ((given-that (syntax-rules ()
((given-that test stmt1 stmt2 ...)
(if test
@@ -2588,7 +2504,6 @@ the @svar{keyword}s, bound to the specified transformers. Each binding of a @sva
(let-syntax ((m (syntax-rules () ((m) x))))
(let ((x 'inner))
(m)))) @result{} outer
-
@end example
syntax: (letrec-syntax @svar{bindings} @svar{body})
@@ -2603,7 +2518,6 @@ can transcribe expressions into uses of the macros introduced by the letrec-synt
expression.
@example
-
(letrec-syntax
((my-or (syntax-rules ()
((my-or) #f)
@@ -2622,7 +2536,6 @@ expression.
(let temp)
(if y)
y))) @result{} 7
-
@end example
@node Pattern language
@@ -2746,7 +2659,6 @@ within @svar{template} are treated as ordinary identifiers. In particular, the t
expand into code containing ellipses.
@example
-
(define-syntax be-like-begin
(syntax-rules ()
((be-like-begin name)
@@ -2757,17 +2669,14 @@ expand into code containing ellipses.
(be-like-begin sequence)
(sequence 1 2 3 4) @result{} 4
-
@end example
As an example, if let and cond are defined as in section 7.3 then
they are hygienic (as required) and the following is not an error.
@example
-
(let ((=> #f))
(cond (#t => 'ok))) @result{} ok
-
@end example
The macro transformer for cond recognizes @code{=>} as a local
@@ -2776,20 +2685,16 @@ variable, and hence an expression, and not as the base identifier
keyword. Thus the example expands into
@example
-
(let ((=> #f))
(if #t (begin => 'ok)))
-
@end example
instead of
@example
-
(let ((=> #f))
(let ((temp #t))
(if temp ('ok temp))))
-
@end example
which would result in an invalid procedure call.
@@ -2808,7 +2713,6 @@ information. Applications cannot count on being able to catch syntax errors with
exception handlers or guards.
@example
-
(define-syntax simple-let
(syntax-rules ()
((_ (head ... ((x . y) val) . tail)
@@ -2819,7 +2723,6 @@ exception handlers or guards.
((_ ((name val) ...) body1 body2 ...)
((lambda (name ...) body1 body2 ...)
val ...))))
-
@end example
@node Program structure
@@ -2926,10 +2829,8 @@ them. The simplest kind of variable definition takes one of the following forms:
lambda expression). This form is equivalent to
@example
-
(define @svar{variable}
(lambda (@svar{formals}) @svar{body})).
-
@end example
@@ -2938,10 +2839,8 @@ them. The simplest kind of variable definition takes one of the following forms:
@svar{Formal} is a single variable. This form is equivalent to
@example
-
(define @svar{variable}
(lambda @svar{formal} @svar{body})).
-
@end example
@menu
@@ -2962,13 +2861,11 @@ However, if @svar{variable} is not bound, or is a syntactic keyword, then the de
error to perform a set! on an unboundvariable.
@example
-
(define add3
(lambda (x) (+ x 3)))
(add3 3) @result{} 6
(define first car)
(first '(1 2)) @result{} 1
-
@end example
@node Internal definitions
@@ -2983,12 +2880,10 @@ definitions described above. The variables defined by internal definitions are l
the entire @svar{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))) @result{} 45
-
@end example
An expanded @svar{body} containing internal definitions can always
@@ -2996,12 +2891,10 @@ be converted into a completely equivalent letrec* expression. For example, the l
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))))
-
@end example
Just as for the equivalent letrec* expression, it is an error if it is not
@@ -3030,14 +2923,12 @@ the same way that the @svar{formals} in a lambda expression are matched to the a
a procedure call.
@example
-
(define-values (x y) (exact-integer-sqrt 17))
(list x y) @result{} (4 1)
(let ()
(define-values (x y) (values 1 2))
(+ x y)) @result{} 3
-
@end example
@node Syntax definitions
@@ -3059,7 +2950,6 @@ syntax keyword before its corresponding definition is an error. In particular, a
precedes an inner definition will not apply an outer definition.
@example
-
(let ((x 1) (y 2))
(define-syntax swap!
(syntax-rules ()
@@ -3069,7 +2959,6 @@ precedes an inner definition will not apply an outer definition.
(set! b tmp)))))
(swap! x y)
(list x y)) @result{} (2 1)
-
@end example
Macros can expand into definitions in any context that permits them. However, it is an
@@ -3081,7 +2970,6 @@ boundary between the internal definitions and the expressions of the body it bel
For example, the following are errors:
@example
-
(define define 3)
(begin (define begin list))
@@ -3096,7 +2984,6 @@ For example, the following are errors:
(foo (plus x y) (+ x y))
(define foo x)
(plus foo x)))
-
@end example
@node Record-type definitions
@@ -3151,20 +3038,17 @@ An instance of define-record-type is equivalent to the following definitions:
For instance, the following record-type definition
@example
-
(define-record-type @svar{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 @svar{pare}.
@example
-
(pare? (kons 1 2)) @result{} #t
(pare? (cons 1 2)) @result{} #f
(kar (kons 1 2)) @result{} 1
@@ -3172,7 +3056,6 @@ and pare? to be a predicate for instances of @svar{pare}.
(let ((k (kons 1 2)))
(set-kar! k 3)
(kar k)) @result{} 3
-
@end example
@node Libraries
@@ -3280,7 +3163,6 @@ small main program [16]. If the main program is entered into a REPL, it is not n
import the base library.
@example
-
(define-library (example grid)
(export make rows cols ref each
(rename put! set!))
@@ -3368,7 +3250,6 @@ import the base library.
;; Run for 80 iterations.
(life grid 80)
-
@end example
@node The REPL
@@ -3545,7 +3426,6 @@ The @code{eqv?} procedure returns #f if:
different side effects) for some arguments.
@example
-
(eqv? 'a 'a) @result{} #t
(eqv? 'a 'b) @result{} #f
(eqv? 2 2) @result{} #t
@@ -3559,7 +3439,6 @@ The @code{eqv?} procedure returns #f if:
(let ((p (lambda (x) x)))
(eqv? p p)) @result{} #t
(eqv? #f 'nil) @result{} #f
-
@end example
The following examples illustrate cases in which the above rules
@@ -3567,7 +3446,6 @@ do not fully specify the behavior of @code{eqv?}. All that can be said about suc
value returned by @code{eqv?} must be a boolean.
@example
-
(eqv? "" "") @result{} unspecified
(eqv? '#() '#()) @result{} unspecified
(eqv? (lambda (x) x)
@@ -3576,7 +3454,6 @@ value returned by @code{eqv?} must be a boolean.
(lambda (y) y)) @result{} unspecified
(eqv? 1.0e0 1.0f0) @result{} unspecified
(eqv? +nan.0 +nan.0) @result{} unspecified
-
@end example
Note that (@code{eqv?} 0.0 -0.0) will return #f if negative zero
@@ -3590,7 +3467,6 @@ value or side effects of the procedures. However, @code{eqv?} may or may not det
equivalence.
@example
-
(define gen-counter
(lambda ()
(let ((n 0))
@@ -3617,7 +3493,6 @@ equivalence.
(g (lambda () (if (eqv? f g) 'g 'both))))
(eqv? f g))
@result{} #f
-
@end example
Since it is an error to modify constant objects (those returned by literal
@@ -3626,13 +3501,11 @@ appropriate. Thus the value of @code{eqv?} on constants is sometimes
implementation-dependent.
@example
-
(eqv? '(a) '(a)) @result{} unspecified
(eqv? "a" "a") @result{} unspecified
(eqv? '(b) (cdr '(a b))) @result{} unspecified
(let ((x '(a)))
(eqv? x x)) @result{} #t
-
@end example
The above definition of @code{eqv?} allows implementations latitude in
@@ -3660,7 +3533,6 @@ either true or false. On empty strings, empty vectors, and empty bytevectors, @c
behave differently from eqv?.
@example
-
(eq? 'a 'a) @result{} #t
(eq? '(a) '(a)) @result{} unspecified
(eq? (list 'a) (list 'a)) @result{} #f
@@ -3678,7 +3550,6 @@ behave differently from eqv?.
(eq? x x)) @result{} #t
(let ((p (lambda (x) x)))
(eq? p p)) @result{} #t
-
@end example
Rationale: It will usually be possible to implement @code{eq?} much more efficiently than
@@ -3700,7 +3571,6 @@ other cases, @code{equal?} may return either #t or #f. Even if its arguments are
structures, @code{equal?} must always terminate.
@example
-
(equal? 'a 'a) @result{} #t
(equal? '(a) '(a)) @result{} #t
(equal? '(a (b) c)
@@ -3713,7 +3583,6 @@ structures, @code{equal?} must always terminate.
'#2=(a b a b . #2#)) @result{} #t
(equal? (lambda (x) x)
(lambda (y) y)) @result{} unspecified
-
@end example
Note: A rule of thumb is that objects are generally equal? if they print the same.
@@ -4036,7 +3905,6 @@ x)).
The numbers +inf.0, -inf.0, and +nan.0 are real but not rational.
@example
-
(complex? 3+4i) @result{} #t
(complex? 3) @result{} #t
(real? 3) @result{} #t
@@ -4052,7 +3920,6 @@ The numbers +inf.0, -inf.0, and +nan.0 are real but not rational.
(integer? 3+0i) @result{} #t
(integer? 3.0) @result{} #t
(integer? 8/4) @result{} #t
-
@end example
Note: The behavior of these type predicates on inexact numbers is unreliable, since
@@ -4073,11 +3940,9 @@ These numerical predicates provide tests for the exactness of a quantity. For an
number, precisely one of these predicates is true.
@example
-
(exact? 3.0) @result{} #f
(exact? #e3.0) @result{} #t
(inexact? 3.) @result{} #t
-
@end example
@end deffn
@@ -4089,11 +3954,9 @@ Returns #t if
z is both exact and an integer; otherwise returns #f.
@example
-
(exact-integer? 32) @result{} #t
(exact-integer? 32.0) @result{} #f
(exact-integer? 32/5) @result{} #f
-
@end example
@end deffn
@@ -4104,11 +3967,9 @@ on complex numbers if their real and imaginary parts are both finite. Otherwise
#f.
@example
-
(finite? 3) @result{} #t
(finite? +inf.0) @result{} #f
(finite? 3.0+inf.0i) @result{} #f
-
@end example
@end deffn
@@ -4118,12 +3979,10 @@ The infinite? procedure returns #t on the real numbers +inf.0 and -inf.0, and on
numbers if their real or imaginary parts or both are infinite. Otherwise it returns #f.
@example
-
(infinite? 3) @result{} #f
(infinite? +inf.0) @result{} #t
(infinite? +nan.0) @result{} #f
(infinite? 3.0+inf.0i) @result{} #t
-
@end example
@end deffn
@@ -4133,12 +3992,10 @@ 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) @result{} #t
(nan? 32) @result{} #f
(nan? +nan.0+5.0i) @result{} #t
(nan? 1+2i) @result{} #f
-
@end example
@end deffn
@@ -4185,10 +4042,8 @@ See note above.
These procedures return the maximum or minimum of their arguments.
@example
-
(max 3 4) @result{} 4 ; exact
(max 3.9 4) @result{} 4.0 ; inexact
-
@end example
Note: If any argument is inexact, then the result will also be inexact (unless the
@@ -4205,13 +4060,11 @@ report a violation of an implementation restriction.
These procedures return the sum or product of their arguments.
@example
-
(+ 3 4) @result{} 7
(+ 3) @result{} 3
(+) @result{} 0
(* 4) @result{} 4
(*) @result{} 1
-
@end example
@end deffn
@@ -4229,13 +4082,11 @@ argument is an exact zero, an implementation may return an exact zero unless one
other arguments is a NaN.
@example
-
(- 3 4) @result{} -1
(- 3 4 5) @result{} -6
(- 3) @result{} -3
(/ 3 4 5) @result{} 3/20
(/ 3) @result{} 1/3
-
@end example
@end deffn
@@ -4244,9 +4095,7 @@ other arguments is a NaN.
The abs procedure returns the absolute value of its argument.
@example
-
(abs -7) @result{} 7
-
@end example
@end deffn
@@ -4354,7 +4203,6 @@ provided all numbers involved in that computation are exact.
Examples:
@example
-
(floor/ 5 2) @result{} 2 1
(floor/ -5 2) @result{} -3 1
(floor/ 5 -2) @result{} -3 -1
@@ -4364,7 +4212,6 @@ Examples:
(truncate/ 5 -2) @result{} -2 1
(truncate/ -5 -2) @result{} 2 -1
(truncate/ -5.0 -2) @result{} 2.0 -1.0
-
@end example
@end deffn
@@ -4386,13 +4233,11 @@ These procedures return the greatest common divisor or least common multiple of
arguments. The result is always non-negative.
@example
-
(gcd 32 -36) @result{} 4
(gcd) @result{} 0
(lcm 32 -36) @result{} 288
(lcm 32.0 -36) @result{} 288.0 ; inexact
(lcm) @result{} 1
-
@end example
@end deffn
@@ -4404,12 +4249,10 @@ 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)) @result{} 3
(denominator (/ 6 4)) @result{} 2
(denominator
(inexact (/ 6 4))) @result{} 2.0
-
@end example
@end deffn
@@ -4441,7 +4284,6 @@ 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) @result{} -5.0
(ceiling -4.3) @result{} -4.0
(truncate -4.3) @result{} -4.0
@@ -4454,7 +4296,6 @@ procedure. If the argument is infinite or a NaN, then it is returned.
(round 7/2) @result{} 4 ; exact
(round 7) @result{} 7
-
@end example
@end deffn
@@ -4472,11 +4313,9 @@ that interval (the simpler 2/5 lies between 2/7 and 3/5). Note that 0 = 0/1 is t
rational of all.
@example
-
(rationalize
(exact .3) 1/10) @result{} 1/3 ; exact
(rationalize .3 1/10) @result{} #i1/3 ; inexact
-
@end example
@end deffn
@@ -4561,10 +4400,8 @@ argument.
Returns the square of z. This is equivalent to @code{(* z z)}.
@example
-
(square 42) @result{} 1764
(square 2.0) @result{} 4.0
-
@end example
@end deffn
@@ -4576,10 +4413,8 @@ z. The result will have either a positive real part, or a zero real part and a n
imaginary part.
@example
-
(sqrt 9) @result{} 3
(sqrt -1) @result{} +i
-
@end example
@end deffn
@@ -4592,10 +4427,8 @@ k = s2 + r and
k < (s + 1)2.
@example
-
(exact-integer-sqrt 4) @result{} 2 0
(exact-integer-sqrt 5) @result{} 2 1
-
@end example
@end deffn
@@ -4641,14 +4474,12 @@ z be a complex number such that
Then all of
@example
-
(make-rectangular x1 x2) @result{} z
(make-polar x3 x4) @result{} z
(real-part z) @result{} x1
(imag-part z) @result{} x2
(magnitude z) @result{} |x3|
(angle z) @result{} xangle
-
@end example
are true, where −π≤xangle ≤π with xangle =
@@ -4709,14 +4540,12 @@ The procedure number->string takes a number and a radix and returns as a string
external representation of the given number in the given radix such that
@example
-
(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,
@@ -4770,11 +4599,9 @@ signaled due to the content of
string.
@example
-
(string->number "100") @result{} 100
(string->number "100" 16) @result{} 256
(string->number "1e2") @result{} 100.0
-
@end example
Note: The domain of string->number may be restricted by implementations in the
@@ -4815,11 +4642,9 @@ Boolean constants evaluate to themselves, so they do not need to be quoted in
programs.
@example
-
#t @result{} #t
#f @result{} #f
'#f @result{} #f
-
@end example
@deffn procedure not obj
@@ -4829,7 +4654,6 @@ The not procedure returns #t if
obj is false, and returns #f otherwise.
@example
-
(not #t) @result{} #f
(not 3) @result{} #f
(not (list 3)) @result{} #f
@@ -4837,7 +4661,6 @@ obj is false, and returns #f otherwise.
(not '()) @result{} #f
(not (list)) @result{} #f
(not 'nil) @result{} #f
-
@end example
@end deffn
@@ -4848,11 +4671,9 @@ The boolean? predicate returns #t if
obj is either #t or #f and returns #f otherwise.
@example
-
(boolean? #f) @result{} #t
(boolean? 0) @result{} #f
(boolean? '()) @result{} #f
-
@end example
@end deffn
@@ -5042,12 +4863,10 @@ pair.
These procedures are compositions of car and cdr as follows:
@example
-
(define (caar x) (car (car x)))
(define (cadr x) (car (cdr x)))
(define (cdar x) (cdr (car x)))
(define (cddr x) (cdr (cdr x)))
-
@end example
@end deffn
@@ -5061,9 +4880,7 @@ These twenty-four procedures are further compositions of car and cdr on the same
principles. For example, caddr could be defined by
@example
-
(define caddr (lambda (x) (car (cdr (cdr x))))).
-
@end example
Arbitrary compositions up to four deep are
@@ -5086,14 +4903,12 @@ obj is a list. Otherwise, it returns #f. By definition, all lists have finite le
terminated by the empty list.
@example
-
(list? '(a b c)) @result{} #t
(list? '()) @result{} #t
(list? '(a . b)) @result{} #f
(let ((x (list 'a)))
(set-cdr! x x)
(list? x)) @result{} #f
-
@end example
@end deffn
@@ -5107,9 +4922,7 @@ k elements. If a second argument is given, then each element is initialized to
fill. Otherwise the initial contents of each element is unspecified.
@example
-
(make-list 2 3) @result{} (3 3)
-
@end example
@end deffn
@@ -5118,10 +4931,8 @@ fill. Otherwise the initial contents of each element is unspecified.
Returns a newly allocated list of its arguments.
@example
-
(list 'a (+ 3 4) 'c) @result{} (a 7 c)
(list) @result{} ()
-
@end example
@end deffn
@@ -5130,11 +4941,9 @@ Returns a newly allocated list of its arguments.
Returns the length of @var{list}.
@example
-
(length '(a b c)) @result{} 3
(length '(a (b) (c d e))) @result{} 3
(length '()) @result{} 0
-
@end example
@end deffn
@@ -5150,14 +4959,12 @@ allocated, except that it shares structure with the last argument. An
improper list results if the last argument is not a proper list.
@example
-
(append '(x) '(y)) @result{} (x y)
(append '(a) '(b c d)) @result{} (a b c d)
(append '(a (b)) '((c))) @result{} (a (b) (c))
(append '(a b) '(c . d)) @result{} (a b c . d)
(append '() 'a) @result{} a
-
@end example
@end deffn
@@ -5167,11 +4974,9 @@ Returns a newly allocated list consisting of the elements of
@var{list} in reverse order.
@example
-
(reverse '(a b c)) @result{} (c b a)
(reverse '(a (b c) d (e (f))))
@result{} ((e (f)) d (b c) a)
-
@end example
@end deffn
@@ -5190,13 +4995,11 @@ list obtained by omitting the first
k elements. The list-tail procedure could be defined by
@example
-
(define list-tail
(lambda (x k)
(if (zero? k)
x
(list-tail (cdr x) (- k 1)))))
-
@end example
@end deffn
@@ -5221,12 +5024,10 @@ list
k).)
@example
-
(list-ref '(a b c d) 2) @result{} c
(list-ref '(a b c d)
(exact (round 1.8)))
@result{} c
-
@end example
@end deffn
@@ -5247,7 +5048,6 @@ k of
list.
@example
-
(let ((ls (list 'one 'two 'five!)))
(list-set! ls 2 'three)
ls)
@@ -5255,7 +5055,6 @@ list.
(list-set! '(0 1 2) 1 "oops")
@result{} error ; constant list
-
@end example
@end deffn
@@ -5291,7 +5090,6 @@ list, while memv uses eqv? and member uses
compare, if given, and equal? otherwise.
@example
-
(memq 'a '(a b c)) @result{} (a b c)
(memq 'b '(a b c)) @result{} (b c)
(memq 'a '(b c d)) @result{} #f
@@ -5303,7 +5101,6 @@ compare, if given, and equal? otherwise.
string-ci=?) @result{} ("b" "c")
(memq 101 '(100 101 102)) @result{} unspecified
(memv 101 '(100 101 102)) @result{} (101 102)
-
@end example
@end deffn
@@ -5334,7 +5131,6 @@ alist, while assv uses eqv? and assoc uses
compare if given and equal? otherwise.
@example
-
(define e '((a 1) (b 2) (c 3)))
(assq 'a e) @result{} (a 1)
(assq 'b e) @result{} (b 2)
@@ -5349,7 +5145,6 @@ compare if given and equal? otherwise.
@result{} unspecified
(assv 5 '((2 3) (5 7) (11 13)))
@result{} (5 7)
-
@end example
Rationale: Although they are often used as predicates, memq, memv, member, assq,
@@ -5374,13 +5169,11 @@ obj which is not a list is returned unchanged. It is an error if
obj is a circular list.
@example
-
(define a '(1 8 2 8)) ; a may be immutable
(define b (list-copy a))
(set-car! b 3) ; b is mutable
b @result{} (3 8 2 8)
a @result{} (1 8 2 8)
-
@end example
@end deffn
@@ -5410,14 +5203,12 @@ Returns #t if
obj is a symbol, otherwise returns #f.
@example
-
(symbol? 'foo) @result{} #t
(symbol? (car '(a b))) @result{} #t
(symbol? "bar") @result{} #f
(symbol? 'nil) @result{} #t
(symbol? '()) @result{} #f
(symbol? #f) @result{} #f
-
@end example
@end deffn
@@ -5437,14 +5228,12 @@ symbol as a string, but without adding escapes. It is an error to apply mutation
procedures like string-set! to strings returned by this procedure.
@example
-
(symbol->string 'flying-fish)
@result{} "flying-fish"
(symbol->string 'Martin) @result{} "Martin"
(symbol->string
(string->symbol "Malvina"))
@result{} "Malvina"
-
@end example
@end deffn
@@ -5456,7 +5245,6 @@ string. This procedure can create symbols with names containing special characte
would require escaping when written, but does not interpret escapes in its input.
@example
-
(string->symbol "mISSISSIppi")
@result{}mISSISSIppi
(eqv? 'bitBlt (string->symbol "bitBlt"))
@@ -5469,7 +5257,6 @@ would require escaping when written, but does not interpret escapes in its input
(symbol->string
(string->symbol "K. Harper, M.D.")))
@result{} #t
-
@end example
@end deffn
@@ -5578,12 +5365,10 @@ This procedure returns the numeric value (0 to 9) of its argument if it is a num
(that is, if char-numeric? returns #t), or #f on any other character.
@example
-
(digit-value #\3) @result{} 3
(digit-value #\x0664) @result{} 4
(digit-value #\x0AE6) @result{} 0
(digit-value #\x0EA6) @result{} #f
-
@end example
@end deffn
@@ -5767,7 +5552,6 @@ k of
string. There is no requirement for this procedure to execute in constant time.
@example
-
(define (f) (make-string 3 #\*))
(define (g) "***")
(string-set! (f) 0 #\?) @result{} unspecified
@@ -5775,7 +5559,6 @@ string. There is no requirement for this procedure to execute in constant time.
(string-set! (symbol->string 'immutable)
0
#\?) @result{} error
-
@end example
@end deffn
@@ -5926,12 +5709,10 @@ string and then into the destination. This can be achieved without allocating st
making sure to copy in the correct direction in such circumstances.
@example
-
(define a "12345")
(define b (string-copy "abcde"))
(string-copy! b 1 a 0 2)
b @result{} "a12de"
-
@end example
@end deffn
@@ -5998,9 +5779,7 @@ Returns a newly allocated vector whose elements contain the given arguments. It
analogous to list.
@example
-
(vector 'a 'b 'c) @result{} #(a b c)
-
@end example
@end deffn
@@ -6026,7 +5805,6 @@ k of
vector.
@example
-
(vector-ref '#(1 1 2 3 5 8 13 21)
5)
@result{} 8
@@ -6034,7 +5812,6 @@ vector.
(exact
(round (* 2 (acos -1)))))
@result{} 13
-
@end example
@end deffn
@@ -6055,7 +5832,6 @@ k of
vector.
@example
-
(let ((vec (vector 0 '(2 2 2 2) "Anna")))
(vector-set! vec 1 '("Sue" "Sue"))
vec)
@@ -6063,7 +5839,6 @@ vector.
(vector-set! '#(0 1 2) 1 "doe")
@result{} error ; constant vector
-
@end example
@end deffn
@@ -6087,14 +5862,12 @@ list.
In both procedures, order is preserved.
@example
-
(vector->list '#(dah dah didah))
@result{} (dah dah didah)
(vector->list '#(dah dah didah) 1 2)
@result{} (dah)
(list->vector '(dididit dah))
@result{} #(dididit dah)
-
@end example
@end deffn
@@ -6132,11 +5905,9 @@ end.
In both procedures, order is preserved.
@example
-
(string->vector "ABC") @result{} #(#\A #\B #\C)
(vector->string
#(#\1 #\2 #\3) @result{} "123"
-
@end example
@end deffn
@@ -6154,14 +5925,12 @@ end. The elements of the new vector are the same (in the sense of eqv?) as the e
of the old.
@example
-
(define a #(1 8 2 8)) ; a may be immutable
(define b (vector-copy a))
(vector-set! b 0 3) ; b is mutable
b @result{} #(3 8 2 8)
(define c (vector-copy b 1 3))
c @result{} #(8 2)
-
@end example
@end deffn
@@ -6199,12 +5968,10 @@ vector and then into the destination. This can be achieved without allocating st
making sure to copy in the correct direction in such circumstances.
@example
-
(define a (vector 1 2 3 4 5))
(define b (vector 10 20 30 40 50))
(vector-copy! b 1 a 0 2)
b @result{} #(10 1 2 40 50)
-
@end example
@end deffn
@@ -6214,10 +5981,8 @@ Returns a newly allocated vector whose elements are the concatenation of the ele
of the given vectors.
@example
-
(vector-append #(a b c) #(d e f))
@result{} #(a b c d e f)
-
@end example
@end deffn
@@ -6236,12 +6001,10 @@ start and
end.
@example
-
(define a (vector 1 2 3 4 5))
(vector-fill! a 'smash 2 4)
a
@result{} #(1 2 smash smash 5)
-
@end example
@end deffn
@@ -6285,9 +6048,7 @@ byte is given, then all elements of the bytevector are initialized to
byte, otherwise the contents of each element are unspecified.
@example
-
(make-bytevector 2 12) @result{} #u8(12 12)
-
@end example
@end deffn
@@ -6296,10 +6057,8 @@ byte, otherwise the contents of each element are unspecified.
Returns a newly allocated bytevector containing its arguments.
@example
-
(bytevector 1 3 5 1 3 5) @result{} #u8(1 3 5 1 3 5)
(bytevector) @result{} #u8()
-
@end example
@end deffn
@@ -6325,11 +6084,9 @@ kth byte of
bytevector.
@example
-
(bytevector-u8-ref '#u8(1 1 2 3 5 8 13 21)
5)
@result{} 8
-
@end example
@end deffn
@@ -6350,12 +6107,10 @@ kth byte of
bytevector.
@example
-
(let ((bv (bytevector 1 2 3 4)))
(bytevector-u8-set! bv 1 3)
bv)
@result{} #u8(1 3 3 4)
-
@end example
@end deffn
@@ -6372,10 +6127,8 @@ start and
end.
@example
-
(define a #u8(1 2 3 4 5))
(bytevector-copy a 2 4)) @result{} #u8(3 4)
-
@end example
@end deffn
@@ -6413,12 +6166,10 @@ bytevector and then into the destination. This can be achieved without allocatin
by making sure to copy in the correct direction in such circumstances.
@example
-
(define a (bytevector 1 2 3 4 5))
(define b (bytevector 10 20 30 40 50))
(bytevector-copy! b 1 a 0 2)
b @result{} #u8(10 1 2 40 50)
-
@end example
Note: This procedure appears in R6RS, but places the source before the destination,
@@ -6431,10 +6182,8 @@ Returns a newly allocated bytevector whose elements are the concatenation of the
elements in the given bytevectors.
@example
-
(bytevector-append #u8(0 1 2) #u8(3 4 5))
@result{} #u8(0 1 2 3 4 5)
-
@end example
@end deffn
@@ -6463,10 +6212,8 @@ start and
end and returns the corresponding bytevector.
@example
-
(utf8->string #u8(#x41)) @result{} "A"
(string->utf8 "λ") @result{} #u8(#xCE #xBB)
-
@end example
@end deffn
@@ -6485,7 +6232,6 @@ Returns #t if
obj is a procedure, otherwise returns #f.
@example
-
(procedure? car) @result{} #t
(procedure? 'car) @result{} #f
(procedure? (lambda (x) (* x x)))
@@ -6494,7 +6240,6 @@ obj is a procedure, otherwise returns #f.
@result{} #f
(call-with-current-continuation procedure?)
@result{} #t
-
@end example
@end deffn
@@ -6505,7 +6250,6 @@ The apply procedure calls
proc with the elements of the list @code{(append (list arg1 @dots{}) args)} as the actual arguments.
@example
-
(apply + (list 3 4)) @result{} 7
(define compose
@@ -6514,7 +6258,6 @@ proc with the elements of the list @code{(append (list arg1 @dots{}) args)} as t
(f (apply g args)))))
((compose sqrt *) 12 75) @result{} 30
-
@end example
@end deffn
@@ -6543,7 +6286,6 @@ lists is unspecified. If multiple returns occur from map, the values returned by
returns are not mutated.
@example
-
(map cadr '((a b) (d e) (g h)))
@result{} (b e h)
@@ -6560,7 +6302,6 @@ returns are not mutated.
'(a b))) @result{} (1 2)
or (2 1)
-
@end example
@end deffn
@@ -6586,7 +6327,6 @@ strings is unspecified. If multiple returns occur from string-map, the values re
earlier returns are not mutated.
@example
-
(string-map char-foldcase "AbdEgH")
@result{} "abdegh"
@@ -6603,7 +6343,6 @@ earlier returns are not mutated.
"studlycaps xxx"
"ululululul")
@result{} "StUdLyCaPs"
-
@end example
@end deffn
@@ -6628,7 +6367,6 @@ vectors is unspecified. If multiple returns occur from vector-map, the values re
earlier returns are not mutated.
@example
-
(vector-map cadr '#((a b) (d e) (g h)))
@result{} #(b e h)
@@ -6647,7 +6385,6 @@ earlier returns are not mutated.
'#(a b))) @result{} #(1 2)
or #(2 1)
-
@end example
@end deffn
@@ -6677,13 +6414,11 @@ It is an error for
proc to mutate any of the lists.
@example
-
(let ((v (make-vector 5)))
(for-each (lambda (i)
(vector-set! v i (* i i)))
'(0 1 2 3 4))
v) @result{} #(0 1 4 9 16)
-
@end example
@end deffn
@@ -6710,13 +6445,11 @@ the shortest string runs out. It is an error for
proc to mutate any of the strings.
@example
-
(let ((v '()))
(string-for-each
(lambda (c) (set! v (cons (char->integer c) v)))
"abcde")
v) @result{} (101 100 99 98 97)
-
@end example
@end deffn
@@ -6743,13 +6476,11 @@ the shortest vector runs out. It is an error for
proc to mutate any of the vectors.
@example
-
(let ((v (make-list 5)))
(vector-for-each
(lambda (i) (list-set! v i (* i i)))
'#(0 1 2 3 4))
v) @result{} (0 1 4 9 16)
-
@end example
@end deffn
@@ -6796,7 +6527,6 @@ there would be no need for a procedure with the power of
call-with-current-continuation.
@example
-
(call-with-current-continuation
(lambda (exit)
(for-each (lambda (x)
@@ -6820,7 +6550,6 @@ call-with-current-continuation.
(list-length '(1 2 3 4)) @result{} 4
(list-length '(a b . c)) @result{} #f
-
@end example
Rationale: A common use of call-with-current-continuation is for structured,
@@ -6849,11 +6578,9 @@ Delivers all of its arguments to its continuation. The values procedure might be
as follows:
@example
-
(define (values . things)
(call-with-current-continuation
(lambda (cont) (apply cont things))))
-
@end example
@end deffn
@@ -6869,13 +6596,11 @@ consumer procedure with those values as arguments. The continuation for the call
consumer is the continuation of the call to call-with-values.
@example
-
(call-with-values (lambda () (values 4 5))
(lambda (a b) b))
@result{} 5
(call-with-values * -) @result{} -1
-
@end example
@end deffn
@@ -6948,7 +6673,6 @@ before or
after is unspecified.
@example
-
(let ((path '())
(c #f))
(let ((add (lambda (s)
@@ -6967,7 +6691,6 @@ after is unspecified.
@result{} (connect talk1 disconnect
connect talk2 disconnect)
-
@end example
@end deffn
@@ -7005,7 +6728,6 @@ for the invocation of
thunk.
@example
-
(call-with-current-continuation
(lambda (k)
(with-exception-handler
@@ -7027,7 +6749,6 @@ thunk.
prints
something went wrong After printing,
the second example then raises another exception.
-
@end example
@end deffn
@@ -7054,7 +6775,6 @@ returns, then it will again become the current exception handler. If the handler
the values it returns become the values returned by the call to raise-continuable.
@example
-
(with-exception-handler
(lambda (con)
(cond
@@ -7068,7 +6788,6 @@ the values it returns become the values returned by the call to raise-continuabl
23)))
prints: should be a number
@result{} 65
-
@end example
@end deffn
@@ -7084,7 +6803,6 @@ message, as well as any
objs, known as the irritants. The procedure error-object? must return #t on such objects.
@example
-
(define (null-list? l)
(cond ((pair? l) #f)
((null? l) #t)
@@ -7092,7 +6810,6 @@ objs, known as the irritants. The procedure error-object? must return #t on such
(error
"null-list?: argument out of domain"
l))))
-
@end example
@end deffn
@@ -7205,7 +6922,6 @@ environment, provided the environment is not immutable. Implementations may exte
eval to allow other objects.
@example
-
(eval '(* 7 3) (environment '(scheme base)))
@result{} 21
@@ -7216,7 +6932,6 @@ eval to allow other objects.
(eval '(define foo 32)
(environment '(scheme base)))
@result{} error is signaled
-
@end example
@end deffn
@@ -7402,7 +7117,6 @@ Returns a string consisting of the characters that have been output to the port
the order they were output. If the result string is modified, the effect is unspecified.
@example
-
(parameterize
((current-output-port
(open-output-string)))
@@ -7413,7 +7127,6 @@ the order they were output. If the result string is modified, the effect is unsp
(get-output-string (current-output-port)))
@result{} "piece by piece by piece.\n"
-
@end example
@end deffn
@@ -7882,10 +7595,8 @@ get-environment-variable can't decode the value. It is also an error to mutate t
resulting string.
@example
-
(get-environment-variable "PATH")
@result{} "/usr/local/bin:/usr/bin:/bin"
-
@end example
@end deffn
@@ -7897,10 +7608,8 @@ strings. The order of the list is unspecified. It is an error to mutate any of t
or the alist itself.
@example
-
(get-environment-variables)
@result{} (("USER" . "root") ("HOME" . "/"))
-
@end example
@end deffn
@@ -7939,14 +7648,12 @@ Returns an exact integer representing the number of jiffies per SI second. This
an implementation-specified constant.
@example
-
(define (time-length)
(let ((list (make-list 100000))
(start (current-jiffy)))
(length list)
(/ (- (current-jiffy) start)
(jiffies-per-second))))
-
@end example
@end deffn
@@ -7956,14 +7663,12 @@ Returns a list of the feature identifiers which cond-expand treats as true. It i
modify this list. Here is an example of what features might return:
@example
-
(features) @result{}
(r7rs ratios exact-complex full-unicode
gnu-linux little-endian
fantastic-scheme
fantastic-scheme-1.0
space-ship-control-system)
-
@end example
@end deffn
@@ -8414,7 +8119,6 @@ quasiquote.
Conditional derived syntax types:
@example
-
(define-syntax cond
(syntax-rules (else =>)
((cond (else result1 result2 ...))
@@ -8500,13 +8204,11 @@ Conditional derived syntax types:
((unless test result1 result2 ...)
(if (not test)
(begin result1 result2 ...)))))
-
@end example
Binding constructs:
@example
-
(define-syntax let
(syntax-rules ()
((let ((name val) ...) body1 body2 ...)
@@ -8527,7 +8229,6 @@ Binding constructs:
(let ((name1 val1))
(let* ((name2 val2) ...)
body1 body2 ...)))))
-
@end example
The following letrec macro uses the symbol @svar{undefined} in place of an expression which
@@ -8537,7 +8238,6 @@ generate the temporary names needed to avoid specifying the order in which the v
are evaluated. This could also be accomplished by using an auxiliary macro.
@example
-
(define-syntax letrec
(syntax-rules ()
((letrec ((var1 init1) ...) body ...)
@@ -8664,7 +8364,6 @@ are evaluated. This could also be accomplished by using an auxiliary macro.
(syntax-rules ()
((begin exp ...)
((lambda () exp ...)))))
-
@end example
The following alternative expansion for begin does not make use of the ability to write
@@ -8672,7 +8371,6 @@ more than one expression in the body of a lambda expression. In any case, note t
these rules apply only if the body of the begin contains no definitions.
@example
-
(define-syntax begin
(syntax-rules ()
((begin exp)
@@ -8682,7 +8380,6 @@ these rules apply only if the body of the begin contains no definitions.
(lambda () exp1)
(lambda args
(begin exp2 ...))))))
-
@end example
The following syntax definition of do uses a trick to expand the variable clauses. As with
@@ -8690,7 +8387,6 @@ letrec above, an auxiliary macro would also work. The expression (if #f #f) is u
obtain an unspecific value.
@example
-
(define-syntax do
(syntax-rules ()
((do ((var init step ...) ...)
@@ -8713,72 +8409,57 @@ obtain an unspecific value.
x)
((do "step" x y)
y)))
-
@end example
Here is a possible implementation of delay, force and delay-force. We
define the expression
@example
-
(delay-force @svar{expression})
-
@end example
to have the same meaning as the procedure call
@example
-
(make-promise #f (lambda () @svar{expression}))
-
@end example
as follows
@example
-
(define-syntax delay-force
(syntax-rules ()
((delay-force expression)
(make-promise #f (lambda () expression)))))
-
@end example
and we define the expression
@example
-
(delay @svar{expression})
-
@end example
to have the same meaning as:
@example
-
(delay-force (make-promise #t @svar{expression}))
-
@end example
as follows
@example
-
(define-syntax delay
(syntax-rules ()
((delay expression)
(delay-force (make-promise #t expression)))))
-
@end example
where make-promise is defined as follows:
@example
-
(define make-promise
(lambda (done? proc)
(list (cons done? proc))))
-
@end example
Finally, we define force to call the procedure expressions in promises
@@ -8787,7 +8468,6 @@ non-lazy result (i.e. a value created by delay instead of delay-force)
is returned, as follows:
@example
-
(define (force promise)
(if (promise-done? promise)
(promise-value promise)
@@ -8795,13 +8475,11 @@ is returned, as follows:
(unless (promise-done? promise)
(promise-update! promise* promise))
(force promise))))
-
@end example
with the following promise accessors:
@example
-
(define promise-done?
(lambda (x) (car (car x))))
(define promise-value
@@ -8811,7 +8489,6 @@ with the following promise accessors:
(set-car! (car old) (promise-done? new))
(set-cdr! (car old) (promise-value new))
(set-car! new (car old))))
-
@end example
The following implementation of make-parameter and
@@ -8820,7 +8497,6 @@ implemented here as procedures, using two arbitrary unique objects @svar{param-s
@svar{param-convert}:
@example
-
(define (make-parameter init . o)
(let* ((converter
(if (pair? o) (car o) (lambda (x) x)))
@@ -8835,14 +8511,12 @@ implemented here as procedures, using two arbitrary unique objects @svar{param-s
converter)
(else
(error "bad parameter syntax"))))))
-
@end example
Then parameterize uses dynamic-wind to
dynamically rebind the associated value:
@example
-
(define-syntax parameterize
(syntax-rules ()
((parameterize ("step")
@@ -8869,14 +8543,12 @@ dynamically rebind the associated value:
()
((param value) ...)
body))))
-
@end example
The following implementation of guard depends on an auxiliary macro, here called
guard-aux.
@example
-
(define-syntax guard
(syntax-rules ()
((guard (var clause ...) e1 e2 ...)
@@ -8959,14 +8631,12 @@ guard-aux.
args)
(cl . rest))))))
(cl (params body0 ...) ...)))))))
-
@end example
This definition of cond-expand does not interact with the features procedure. It requires
that each feature identifier provided by the implementation be explicitly mentioned.
@example
-
(define-syntax cond-expand
;; Extend this to mention all feature ids and libraries
(syntax-rules (and or not else r7rs library scheme base)
@@ -9025,7 +8695,6 @@ that each feature identifier provided by the implementation be explicitly mentio
body ...)
more-clauses ...)
(cond-expand more-clauses ...))))
-
@end example
@node Appendices
@@ -9814,7 +9483,6 @@ length of the integration step.
The value returned by integrate-system is an infinite stream of system states.
@example
-
(define (integrate-system system-derivative
initial-state
h)
@@ -9824,7 +9492,6 @@ The value returned by integrate-system is an infinite stream of system states.
(delay (map-streams next
states)))))
states)))
-
@end example
The procedure runge-kutta-4 takes a function, f, that produces a system
@@ -9832,7 +9499,6 @@ derivative from a system state. It produces a function that takes a system state
produces a new system state.
@example
-
(define (runge-kutta-4 f h)
(let ((*h (scale-vector h))
(*2 (scale-vector 2))
@@ -9873,7 +9539,6 @@ produces a new system state.
(define (scale-vector s)
(elementwise (lambda (x) (* x s))))
-
@end example
The map-streams procedure is analogous to map: it
@@ -9881,11 +9546,9 @@ applies its first argument (a procedure) to all the elements of its second argum
stream).
@example
-
(define (map-streams f s)
(cons (f (head s))
(delay (map-streams f (tail s)))))
-
@end example
Infinite streams are implemented as pairs whose car
@@ -9893,11 +9556,9 @@ holds the first element of the stream and whose cdr holds a promise to deliver t
the stream.
@example
-
(define head car)
(define (tail stream)
(force (cdr stream)))
-
@end example
The following illustrates the use of integrate-system in integrating the system
@@ -9913,7 +9574,6 @@ The following illustrates the use of integrate-system in integrating the system
which models a damped oscillator.
@example
-
(define (damped-oscillator R L C)
(lambda (state)
(let ((Vc (vector-ref state 0))
@@ -9926,7 +9586,6 @@ which models a damped oscillator.
(damped-oscillator 10000 1000 .001)
'#(1 0)
.01))
-
@end example
@node References