2 @c This is part of the GNU Guile Reference Manual.
3 @c Copyright (C) 2010, 2011, 2012
4 @c Free Software Foundation, Inc.
5 @c See the file guile.texi for copying conditions.
11 @xref{R6RS Libraries}, for more information on how to define R6RS libraries, and
12 their integration with Guile modules.
15 * R6RS Incompatibilities:: Guile mostly implements R6RS.
16 * R6RS Standard Libraries:: Modules defined by the R6RS.
19 @node R6RS Incompatibilities
20 @subsection Incompatibilities with the R6RS
22 There are some incompatibilities between Guile and the R6RS. Some of
23 them are intentional, some of them are bugs, and some are simply
24 unimplemented features. Please let the Guile developers know if you
25 find one that is not on this list.
29 The R6RS specifies many situations in which a conforming implementation
30 must signal a specific error. Guile doesn't really care about that too
31 much---if a correct R6RS program would not hit that error, we don't
32 bother checking for it.
35 Multiple @code{library} forms in one file are not yet supported. This
36 is because the expansion of @code{library} sets the current module, but
37 does not restore it. This is a bug.
40 R6RS unicode escapes within strings are disabled by default, because
41 they conflict with Guile's already-existing escapes. The same is the
42 case for R6RS treatment of escaped newlines in strings.
44 R6RS behavior can be turned on via a reader option. @xref{String
45 Syntax}, for more information.
48 A @code{set!} to a variable transformer may only expand to an
49 expression, not a definition---even if the original @code{set!}
50 expression was in definition context.
53 Instead of using the algorithm detailed in chapter 10 of the R6RS,
54 expansion of toplevel forms happens sequentially.
56 For example, while the expansion of the following set of toplevel
57 definitions does the correct thing:
63 (or (= x 0) (odd? (- x 1)))))
66 ((odd? x) (not (even? x)))))
72 The same definitions outside of the @code{begin} wrapper do not:
77 (or (= x 0) (odd? (- x 1)))))
80 ((odd? x) (not (even? x)))))
82 <unnamed port>:4:18: In procedure even?:
83 <unnamed port>:4:18: Wrong type to apply: #<syntax-transformer odd?>
86 This is because when expanding the right-hand-side of @code{even?}, the
87 reference to @code{odd?} is not yet marked as a syntax transformer, so
88 it is assumed to be a function.
90 This bug will only affect top-level programs, not code in @code{library}
91 forms. Fixing it for toplevel forms seems doable, but tricky to
92 implement in a backward-compatible way. Suggestions and/or patches would
96 The @code{(rnrs io ports)} module is incomplete. Work is
100 Guile does not prevent use of textual I/O procedures on binary ports.
101 More generally, it does not make a sharp distinction between binary and
102 textual ports (@pxref{R6RS Port Manipulation, binary-port?}).
105 @node R6RS Standard Libraries
106 @subsection R6RS Standard Libraries
108 In contrast with earlier versions of the Revised Report, the R6RS
109 organizes the procedures and syntactic forms required of conforming
110 implementations into a set of ``standard libraries'' which can be
111 imported as necessary by user programs and libraries. Here we briefly
112 list the libraries that have been implemented for Guile.
114 We do not attempt to document these libraries fully here, as most of
115 their functionality is already available in Guile itself. The
116 expectation is that most Guile users will use the well-known and
117 well-documented Guile modules. These R6RS libraries are mostly useful
118 to users who want to port their code to other R6RS systems.
120 The documentation in the following sections reproduces some of the
121 content of the library section of the Report, but is mostly intended to
122 provide supplementary information about Guile's implementation of the
123 R6RS standard libraries. For complete documentation, design rationales
124 and further examples, we advise you to consult the ``Standard
125 Libraries'' section of the Report (@pxref{Standard Libraries,
126 R6RS Standard Libraries,, r6rs, The Revised^6 Report on the Algorithmic
130 * Library Usage:: What to know about Guile's library support.
131 * rnrs base:: The base library.
132 * rnrs unicode:: Access to Unicode operations.
133 * rnrs bytevectors:: Functions for working with binary data.
134 * rnrs lists:: List utilities.
135 * rnrs sorting:: Sorting for lists and vectors.
136 * rnrs control:: Additional control structures.
138 * R6RS Records:: A note about R6RS records.
139 * rnrs records syntactic:: Syntactic API for R6RS records.
140 * rnrs records procedural:: Procedural API for R6RS records.
141 * rnrs records inspection:: Reflection on R6RS records.
143 * rnrs exceptions:: Handling exceptional situations.
144 * rnrs conditions:: Data structures for exceptions.
146 * I/O Conditions:: Predefined I/O error types.
147 * rnrs io ports:: Support for port-based I/O.
148 * rnrs io simple:: High-level I/O API.
150 * rnrs files:: Functions for working with files.
151 * rnrs programs:: Functions for working with processes.
152 * rnrs arithmetic fixnums:: Fixed-precision arithmetic operations.
153 * rnrs arithmetic flonums:: Floating-point arithmetic operations.
154 * rnrs arithmetic bitwise:: Exact bitwise arithmetic operations.
155 * rnrs syntax-case:: Support for `syntax-case' macros.
156 * rnrs hashtables:: Hashtables.
157 * rnrs enums:: Enumerations.
158 * rnrs:: The composite library.
159 * rnrs eval:: Support for on-the-fly evaluation.
160 * rnrs mutable-pairs:: Support for mutable pairs.
161 * rnrs mutable-strings:: Support for mutable strings.
162 * rnrs r5rs:: Compatibility layer for R5RS Scheme.
167 @subsubsection Library Usage
169 Guile implements the R6RS `library' form as a transformation to a native
170 Guile module definition. As a consequence of this, all of the libraries
171 described in the following subsections, in addition to being available
172 for use by R6RS libraries and top-level programs, can also be imported
173 as if they were normal Guile modules---via a @code{use-modules} form,
174 say. For example, the R6RS ``composite'' library can be imported by:
181 (use-modules ((rnrs) :version (6)))
184 For more information on Guile's library implementation, see
185 (@pxref{R6RS Libraries}).
188 @subsubsection rnrs base
190 The @code{(rnrs base (6))} library exports the procedures and syntactic
191 forms described in the main section of the Report
192 (@pxref{Base library, R6RS Base library,, r6rs,
193 The Revised^6 Report on the Algorithmic Language Scheme}). They are
194 grouped below by the existing manual sections to which they correspond.
196 @deffn {Scheme Procedure} boolean? obj
197 @deffnx {Scheme Procedure} not x
198 @xref{Booleans}, for documentation.
201 @deffn {Scheme Procedure} symbol? obj
202 @deffnx {Scheme Procedure} symbol->string sym
203 @deffnx {Scheme Procedure} string->symbol str
204 @xref{Symbol Primitives}, for documentation.
207 @deffn {Scheme Procedure} char? obj
208 @deffnx {Scheme Procedure} char=?
209 @deffnx {Scheme Procedure} char<?
210 @deffnx {Scheme Procedure} char>?
211 @deffnx {Scheme Procedure} char<=?
212 @deffnx {Scheme Procedure} char>=?
213 @deffnx {Scheme Procedure} integer->char n
214 @deffnx {Scheme Procedure} char->integer chr
215 @xref{Characters}, for documentation.
218 @deffn {Scheme Procedure} list? x
219 @deffnx {Scheme Procedure} null? x
220 @xref{List Predicates}, for documentation.
223 @deffn {Scheme Procedure} pair? x
224 @deffnx {Scheme Procedure} cons x y
225 @deffnx {Scheme Procedure} car pair
226 @deffnx {Scheme Procedure} cdr pair
227 @deffnx {Scheme Procedure} caar pair
228 @deffnx {Scheme Procedure} cadr pair
229 @deffnx {Scheme Procedure} cdar pair
230 @deffnx {Scheme Procedure} cddr pair
231 @deffnx {Scheme Procedure} caaar pair
232 @deffnx {Scheme Procedure} caadr pair
233 @deffnx {Scheme Procedure} cadar pair
234 @deffnx {Scheme Procedure} cdaar pair
235 @deffnx {Scheme Procedure} caddr pair
236 @deffnx {Scheme Procedure} cdadr pair
237 @deffnx {Scheme Procedure} cddar pair
238 @deffnx {Scheme Procedure} cdddr pair
239 @deffnx {Scheme Procedure} caaaar pair
240 @deffnx {Scheme Procedure} caaadr pair
241 @deffnx {Scheme Procedure} caadar pair
242 @deffnx {Scheme Procedure} cadaar pair
243 @deffnx {Scheme Procedure} cdaaar pair
244 @deffnx {Scheme Procedure} cddaar pair
245 @deffnx {Scheme Procedure} cdadar pair
246 @deffnx {Scheme Procedure} cdaadr pair
247 @deffnx {Scheme Procedure} cadadr pair
248 @deffnx {Scheme Procedure} caaddr pair
249 @deffnx {Scheme Procedure} caddar pair
250 @deffnx {Scheme Procedure} cadddr pair
251 @deffnx {Scheme Procedure} cdaddr pair
252 @deffnx {Scheme Procedure} cddadr pair
253 @deffnx {Scheme Procedure} cdddar pair
254 @deffnx {Scheme Procedure} cddddr pair
255 @xref{Pairs}, for documentation.
258 @deffn {Scheme Procedure} number? obj
259 @xref{Numerical Tower}, for documentation.
262 @deffn {Scheme Procedure} string? obj
263 @xref{String Predicates}, for documentation.
266 @deffn {Scheme Procedure} procedure? obj
267 @xref{Procedure Properties}, for documentation.
270 @deffn {Scheme Syntax} define name value
271 @deffnx {Scheme Syntax} set! variable-name value
272 @xref{Definition}, for documentation.
275 @deffn {Scheme Syntax} define-syntax keyword expression
276 @deffnx {Scheme Syntax} let-syntax ((keyword transformer) @dots{})
278 @deffnx {Scheme Syntax} letrec-syntax ((keyword transformer) @dots{})
280 @xref{Defining Macros}, for documentation.
283 @deffn {Scheme Syntax} identifier-syntax exp
284 @xref{Identifier Macros}, for documentation.
287 @deffn {Scheme Syntax} syntax-rules literals (pattern template) ...
288 @xref{Syntax Rules}, for documentation.
291 @deffn {Scheme Syntax} lambda formals body
292 @xref{Lambda}, for documentation.
295 @deffn {Scheme Syntax} let bindings body
296 @deffnx {Scheme Syntax} let* bindings body
297 @deffnx {Scheme Syntax} letrec bindings body
298 @deffnx {Scheme Syntax} letrec* bindings body
299 @xref{Local Bindings}, for documentation.
302 @deffn {Scheme Syntax} let-values bindings body
303 @deffnx {Scheme Syntax} let*-values bindings body
304 @xref{SRFI-11}, for documentation.
307 @deffn {Scheme Syntax} begin expr1 expr2 ...
308 @xref{begin}, for documentation.
311 @deffn {Scheme Syntax} quote expr
312 @deffnx {Scheme Syntax} quasiquote expr
313 @deffnx {Scheme Syntax} unquote expr
314 @deffnx {Scheme Syntax} unquote-splicing expr
315 @xref{Expression Syntax}, for documentation.
318 @deffn {Scheme Syntax} if test consequence [alternate]
319 @deffnx {Scheme Syntax} cond clause1 clause2 ...
320 @deffnx {Scheme Syntax} case key clause1 clause2 ...
321 @xref{Conditionals}, for documentation.
324 @deffn {Scheme Syntax} and expr ...
325 @deffnx {Scheme Syntax} or expr ...
326 @xref{and or}, for documentation.
329 @deffn {Scheme Procedure} eq? x y
330 @deffnx {Scheme Procedure} eqv? x y
331 @deffnx {Scheme Procedure} equal? x y
332 @deffnx {Scheme Procedure} symbol=? symbol1 symbol2 ...
333 @xref{Equality}, for documentation.
335 @code{symbol=?} is identical to @code{eq?}.
338 @deffn {Scheme Procedure} complex? z
339 @xref{Complex Numbers}, for documentation.
342 @deffn {Scheme Procedure} real-part z
343 @deffnx {Scheme Procedure} imag-part z
344 @deffnx {Scheme Procedure} make-rectangular real_part imaginary_part
345 @deffnx {Scheme Procedure} make-polar x y
346 @deffnx {Scheme Procedure} magnitude z
347 @deffnx {Scheme Procedure} angle z
348 @xref{Complex}, for documentation.
351 @deffn {Scheme Procedure} sqrt z
352 @deffnx {Scheme Procedure} exp z
353 @deffnx {Scheme Procedure} expt z1 z2
354 @deffnx {Scheme Procedure} log z
355 @deffnx {Scheme Procedure} sin z
356 @deffnx {Scheme Procedure} cos z
357 @deffnx {Scheme Procedure} tan z
358 @deffnx {Scheme Procedure} asin z
359 @deffnx {Scheme Procedure} acos z
360 @deffnx {Scheme Procedure} atan z
361 @xref{Scientific}, for documentation.
364 @deffn {Scheme Procedure} real? x
365 @deffnx {Scheme Procedure} rational? x
366 @deffnx {Scheme Procedure} numerator x
367 @deffnx {Scheme Procedure} denominator x
368 @deffnx {Scheme Procedure} rationalize x eps
369 @xref{Reals and Rationals}, for documentation.
372 @deffn {Scheme Procedure} exact? x
373 @deffnx {Scheme Procedure} inexact? x
374 @deffnx {Scheme Procedure} exact z
375 @deffnx {Scheme Procedure} inexact z
376 @xref{Exactness}, for documentation. The @code{exact} and
377 @code{inexact} procedures are identical to the @code{inexact->exact} and
378 @code{exact->inexact} procedures provided by Guile's code library.
381 @deffn {Scheme Procedure} integer? x
382 @xref{Integers}, for documentation.
385 @deffn {Scheme Procedure} odd? n
386 @deffnx {Scheme Procedure} even? n
387 @deffnx {Scheme Procedure} gcd x ...
388 @deffnx {Scheme Procedure} lcm x ...
389 @deffnx {Scheme Procedure} exact-integer-sqrt k
390 @xref{Integer Operations}, for documentation.
393 @deffn {Scheme Procedure} =
394 @deffnx {Scheme Procedure} <
395 @deffnx {Scheme Procedure} >
396 @deffnx {Scheme Procedure} <=
397 @deffnx {Scheme Procedure} >=
398 @deffnx {Scheme Procedure} zero? x
399 @deffnx {Scheme Procedure} positive? x
400 @deffnx {Scheme Procedure} negative? x
401 @xref{Comparison}, for documentation.
404 @deffn {Scheme Procedure} for-each f lst1 lst2 ...
405 @xref{SRFI-1 Fold and Map}, for documentation.
408 @deffn {Scheme Procedure} list elem @dots{}
409 @xref{List Constructors}, for documentation.
412 @deffn {Scheme Procedure} length lst
413 @deffnx {Scheme Procedure} list-ref lst k
414 @deffnx {Scheme Procedure} list-tail lst k
415 @xref{List Selection}, for documentation.
418 @deffn {Scheme Procedure} append lst @dots{} obj
419 @deffnx {Scheme Procedure} append
420 @deffnx {Scheme Procedure} reverse lst
421 @xref{Append/Reverse}, for documentation.
424 @deffn {Scheme Procedure} number->string n [radix]
425 @deffnx {Scheme Procedure} string->number str [radix]
426 @xref{Conversion}, for documentation.
429 @deffn {Scheme Procedure} string char ...
430 @deffnx {Scheme Procedure} make-string k [chr]
431 @deffnx {Scheme Procedure} list->string lst
432 @xref{String Constructors}, for documentation.
435 @deffn {Scheme Procedure} string->list str [start [end]]
436 @xref{List/String Conversion}, for documentation.
439 @deffn {Scheme Procedure} string-length str
440 @deffnx {Scheme Procedure} string-ref str k
441 @deffnx {Scheme Procedure} string-copy str [start [end]]
442 @deffnx {Scheme Procedure} substring str start [end]
443 @xref{String Selection}, for documentation.
446 @deffn {Scheme Procedure} string=? s1 s2 s3 @dots{}
447 @deffnx {Scheme Procedure} string<? s1 s2 s3 @dots{}
448 @deffnx {Scheme Procedure} string>? s1 s2 s3 @dots{}
449 @deffnx {Scheme Procedure} string<=? s1 s2 s3 @dots{}
450 @deffnx {Scheme Procedure} string>=? s1 s2 s3 @dots{}
451 @xref{String Comparison}, for documentation.
454 @deffn {Scheme Procedure} string-append arg @dots{}
455 @xref{Reversing and Appending Strings}, for documentation.
458 @deffn {Scheme Procedure} string-for-each proc s [start [end]]
459 @xref{Mapping Folding and Unfolding}, for documentation.
462 @deffn {Scheme Procedure} + z1 ...
463 @deffnx {Scheme Procedure} - z1 z2 ...
464 @deffnx {Scheme Procedure} * z1 ...
465 @deffnx {Scheme Procedure} / z1 z2 ...
466 @deffnx {Scheme Procedure} max x1 x2 ...
467 @deffnx {Scheme Procedure} min x1 x2 ...
468 @deffnx {Scheme Procedure} abs x
469 @deffnx {Scheme Procedure} truncate x
470 @deffnx {Scheme Procedure} floor x
471 @deffnx {Scheme Procedure} ceiling x
472 @deffnx {Scheme Procedure} round x
473 @xref{Arithmetic}, for documentation.
479 @deffn {Scheme Procedure} div x y
480 @deffnx {Scheme Procedure} mod x y
481 @deffnx {Scheme Procedure} div-and-mod x y
482 These procedures accept two real numbers @var{x} and @var{y}, where the
483 divisor @var{y} must be non-zero. @code{div} returns the integer @var{q}
484 and @code{mod} returns the real number @var{r} such that
485 @math{@var{x} = @var{q}*@var{y} + @var{r}} and @math{0 <= @var{r} < abs(@var{y})}.
486 @code{div-and-mod} returns both @var{q} and @var{r}, and is more
487 efficient than computing each separately. Note that when @math{@var{y} > 0},
488 @code{div} returns @math{floor(@var{x}/@var{y})}, otherwise
489 it returns @math{ceiling(@var{x}/@var{y})}.
492 (div 123 10) @result{} 12
493 (mod 123 10) @result{} 3
494 (div-and-mod 123 10) @result{} 12 and 3
495 (div-and-mod 123 -10) @result{} -12 and 3
496 (div-and-mod -123 10) @result{} -13 and 7
497 (div-and-mod -123 -10) @result{} 13 and 7
498 (div-and-mod -123.2 -63.5) @result{} 2.0 and 3.8
499 (div-and-mod 16/3 -10/7) @result{} -3 and 22/21
505 @rnindex div0-and-mod0
506 @deffn {Scheme Procedure} div0 x y
507 @deffnx {Scheme Procedure} mod0 x y
508 @deffnx {Scheme Procedure} div0-and-mod0 x y
509 These procedures accept two real numbers @var{x} and @var{y}, where the
510 divisor @var{y} must be non-zero. @code{div0} returns the
511 integer @var{q} and @code{mod0} returns the real number
512 @var{r} such that @math{@var{x} = @var{q}*@var{y} + @var{r}} and
513 @math{-abs(@var{y}/2) <= @var{r} < abs(@var{y}/2)}. @code{div0-and-mod0}
514 returns both @var{q} and @var{r}, and is more efficient than computing
517 Note that @code{div0} returns @math{@var{x}/@var{y}} rounded to the
518 nearest integer. When @math{@var{x}/@var{y}} lies exactly half-way
519 between two integers, the tie is broken according to the sign of
520 @var{y}. If @math{@var{y} > 0}, ties are rounded toward positive
521 infinity, otherwise they are rounded toward negative infinity.
522 This is a consequence of the requirement that
523 @math{-abs(@var{y}/2) <= @var{r} < abs(@var{y}/2)}.
526 (div0 123 10) @result{} 12
527 (mod0 123 10) @result{} 3
528 (div0-and-mod0 123 10) @result{} 12 and 3
529 (div0-and-mod0 123 -10) @result{} -12 and 3
530 (div0-and-mod0 -123 10) @result{} -12 and -3
531 (div0-and-mod0 -123 -10) @result{} 12 and -3
532 (div0-and-mod0 -123.2 -63.5) @result{} 2.0 and 3.8
533 (div0-and-mod0 16/3 -10/7) @result{} -4 and -8/21
537 @deffn {Scheme Procedure} real-valued? obj
538 @deffnx {Scheme Procedure} rational-valued? obj
539 @deffnx {Scheme Procedure} integer-valued? obj
540 These procedures return @code{#t} if and only if their arguments can,
541 respectively, be coerced to a real, rational, or integer value without a
542 loss of numerical precision.
544 @code{real-valued?} will return @code{#t} for complex numbers whose
545 imaginary parts are zero.
548 @deffn {Scheme Procedure} nan? x
549 @deffnx {Scheme Procedure} infinite? x
550 @deffnx {Scheme Procedure} finite? x
551 @code{nan?} returns @code{#t} if @var{x} is a NaN value, @code{#f}
552 otherwise. @code{infinite?} returns @code{#t} if @var{x} is an infinite
553 value, @code{#f} otherwise. @code{finite?} returns @code{#t} if @var{x}
554 is neither infinite nor a NaN value, otherwise it returns @code{#f}.
555 Every real number satisfies exactly one of these predicates. An
556 exception is raised if @var{x} is not real.
559 @deffn {Scheme Syntax} assert expr
560 Raises an @code{&assertion} condition if @var{expr} evaluates to
561 @code{#f}; otherwise evaluates to the value of @var{expr}.
564 @deffn {Scheme Procedure} error who message irritant1 ...
565 @deffnx {Scheme Procedure} assertion-violation who message irritant1 ...
566 These procedures raise compound conditions based on their arguments:
567 If @var{who} is not @code{#f}, the condition will include a @code{&who}
568 condition whose @code{who} field is set to @var{who}; a @code{&message}
569 condition will be included with a @code{message} field equal to
570 @var{message}; an @code{&irritants} condition will be included with its
571 @code{irritants} list given by @code{irritant1 ...}.
573 @code{error} produces a compound condition with the simple conditions
574 described above, as well as an @code{&error} condition;
575 @code{assertion-violation} produces one that includes an
576 @code{&assertion} condition.
579 @deffn {Scheme Procedure} vector-map proc v
580 @deffnx {Scheme Procedure} vector-for-each proc v
581 These procedures implement the @code{map} and @code{for-each} contracts
585 @deffn {Scheme Procedure} vector arg @dots{}
586 @deffnx {Scheme Procedure} vector? obj
587 @deffnx {Scheme Procedure} make-vector len
588 @deffnx {Scheme Procedure} make-vector len fill
589 @deffnx {Scheme Procedure} list->vector l
590 @deffnx {Scheme Procedure} vector->list v
591 @xref{Vector Creation}, for documentation.
594 @deffn {Scheme Procedure} vector-length vector
595 @deffnx {Scheme Procedure} vector-ref vector k
596 @deffnx {Scheme Procedure} vector-set! vector k obj
597 @deffnx {Scheme Procedure} vector-fill! v fill
598 @xref{Vector Accessors}, for documentation.
601 @deffn {Scheme Procedure} call-with-current-continuation proc
602 @deffnx {Scheme Procedure} call/cc proc
603 @xref{Continuations}, for documentation.
606 @deffn {Scheme Procedure} values arg @dots{}
607 @deffnx {Scheme Procedure} call-with-values producer consumer
608 @xref{Multiple Values}, for documentation.
611 @deffn {Scheme Procedure} dynamic-wind in_guard thunk out_guard
612 @xref{Dynamic Wind}, for documentation.
615 @deffn {Scheme Procedure} apply proc arg @dots{} arglst
616 @xref{Fly Evaluation}, for documentation.
620 @subsubsection rnrs unicode
622 The @code{(rnrs unicode (6))} library provides procedures for
623 manipulating Unicode characters and strings.
625 @deffn {Scheme Procedure} char-upcase char
626 @deffnx {Scheme Procedure} char-downcase char
627 @deffnx {Scheme Procedure} char-titlecase char
628 @deffnx {Scheme Procedure} char-foldcase char
629 These procedures translate their arguments from one Unicode character
630 set to another. @code{char-upcase}, @code{char-downcase}, and
631 @code{char-titlecase} are identical to their counterparts in the
632 Guile core library; @xref{Characters}, for documentation.
634 @code{char-foldcase} returns the result of applying @code{char-upcase}
635 to its argument, followed by @code{char-downcase}---except in the case
636 of the Turkic characters @code{U+0130} and @code{U+0131}, for which the
637 procedure acts as the identity function.
640 @deffn {Scheme Procedure} char-ci=? char1 char2 char3 ...
641 @deffnx {Scheme Procedure} char-ci<? char1 char2 char3 ...
642 @deffnx {Scheme Procedure} char-ci>? char1 char2 char3 ...
643 @deffnx {Scheme Procedure} char-ci<=? char1 char2 char3 ...
644 @deffnx {Scheme Procedure} char-ci>=? char1 char2 char3 ...
645 These procedures facilitate case-insensitive comparison of Unicode
646 characters. They are identical to the procedures provided by Guile's
647 core library. @xref{Characters}, for documentation.
650 @deffn {Scheme Procedure} char-alphabetic? char
651 @deffnx {Scheme Procedure} char-numeric? char
652 @deffnx {Scheme Procedure} char-whitespace? char
653 @deffnx {Scheme Procedure} char-upper-case? char
654 @deffnx {Scheme Procedure} char-lower-case? char
655 @deffnx {Scheme Procedure} char-title-case? char
656 These procedures implement various Unicode character set predicates.
657 They are identical to the procedures provided by Guile's core library.
658 @xref{Characters}, for documentation.
661 @deffn {Scheme Procedure} char-general-category char
662 @xref{Characters}, for documentation.
665 @deffn {Scheme Procedure} string-upcase string
666 @deffnx {Scheme Procedure} string-downcase string
667 @deffnx {Scheme Procedure} string-titlecase string
668 @deffnx {Scheme Procedure} string-foldcase string
669 These procedures perform Unicode case folding operations on their input.
670 @xref{Alphabetic Case Mapping}, for documentation.
673 @deffn {Scheme Procedure} string-ci=? string1 string2 string3 ...
674 @deffnx {Scheme Procedure} string-ci<? string1 string2 string3 ...
675 @deffnx {Scheme Procedure} string-ci>? string1 string2 string3 ...
676 @deffnx {Scheme Procedure} string-ci<=? string1 string2 string3 ...
677 @deffnx {Scheme Procedure} string-ci>=? string1 string2 string3 ...
678 These procedures perform case-insensitive comparison on their input.
679 @xref{String Comparison}, for documentation.
682 @deffn {Scheme Procedure} string-normalize-nfd string
683 @deffnx {Scheme Procedure} string-normalize-nfkd string
684 @deffnx {Scheme Procedure} string-normalize-nfc string
685 @deffnx {Scheme Procedure} string-normalize-nfkc string
686 These procedures perform Unicode string normalization operations on
687 their input. @xref{String Comparison}, for documentation.
690 @node rnrs bytevectors
691 @subsubsection rnrs bytevectors
693 The @code{(rnrs bytevectors (6))} library provides procedures for
694 working with blocks of binary data. This functionality is documented
695 in its own section of the manual; @xref{Bytevectors}.
698 @subsubsection rnrs lists
700 The @code{(rnrs lists (6))} library provides procedures additional
701 procedures for working with lists.
703 @deffn {Scheme Procedure} find proc list
704 This procedure is identical to the one defined in Guile's SRFI-1
705 implementation. @xref{SRFI-1 Searching}, for documentation.
708 @deffn {Scheme Procedure} for-all proc list1 list2 ...
709 @deffnx {Scheme Procedure} exists proc list1 list2 ...
711 The @code{for-all} procedure is identical to the @code{every} procedure
712 defined by SRFI-1; the @code{exists} procedure is identical to SRFI-1's
713 @code{any}. @xref{SRFI-1 Searching}, for documentation.
716 @deffn {Scheme Procedure} filter proc list
717 @deffnx {Scheme Procedure} partition proc list
718 These procedures are identical to the ones provided by SRFI-1.
719 @xref{List Modification}, for a description of @code{filter};
720 @xref{SRFI-1 Filtering and Partitioning}, for @code{partition}.
723 @deffn {Scheme Procedure} fold-left combine nil list1 list2 @dots{}
724 @deffnx {Scheme Procedure} fold-right combine nil list1 list2 @dots{}
725 These procedures are identical to the @code{fold} and @code{fold-right}
726 procedures provided by SRFI-1. @xref{SRFI-1 Fold and Map}, for
730 @deffn {Scheme Procedure} remp proc list
731 @deffnx {Scheme Procedure} remove obj list
732 @deffnx {Scheme Procedure} remv obj list
733 @deffnx {Scheme Procedure} remq obj list
734 @code{remove}, @code{remv}, and @code{remq} are identical to the
735 @code{delete}, @code{delv}, and @code{delq} procedures provided by
736 Guile's core library, (@pxref{List Modification}). @code{remp} is
737 identical to the alternate @code{remove} procedure provided by SRFI-1;
738 @xref{SRFI-1 Deleting}.
741 @deffn {Scheme Procedure} memp proc list
742 @deffnx {Scheme Procedure} member obj list
743 @deffnx {Scheme Procedure} memv obj list
744 @deffnx {Scheme Procedure} memq obj list
745 @code{member}, @code{memv}, and @code{memq} are identical to the
746 procedures provided by Guile's core library; @xref{List Searching},
747 for their documentation. @code{memp} uses the specified predicate
748 function @code{proc} to test elements of the list @var{list}---it
749 behaves similarly to @code{find}, except that it returns the first
750 sublist of @var{list} whose @code{car} satisfies @var{proc}.
753 @deffn {Scheme Procedure} assp proc alist
754 @deffnx {Scheme Procedure} assoc obj alist
755 @deffnx {Scheme Procedure} assv obj alist
756 @deffnx {Scheme Procedure} assq obj alist
757 @code{assoc}, @code{assv}, and @code{assq} are identical to the
758 procedures provided by Guile's core library;
759 @xref{Alist Key Equality}, for their documentation. @code{assp} uses
760 the specified predicate function @code{proc} to test keys in the
761 association list @var{alist}.
764 @deffn {Scheme Procedure} cons* obj1 ... obj
765 @deffnx {Scheme Procedure} cons* obj
766 This procedure is identical to the one exported by Guile's core
767 library. @xref{List Constructors}, for documentation.
771 @subsubsection rnrs sorting
773 The @code{(rnrs sorting (6))} library provides procedures for sorting
776 @deffn {Scheme Procedure} list-sort proc list
777 @deffnx {Scheme Procedure} vector-sort proc vector
778 These procedures return their input sorted in ascending order, without
779 modifying the original data. @var{proc} must be a procedure that takes
780 two elements from the input list or vector as arguments, and returns a
781 true value if the first is ``less'' than the second, @code{#f}
782 otherwise. @code{list-sort} returns a list; @code{vector-sort} returns
785 Both @code{list-sort} and @code{vector-sort} are implemented in terms of
786 the @code{stable-sort} procedure from Guile's core library.
787 @xref{Sorting}, for a discussion of the behavior of that procedure.
790 @deffn {Scheme Procedure} vector-sort! proc vector
791 Performs a destructive, ``in-place'' sort of @var{vector}, using
792 @var{proc} as described above to determine an ascending ordering of
793 elements. @code{vector-sort!} returns an unspecified value.
795 This procedure is implemented in terms of the @code{sort!} procedure
796 from Guile's core library. @xref{Sorting}, for more information.
800 @subsubsection rnrs control
802 The @code{(rnrs control (6))} library provides syntactic forms useful
803 for constructing conditional expressions and controlling the flow of
806 @deffn {Scheme Syntax} when test expression1 expression2 ...
807 @deffnx {Scheme Syntax} unless test expression1 expression2 ...
808 The @code{when} form is evaluated by evaluating the specified @var{test}
809 expression; if the result is a true value, the @var{expression}s that
810 follow it are evaluated in order, and the value of the final
811 @var{expression} becomes the value of the entire @code{when} expression.
813 The @code{unless} form behaves similarly, with the exception that the
814 specified @var{expression}s are only evaluated if the value of
818 @deffn {Scheme Syntax} do ((variable init step) ...) (test expression ...) command ...
819 This form is identical to the one provided by Guile's core library.
820 @xref{while do}, for documentation.
823 @deffn {Scheme Syntax} case-lambda clause ...
824 This form is identical to the one provided by Guile's core library.
825 @xref{Case-lambda}, for documentation.
829 @subsubsection R6RS Records
831 The manual sections below describe Guile's implementation of R6RS
832 records, which provide support for user-defined data types. The R6RS
833 records API provides a superset of the features provided by Guile's
834 ``native'' records, as well as those of the SRFI-9 records API;
835 @xref{Records}, and @ref{SRFI-9}, for a description of those
838 As with SRFI-9 and Guile's native records, R6RS records are constructed
839 using a record-type descriptor that specifies attributes like the
840 record's name, its fields, and the mutability of those fields.
842 R6RS records extend this framework to support single inheritance via the
843 specification of a ``parent'' type for a record type at definition time.
844 Accessors and mutator procedures for the fields of a parent type may be
845 applied to records of a subtype of this parent. A record type may be
846 @dfn{sealed}, in which case it cannot be used as the parent of another
849 The inheritance mechanism for record types also informs the process of
850 initializing the fields of a record and its parents. Constructor
851 procedures that generate new instances of a record type are obtained
852 from a record constructor descriptor, which encapsulates the record-type
853 descriptor of the record to be constructed along with a @dfn{protocol}
854 procedure that defines how constructors for record subtypes delegate to
855 the constructors of their parent types.
857 A protocol is a procedure used by the record system at construction time
858 to bind arguments to the fields of the record being constructed. The
859 protocol procedure is passed a procedure @var{n} that accepts the
860 arguments required to construct the record's parent type; this
861 procedure, when invoked, will return a procedure @var{p} that accepts
862 the arguments required to construct a new instance of the record type
863 itself and returns a new instance of the record type.
865 The protocol should in turn return a procedure that uses @var{n} and
866 @var{p} to initialize the fields of the record type and its parent
867 type(s). This procedure will be the constructor returned by
869 As a trivial example, consider the hypothetical record type
870 @code{pixel}, which encapsulates an x-y location on a screen, and
871 @code{voxel}, which has @code{pixel} as its parent type and stores an
872 additional coordinate. The following protocol produces a constructor
873 procedure that accepts all three coordinates, uses the first two to
874 initialize the fields of @code{pixel}, and binds the third to the single
875 field of @code{voxel}.
884 It may be helpful to think of protocols as ``constructor factories''
885 that produce chains of delegating constructors glued together by the
886 helper procedure @var{n}.
888 An R6RS record type may be declared to be @dfn{nongenerative} via the
889 use of a unique generated or user-supplied symbol---or
890 @dfn{uid}---such that subsequent record type declarations with the same
891 uid and attributes will return the previously-declared record-type
894 R6RS record types may also be declared to be @dfn{opaque}, in which case
895 the various predicates and introspection procedures defined in
896 @code{(rnrs records introspection)} will behave as if records of this
897 type are not records at all.
899 Note that while the R6RS records API shares much of its namespace with
900 both the SRFI-9 and native Guile records APIs, it is not currently
901 compatible with either.
903 @node rnrs records syntactic
904 @subsubsection rnrs records syntactic
906 The @code{(rnrs records syntactic (6))} library exports the syntactic
907 API for working with R6RS records.
909 @deffn {Scheme Syntax} define-record-type name-spec record-clause @dots{}
910 Defines a new record type, introducing bindings for a record-type
911 descriptor, a record constructor descriptor, a constructor procedure,
912 a record predicate, and accessor and mutator procedures for the new
913 record type's fields.
915 @var{name-spec} must either be an identifier or must take the form
916 @code{(record-name constructor-name predicate-name)}, where
917 @var{record-name}, @var{constructor-name}, and @var{predicate-name} are
918 all identifiers and specify the names to which, respectively, the
919 record-type descriptor, constructor, and predicate procedures will be
920 bound. If @var{name-spec} is only an identifier, it specifies the name
921 to which the generated record-type descriptor will be bound.
923 Each @var{record-clause} must be one of the following:
927 @code{(fields field-spec*)}, where each @var{field-spec} specifies a
928 field of the new record type and takes one of the following forms:
931 @code{(immutable field-name accessor-name)}, which specifies an
932 immutable field with the name @var{field-name} and binds an accessor
933 procedure for it to the name given by @var{accessor-name}
935 @code{(mutable field-name accessor-name mutator-name)}, which specifies
936 a mutable field with the name @var{field-name} and binds accessor and
937 mutator procedures to @var{accessor-name} and @var{mutator-name},
940 @code{(immutable field-name)}, which specifies an immutable field with
941 the name @var{field-name}; an accessor procedure for it will be created
942 and named by appending record name and @var{field-name} with a hyphen
945 @code{(mutable field-name}), which specifies a mutable field with the
946 name @var{field-name}; an accessor procedure for it will be created and
947 named as described above; a mutator procedure will also be created and
948 named by appending @code{-set!} to the accessor name
950 @code{field-name}, which specifies an immutable field with the name
951 @var{field-name}; an access procedure for it will be created and named
955 @code{(parent parent-name)}, where @var{parent-name} is a symbol giving
956 the name of the record type to be used as the parent of the new record
959 @code{(protocol expression)}, where @var{expression} evaluates to a
960 protocol procedure which behaves as described above, and is used to
961 create a record constructor descriptor for the new record type
963 @code{(sealed sealed?)}, where @var{sealed?} is a boolean value that
964 specifies whether or not the new record type is sealed
966 @code{(opaque opaque?)}, where @var{opaque?} is a boolean value that
967 specifies whether or not the new record type is opaque
969 @code{(nongenerative [uid])}, which specifies that the record type is
970 nongenerative via the optional uid @var{uid}. If @var{uid} is not
971 specified, a unique uid will be generated at expansion time
973 @code{(parent-rtd parent-rtd parent-cd)}, a more explicit form of the
974 @code{parent} form above; @var{parent-rtd} and @var{parent-cd} should
975 evaluate to a record-type descriptor and a record constructor
976 descriptor, respectively
980 @deffn {Scheme Syntax} record-type-descriptor record-name
981 Evaluates to the record-type descriptor associated with the type
982 specified by @var{record-name}.
985 @deffn {Scheme Syntax} record-constructor-descriptor record-name
986 Evaluates to the record-constructor descriptor associated with the type
987 specified by @var{record-name}.
990 @node rnrs records procedural
991 @subsubsection rnrs records procedural
993 The @code{(rnrs records procedural (6))} library exports the procedural
994 API for working with R6RS records.
996 @deffn {Scheme Procedure} make-record-type-descriptor name parent uid sealed? opaque? fields
997 Returns a new record-type descriptor with the specified characteristics:
998 @var{name} must be a symbol giving the name of the new record type;
999 @var{parent} must be either @code{#f} or a non-sealed record-type
1000 descriptor for the returned record type to extend; @var{uid} must be
1001 either @code{#f}, indicating that the record type is generative, or
1002 a symbol giving the type's nongenerative uid; @var{sealed?} and
1003 @var{opaque?} must be boolean values that specify the sealedness and
1004 opaqueness of the record type; @var{fields} must be a vector of zero or
1005 more field specifiers of the form @code{(mutable name)} or
1006 @code{(immutable name)}, where name is a symbol giving a name for the
1009 If @var{uid} is not @code{#f}, it must be a symbol
1012 @deffn {Scheme Procedure} record-type-descriptor? obj
1013 Returns @code{#t} if @var{obj} is a record-type descriptor, @code{#f}
1017 @deffn {Scheme Procedure} make-record-constructor-descriptor rtd parent-constructor-descriptor protocol
1018 Returns a new record constructor descriptor that can be used to produce
1019 constructors for the record type specified by the record-type descriptor
1020 @var{rtd} and whose delegation and binding behavior are specified by the
1021 protocol procedure @var{protocol}.
1023 @var{parent-constructor-descriptor} specifies a record constructor
1024 descriptor for the parent type of @var{rtd}, if one exists. If
1025 @var{rtd} represents a base type, then
1026 @var{parent-constructor-descriptor} must be @code{#f}. If @var{rtd}
1027 is an extension of another type, @var{parent-constructor-descriptor} may
1028 still be @code{#f}, but protocol must also be @code{#f} in this case.
1031 @deffn {Scheme Procedure} record-constructor rcd
1032 Returns a record constructor procedure by invoking the protocol
1033 defined by the record-constructor descriptor @var{rcd}.
1036 @deffn {Scheme Procedure} record-predicate rtd
1037 Returns the record predicate procedure for the record-type descriptor
1041 @deffn {Scheme Procedure} record-accessor rtd k
1042 Returns the record field accessor procedure for the @var{k}th field of
1043 the record-type descriptor @var{rtd}.
1046 @deffn {Scheme Procedure} record-mutator rtd k
1047 Returns the record field mutator procedure for the @var{k}th field of
1048 the record-type descriptor @var{rtd}. An @code{&assertion} condition
1049 will be raised if this field is not mutable.
1052 @node rnrs records inspection
1053 @subsubsection rnrs records inspection
1055 The @code{(rnrs records inspection (6))} library provides procedures
1056 useful for accessing metadata about R6RS records.
1058 @deffn {Scheme Procedure} record? obj
1059 Return @code{#t} if the specified object is a non-opaque R6RS record,
1060 @code{#f} otherwise.
1063 @deffn {Scheme Procedure} record-rtd record
1064 Returns the record-type descriptor for @var{record}. An
1065 @code{&assertion} is raised if @var{record} is opaque.
1068 @deffn {Scheme Procedure} record-type-name rtd
1069 Returns the name of the record-type descriptor @var{rtd}.
1072 @deffn {Scheme Procedure} record-type-parent rtd
1073 Returns the parent of the record-type descriptor @var{rtd}, or @code{#f}
1077 @deffn {Scheme Procedure} record-type-uid rtd
1078 Returns the uid of the record-type descriptor @var{rtd}, or @code{#f} if
1082 @deffn {Scheme Procedure} record-type-generative? rtd
1083 Returns @code{#t} if the record-type descriptor @var{rtd} is generative,
1084 @code{#f} otherwise.
1087 @deffn {Scheme Procedure} record-type-sealed? rtd
1088 Returns @code{#t} if the record-type descriptor @var{rtd} is sealed,
1089 @code{#f} otherwise.
1092 @deffn {Scheme Procedure} record-type-opaque? rtd
1093 Returns @code{#t} if the record-type descriptor @var{rtd} is opaque,
1094 @code{#f} otherwise.
1097 @deffn {Scheme Procedure} record-type-field-names rtd
1098 Returns a vector of symbols giving the names of the fields defined by
1099 the record-type descriptor @var{rtd} (and not any of its sub- or
1103 @deffn {Scheme Procedure} record-field-mutable? rtd k
1104 Returns @code{#t} if the field at index @var{k} of the record-type
1105 descriptor @var{rtd} (and not any of its sub- or supertypes) is mutable.
1108 @node rnrs exceptions
1109 @subsubsection rnrs exceptions
1111 The @code{(rnrs exceptions (6))} library provides functionality related
1112 to signaling and handling exceptional situations. This functionality is
1113 similar to the exception handling systems provided by Guile's core
1114 library @xref{Exceptions}, and by the SRFI-18 and SRFI-34
1115 modules---@xref{SRFI-18 Exceptions}, and @ref{SRFI-34},
1116 respectively---but there are some key differences in concepts and
1119 A raised exception may be @dfn{continuable} or @dfn{non-continuable}.
1120 When an exception is raised non-continuably, another exception, with the
1121 condition type @code{&non-continuable}, will be raised when the
1122 exception handler returns locally. Raising an exception continuably
1123 captures the current continuation and invokes it after a local return
1124 from the exception handler.
1126 Like SRFI-18 and SRFI-34, R6RS exceptions are implemented on top of
1127 Guile's native @code{throw} and @code{catch} forms, and use custom
1128 ``throw keys'' to identify their exception types. As a consequence,
1129 Guile's @code{catch} form can handle exceptions thrown by these APIs,
1130 but the reverse is not true: Handlers registered by the
1131 @code{with-exception-handler} procedure described below will only be
1132 called on exceptions thrown by the corresponding @code{raise} procedure.
1134 @deffn {Scheme Procedure} with-exception-handler handler thunk
1135 Installs @var{handler}, which must be a procedure taking one argument,
1136 as the current exception handler during the invocation of @var{thunk}, a
1137 procedure taking zero arguments. The handler in place at the time
1138 @code{with-exception-handler} is called is made current again once
1139 either @var{thunk} returns or @var{handler} is invoked after an
1140 exception is thrown from within @var{thunk}.
1142 This procedure is similar to the @code{with-throw-handler} procedure
1143 provided by Guile's code library; (@pxref{Throw Handlers}).
1146 @deffn {Scheme Syntax} guard (variable clause1 clause2 ...) body
1147 Evaluates the expression given by @var{body}, first creating an ad hoc
1148 exception handler that binds a raised exception to @var{variable} and
1149 then evaluates the specified @var{clause}s as if they were part of a
1150 @code{cond} expression, with the value of the first matching clause
1151 becoming the value of the @code{guard} expression
1152 (@pxref{Conditionals}). If none of the clause's test expressions
1153 evaluates to @code{#t}, the exception is re-raised, with the exception
1154 handler that was current before the evaluation of the @code{guard} form.
1156 For example, the expression
1159 (guard (ex ((eq? ex 'foo) 'bar) ((eq? ex 'bar) 'baz))
1163 evaluates to @code{baz}.
1166 @deffn {Scheme Procedure} raise obj
1167 Raises a non-continuable exception by invoking the currently-installed
1168 exception handler on @var{obj}. If the handler returns, a
1169 @code{&non-continuable} exception will be raised in the dynamic context
1170 in which the handler was installed.
1173 @deffn {Scheme Procedure} raise-continuable obj
1174 Raises a continuable exception by invoking currently-installed exception
1175 handler on @var{obj}.
1178 @node rnrs conditions
1179 @subsubsection rnrs conditions
1181 The @code{(rnrs condition (6))} library provides forms and procedures
1182 for constructing new condition types, as well as a library of
1183 pre-defined condition types that represent a variety of common
1184 exceptional situations. Conditions are records of a subtype of the
1185 @code{&condition} record type, which is neither sealed nor opaque.
1186 @xref{R6RS Records}.
1188 Conditions may be manipulated singly, as @dfn{simple conditions}, or
1189 when composed with other conditions to form @dfn{compound conditions}.
1190 Compound conditions do not ``nest''---constructing a new compound
1191 condition out of existing compound conditions will ``flatten'' them
1192 into their component simple conditions. For example, making a new
1193 condition out of a @code{&message} condition and a compound condition
1194 that contains an @code{&assertion} condition and another @code{&message}
1195 condition will produce a compound condition that contains two
1196 @code{&message} conditions and one @code{&assertion} condition.
1198 The record type predicates and field accessors described below can
1199 operate on either simple or compound conditions. In the latter case,
1200 the predicate returns @code{#t} if the compound condition contains a
1201 component simple condition of the appropriate type; the field accessors
1202 return the requisite fields from the first component simple condition
1203 found to be of the appropriate type.
1205 This library is quite similar to the SRFI-35 conditions module
1206 (@pxref{SRFI-35}). Among other minor differences, the
1207 @code{(rnrs conditions)} library features slightly different semantics
1208 around condition field accessors, and comes with a larger number of
1209 pre-defined condition types. The two APIs are not currently compatible,
1210 however; the @code{condition?} predicate from one API will return
1211 @code{#f} when applied to a condition object created in the other.
1213 @deffn {Condition Type} &condition
1214 @deffnx {Scheme Procedure} condition? obj
1215 The base record type for conditions.
1218 @deffn {Scheme Procedure} condition condition1 ...
1219 @deffnx {Scheme Procedure} simple-conditions condition
1220 The @code{condition} procedure creates a new compound condition out of
1221 its condition arguments, flattening any specified compound conditions
1222 into their component simple conditions as described above.
1224 @code{simple-conditions} returns a list of the component simple
1225 conditions of the compound condition @code{condition}, in the order in
1226 which they were specified at construction time.
1229 @deffn {Scheme Procedure} condition-predicate rtd
1230 @deffnx {Scheme Procedure} condition-accessor rtd proc
1231 These procedures return condition predicate and accessor procedures for
1232 the specified condition record type @var{rtd}.
1235 @deffn {Scheme Syntax} define-condition-type condition-type supertype constructor predicate field-spec ...
1236 Evaluates to a new record type definition for a condition type with the
1237 name @var{condition-type} that has the condition type @var{supertype} as
1238 its parent. A default constructor, which binds its arguments to the
1239 fields of this type and its parent types, will be bound to the
1240 identifier @var{constructor}; a condition predicate will be bound to
1241 @var{predicate}. The fields of the new type, which are immutable, are
1242 specified by the @var{field-spec}s, each of which must be of the form:
1246 where @var{field} gives the name of the field and @var{accessor} gives
1247 the name for a binding to an accessor procedure created for this field.
1250 @deffn {Condition Type} &message
1251 @deffnx {Scheme Procedure} make-message-condition message
1252 @deffnx {Scheme Procedure} message-condition? obj
1253 @deffnx {Scheme Procedure} condition-message condition
1254 A type that includes a message describing the condition that occurred.
1257 @deffn {Condition Type} &warning
1258 @deffnx {Scheme Procedure} make-warning
1259 @deffnx {Scheme Procedure} warning? obj
1260 A base type for representing non-fatal conditions during execution.
1263 @deffn {Condition Type} &serious
1264 @deffnx {Scheme Procedure} make-serious-condition
1265 @deffnx {Scheme Procedure} serious-condition? obj
1266 A base type for conditions representing errors serious enough that
1270 @deffn {Condition Type} &error
1271 @deffnx {Scheme Procedure} make-error
1272 @deffnx {Scheme Procedure} error? obj
1273 A base type for conditions representing errors.
1276 @deffn {Condition Type} &violation
1277 @deffnx {Scheme Procedure} make-violation
1278 @deffnx {Scheme Procedure} violation?
1279 A subtype of @code{&serious} that can be used to represent violations
1280 of a language or library standard.
1283 @deffn {Condition Type} &assertion
1284 @deffnx {Scheme Procedure} make-assertion-violation
1285 @deffnx {Scheme Procedure} assertion-violation? obj
1286 A subtype of @code{&violation} that indicates an invalid call to a
1290 @deffn {Condition Type} &irritants
1291 @deffnx {Scheme Procedure} make-irritants-condition irritants
1292 @deffnx {Scheme Procedure} irritants-condition? obj
1293 @deffnx {Scheme Procedure} condition-irritants condition
1294 A base type used for storing information about the causes of another
1295 condition in a compound condition.
1298 @deffn {Condition Type} &who
1299 @deffnx {Scheme Procedure} make-who-condition who
1300 @deffnx {Scheme Procedure} who-condition? obj
1301 @deffnx {Scheme Procedure} condition-who condition
1302 A base type used for storing the identity, a string or symbol, of the
1303 entity responsible for another condition in a compound condition.
1306 @deffn {Condition Type} &non-continuable
1307 @deffnx {Scheme Procedure} make-non-continuable-violation
1308 @deffnx {Scheme Procedure} non-continuable-violation? obj
1309 A subtype of @code{&violation} used to indicate that an exception
1310 handler invoked by @code{raise} has returned locally.
1313 @deffn {Condition Type} &implementation-restriction
1314 @deffnx {Scheme Procedure} make-implementation-restriction-violation
1315 @deffnx {Scheme Procedure} implementation-restriction-violation? obj
1316 A subtype of @code{&violation} used to indicate a violation of an
1317 implementation restriction.
1320 @deffn {Condition Type} &lexical
1321 @deffnx {Scheme Procedure} make-lexical-violation
1322 @deffnx {Scheme Procedure} lexical-violation? obj
1323 A subtype of @code{&violation} used to indicate a syntax violation at
1324 the level of the datum syntax.
1327 @deffn {Condition Type} &syntax
1328 @deffnx {Scheme Procedure} make-syntax-violation form subform
1329 @deffnx {Scheme Procedure} syntax-violation? obj
1330 @deffnx {Scheme Procedure} syntax-violation-form condition
1331 @deffnx {Scheme Procedure} syntax-violation-subform condition
1332 A subtype of @code{&violation} that indicates a syntax violation. The
1333 @var{form} and @var{subform} fields, which must be datum values,
1334 indicate the syntactic form responsible for the condition.
1337 @deffn {Condition Type} &undefined
1338 @deffnx {Scheme Procedure} make-undefined-violation
1339 @deffnx {Scheme Procedure} undefined-violation? obj
1340 A subtype of @code{&violation} that indicates a reference to an unbound
1344 @node I/O Conditions
1345 @subsubsection I/O Conditions
1347 These condition types are exported by both the
1348 @code{(rnrs io ports (6))} and @code{(rnrs io simple (6))} libraries.
1350 @deffn {Condition Type} &i/o
1351 @deffnx {Scheme Procedure} make-i/o-error
1352 @deffnx {Scheme Procedure} i/o-error? obj
1353 A condition supertype for more specific I/O errors.
1356 @deffn {Condition Type} &i/o-read
1357 @deffnx {Scheme Procedure} make-i/o-read-error
1358 @deffnx {Scheme Procedure} i/o-read-error? obj
1359 A subtype of @code{&i/o}; represents read-related I/O errors.
1362 @deffn {Condition Type} &i/o-write
1363 @deffnx {Scheme Procedure} make-i/o-write-error
1364 @deffnx {Scheme Procedure} i/o-write-error? obj
1365 A subtype of @code{&i/o}; represents write-related I/O errors.
1368 @deffn {Condition Type} &i/o-invalid-position
1369 @deffnx {Scheme Procedure} make-i/o-invalid-position-error position
1370 @deffnx {Scheme Procedure} i/o-invalid-position-error? obj
1371 @deffnx {Scheme Procedure} i/o-error-position condition
1372 A subtype of @code{&i/o}; represents an error related to an attempt to
1373 set the file position to an invalid position.
1376 @deffn {Condition Type} &i/o-filename
1377 @deffnx {Scheme Procedure} make-io-filename-error filename
1378 @deffnx {Scheme Procedure} i/o-filename-error? obj
1379 @deffnx {Scheme Procedure} i/o-error-filename condition
1380 A subtype of @code{&i/o}; represents an error related to an operation on
1384 @deffn {Condition Type} &i/o-file-protection
1385 @deffnx {Scheme Procedure} make-i/o-file-protection-error filename
1386 @deffnx {Scheme Procedure} i/o-file-protection-error? obj
1387 A subtype of @code{&i/o-filename}; represents an error resulting from an
1388 attempt to access a named file for which the caller had insufficient
1392 @deffn {Condition Type} &i/o-file-is-read-only
1393 @deffnx {Scheme Procedure} make-i/o-file-is-read-only-error filename
1394 @deffnx {Scheme Procedure} i/o-file-is-read-only-error? obj
1395 A subtype of @code{&i/o-file-protection}; represents an error related to
1396 an attempt to write to a read-only file.
1399 @deffn {Condition Type} &i/o-file-already-exists
1400 @deffnx {Scheme Procedure} make-i/o-file-already-exists-error filename
1401 @deffnx {Scheme Procedure} i/o-file-already-exists-error? obj
1402 A subtype of @code{&i/o-filename}; represents an error related to an
1403 operation on an existing file that was assumed not to exist.
1406 @deffn {Condition Type} &i/o-file-does-not-exist
1407 @deffnx {Scheme Procedure} make-i/o-file-does-not-exist-error
1408 @deffnx {Scheme Procedure} i/o-file-does-not-exist-error? obj
1409 A subtype of @code{&i/o-filename}; represents an error related to an
1410 operation on a non-existent file that was assumed to exist.
1413 @deffn {Condition Type} &i/o-port
1414 @deffnx {Scheme Procedure} make-i/o-port-error port
1415 @deffnx {Scheme Procedure} i/o-port-error? obj
1416 @deffnx {Scheme Procedure} i/o-error-port condition
1417 A subtype of @code{&i/o}; represents an error related to an operation on
1418 the port @var{port}.
1422 @subsubsection rnrs io ports
1424 The @code{(rnrs io ports (6))} library provides various procedures and
1425 syntactic forms for use in writing to and reading from ports. This
1426 functionality is documented in its own section of the manual;
1427 (@pxref{R6RS I/O Ports}).
1429 @node rnrs io simple
1430 @subsubsection rnrs io simple
1432 The @code{(rnrs io simple (6))} library provides convenience functions
1433 for performing textual I/O on ports. This library also exports all of
1434 the condition types and associated procedures described in (@pxref{I/O
1435 Conditions}). In the context of this section, when stating that a
1436 procedure behaves ``identically'' to the corresponding procedure in
1437 Guile's core library, this is modulo the behavior wrt. conditions: such
1438 procedures raise the appropriate R6RS conditions in case of error, but
1439 otherwise behave identically.
1441 @c FIXME: remove the following note when proper condition behavior has
1445 There are still known issues regarding condition-correctness; some
1446 errors may still be thrown as native Guile exceptions instead of the
1447 appropriate R6RS conditions.
1450 @deffn {Scheme Procedure} eof-object
1451 @deffnx {Scheme Procedure} eof-object? obj
1452 These procedures are identical to the ones provided by the
1453 @code{(rnrs io ports (6))} library. @xref{R6RS I/O Ports}, for
1457 @deffn {Scheme Procedure} input-port? obj
1458 @deffnx {Scheme Procedure} output-port? obj
1459 These procedures are identical to the ones provided by Guile's core
1460 library. @xref{Ports}, for documentation.
1463 @deffn {Scheme Procedure} call-with-input-file filename proc
1464 @deffnx {Scheme Procedure} call-with-output-file filename proc
1465 @deffnx {Scheme Procedure} open-input-file filename
1466 @deffnx {Scheme Procedure} open-output-file filename
1467 @deffnx {Scheme Procedure} with-input-from-file filename thunk
1468 @deffnx {Scheme Procedure} with-output-to-file filename thunk
1469 These procedures are identical to the ones provided by Guile's core
1470 library. @xref{File Ports}, for documentation.
1473 @deffn {Scheme Procedure} close-input-port input-port
1474 @deffnx {Scheme Procedure} close-output-port output-port
1475 These procedures are identical to the ones provided by Guile's core
1476 library. @xref{Closing}, for documentation.
1479 @deffn {Scheme Procedure} peek-char
1480 @deffnx {Scheme Procedure} peek-char textual-input-port
1481 @deffnx {Scheme Procedure} read-char
1482 @deffnx {Scheme Procedure} read-char textual-input-port
1483 These procedures are identical to the ones provided by Guile's core
1484 library. @xref{Reading}, for documentation.
1487 @deffn {Scheme Procedure} read
1488 @deffnx {Scheme Procedure} read textual-input-port
1489 This procedure is identical to the one provided by Guile's core library.
1490 @xref{Scheme Read}, for documentation.
1493 @deffn {Scheme Procedure} display obj
1494 @deffnx {Scheme Procedure} display obj textual-output-port
1495 @deffnx {Scheme Procedure} newline
1496 @deffnx {Scheme Procedure} newline textual-output-port
1497 @deffnx {Scheme Procedure} write obj
1498 @deffnx {Scheme Procedure} write obj textual-output-port
1499 @deffnx {Scheme Procedure} write-char char
1500 @deffnx {Scheme Procedure} write-char char textual-output-port
1501 These procedures are identical to the ones provided by Guile's core
1502 library. @xref{Writing}, for documentation.
1506 @subsubsection rnrs files
1508 The @code{(rnrs files (6))} library provides the @code{file-exists?} and
1509 @code{delete-file} procedures, which test for the existence of a file
1510 and allow the deletion of files from the file system, respectively.
1512 These procedures are identical to the ones provided by Guile's core
1513 library. @xref{File System}, for documentation.
1516 @subsubsection rnrs programs
1518 The @code{(rnrs programs (6))} library provides procedures for
1519 process management and introspection.
1521 @deffn {Scheme Procedure} command-line
1522 This procedure is identical to the one provided by Guile's core library.
1523 @xref{Runtime Environment}, for documentation.
1526 @deffn {Scheme Procedure} exit
1527 @deffnx {Scheme Procedure} exit obj
1528 This procedure is identical to the one provided by Guile's core library.
1531 @node rnrs arithmetic fixnums
1532 @subsubsection rnrs arithmetic fixnums
1534 The @code{(rnrs arithmetic fixnums (6))} library provides procedures for
1535 performing arithmetic operations on an implementation-dependent range of
1536 exact integer values, which R6RS refers to as @dfn{fixnums}. In Guile,
1537 the size of a fixnum is determined by the size of the @code{SCM} type; a
1538 single SCM struct is guaranteed to be able to hold an entire fixnum,
1539 making fixnum computations particularly
1540 efficient---(@pxref{The SCM Type}). On 32-bit systems, the most
1541 negative and most positive fixnum values are, respectively, -536870912
1544 Unless otherwise specified, all of the procedures below take fixnums as
1545 arguments, and will raise an @code{&assertion} condition if passed a
1546 non-fixnum argument or an @code{&implementation-restriction} condition
1547 if their result is not itself a fixnum.
1549 @deffn {Scheme Procedure} fixnum? obj
1550 Returns @code{#t} if @var{obj} is a fixnum, @code{#f} otherwise.
1553 @deffn {Scheme Procedure} fixnum-width
1554 @deffnx {Scheme Procedure} least-fixnum
1555 @deffnx {Scheme Procedure} greatest-fixnum
1556 These procedures return, respectively, the maximum number of bits
1557 necessary to represent a fixnum value in Guile, the minimum fixnum
1558 value, and the maximum fixnum value.
1561 @deffn {Scheme Procedure} fx=? fx1 fx2 fx3 ...
1562 @deffnx {Scheme Procedure} fx>? fx1 fx2 fx3 ...
1563 @deffnx {Scheme Procedure} fx<? fx1 fx2 fx3 ...
1564 @deffnx {Scheme Procedure} fx>=? fx1 fx2 fx3 ...
1565 @deffnx {Scheme Procedure} fx<=? fx1 fx2 fx3 ...
1566 These procedures return @code{#t} if their fixnum arguments are
1567 (respectively): equal, monotonically increasing, monotonically
1568 decreasing, monotonically nondecreasing, or monotonically nonincreasing;
1569 @code{#f} otherwise.
1572 @deffn {Scheme Procedure} fxzero? fx
1573 @deffnx {Scheme Procedure} fxpositive? fx
1574 @deffnx {Scheme Procedure} fxnegative? fx
1575 @deffnx {Scheme Procedure} fxodd? fx
1576 @deffnx {Scheme Procedure} fxeven? fx
1577 These numerical predicates return @code{#t} if @var{fx} is,
1578 respectively, zero, greater than zero, less than zero, odd, or even;
1579 @code{#f} otherwise.
1582 @deffn {Scheme Procedure} fxmax fx1 fx2 ...
1583 @deffnx {Scheme Procedure} fxmin fx1 fx2 ...
1584 These procedures return the maximum or minimum of their arguments.
1587 @deffn {Scheme Procedure} fx+ fx1 fx2
1588 @deffnx {Scheme Procedure} fx* fx1 fx2
1589 These procedures return the sum or product of their arguments.
1592 @deffn {Scheme Procedure} fx- fx1 fx2
1593 @deffnx {Scheme Procedure} fx- fx
1594 Returns the difference of @var{fx1} and @var{fx2}, or the negation of
1595 @var{fx}, if called with a single argument.
1597 An @code{&assertion} condition is raised if the result is not itself a
1601 @deffn {Scheme Procedure} fxdiv-and-mod fx1 fx2
1602 @deffnx {Scheme Procedure} fxdiv fx1 fx2
1603 @deffnx {Scheme Procedure} fxmod fx1 fx2
1604 @deffnx {Scheme Procedure} fxdiv0-and-mod0 fx1 fx2
1605 @deffnx {Scheme Procedure} fxdiv0 fx1 fx2
1606 @deffnx {Scheme Procedure} fxmod0 fx1 fx2
1607 These procedures implement number-theoretic division on fixnums;
1608 @xref{(rnrs base)}, for a description of their semantics.
1611 @deffn {Scheme Procedure} fx+/carry fx1 fx2 fx3
1612 Returns the two fixnum results of the following computation:
1614 (let* ((s (+ fx1 fx2 fx3))
1615 (s0 (mod0 s (expt 2 (fixnum-width))))
1616 (s1 (div0 s (expt 2 (fixnum-width)))))
1621 @deffn {Scheme Procedure} fx-/carry fx1 fx2 fx3
1622 Returns the two fixnum results of the following computation:
1624 (let* ((d (- fx1 fx2 fx3))
1625 (d0 (mod0 d (expt 2 (fixnum-width))))
1626 (d1 (div0 d (expt 2 (fixnum-width)))))
1631 @deffn {Scheme Procedure} fx*/carry fx1 fx2 fx3
1633 Returns the two fixnum results of the following computation:
1634 (let* ((s (+ (* fx1 fx2) fx3))
1635 (s0 (mod0 s (expt 2 (fixnum-width))))
1636 (s1 (div0 s (expt 2 (fixnum-width)))))
1641 @deffn {Scheme Procedure} fxnot fx
1642 @deffnx {Scheme Procedure} fxand fx1 ...
1643 @deffnx {Scheme Procedure} fxior fx1 ...
1644 @deffnx {Scheme Procedure} fxxor fx1 ...
1645 These procedures are identical to the @code{lognot}, @code{logand},
1646 @code{logior}, and @code{logxor} procedures provided by Guile's core
1647 library. @xref{Bitwise Operations}, for documentation.
1650 @deffn {Scheme Procedure} fxif fx1 fx2 fx3
1651 Returns the bitwise ``if'' of its fixnum arguments. The bit at position
1652 @code{i} in the return value will be the @code{i}th bit from @var{fx2}
1653 if the @code{i}th bit of @var{fx1} is 1, the @code{i}th bit from
1657 @deffn {Scheme Procedure} fxbit-count fx
1658 Returns the number of 1 bits in the two's complement representation of
1662 @deffn {Scheme Procedure} fxlength fx
1663 Returns the number of bits necessary to represent @var{fx}.
1666 @deffn {Scheme Procedure} fxfirst-bit-set fx
1667 Returns the index of the least significant 1 bit in the two's complement
1668 representation of @var{fx}.
1671 @deffn {Scheme Procedure} fxbit-set? fx1 fx2
1672 Returns @code{#t} if the @var{fx2}th bit in the two's complement
1673 representation of @var{fx1} is 1, @code{#f} otherwise.
1676 @deffn {Scheme Procedure} fxcopy-bit fx1 fx2 fx3
1677 Returns the result of setting the @var{fx2}th bit of @var{fx1} to the
1678 @var{fx2}th bit of @var{fx3}.
1681 @deffn {Scheme Procedure} fxbit-field fx1 fx2 fx3
1682 Returns the integer representation of the contiguous sequence of bits in
1683 @var{fx1} that starts at position @var{fx2} (inclusive) and ends at
1684 position @var{fx3} (exclusive).
1687 @deffn {Scheme Procedure} fxcopy-bit-field fx1 fx2 fx3 fx4
1688 Returns the result of replacing the bit field in @var{fx1} with start
1689 and end positions @var{fx2} and @var{fx3} with the corresponding bit
1690 field from @var{fx4}.
1693 @deffn {Scheme Procedure} fxarithmetic-shift fx1 fx2
1694 @deffnx {Scheme Procedure} fxarithmetic-shift-left fx1 fx2
1695 @deffnx {Scheme Procedure} fxarithmetic-shift-right fx1 fx2
1696 Returns the result of shifting the bits of @var{fx1} right or left by
1697 the @var{fx2} positions. @code{fxarithmetic-shift} is identical
1698 to @code{fxarithmetic-shift-left}.
1701 @deffn {Scheme Procedure} fxrotate-bit-field fx1 fx2 fx3 fx4
1702 Returns the result of cyclically permuting the bit field in @var{fx1}
1703 with start and end positions @var{fx2} and @var{fx3} by @var{fx4} bits
1704 in the direction of more significant bits.
1707 @deffn {Scheme Procedure} fxreverse-bit-field fx1 fx2 fx3
1708 Returns the result of reversing the order of the bits of @var{fx1}
1709 between position @var{fx2} (inclusive) and position @var{fx3}
1713 @node rnrs arithmetic flonums
1714 @subsubsection rnrs arithmetic flonums
1716 The @code{(rnrs arithmetic flonums (6))} library provides procedures for
1717 performing arithmetic operations on inexact representations of real
1718 numbers, which R6RS refers to as @dfn{flonums}.
1720 Unless otherwise specified, all of the procedures below take flonums as
1721 arguments, and will raise an @code{&assertion} condition if passed a
1722 non-flonum argument.
1724 @deffn {Scheme Procedure} flonum? obj
1725 Returns @code{#t} if @var{obj} is a flonum, @code{#f} otherwise.
1728 @deffn {Scheme Procedure} real->flonum x
1729 Returns the flonum that is numerically closest to the real number
1733 @deffn {Scheme Procedure} fl=? fl1 fl2 fl3 ...
1734 @deffnx {Scheme Procedure} fl<? fl1 fl2 fl3 ...
1735 @deffnx {Scheme Procedure} fl<=? fl1 fl2 fl3 ...
1736 @deffnx {Scheme Procedure} fl>? fl1 fl2 fl3 ...
1737 @deffnx {Scheme Procedure} fl>=? fl1 fl2 fl3 ...
1738 These procedures return @code{#t} if their flonum arguments are
1739 (respectively): equal, monotonically increasing, monotonically
1740 decreasing, monotonically nondecreasing, or monotonically nonincreasing;
1741 @code{#f} otherwise.
1744 @deffn {Scheme Procedure} flinteger? fl
1745 @deffnx {Scheme Procedure} flzero? fl
1746 @deffnx {Scheme Procedure} flpositive? fl
1747 @deffnx {Scheme Procedure} flnegative? fl
1748 @deffnx {Scheme Procedure} flodd? fl
1749 @deffnx {Scheme Procedure} fleven? fl
1750 These numerical predicates return @code{#t} if @var{fl} is,
1751 respectively, an integer, zero, greater than zero, less than zero, odd,
1752 even, @code{#f} otherwise. In the case of @code{flodd?} and
1753 @code{fleven?}, @var{fl} must be an integer-valued flonum.
1756 @deffn {Scheme Procedure} flfinite? fl
1757 @deffnx {Scheme Procedure} flinfinite? fl
1758 @deffnx {Scheme Procedure} flnan? fl
1759 These numerical predicates return @code{#t} if @var{fl} is,
1760 respectively, not infinite, infinite, or a @code{NaN} value.
1763 @deffn {Scheme Procedure} flmax fl1 fl2 ...
1764 @deffnx {Scheme Procedure} flmin fl1 fl2 ...
1765 These procedures return the maximum or minimum of their arguments.
1768 @deffn {Scheme Procedure} fl+ fl1 ...
1769 @deffnx {Scheme Procedure} fl* fl ...
1770 These procedures return the sum or product of their arguments.
1773 @deffn {Scheme Procedure} fl- fl1 fl2 ...
1774 @deffnx {Scheme Procedure} fl- fl
1775 @deffnx {Scheme Procedure} fl/ fl1 fl2 ...
1776 @deffnx {Scheme Procedure} fl/ fl
1777 These procedures return, respectively, the difference or quotient of
1778 their arguments when called with two arguments; when called with a
1779 single argument, they return the additive or multiplicative inverse of
1783 @deffn {Scheme Procedure} flabs fl
1784 Returns the absolute value of @var{fl}.
1787 @deffn {Scheme Procedure} fldiv-and-mod fl1 fl2
1788 @deffnx {Scheme Procedure} fldiv fl1 fl2
1789 @deffnx {Scheme Procedure} fldmod fl1 fl2
1790 @deffnx {Scheme Procedure} fldiv0-and-mod0 fl1 fl2
1791 @deffnx {Scheme Procedure} fldiv0 fl1 fl2
1792 @deffnx {Scheme Procedure} flmod0 fl1 fl2
1793 These procedures implement number-theoretic division on flonums;
1794 @xref{(rnrs base)}, for a description for their semantics.
1797 @deffn {Scheme Procedure} flnumerator fl
1798 @deffnx {Scheme Procedure} fldenominator fl
1799 These procedures return the numerator or denominator of @var{fl} as a
1803 @deffn {Scheme Procedure} flfloor fl1
1804 @deffnx {Scheme Procedure} flceiling fl
1805 @deffnx {Scheme Procedure} fltruncate fl
1806 @deffnx {Scheme Procedure} flround fl
1807 These procedures are identical to the @code{floor}, @code{ceiling},
1808 @code{truncate}, and @code{round} procedures provided by Guile's core
1809 library. @xref{Arithmetic}, for documentation.
1812 @deffn {Scheme Procedure} flexp fl
1813 @deffnx {Scheme Procedure} fllog fl
1814 @deffnx {Scheme Procedure} fllog fl1 fl2
1815 @deffnx {Scheme Procedure} flsin fl
1816 @deffnx {Scheme Procedure} flcos fl
1817 @deffnx {Scheme Procedure} fltan fl
1818 @deffnx {Scheme Procedure} flasin fl
1819 @deffnx {Scheme Procedure} flacos fl
1820 @deffnx {Scheme Procedure} flatan fl
1821 @deffnx {Scheme Procedure} flatan fl1 fl2
1822 These procedures, which compute the usual transcendental functions, are
1823 the flonum variants of the procedures provided by the R6RS base library
1824 (@pxref{(rnrs base)}).
1827 @deffn {Scheme Procedure} flsqrt fl
1828 Returns the square root of @var{fl}. If @var{fl} is @code{-0.0},
1829 @var{-0.0} is returned; for other negative values, a @code{NaN} value
1833 @deffn {Scheme Procedure} flexpt fl1 fl2
1834 Returns the value of @var{fl1} raised to the power of @var{fl2}.
1837 The following condition types are provided to allow Scheme
1838 implementations that do not support infinities or @code{NaN} values
1839 to indicate that a computation resulted in such a value. Guile supports
1840 both of these, so these conditions will never be raised by Guile's
1841 standard libraries implementation.
1843 @deffn {Condition Type} &no-infinities
1844 @deffnx {Scheme Procedure} make-no-infinities-violation obj
1845 @deffnx {Scheme Procedure} no-infinities-violation?
1846 A condition type indicating that a computation resulted in an infinite
1847 value on a Scheme implementation incapable of representing infinities.
1850 @deffn {Condition Type} &no-nans
1851 @deffnx {Scheme Procedure} make-no-nans-violation obj
1852 @deffnx {Scheme Procedure} no-nans-violation? obj
1853 A condition type indicating that a computation resulted in a @code{NaN}
1854 value on a Scheme implementation incapable of representing @code{NaN}s.
1857 @deffn {Scheme Procedure} fixnum->flonum fx
1858 Returns the flonum that is numerically closest to the fixnum @var{fx}.
1861 @node rnrs arithmetic bitwise
1862 @subsubsection rnrs arithmetic bitwise
1864 The @code{(rnrs arithmetic bitwise (6))} library provides procedures for
1865 performing bitwise arithmetic operations on the two's complement
1866 representations of fixnums.
1868 This library and the procedures it exports share functionality with
1869 SRFI-60, which provides support for bitwise manipulation of integers
1872 @deffn {Scheme Procedure} bitwise-not ei
1873 @deffnx {Scheme Procedure} bitwise-and ei1 ...
1874 @deffnx {Scheme Procedure} bitwise-ior ei1 ...
1875 @deffnx {Scheme Procedure} bitwise-xor ei1 ...
1876 These procedures are identical to the @code{lognot}, @code{logand},
1877 @code{logior}, and @code{logxor} procedures provided by Guile's core
1878 library. @xref{Bitwise Operations}, for documentation.
1881 @deffn {Scheme Procedure} bitwise-if ei1 ei2 ei3
1882 Returns the bitwise ``if'' of its arguments. The bit at position
1883 @code{i} in the return value will be the @code{i}th bit from @var{ei2}
1884 if the @code{i}th bit of @var{ei1} is 1, the @code{i}th bit from
1888 @deffn {Scheme Procedure} bitwise-bit-count ei
1889 Returns the number of 1 bits in the two's complement representation of
1893 @deffn {Scheme Procedure} bitwise-length ei
1894 Returns the number of bits necessary to represent @var{ei}.
1897 @deffn {Scheme Procedure} bitwise-first-bit-set ei
1898 Returns the index of the least significant 1 bit in the two's complement
1899 representation of @var{ei}.
1902 @deffn {Scheme Procedure} bitwise-bit-set? ei1 ei2
1903 Returns @code{#t} if the @var{ei2}th bit in the two's complement
1904 representation of @var{ei1} is 1, @code{#f} otherwise.
1907 @deffn {Scheme Procedure} bitwise-copy-bit ei1 ei2 ei3
1908 Returns the result of setting the @var{ei2}th bit of @var{ei1} to the
1909 @var{ei2}th bit of @var{ei3}.
1912 @deffn {Scheme Procedure} bitwise-bit-field ei1 ei2 ei3
1913 Returns the integer representation of the contiguous sequence of bits in
1914 @var{ei1} that starts at position @var{ei2} (inclusive) and ends at
1915 position @var{ei3} (exclusive).
1918 @deffn {Scheme Procedure} bitwise-copy-bit-field ei1 ei2 ei3 ei4
1919 Returns the result of replacing the bit field in @var{ei1} with start
1920 and end positions @var{ei2} and @var{ei3} with the corresponding bit
1921 field from @var{ei4}.
1924 @deffn {Scheme Procedure} bitwise-arithmetic-shift ei1 ei2
1925 @deffnx {Scheme Procedure} bitwise-arithmetic-shift-left ei1 ei2
1926 @deffnx {Scheme Procedure} bitwise-arithmetic-shift-right ei1 ei2
1927 Returns the result of shifting the bits of @var{ei1} right or left by
1928 the @var{ei2} positions. @code{bitwise-arithmetic-shift} is identical
1929 to @code{bitwise-arithmetic-shift-left}.
1932 @deffn {Scheme Procedure} bitwise-rotate-bit-field ei1 ei2 ei3 ei4
1933 Returns the result of cyclically permuting the bit field in @var{ei1}
1934 with start and end positions @var{ei2} and @var{ei3} by @var{ei4} bits
1935 in the direction of more significant bits.
1938 @deffn {Scheme Procedure} bitwise-reverse-bit-field ei1 ei2 ei3
1939 Returns the result of reversing the order of the bits of @var{ei1}
1940 between position @var{ei2} (inclusive) and position @var{ei3}
1944 @node rnrs syntax-case
1945 @subsubsection rnrs syntax-case
1947 The @code{(rnrs syntax-case (6))} library provides access to the
1948 @code{syntax-case} system for writing hygienic macros. With one
1949 exception, all of the forms and procedures exported by this library
1950 are ``re-exports'' of Guile's native support for @code{syntax-case};
1951 @xref{Syntax Case}, for documentation, examples, and rationale.
1953 @deffn {Scheme Procedure} make-variable-transformer proc
1954 Creates a new variable transformer out of @var{proc}, a procedure that
1955 takes a syntax object as input and returns a syntax object. If an
1956 identifier to which the result of this procedure is bound appears on the
1957 left-hand side of a @code{set!} expression, @var{proc} will be called
1958 with a syntax object representing the entire @code{set!} expression,
1959 and its return value will replace that @code{set!} expression.
1962 @deffn {Scheme Syntax} syntax-case expression (literal ...) clause ...
1963 The @code{syntax-case} pattern matching form.
1966 @deffn {Scheme Syntax} syntax template
1967 @deffnx {Scheme Syntax} quasisyntax template
1968 @deffnx {Scheme Syntax} unsyntax template
1969 @deffnx {Scheme Syntax} unsyntax-splicing template
1970 These forms allow references to be made in the body of a syntax-case
1971 output expression subform to datum and non-datum values. They are
1972 identical to the forms provided by Guile's core library;
1973 @xref{Syntax Case}, for documentation.
1976 @deffn {Scheme Procedure} identifier? obj
1977 @deffnx {Scheme Procedure} bound-identifier=? id1 id2
1978 @deffnx {Scheme Procedure} free-identifier=? id1 id2
1979 These predicate procedures operate on syntax objects representing
1980 Scheme identifiers. @code{identifier?} returns @code{#t} if @var{obj}
1981 represents an identifier, @code{#f} otherwise.
1982 @code{bound-identifier=?} returns @code{#t} if and only if a binding for
1983 @var{id1} would capture a reference to @var{id2} in the transformer's
1984 output, or vice-versa. @code{free-identifier=?} returns @code{#t} if
1985 and only @var{id1} and @var{id2} would refer to the same binding in the
1986 output of the transformer, independent of any bindings introduced by the
1990 @deffn {Scheme Procedure} generate-temporaries l
1991 Returns a list, of the same length as @var{l}, which must be a list or
1992 a syntax object representing a list, of globally unique symbols.
1995 @deffn {Scheme Procedure} syntax->datum syntax-object
1996 @deffnx {Scheme Procedure} datum->syntax template-id datum
1997 These procedures convert wrapped syntax objects to and from Scheme datum
1998 values. The syntax object returned by @code{datum->syntax} shares
1999 contextual information with the syntax object @var{template-id}.
2002 @deffn {Scheme Procedure} syntax-violation whom message form
2003 @deffnx {Scheme Procedure} syntax-violation whom message form subform
2004 Constructs a new compound condition that includes the following
2008 If @var{whom} is not @code{#f}, a @code{&who} condition with the
2009 @var{whom} as its field
2011 A @code{&message} condition with the specified @var{message}
2013 A @code{&syntax} condition with the specified @var{form} and optional
2014 @var{subform} fields
2018 @node rnrs hashtables
2019 @subsubsection rnrs hashtables
2021 The @code{(rnrs hashtables (6))} library provides structures and
2022 procedures for creating and accessing hash tables. The hash tables API
2023 defined by R6RS is substantially similar to both Guile's native hash
2024 tables implementation as well as the one provided by SRFI-69;
2025 @xref{Hash Tables}, and @ref{SRFI-69}, respectively. Note that you can
2026 write portable R6RS library code that manipulates SRFI-69 hash tables
2027 (by importing the @code{(srfi :69)} library); however, hash tables
2028 created by one API cannot be used by another.
2030 Like SRFI-69 hash tables---and unlike Guile's native ones---R6RS hash
2031 tables associate hash and equality functions with a hash table at the
2032 time of its creation. Additionally, R6RS allows for the creation
2033 (via @code{hashtable-copy}; see below) of immutable hash tables.
2035 @deffn {Scheme Procedure} make-eq-hashtable
2036 @deffnx {Scheme Procedure} make-eq-hashtable k
2037 Returns a new hash table that uses @code{eq?} to compare keys and
2038 Guile's @code{hashq} procedure as a hash function. If @var{k} is given,
2039 it specifies the initial capacity of the hash table.
2042 @deffn {Scheme Procedure} make-eqv-hashtable
2043 @deffnx {Scheme Procedure} make-eqv-hashtable k
2044 Returns a new hash table that uses @code{eqv?} to compare keys and
2045 Guile's @code{hashv} procedure as a hash function. If @var{k} is given,
2046 it specifies the initial capacity of the hash table.
2049 @deffn {Scheme Procedure} make-hashtable hash-function equiv
2050 @deffnx {Scheme Procedure} make-hashtable hash-function equiv k
2051 Returns a new hash table that uses @var{equiv} to compare keys and
2052 @var{hash-function} as a hash function. @var{equiv} must be a procedure
2053 that accepts two arguments and returns a true value if they are
2054 equivalent, @code{#f} otherwise; @var{hash-function} must be a procedure
2055 that accepts one argument and returns a non-negative integer.
2057 If @var{k} is given, it specifies the initial capacity of the hash
2061 @deffn {Scheme Procedure} hashtable? obj
2062 Returns @code{#t} if @var{obj} is an R6RS hash table, @code{#f}
2066 @deffn {Scheme Procedure} hashtable-size hashtable
2067 Returns the number of keys currently in the hash table @var{hashtable}.
2070 @deffn {Scheme Procedure} hashtable-ref hashtable key default
2071 Returns the value associated with @var{key} in the hash table
2072 @var{hashtable}, or @var{default} if none is found.
2075 @deffn {Scheme Procedure} hashtable-set! hashtable key obj
2076 Associates the key @var{key} with the value @var{obj} in the hash table
2077 @var{hashtable}, and returns an unspecified value. An @code{&assertion}
2078 condition is raised if @var{hashtable} is immutable.
2081 @deffn {Scheme Procedure} hashtable-delete! hashtable key
2082 Removes any association found for the key @var{key} in the hash table
2083 @var{hashtable}, and returns an unspecified value. An @code{&assertion}
2084 condition is raised if @var{hashtable} is immutable.
2087 @deffn {Scheme Procedure} hashtable-contains? hashtable key
2088 Returns @code{#t} if the hash table @var{hashtable} contains an
2089 association for the key @var{key}, @code{#f} otherwise.
2092 @deffn {Scheme Procedure} hashtable-update! hashtable key proc default
2093 Associates with @var{key} in the hash table @var{hashtable} the result
2094 of calling @var{proc}, which must be a procedure that takes one
2095 argument, on the value currently associated @var{key} in
2096 @var{hashtable}---or on @var{default} if no such association exists.
2097 An @code{&assertion} condition is raised if @var{hashtable} is
2101 @deffn {Scheme Procedure} hashtable-copy hashtable
2102 @deffnx {Scheme Procedure} hashtable-copy hashtable mutable
2103 Returns a copy of the hash table @var{hashtable}. If the optional
2104 argument @var{mutable} is provided and is a true value, the new hash
2105 table will be mutable.
2108 @deffn {Scheme Procedure} hashtable-clear! hashtable
2109 @deffnx {Scheme Procedure} hashtable-clear! hashtable k
2110 Removes all of the associations from the hash table @var{hashtable}.
2111 The optional argument @var{k}, which specifies a new capacity for the
2112 hash table, is accepted by Guile's @code{(rnrs hashtables)}
2113 implementation, but is ignored.
2116 @deffn {Scheme Procedure} hashtable-keys hashtable
2117 Returns a vector of the keys with associations in the hash table
2118 @var{hashtable}, in an unspecified order.
2121 @deffn {Scheme Procedure} hashtable-entries hashtable
2122 Return two values---a vector of the keys with associations in the hash
2123 table @var{hashtable}, and a vector of the values to which these keys
2124 are mapped, in corresponding but unspecified order.
2127 @deffn {Scheme Procedure} hashtable-equivalence-function hashtable
2128 Returns the equivalence predicated use by @var{hashtable}. This
2129 procedure returns @code{eq?} and @code{eqv?}, respectively, for hash
2130 tables created by @code{make-eq-hashtable} and
2131 @code{make-eqv-hashtable}.
2134 @deffn {Scheme Procedure} hashtable-hash-function hashtable
2135 Returns the hash function used by @var{hashtable}. For hash tables
2136 created by @code{make-eq-hashtable} or @code{make-eqv-hashtable},
2137 @code{#f} is returned.
2140 @deffn {Scheme Procedure} hashtable-mutable? hashtable
2141 Returns @code{#t} if @var{hashtable} is mutable, @code{#f} otherwise.
2144 A number of hash functions are provided for convenience:
2146 @deffn {Scheme Procedure} equal-hash obj
2147 Returns an integer hash value for @var{obj}, based on its structure and
2148 current contents. This hash function is suitable for use with
2149 @code{equal?} as an equivalence function.
2152 @deffn {Scheme Procedure} string-hash string
2153 @deffnx {Scheme Procedure} symbol-hash symbol
2154 These procedures are identical to the ones provided by Guile's core
2155 library. @xref{Hash Table Reference}, for documentation.
2158 @deffn {Scheme Procedure} string-ci-hash string
2159 Returns an integer hash value for @var{string} based on its contents,
2160 ignoring case. This hash function is suitable for use with
2161 @code{string-ci=?} as an equivalence function.
2165 @subsubsection rnrs enums
2167 The @code{(rnrs enums (6))} library provides structures and procedures
2168 for working with enumerable sets of symbols. Guile's implementation
2169 defines an @dfn{enum-set} record type that encapsulates a finite set of
2170 distinct symbols, the @dfn{universe}, and a subset of these symbols,
2171 which define the enumeration set.
2173 The SRFI-1 list library provides a number of procedures for performing
2174 set operations on lists; Guile's @code{(rnrs enums)} implementation
2175 makes use of several of them. @xref{SRFI-1 Set Operations}, for
2178 @deffn {Scheme Procedure} make-enumeration symbol-list
2179 Returns a new enum-set whose universe and enumeration set are both equal
2180 to @var{symbol-list}, a list of symbols.
2183 @deffn {Scheme Procedure} enum-set-universe enum-set
2184 Returns an enum-set representing the universe of @var{enum-set},
2188 @deffn {Scheme Procedure} enum-set-indexer enum-set
2189 Returns a procedure that takes a single argument and returns the
2190 zero-indexed position of that argument in the universe of
2191 @var{enum-set}, or @code{#f} if its argument is not a member of that
2195 @deffn {Scheme Procedure} enum-set-constructor enum-set
2196 Returns a procedure that takes a single argument, a list of symbols
2197 from the universe of @var{enum-set}, an enum-set, and returns a new
2198 enum-set with the same universe that represents a subset containing the
2202 @deffn {Scheme Procedure} enum-set->list enum-set
2203 Returns a list containing the symbols of the set represented by
2204 @var{enum-set}, an enum-set, in the order that they appear in the
2205 universe of @var{enum-set}.
2208 @deffn {Scheme Procedure} enum-set-member? symbol enum-set
2209 @deffnx {Scheme Procedure} enum-set-subset? enum-set1 enum-set2
2210 @deffnx {Scheme Procedure} enum-set=? enum-set1 enum-set2
2211 These procedures test for membership of symbols and enum-sets in other
2212 enum-sets. @code{enum-set-member?} returns @code{#t} if and only if
2213 @var{symbol} is a member of the subset specified by @var{enum-set}.
2214 @code{enum-set-subset?} returns @code{#t} if and only if the universe of
2215 @var{enum-set1} is a subset of the universe of @var{enum-set2} and
2216 every symbol in @var{enum-set1} is present in @var{enum-set2}.
2217 @code{enum-set=?} returns @code{#t} if and only if @var{enum-set1} is a
2218 subset, as per @code{enum-set-subset?} of @var{enum-set2} and vice
2222 @deffn {Scheme Procedure} enum-set-union enum-set1 enum-set2
2223 @deffnx {Scheme Procedure} enum-set-intersection enum-set1 enum-set2
2224 @deffnx {Scheme Procedure} enum-set-difference enum-set1 enum-set2
2225 These procedures return, respectively, the union, intersection, and
2226 difference of their enum-set arguments.
2229 @deffn {Scheme Procedure} enum-set-complement enum-set
2230 Returns @var{enum-set}'s complement (an enum-set), with regard to its
2234 @deffn {Scheme Procedure} enum-set-projection enum-set1 enum-set2
2235 Returns the projection of the enum-set @var{enum-set1} onto the universe
2236 of the enum-set @var{enum-set2}.
2239 @deffn {Scheme Syntax} define-enumeration type-name (symbol ...) constructor-syntax
2240 Evaluates to two new definitions: A constructor bound to
2241 @var{constructor-syntax} that behaves similarly to constructors created
2242 by @code{enum-set-constructor}, above, and creates new @var{enum-set}s
2243 in the universe specified by @code{(symbol ...)}; and a ``predicate
2244 macro'' bound to @var{type-name}, which has the following form:
2247 (@var{type-name} sym)
2250 If @var{sym} is a member of the universe specified by the @var{symbol}s
2251 above, this form evaluates to @var{sym}. Otherwise, a @code{&syntax}
2252 condition is raised.
2258 The @code{(rnrs (6))} library is a composite of all of the other R6RS
2259 standard libraries---it imports and re-exports all of their exported
2260 procedures and syntactic forms---with the exception of the following
2264 @item @code{(rnrs eval (6))}
2265 @item @code{(rnrs mutable-pairs (6))}
2266 @item @code{(rnrs mutable-strings (6))}
2267 @item @code{(rnrs r5rs (6))}
2271 @subsubsection rnrs eval
2273 The @code{(rnrs eval (6)} library provides procedures for performing
2274 ``on-the-fly'' evaluation of expressions.
2276 @deffn {Scheme Procedure} eval expression environment
2277 Evaluates @var{expression}, which must be a datum representation of a
2278 valid Scheme expression, in the environment specified by
2279 @var{environment}. This procedure is identical to the one provided by
2280 Guile's code library; @xref{Fly Evaluation}, for documentation.
2283 @deffn {Scheme Procedure} environment import-spec ...
2284 Constructs and returns a new environment based on the specified
2285 @var{import-spec}s, which must be datum representations of the import
2286 specifications used with the @code{import} form. @xref{R6RS Libraries},
2290 @node rnrs mutable-pairs
2291 @subsubsection rnrs mutable-pairs
2293 The @code{(rnrs mutable-pairs (6))} library provides the @code{set-car!}
2294 and @code{set-cdr!} procedures, which allow the @code{car} and
2295 @code{cdr} fields of a pair to be modified.
2297 These procedures are identical to the ones provide by Guile's core
2298 library. @xref{Pairs}, for documentation. All pairs in Guile are
2299 mutable; consequently, these procedures will never throw the
2300 @code{&assertion} condition described in the R6RS libraries
2303 @node rnrs mutable-strings
2304 @subsubsection rnrs mutable-strings
2306 The @code{(rnrs mutable-strings (6))} library provides the
2307 @code{string-set!} and @code{string-fill!} procedures, which allow the
2308 content of strings to be modified ``in-place.''
2310 These procedures are identical to the ones provided by Guile's core
2311 library. @xref{String Modification}, for documentation. All strings in
2312 Guile are mutable; consequently, these procedures will never throw the
2313 @code{&assertion} condition described in the R6RS libraries
2317 @subsubsection rnrs r5rs
2319 The @code{(rnrs r5rs (6))} library exports bindings for some procedures
2320 present in R5RS but omitted from the R6RS base library specification.
2322 @deffn {Scheme Procedure} exact->inexact z
2323 @deffnx {Scheme Procedure} inexact->exact z
2324 These procedures are identical to the ones provided by Guile's core
2325 library. @xref{Exactness}, for documentation.
2328 @deffn {Scheme Procedure} quotient n1 n2
2329 @deffnx {Scheme Procedure} remainder n1 n2
2330 @deffnx {Scheme Procedure} modulo n1 n2
2331 These procedures are identical to the ones provided by Guile's core
2332 library. @xref{Integer Operations}, for documentation.
2335 @deffn {Scheme Syntax} delay expr
2336 @deffnx {Scheme Procedure} force promise
2337 The @code{delay} form and the @code{force} procedure are identical to
2338 their counterparts in Guile's core library. @xref{Delayed Evaluation},
2342 @deffn {Scheme Procedure} null-environment n
2343 @deffnx {Scheme Procedure} scheme-report-environment n
2344 These procedures are identical to the ones provided by the
2345 @code{(ice-9 r5rs)} Guile module. @xref{Environments}, for
2349 @c r6rs.texi ends here
2352 @c TeX-master: "guile.texi"