*** empty log message ***
[bpt/guile.git] / doc / ref / srfi-modules.texi
CommitLineData
a0e07ba4
NJ
1@page
2@node SRFI Support
3@chapter SRFI Support Modules
8742c48b 4@cindex SRFI
a0e07ba4
NJ
5
6SRFI is an acronym for Scheme Request For Implementation. The SRFI
7documents define a lot of syntactic and procedure extensions to standard
8Scheme as defined in R5RS.
9
10Guile has support for a number of SRFIs. This chapter gives an overview
11over the available SRFIs and some usage hints. For complete
12documentation, design rationales and further examples, we advise you to
13get the relevant SRFI documents from the SRFI home page
14@url{http://srfi.schemers.org}.
15
16@menu
17* About SRFI Usage:: What to know about Guile's SRFI support.
18* SRFI-0:: cond-expand
19* SRFI-1:: List library.
20* SRFI-2:: and-let*.
21* SRFI-4:: Homogeneous numeric vector datatypes.
22* SRFI-6:: Basic String Ports.
23* SRFI-8:: receive.
24* SRFI-9:: define-record-type.
25* SRFI-10:: Hash-Comma Reader Extension.
26* SRFI-11:: let-values and let-values*.
27* SRFI-13:: String library.
28* SRFI-14:: Character-set library.
29* SRFI-16:: case-lambda
30* SRFI-17:: Generalized set!
bfc9c8e0 31* SRFI-19:: Time/Date library.
a0e07ba4
NJ
32@end menu
33
34
35@node About SRFI Usage
36@section About SRFI Usage
37
38@c FIXME::martin: Review me!
39
40SRFI support in Guile is currently implemented partly in the core
41library, and partly as add-on modules. That means that some SRFIs are
42automatically available when the interpreter is started, whereas the
43other SRFIs require you to use the appropriate support module
12991fed 44explicitly.
a0e07ba4
NJ
45
46There are several reasons for this inconsistency. First, the feature
47checking syntactic form @code{cond-expand} (@pxref{SRFI-0}) must be
48available immediately, because it must be there when the user wants to
49check for the Scheme implementation, that is, before she can know that
50it is safe to use @code{use-modules} to load SRFI support modules. The
51second reason is that some features defined in SRFIs had been
52implemented in Guile before the developers started to add SRFI
53implementations as modules (for example SRFI-6 (@pxref{SRFI-6})). In
54the future, it is possible that SRFIs in the core library might be
55factored out into separate modules, requiring explicit module loading
56when they are needed. So you should be prepared to have to use
57@code{use-modules} someday in the future to access SRFI-6 bindings. If
58you want, you can do that already. We have included the module
59@code{(srfi srfi-6)} in the distribution, which currently does nothing,
60but ensures that you can write future-safe code.
61
62Generally, support for a specific SRFI is made available by using
63modules named @code{(srfi srfi-@var{number})}, where @var{number} is the
64number of the SRFI needed. Another possibility is to use the command
65line option @code{--use-srfi}, which will load the necessary modules
66automatically (@pxref{Invoking Guile}).
67
68
69@node SRFI-0
70@section SRFI-0 - cond-expand
8742c48b 71@cindex SRFI-0
a0e07ba4
NJ
72
73@c FIXME::martin: Review me!
74
75SRFI-0 defines a means for checking whether a Scheme implementation has
76support for a specified feature. The syntactic form @code{cond-expand},
77which implements this means, has the following syntax.
78
79@example
80@group
81<cond-expand>
82 --> (cond-expand <cond-expand-clause>+)
83 | (cond-expand <cond-expand-clause>* (else <command-or-definition>))
84<cond-expand-clause>
85 --> (<feature-requirement> <command-or-definition>*)
86<feature-requirement>
87 --> <feature-identifier>
88 | (and <feature-requirement>*)
89 | (or <feature-requirement>*)
90 | (not <feature-requirement>)
91<feature-identifier>
92 --> <a symbol which is the name or alias of a SRFI>
93@end group
94@end example
95
96When evaluated, this form checks all clauses in order, until it finds
97one whose feature requirement is satisfied. Then the form expands into
98the commands or definitions in the clause. A requirement is tested as
99follows:
100
101@itemize @bullet
102@item
103If it is a symbol, it is satisfied if the feature identifier is
104supported.
105
106@item
107If it is an @code{and} form, all requirements must be satisfied. If no
108requirements are given, it is satisfied, too.
109
110@item
111If it is an @code{or} form, at least one of the requirements must be
112satisfied. If no requirements are given, it is not satisfied.
113
114@item
115If it is a @code{not} form, the feature requirement must @emph{not} be
116satisfied.
117
118@item
119If the feature requirement is the keyword @code{else} and it is the last
120clause, it is satisfied if no prior clause matched.
121@end itemize
122
123If no clause is satisfied, an error is signalled.
124
125Since @code{cond-expand} is needed to tell what a Scheme implementation
126provides, it must be accessible without using any
85a9b4ed 127implementation-dependent operations, such as @code{use-modules} in
a0e07ba4
NJ
128Guile. Thus, it is not necessary to use any module to get access to
129this form.
130
131Currently, the feature identifiers @code{guile}, @code{r5rs} and
132@code{srfi-0} are supported. The other SRFIs are not in that list by
133default, because the SRFI modules must be explicitly used before their
12991fed 134exported bindings can be used.
a0e07ba4
NJ
135
136So if a Scheme program wishes to use SRFI-8, it has two possibilities:
137First, it can check whether the running Scheme implementation is Guile,
138and if it is, it can use the appropriate module:
139
140@lisp
141(cond-expand
142 (guile
143 (use-modules (srfi srfi-8)))
144 (srfi-8
145 #t))
146 ;; otherwise fail.
147@end lisp
148
149The other possibility is to use the @code{--use-srfi} command line
150option when invoking Guile (@pxref{Invoking Guile}). When you do that,
151the specified SRFI support modules will be loaded and add their feature
152identifier to the list of symbols checked by @code{cond-expand}.
153
154So, if you invoke Guile like this:
155
156@example
157$ guile --use-srfi=8
158@end example
159
160the following snippet will expand to @code{'hooray}.
161
162@lisp
163(cond-expand (srfi-8 'hooray))
164@end lisp
165
166
167@node SRFI-1
168@section SRFI-1 - List library
8742c48b 169@cindex SRFI-1
a0e07ba4
NJ
170
171@c FIXME::martin: Review me!
172
173The list library defined in SRFI-1 contains a lot of useful list
174processing procedures for construction, examining, destructuring and
175manipulating lists and pairs.
176
177Since SRFI-1 also defines some procedures which are already contained
178in R5RS and thus are supported by the Guile core library, some list
179and pair procedures which appear in the SRFI-1 document may not appear
180in this section. So when looking for a particular list/pair
181processing procedure, you should also have a look at the sections
182@ref{Lists} and @ref{Pairs}.
183
184@menu
185* SRFI-1 Constructors:: Constructing new lists.
186* SRFI-1 Predicates:: Testing list for specific properties.
187* SRFI-1 Selectors:: Selecting elements from lists.
188* SRFI-1 Length Append etc:: Length calculation and list appending.
189* SRFI-1 Fold and Map:: Higher-order list processing.
190* SRFI-1 Filtering and Partitioning:: Filter lists based on predicates.
85a9b4ed 191* SRFI-1 Searching:: Search for elements.
a0e07ba4
NJ
192* SRFI-1 Deleting:: Delete elements from lists.
193* SRFI-1 Association Lists:: Handle association lists.
194* SRFI-1 Set Operations:: Use lists for representing sets.
195@end menu
196
197@node SRFI-1 Constructors
198@subsection Constructors
199
200@c FIXME::martin: Review me!
201
202New lists can be constructed by calling one of the following
203procedures.
204
8f85c0c6 205@deffn {Scheme Procedure} xcons d a
a0e07ba4
NJ
206Like @code{cons}, but with interchanged arguments. Useful mostly when
207passed to higher-order procedures.
208@end deffn
209
8f85c0c6 210@deffn {Scheme Procedure} list-tabulate n init-proc
a0e07ba4
NJ
211Return an @var{n}-element list, where each list element is produced by
212applying the procedure @var{init-proc} to the corresponding list
213index. The order in which @var{init-proc} is applied to the indices
214is not specified.
215@end deffn
216
8f85c0c6 217@deffn {Scheme Procedure} circular-list elt1 elt2 @dots{}
a0e07ba4
NJ
218Return a circular list containing the given arguments @var{elt1}
219@var{elt2} @dots{}.
220@end deffn
221
8f85c0c6 222@deffn {Scheme Procedure} iota count [start step]
a0e07ba4
NJ
223Return a list containing @var{count} elements, where each element is
224calculated as follows:
225
226@var{start} + (@var{count} - 1) * @var{step}
227
228@var{start} defaults to 0 and @var{step} defaults to 1.
229@end deffn
230
231
232@node SRFI-1 Predicates
233@subsection Predicates
234
235@c FIXME::martin: Review me!
236
237The procedures in this section test specific properties of lists.
238
8f85c0c6 239@deffn {Scheme Procedure} proper-list? obj
a0e07ba4
NJ
240Return @code{#t} if @var{obj} is a proper list, that is a finite list,
241terminated with the empty list. Otherwise, return @code{#f}.
242@end deffn
243
8f85c0c6 244@deffn {Scheme Procedure} circular-list? obj
a0e07ba4
NJ
245Return @code{#t} if @var{obj} is a circular list, otherwise return
246@code{#f}.
247@end deffn
248
8f85c0c6 249@deffn {Scheme Procedure} dotted-list? obj
a0e07ba4
NJ
250Return @code{#t} if @var{obj} is a dotted list, return @code{#f}
251otherwise. A dotted list is a finite list which is not terminated by
252the empty list, but some other value.
253@end deffn
254
8f85c0c6 255@deffn {Scheme Procedure} null-list? lst
a0e07ba4
NJ
256Return @code{#t} if @var{lst} is the empty list @code{()}, @code{#f}
257otherwise. If something else than a proper or circular list is passed
85a9b4ed 258as @var{lst}, an error is signalled. This procedure is recommended
a0e07ba4
NJ
259for checking for the end of a list in contexts where dotted lists are
260not allowed.
261@end deffn
262
8f85c0c6 263@deffn {Scheme Procedure} not-pair? obj
a0e07ba4
NJ
264Return @code{#t} is @var{obj} is not a pair, @code{#f} otherwise.
265This is shorthand notation @code{(not (pair? @var{obj}))} and is
266supposed to be used for end-of-list checking in contexts where dotted
267lists are allowed.
268@end deffn
269
8f85c0c6 270@deffn {Scheme Procedure} list= elt= list1 @dots{}
a0e07ba4
NJ
271Return @code{#t} if all argument lists are equal, @code{#f} otherwise.
272List equality is determined by testing whether all lists have the same
273length and the corresponding elements are equal in the sense of the
274equality predicate @var{elt=}. If no or only one list is given,
275@code{#t} is returned.
276@end deffn
277
278
279@node SRFI-1 Selectors
280@subsection Selectors
281
282@c FIXME::martin: Review me!
283
8f85c0c6
NJ
284@deffn {Scheme Procedure} first pair
285@deffnx {Scheme Procedure} second pair
286@deffnx {Scheme Procedure} third pair
287@deffnx {Scheme Procedure} fourth pair
288@deffnx {Scheme Procedure} fifth pair
289@deffnx {Scheme Procedure} sixth pair
290@deffnx {Scheme Procedure} seventh pair
291@deffnx {Scheme Procedure} eighth pair
292@deffnx {Scheme Procedure} ninth pair
293@deffnx {Scheme Procedure} tenth pair
a0e07ba4
NJ
294These are synonyms for @code{car}, @code{cadr}, @code{caddr}, @dots{}.
295@end deffn
296
8f85c0c6 297@deffn {Scheme Procedure} car+cdr pair
a0e07ba4
NJ
298Return two values, the @sc{car} and the @sc{cdr} of @var{pair}.
299@end deffn
300
8f85c0c6
NJ
301@deffn {Scheme Procedure} take lst i
302@deffnx {Scheme Procedure} take! lst i
a0e07ba4
NJ
303Return a list containing the first @var{i} elements of @var{lst}.
304
305@code{take!} may modify the structure of the argument list @var{lst}
306in order to produce the result.
307@end deffn
308
8f85c0c6 309@deffn {Scheme Procedure} drop lst i
a0e07ba4
NJ
310Return a list containing all but the first @var{i} elements of
311@var{lst}.
312@end deffn
313
8f85c0c6 314@deffn {Scheme Procedure} take-right lst i
a0e07ba4
NJ
315Return the a list containing the @var{i} last elements of @var{lst}.
316@end deffn
317
8f85c0c6
NJ
318@deffn {Scheme Procedure} drop-right lst i
319@deffnx {Scheme Procedure} drop-right! lst i
a0e07ba4
NJ
320Return the a list containing all but the @var{i} last elements of
321@var{lst}.
322
323@code{drop-right!} may modify the structure of the argument list
324@var{lst} in order to produce the result.
325@end deffn
326
8f85c0c6
NJ
327@deffn {Scheme Procedure} split-at lst i
328@deffnx {Scheme Procedure} split-at! lst i
a0e07ba4
NJ
329Return two values, a list containing the first @var{i} elements of the
330list @var{lst} and a list containing the remaining elements.
331
332@code{split-at!} may modify the structure of the argument list
333@var{lst} in order to produce the result.
334@end deffn
335
8f85c0c6 336@deffn {Scheme Procedure} last lst
a0e07ba4
NJ
337Return the last element of the non-empty, finite list @var{lst}.
338@end deffn
339
340
341@node SRFI-1 Length Append etc
342@subsection Length, Append, Concatenate, etc.
343
344@c FIXME::martin: Review me!
345
8f85c0c6 346@deffn {Scheme Procedure} length+ lst
a0e07ba4
NJ
347Return the length of the argument list @var{lst}. When @var{lst} is a
348circular list, @code{#f} is returned.
349@end deffn
350
8f85c0c6
NJ
351@deffn {Scheme Procedure} concatenate list-of-lists
352@deffnx {Scheme Procedure} concatenate! list-of-lists
a0e07ba4
NJ
353Construct a list by appending all lists in @var{list-of-lists}.
354
355@code{concatenate!} may modify the structure of the given lists in
356order to produce the result.
357@end deffn
358
8f85c0c6
NJ
359@deffn {Scheme Procedure} append-reverse rev-head tail
360@deffnx {Scheme Procedure} append-reverse! rev-head tail
a0e07ba4
NJ
361Reverse @var{rev-head}, append @var{tail} and return the result. This
362is equivalent to @code{(append (reverse @var{rev-head}) @var{tail})},
363but more efficient.
364
365@code{append-reverse!} may modify @var{rev-head} in order to produce
366the result.
367@end deffn
368
8f85c0c6 369@deffn {Scheme Procedure} zip lst1 lst2 @dots{}
a0e07ba4
NJ
370Return a list as long as the shortest of the argument lists, where
371each element is a list. The first list contains the first elements of
372the argument lists, the second list contains the second elements, and
373so on.
374@end deffn
375
8f85c0c6
NJ
376@deffn {Scheme Procedure} unzip1 lst
377@deffnx {Scheme Procedure} unzip2 lst
378@deffnx {Scheme Procedure} unzip3 lst
379@deffnx {Scheme Procedure} unzip4 lst
380@deffnx {Scheme Procedure} unzip5 lst
a0e07ba4
NJ
381@code{unzip1} takes a list of lists, and returns a list containing the
382first elements of each list, @code{unzip2} returns two lists, the
383first containing the first elements of each lists and the second
384containing the second elements of each lists, and so on.
385@end deffn
386
e508c863
KR
387@deffn {Scheme Procedure} count pred lst1 @dots{} lstN
388Return a count of the number of times @var{pred} returns true when
389called on elements from the given lists.
390
391@var{pred} is called with @var{N} parameters @code{(@var{pred}
392@var{elem1} @dots{} @var{elemN})}, each element being from the
393corresponding @var{lst1} @dots{} @var{lstN}. The first call is with
394the first element of each list, the second with the second element
395from each, and so on.
396
397Counting stops when the end of the shortest list is reached. At least
398one list must be non-circular.
399@end deffn
400
a0e07ba4
NJ
401
402@node SRFI-1 Fold and Map
403@subsection Fold, Unfold & Map
404
405@c FIXME::martin: Review me!
406
8f85c0c6 407@deffn {Scheme Procedure} fold kons knil lst1 lst2 @dots{}
a0e07ba4
NJ
408Fold the procedure @var{kons} across all elements of @var{lst1},
409@var{lst2}, @dots{}. Produce the result of
410
411@code{(@var{kons} @var{en1} @var{en2} @dots{} (@var{kons} @var{e21}
412@var{e22} (@var{kons} @var{e11} @var{e12} @var{knil})))},
413
414if @var{enm} are the elements of the lists @var{lst1}, @var{lst2},
415@dots{}.
416@end deffn
417
8f85c0c6 418@deffn {Scheme Procedure} fold-right kons knil lst1 lst2 @dots{}
a0e07ba4
NJ
419Similar to @code{fold}, but applies @var{kons} in right-to-left order
420to the list elements, that is:
421
422@code{(@var{kons} @var{e11} @var{e12}(@var{kons} @var{e21}
423@var{e22} @dots{} (@var{kons} @var{en1} @var{en2} @var{knil})))},
424@end deffn
425
8f85c0c6 426@deffn {Scheme Procedure} pair-fold kons knil lst1 lst2 @dots{}
a0e07ba4
NJ
427Like @code{fold}, but apply @var{kons} to the pairs of the list
428instead of the list elements.
429@end deffn
430
8f85c0c6 431@deffn {Scheme Procedure} pair-fold-right kons knil lst1 lst2 @dots{}
a0e07ba4
NJ
432Like @code{fold-right}, but apply @var{kons} to the pairs of the list
433instead of the list elements.
434@end deffn
435
8f85c0c6 436@deffn {Scheme Procedure} reduce f ridentity lst
1ae7b878
KR
437@code{reduce} is a variant of @code{fold}. If @var{lst} is
438@code{()}, @var{ridentity} is returned. Otherwise, @code{(fold f (car
a0e07ba4
NJ
439@var{lst}) (cdr @var{lst}))} is returned.
440@end deffn
441
8f85c0c6 442@deffn {Scheme Procedure} reduce-right f ridentity lst
b5aa0215 443This is the @code{fold-right} variant of @code{reduce}.
a0e07ba4
NJ
444@end deffn
445
8f85c0c6 446@deffn {Scheme Procedure} unfold p f g seed [tail-gen]
a0e07ba4
NJ
447@code{unfold} is defined as follows:
448
449@lisp
450(unfold p f g seed) =
451 (if (p seed) (tail-gen seed)
452 (cons (f seed)
453 (unfold p f g (g seed))))
454@end lisp
455
456@table @var
457@item p
458Determines when to stop unfolding.
459
460@item f
461Maps each seed value to the corresponding list element.
462
463@item g
464Maps each seed value to next seed valu.
465
466@item seed
467The state value for the unfold.
468
469@item tail-gen
470Creates the tail of the list; defaults to @code{(lambda (x) '())}.
471@end table
472
473@var{g} produces a series of seed values, which are mapped to list
474elements by @var{f}. These elements are put into a list in
475left-to-right order, and @var{p} tells when to stop unfolding.
476@end deffn
477
8f85c0c6 478@deffn {Scheme Procedure} unfold-right p f g seed [tail]
a0e07ba4
NJ
479Construct a list with the following loop.
480
481@lisp
482(let lp ((seed seed) (lis tail))
483 (if (p seed) lis
484 (lp (g seed)
485 (cons (f seed) lis))))
486@end lisp
487
488@table @var
489@item p
490Determines when to stop unfolding.
491
492@item f
493Maps each seed value to the corresponding list element.
494
495@item g
496Maps each seed value to next seed valu.
497
498@item seed
499The state value for the unfold.
500
501@item tail-gen
502Creates the tail of the list; defaults to @code{(lambda (x) '())}.
503@end table
504
505@end deffn
506
8f85c0c6 507@deffn {Scheme Procedure} map f lst1 lst2 @dots{}
a0e07ba4
NJ
508Map the procedure over the list(s) @var{lst1}, @var{lst2}, @dots{} and
509return a list containing the results of the procedure applications.
510This procedure is extended with respect to R5RS, because the argument
511lists may have different lengths. The result list will have the same
512length as the shortest argument lists. The order in which @var{f}
513will be applied to the list element(s) is not specified.
514@end deffn
515
8f85c0c6 516@deffn {Scheme Procedure} for-each f lst1 lst2 @dots{}
a0e07ba4
NJ
517Apply the procedure @var{f} to each pair of corresponding elements of
518the list(s) @var{lst1}, @var{lst2}, @dots{}. The return value is not
519specified. This procedure is extended with respect to R5RS, because
520the argument lists may have different lengths. The shortest argument
521list determines the number of times @var{f} is called. @var{f} will
85a9b4ed 522be applied to the list elements in left-to-right order.
a0e07ba4
NJ
523
524@end deffn
525
8f85c0c6
NJ
526@deffn {Scheme Procedure} append-map f lst1 lst2 @dots{}
527@deffnx {Scheme Procedure} append-map! f lst1 lst2 @dots{}
12991fed 528Equivalent to
a0e07ba4
NJ
529
530@lisp
12991fed 531(apply append (map f clist1 clist2 ...))
a0e07ba4
NJ
532@end lisp
533
12991fed 534and
a0e07ba4
NJ
535
536@lisp
12991fed 537(apply append! (map f clist1 clist2 ...))
a0e07ba4
NJ
538@end lisp
539
540Map @var{f} over the elements of the lists, just as in the @code{map}
541function. However, the results of the applications are appended
542together to make the final result. @code{append-map} uses
543@code{append} to append the results together; @code{append-map!} uses
544@code{append!}.
545
546The dynamic order in which the various applications of @var{f} are
547made is not specified.
548@end deffn
549
8f85c0c6 550@deffn {Scheme Procedure} map! f lst1 lst2 @dots{}
a0e07ba4
NJ
551Linear-update variant of @code{map} -- @code{map!} is allowed, but not
552required, to alter the cons cells of @var{lst1} to construct the
553result list.
554
555The dynamic order in which the various applications of @var{f} are
556made is not specified. In the n-ary case, @var{lst2}, @var{lst3},
557@dots{} must have at least as many elements as @var{lst1}.
558@end deffn
559
8f85c0c6 560@deffn {Scheme Procedure} pair-for-each f lst1 lst2 @dots{}
a0e07ba4
NJ
561Like @code{for-each}, but applies the procedure @var{f} to the pairs
562from which the argument lists are constructed, instead of the list
563elements. The return value is not specified.
564@end deffn
565
8f85c0c6 566@deffn {Scheme Procedure} filter-map f lst1 lst2 @dots{}
a0e07ba4
NJ
567Like @code{map}, but only results from the applications of @var{f}
568which are true are saved in the result list.
569@end deffn
570
571
572@node SRFI-1 Filtering and Partitioning
573@subsection Filtering and Partitioning
574
575@c FIXME::martin: Review me!
576
577Filtering means to collect all elements from a list which satisfy a
578specific condition. Partitioning a list means to make two groups of
579list elements, one which contains the elements satisfying a condition,
580and the other for the elements which don't.
581
8f85c0c6
NJ
582@deffn {Scheme Procedure} filter pred lst
583@deffnx {Scheme Procedure} filter! pred lst
a0e07ba4
NJ
584Return a list containing all elements from @var{lst} which satisfy the
585predicate @var{pred}. The elements in the result list have the same
586order as in @var{lst}. The order in which @var{pred} is applied to
587the list elements is not specified.
588
589@code{filter!} is allowed, but not required to modify the structure of
590@end deffn
591
8f85c0c6
NJ
592@deffn {Scheme Procedure} partition pred lst
593@deffnx {Scheme Procedure} partition! pred lst
a0e07ba4
NJ
594Return two lists, one containing all elements from @var{lst} which
595satisfy the predicate @var{pred}, and one list containing the elements
596which do not satisfy the predicated. The elements in the result lists
597have the same order as in @var{lst}. The order in which @var{pred} is
598applied to the list elements is not specified.
599
600@code{partition!} is allowed, but not required to modify the structure of
601the input list.
602@end deffn
603
8f85c0c6
NJ
604@deffn {Scheme Procedure} remove pred lst
605@deffnx {Scheme Procedure} remove! pred lst
a0e07ba4
NJ
606Return a list containing all elements from @var{lst} which do not
607satisfy the predicate @var{pred}. The elements in the result list
608have the same order as in @var{lst}. The order in which @var{pred} is
609applied to the list elements is not specified.
610
611@code{remove!} is allowed, but not required to modify the structure of
612the input list.
613@end deffn
614
615
616@node SRFI-1 Searching
617@subsection Searching
618
619@c FIXME::martin: Review me!
620
621The procedures for searching elements in lists either accept a
622predicate or a comparison object for determining which elements are to
623be searched.
624
8f85c0c6 625@deffn {Scheme Procedure} find pred lst
a0e07ba4
NJ
626Return the first element of @var{lst} which satisfies the predicate
627@var{pred} and @code{#f} if no such element is found.
628@end deffn
629
8f85c0c6 630@deffn {Scheme Procedure} find-tail pred lst
a0e07ba4
NJ
631Return the first pair of @var{lst} whose @sc{car} satisfies the
632predicate @var{pred} and @code{#f} if no such element is found.
633@end deffn
634
8f85c0c6
NJ
635@deffn {Scheme Procedure} take-while pred lst
636@deffnx {Scheme Procedure} take-while! pred lst
a0e07ba4
NJ
637Return the longest initial prefix of @var{lst} whose elements all
638satisfy the predicate @var{pred}.
639
640@code{take-while!} is allowed, but not required to modify the input
641list while producing the result.
642@end deffn
643
8f85c0c6 644@deffn {Scheme Procedure} drop-while pred lst
a0e07ba4
NJ
645Drop the longest initial prefix of @var{lst} whose elements all
646satisfy the predicate @var{pred}.
647@end deffn
648
8f85c0c6
NJ
649@deffn {Scheme Procedure} span pred lst
650@deffnx {Scheme Procedure} span! pred lst
651@deffnx {Scheme Procedure} break pred lst
652@deffnx {Scheme Procedure} break! pred lst
a0e07ba4
NJ
653@code{span} splits the list @var{lst} into the longest initial prefix
654whose elements all satisfy the predicate @var{pred}, and the remaining
655tail. @code{break} inverts the sense of the predicate.
656
657@code{span!} and @code{break!} are allowed, but not required to modify
658the structure of the input list @var{lst} in order to produce the
659result.
660@end deffn
661
8f85c0c6 662@deffn {Scheme Procedure} any pred lst1 lst2 @dots{}
a0e07ba4
NJ
663Apply @var{pred} across the lists and return a true value if the
664predicate returns true for any of the list elements(s); return
665@code{#f} otherwise. The true value returned is always the result of
85a9b4ed 666the first successful application of @var{pred}.
a0e07ba4
NJ
667@end deffn
668
8f85c0c6 669@deffn {Scheme Procedure} every pred lst1 lst2 @dots{}
a0e07ba4
NJ
670Apply @var{pred} across the lists and return a true value if the
671predicate returns true for every of the list elements(s); return
672@code{#f} otherwise. The true value returned is always the result of
85a9b4ed 673the final successful application of @var{pred}.
a0e07ba4
NJ
674@end deffn
675
8f85c0c6 676@deffn {Scheme Procedure} list-index pred lst1 lst2 @dots{}
a0e07ba4
NJ
677Return the index of the leftmost element that satisfies @var{pred}.
678@end deffn
679
8f85c0c6 680@deffn {Scheme Procedure} member x lst [=]
a0e07ba4
NJ
681Return the first sublist of @var{lst} whose @sc{car} is equal to
682@var{x}. If @var{x} does no appear in @var{lst}, return @code{#f}.
683Equality is determined by the equality predicate @var{=}, or
684@code{equal?} if @var{=} is not given.
685@end deffn
686
687
688@node SRFI-1 Deleting
689@subsection Deleting
690
691@c FIXME::martin: Review me!
692
8f85c0c6
NJ
693@deffn {Scheme Procedure} delete x lst [=]
694@deffnx {Scheme Procedure} delete! x lst [=]
b6b9376a
KR
695Return a list containing the elements of @var{lst} but with those
696equal to @var{x} deleted. The returned elements will be in the same
697order as they were in @var{lst}.
698
699Equality is determined by the @var{=} predicate, or @code{equal?} if
700not given. An equality call is made just once for each element, but
701the order in which the calls are made on the elements is unspecified.
a0e07ba4 702
243bdb63 703The equality calls are always @code{(= x elem)}, ie.@: the given @var{x}
b6b9376a
KR
704is first. This means for instance elements greater than 5 can be
705deleted with @code{(delete 5 lst <)}.
706
707@code{delete} does not modify @var{lst}, but the return might share a
708common tail with @var{lst}. @code{delete!} may modify the structure
709of @var{lst} to construct its return.
a0e07ba4
NJ
710@end deffn
711
8f85c0c6
NJ
712@deffn {Scheme Procedure} delete-duplicates lst [=]
713@deffnx {Scheme Procedure} delete-duplicates! lst [=]
b6b9376a
KR
714Return a list containing the elements of @var{lst} but without
715duplicates.
716
717When elements are equal, only the first in @var{lst} is retained.
718Equal elements can be anywhere in @var{lst}, they don't have to be
719adjacent. The returned list will have the retained elements in the
720same order as they were in @var{lst}.
721
722Equality is determined by the @var{=} predicate, or @code{equal?} if
723not given. Calls @code{(= x y)} are made with element @var{x} being
724before @var{y} in @var{lst}. A call is made at most once for each
725combination, but the sequence of the calls across the elements is
726unspecified.
727
728@code{delete-duplicates} does not modify @var{lst}, but the return
729might share a common tail with @var{lst}. @code{delete-duplicates!}
730may modify the structure of @var{lst} to construct its return.
731
732In the worst case, this is an @math{O(N^2)} algorithm because it must
733check each element against all those preceding it. For long lists it
734is more efficient to sort and then compare only adjacent elements.
a0e07ba4
NJ
735@end deffn
736
737
738@node SRFI-1 Association Lists
739@subsection Association Lists
740
741@c FIXME::martin: Review me!
742
743Association lists are described in detail in section @ref{Association
744Lists}. The present section only documents the additional procedures
745for dealing with association lists defined by SRFI-1.
746
8f85c0c6 747@deffn {Scheme Procedure} assoc key alist [=]
a0e07ba4
NJ
748Return the pair from @var{alist} which matches @var{key}. Equality is
749determined by @var{=}, which defaults to @code{equal?} if not given.
750@var{alist} must be an association lists---a list of pairs.
751@end deffn
752
8f85c0c6 753@deffn {Scheme Procedure} alist-cons key datum alist
a0e07ba4
NJ
754Equivalent to
755
756@lisp
757(cons (cons @var{key} @var{datum}) @var{alist})
758@end lisp
759
760This procedure is used to coons a new pair onto an existing
761association list.
762@end deffn
763
8f85c0c6 764@deffn {Scheme Procedure} alist-copy alist
a0e07ba4
NJ
765Return a newly allocated copy of @var{alist}, that means that the
766spine of the list as well as the pairs are copied.
767@end deffn
768
8f85c0c6
NJ
769@deffn {Scheme Procedure} alist-delete key alist [=]
770@deffnx {Scheme Procedure} alist-delete! key alist [=]
a0e07ba4
NJ
771Return a list containing the pairs of @var{alist}, but without the
772pairs whose @sc{cars} are equal to @var{key}. Equality is determined
773by @var{=}, which defaults to @code{equal?} if not given.
774
775@code{alist-delete!} is allowed, but not required to modify the
776structure of the list @var{alist} in order to produce the result.
777@end deffn
778
779
780@node SRFI-1 Set Operations
781@subsection Set Operations on Lists
782
783@c FIXME::martin: Review me!
784
785Lists can be used for representing sets of objects. The procedures
786documented in this section can be used for such set representations.
85a9b4ed 787Man combining several sets or adding elements, they make sure that no
a0e07ba4
NJ
788object is contained more than once in a given list. Please note that
789lists are not a too efficient implementation method for sets, so if
790you need high performance, you should think about implementing a
791custom data structure for representing sets, such as trees, bitsets,
792hash tables or something similar.
793
794All these procedures accept an equality predicate as the first
795argument. This predicate is used for testing the objects in the list
796sets for sameness.
797
8f85c0c6 798@deffn {Scheme Procedure} lset<= = list1 @dots{}
a0e07ba4
NJ
799Return @code{#t} if every @var{listi} is a subset of @var{listi+1},
800otherwise return @code{#f}. Returns @code{#t} if called with less
801than two arguments. @var{=} is used for testing element equality.
802@end deffn
803
8f85c0c6 804@deffn {Scheme Procedure} lset= = list1 list2 @dots{}
a0e07ba4
NJ
805Return @code{#t} if all argument lists are equal. @var{=} is used for
806testing element equality.
807@end deffn
808
8f85c0c6
NJ
809@deffn {Scheme Procedure} lset-adjoin = list elt1 @dots{}
810@deffnx {Scheme Procedure} lset-adjoin! = list elt1 @dots{}
a0e07ba4
NJ
811Add all @var{elts} to the list @var{list}, suppressing duplicates and
812return the resulting list. @code{lset-adjoin!} is allowed, but not
813required to modify its first argument. @var{=} is used for testing
814element equality.
815@end deffn
816
8f85c0c6
NJ
817@deffn {Scheme Procedure} lset-union = list1 @dots{}
818@deffnx {Scheme Procedure} lset-union! = list1 @dots{}
a0e07ba4
NJ
819Return the union of all argument list sets. The union is the set of
820all elements which appear in any of the argument sets.
821@code{lset-union!} is allowed, but not required to modify its first
822argument. @var{=} is used for testing element equality.
823@end deffn
824
8f85c0c6
NJ
825@deffn {Scheme Procedure} lset-intersection = list1 list2 @dots{}
826@deffnx {Scheme Procedure} lset-intersection! = list1 list2 @dots{}
a0e07ba4
NJ
827Return the intersection of all argument list sets. The intersection
828is the set containing all elements which appear in all argument sets.
829@code{lset-intersection!} is allowed, but not required to modify its
830first argument. @var{=} is used for testing element equality.
831@end deffn
832
8f85c0c6
NJ
833@deffn {Scheme Procedure} lset-difference = list1 list2 @dots{}
834@deffnx {Scheme Procedure} lset-difference! = list1 list2 @dots{}
a0e07ba4
NJ
835Return the difference of all argument list sets. The difference is
836the the set containing all elements of the first list which do not
837appear in the other lists. @code{lset-difference!} is allowed, but
838not required to modify its first argument. @var{=} is used for testing
839element equality.
840@end deffn
841
8f85c0c6
NJ
842@deffn {Scheme Procedure} lset-xor = list1 @dots{}
843@deffnx {Scheme Procedure} lset-xor! = list1 @dots{}
a0e07ba4
NJ
844Return the set containing all elements which appear in the first
845argument list set, but not in the second; or, more generally: which
846appear in an odd number of sets. @code{lset-xor!} is allowed, but
847not required to modify its first argument. @var{=} is used for testing
848element equality.
849@end deffn
850
8f85c0c6
NJ
851@deffn {Scheme Procedure} lset-diff+intersection = list1 list2 @dots{}
852@deffnx {Scheme Procedure} lset-diff+intersection! = list1 list2 @dots{}
a0e07ba4
NJ
853Return two values, the difference and the intersection of the argument
854list sets. This works like a combination of @code{lset-difference} and
855@code{lset-intersection}, but is more efficient.
856@code{lset-diff+intersection!} is allowed, but not required to modify
857its first argument. @var{=} is used for testing element equality. You
858have to use some means to deal with the multiple values these
859procedures return (@pxref{Multiple Values}).
860@end deffn
861
862
863@node SRFI-2
864@section SRFI-2 - and-let*
8742c48b 865@cindex SRFI-2
a0e07ba4 866
4fd0db14
KR
867@noindent
868The following syntax can be obtained with
a0e07ba4 869
4fd0db14
KR
870@lisp
871(use-modules (srfi srfi-2))
872@end lisp
a0e07ba4 873
4fd0db14
KR
874@deffn {library syntax} and-let* (clause @dots{}) body @dots{}
875A combination of @code{and} and @code{let*}.
876
877Each @var{clause} is evaluated in turn, and if @code{#f} is obtained
878then evaluation stops and @code{#f} is returned. If all are
879non-@code{#f} then @var{body} is evaluated and the last form gives the
880return value. Each @var{clause} should be one of the following,
881
882@table @code
883@item (symbol expr)
884Evaluate @var{expr}, check for @code{#f}, and bind it to @var{symbol}.
885Like @code{let*}, that binding is available to subsequent clauses.
886@item (expr)
887Evaluate @var{expr} and check for @code{#f}.
888@item symbol
889Get the value bound to @var{symbol} and check for @code{#f}.
890@end table
a0e07ba4 891
4fd0db14
KR
892Notice that @code{(expr)} has an ``extra'' pair of parentheses, for
893instance @code{((eq? x y))}. One way to remember this is to imagine
894the @code{symbol} in @code{(symbol expr)} is omitted.
a0e07ba4 895
4fd0db14
KR
896@code{and-let*} is good for calculations where a @code{#f} value means
897termination, but where a non-@code{#f} value is going to be needed in
898subsequent expressions.
899
900The following illustrates this, it returns text between brackets
901@samp{[...]} in a string, or @code{#f} if there are no such brackets
902(ie.@: either @code{string-index} gives @code{#f}).
903
904@example
905(define (extract-brackets str)
906 (and-let* ((start (string-index str #\[))
907 (end (string-index str #\] start)))
908 (substring str (1+ start) end)))
909@end example
910
911The following shows plain variables and expressions tested too.
912@code{diagnostic-levels} is taken to be an alist associating a
913diagnostic type with a level. @code{str} is printed only if the type
914is known and its level is high enough.
915
916@example
917(define (show-diagnostic type str)
918 (and-let* (want-diagnostics
919 (level (assq-ref diagnostic-levels type))
920 ((>= level current-diagnostic-level)))
921 (display str)))
922@end example
923
924The advantage of @code{and-let*} is that an extended sequence of
925expressions and tests doesn't require lots of nesting as would arise
926from separate @code{and} and @code{let*}, or from @code{cond} with
927@code{=>}.
928
929@end deffn
a0e07ba4
NJ
930
931
932@node SRFI-4
933@section SRFI-4 - Homogeneous numeric vector datatypes.
8742c48b 934@cindex SRFI-4
a0e07ba4
NJ
935
936@c FIXME::martin: Review me!
937
938SRFI-4 defines a set of datatypes for vectors whose elements are all
939of the same numeric type. Vectors for signed and unsigned exact
940integer or inexact real numbers in several precisions are available.
941
942Procedures similar to the vector procedures (@pxref{Vectors}) are
943provided for handling these homogeneous vectors, but they are distinct
944datatypes.
945
946The reason for providing this set of datatypes is that with the
947limitation (all elements must have the same type), it is possible to
948implement them much more memory-efficient than normal, heterogenous
949vectors.
950
951If you want to use these datatypes and the corresponding procedures,
952you have to use the module @code{(srfi srfi-4)}.
953
954Ten vector data types are provided: Unsigned and signed integer values
955with 8, 16, 32 and 64 bits and floating point values with 32 and 64
956bits. In the following descriptions, the tags @code{u8}, @code{s8},
957@code{u16}, @code{s16}, @code{u32}, @code{s32}, @code{u64},
958@code{s64}, @code{f32}, @code{f64}, respectively, are used for
959denoting the various types.
960
961@menu
962* SRFI-4 - Read Syntax:: How to write homogeneous vector literals.
963* SRFI-4 - Procedures:: Available homogeneous vector procedures.
964@end menu
965
966
967@node SRFI-4 - Read Syntax
968@subsection SRFI-4 - Read Syntax
969
970Homogeneous numeric vectors have an external representation (read
971syntax) similar to normal Scheme vectors, but with an additional tag
972telling the vector's type.
973
974@lisp
975#u16(1 2 3)
976@end lisp
977
978denotes a homogeneous numeric vector of three elements, which are the
979values 1, 2 and 3, represented as 16-bit unsigned integers.
980Correspondingly,
981
982@lisp
983#f64(3.1415 2.71)
984@end lisp
985
986denotes a vector of two elements, which are the values 3.1415 and
9872.71, represented as floating-point values of 64 bit precision.
988
989Please note that the read syntax for floating-point vectors conflicts
990with Standard Scheme, because there @code{#f} is defined to be the
991literal false value. That means, that with the loaded SRFI-4 module,
992it is not possible to enter some list like
993
994@lisp
995'(1 #f3)
996@end lisp
997
998and hope that it will be parsed as a three-element list with the
999elements 1, @code{#f} and 3. In normal use, this should be no
1000problem, because people tend to terminate tokens sensibly when writing
1001Scheme expressions.
1002
1003@node SRFI-4 - Procedures
1004@subsection SRFI-4 Procedures
1005
1006The procedures listed in this section are provided for all homogeneous
1007numeric vector datatypes. For brevity, they are not all documented,
1008but a summary of the procedures is given. In the following
1009descriptions, you can replace @code{TAG} by any of the datatype
1010indicators @code{u8}, @code{s8}, @code{u16}, @code{s16}, @code{u32},
1011@code{s32}, @code{u64}, @code{s64}, @code{f32} and @code{f64}.
1012
1013For example, you can use the procedures @code{u8vector?},
1014@code{make-s8vector}, @code{u16vector}, @code{u32vector-length},
1015@code{s64vector-ref}, @code{f32vector-set!} or @code{f64vector->list}.
1016
8f85c0c6 1017@deffn {Scheme Procedure} TAGvector? obj
a0e07ba4
NJ
1018Return @code{#t} if @var{obj} is a homogeneous numeric vector of type
1019@code{TAG}.
1020@end deffn
1021
8f85c0c6 1022@deffn {Scheme Procedure} make-TAGvector n [value]
a0e07ba4
NJ
1023Create a newly allocated homogeneous numeric vector of type
1024@code{TAG}, which can hold @var{n} elements. If @var{value} is given,
1025the vector is initialized with the value, otherwise, the contents of
1026the returned vector is not specified.
1027@end deffn
1028
8f85c0c6 1029@deffn {Scheme Procedure} TAGvector value1 @dots{}
a0e07ba4
NJ
1030Create a newly allocated homogeneous numeric vector of type
1031@code{TAG}. The returned vector is as long as the number of arguments
1032given, and is initialized with the argument values.
1033@end deffn
1034
8f85c0c6 1035@deffn {Scheme Procedure} TAGvector-length TAGvec
a0e07ba4
NJ
1036Return the number of elements in @var{TAGvec}.
1037@end deffn
1038
8f85c0c6 1039@deffn {Scheme Procedure} TAGvector-ref TAGvec i
a0e07ba4
NJ
1040Return the element at index @var{i} in @var{TAGvec}.
1041@end deffn
1042
8f85c0c6 1043@deffn {Scheme Procedure} TAGvector-ref TAGvec i value
a0e07ba4
NJ
1044Set the element at index @var{i} in @var{TAGvec} to @var{value}. The
1045return value is not specified.
1046@end deffn
1047
8f85c0c6 1048@deffn {Scheme Procedure} TAGvector->list TAGvec
a0e07ba4
NJ
1049Return a newly allocated list holding all elements of @var{TAGvec}.
1050@end deffn
1051
8f85c0c6 1052@deffn {Scheme Procedure} list->TAGvector lst
a0e07ba4
NJ
1053Return a newly allocated homogeneous numeric vector of type @code{TAG},
1054initialized with the elements of the list @var{lst}.
1055@end deffn
1056
1057
1058@node SRFI-6
1059@section SRFI-6 - Basic String Ports
8742c48b 1060@cindex SRFI-6
a0e07ba4
NJ
1061
1062SRFI-6 defines the procedures @code{open-input-string},
1063@code{open-output-string} and @code{get-output-string}. These
1064procedures are included in the Guile core, so using this module does not
1065make any difference at the moment. But it is possible that support for
1066SRFI-6 will be factored out of the core library in the future, so using
1067this module does not hurt, after all.
1068
1069@node SRFI-8
1070@section SRFI-8 - receive
8742c48b 1071@cindex SRFI-8
a0e07ba4
NJ
1072
1073@code{receive} is a syntax for making the handling of multiple-value
1074procedures easier. It is documented in @xref{Multiple Values}.
1075
1076
1077@node SRFI-9
1078@section SRFI-9 - define-record-type
8742c48b 1079@cindex SRFI-9
a0e07ba4
NJ
1080
1081This is the SRFI way for defining record types. The Guile
1082implementation is a layer above Guile's normal record construction
1083procedures (@pxref{Records}). The nice thing about this kind of record
1084definition method is that no new names are implicitly created, all
1085constructor, accessor and predicates are explicitly given. This reduces
1086the risk of variable capture.
1087
1088The syntax of a record type definition is:
1089
1090@example
1091@group
1092<record type definition>
1093 -> (define-record-type <type name>
1094 (<constructor name> <field tag> ...)
1095 <predicate name>
1096 <field spec> ...)
1097<field spec> -> (<field tag> <accessor name>)
1098 -> (<field tag> <accessor name> <modifier name>)
1099<field tag> -> <identifier>
1100<... name> -> <identifier>
1101@end group
1102@end example
1103
1104Usage example:
1105
1106@example
1107guile> (use-modules (srfi srfi-9))
12991fed 1108guile> (define-record-type :foo (make-foo x) foo?
a0e07ba4
NJ
1109 (x get-x) (y get-y set-y!))
1110guile> (define f (make-foo 1))
1111guile> f
1112#<:foo x: 1 y: #f>
1113guile> (get-x f)
11141
1115guile> (set-y! f 2)
11162
1117guile> (get-y f)
11182
1119guile> f
1120#<:foo x: 1 y: 2>
1121guile> (foo? f)
1122#t
1123guile> (foo? 1)
1124#f
1125@end example
1126
1127
1128@node SRFI-10
1129@section SRFI-10 - Hash-Comma Reader Extension
8742c48b 1130@cindex SRFI-10
a0e07ba4
NJ
1131
1132@cindex hash-comma
1133@cindex #,()
1134The module @code{(srfi srfi-10)} implements the syntax extension
1135@code{#,()}, also called hash-comma, which is defined in SRFI-10.
1136
1137The support for SRFI-10 consists of the procedure
1138@code{define-reader-ctor} for defining new reader constructors and the
1139read syntax form
1140
1141@example
1142#,(@var{ctor} @var{datum} ...)
1143@end example
1144
1145where @var{ctor} must be a symbol for which a read constructor was
85a9b4ed 1146defined previously, using @code{define-reader-ctor}.
a0e07ba4
NJ
1147
1148Example:
1149
1150@lisp
4310df36 1151(use-modules (ice-9 rdelim)) ; for read-line
a0e07ba4
NJ
1152(define-reader-ctor 'file open-input-file)
1153(define f '#,(file "/etc/passwd"))
1154(read-line f)
1155@result{}
1156"root:x:0:0:root:/root:/bin/bash"
1157@end lisp
1158
1159Please note the quote before the @code{#,(file ...)} expression. This
1160is necessary because ports are not self-evaluating in Guile.
1161
8f85c0c6 1162@deffn {Scheme Procedure} define-reader-ctor symbol proc
a0e07ba4
NJ
1163Define @var{proc} as the reader constructor for hash-comma forms with a
1164tag @var{symbol}. @var{proc} will be applied to the datum(s) following
1165the tag in the hash-comma expression after the complete form has been
1166read in. The result of @var{proc} is returned by the Scheme reader.
1167@end deffn
1168
1169
1170@node SRFI-11
1171@section SRFI-11 - let-values
8742c48b 1172@cindex SRFI-11
a0e07ba4 1173
8742c48b
KR
1174@findex let-values
1175@findex let-values*
a0e07ba4
NJ
1176This module implements the binding forms for multiple values
1177@code{let-values} and @code{let-values*}. These forms are similar to
1178@code{let} and @code{let*} (@pxref{Local Bindings}), but they support
1179binding of the values returned by multiple-valued expressions.
1180
1181Write @code{(use-modules (srfi srfi-11))} to make the bindings
1182available.
1183
1184@lisp
1185(let-values (((x y) (values 1 2))
1186 ((z f) (values 3 4)))
1187 (+ x y z f))
1188@result{}
118910
1190@end lisp
1191
1192@code{let-values} performs all bindings simultaneously, which means that
1193no expression in the binding clauses may refer to variables bound in the
1194same clause list. @code{let-values*}, on the other hand, performs the
1195bindings sequentially, just like @code{let*} does for single-valued
1196expressions.
1197
1198
1199@node SRFI-13
1200@section SRFI-13 - String Library
8742c48b 1201@cindex SRFI-13
a0e07ba4
NJ
1202
1203In this section, we will describe all procedures defined in SRFI-13
1204(string library) and implemented by the module @code{(srfi srfi-13)}.
1205
1206Note that only the procedures from SRFI-13 are documented here which are
1207not already contained in Guile. For procedures not documented here
1208please refer to the relevant chapters in the Guile Reference Manual, for
1209example the documentation of strings and string procedures
1210(@pxref{Strings}).
1211
40f316d0
MG
1212All of the procedures defined in SRFI-13, which are not already
1213included in the Guile core library, are implemented in the module
1214@code{(srfi srfi-13)}. The procedures which are both in Guile and in
1215SRFI-13 are slightly extended in this module. Their bindings
1216overwrite those in the Guile core.
a0e07ba4
NJ
1217
1218The procedures which are defined in the section @emph{Low-level
1219procedures} of SRFI-13 for parsing optional string indices, substring
1220specification checking and Knuth-Morris-Pratt-Searching are not
1221implemented.
1222
1223The procedures @code{string-contains} and @code{string-contains-ci} are
1224not implemented very efficiently at the moment. This will be changed as
1225soon as possible.
1226
1227@menu
1228* Loading SRFI-13:: How to load SRFI-13 support.
1229* SRFI-13 Predicates:: String predicates.
1230* SRFI-13 Constructors:: String constructing procedures.
1231* SRFI-13 List/String Conversion:: Conversion from/to lists.
1232* SRFI-13 Selection:: Selection portions of strings.
85a9b4ed 1233* SRFI-13 Modification:: Modify strings in-place.
a0e07ba4
NJ
1234* SRFI-13 Comparison:: Compare strings.
1235* SRFI-13 Prefixes/Suffixes:: Detect common pre-/suffixes.
1236* SRFI-13 Searching:: Searching for substrings.
1237* SRFI-13 Case Mapping:: Mapping to lower-/upper-case.
1238* SRFI-13 Reverse/Append:: Reverse and append strings.
1239* SRFI-13 Fold/Unfold/Map:: Construct/deconstruct strings.
40f316d0 1240* SRFI-13 Replicate/Rotate:: Replicate and rotate portions of strings.
a0e07ba4
NJ
1241* SRFI-13 Miscellaneous:: Left-over string procedures.
1242* SRFI-13 Filtering/Deleting:: Filter and delete characters from strings.
1243@end menu
1244
1245
1246@node Loading SRFI-13
1247@subsection Loading SRFI-13
1248
1249When Guile is properly installed, SRFI-13 support can be loaded into a
1250running Guile by using the @code{(srfi srfi-13)} module.
1251
1252@example
1253$ guile
1254guile> (use-modules (srfi srfi-13))
1255guile>
1256@end example
1257
1258When this step causes any errors, Guile is not properly installed.
1259
1260One possible reason is that Guile cannot find either the Scheme module
1261file @file{srfi-13.scm}, or it cannot find the shared object file
1262@file{libguile-srfi-srfi-13-14.so}. Make sure that the former is in the
1263Guile load path and that the latter is either installed in some default
1264location like @file{/usr/local/lib} or that the directory it was
1265installed to is in your @code{LTDL_LIBRARY_PATH}. The same applies to
1266@file{srfi-14.scm}.
1267
1268Now you can test whether the SRFI-13 procedures are working by calling
1269the @code{string-concatenate} procedure.
1270
1271@example
1272guile> (string-concatenate '("Hello" " " "World!"))
1273"Hello World!"
1274@end example
1275
1276@node SRFI-13 Predicates
12991fed 1277@subsection Predicates
a0e07ba4
NJ
1278
1279In addition to the primitives @code{string?} and @code{string-null?},
1280which are already in the Guile core, the string predicates
1281@code{string-any} and @code{string-every} are defined by SRFI-13.
1282
8f85c0c6 1283@deffn {Scheme Procedure} string-any pred s [start end]
a0e07ba4
NJ
1284Check if the predicate @var{pred} is true for any character in
1285the string @var{s}, proceeding from left (index @var{start}) to
1286right (index @var{end}). If @code{string-any} returns true,
1287the returned true value is the one produced by the first
1288successful application of @var{pred}.
1289@end deffn
1290
8f85c0c6 1291@deffn {Scheme Procedure} string-every pred s [start end]
a0e07ba4
NJ
1292Check if the predicate @var{pred} is true for every character
1293in the string @var{s}, proceeding from left (index @var{start})
1294to right (index @var{end}). If @code{string-every} returns
1295true, the returned true value is the one produced by the final
1296application of @var{pred} to the last character of @var{s}.
1297@end deffn
1298
1299
1300@c ===================================================================
1301
1302@node SRFI-13 Constructors
1303@subsection Constructors
1304
1305SRFI-13 defines several procedures for constructing new strings. In
1306addition to @code{make-string} and @code{string} (available in the Guile
1307core library), the procedure @code{string-tabulate} does exist.
1308
8f85c0c6 1309@deffn {Scheme Procedure} string-tabulate proc len
a0e07ba4
NJ
1310@var{proc} is an integer->char procedure. Construct a string
1311of size @var{len} by applying @var{proc} to each index to
1312produce the corresponding string element. The order in which
1313@var{proc} is applied to the indices is not specified.
1314@end deffn
1315
1316
1317@c ===================================================================
1318
1319@node SRFI-13 List/String Conversion
1320@subsection List/String Conversion
1321
1322The procedure @code{string->list} is extended by SRFI-13, that is why it
1323is included in @code{(srfi srfi-13)}. The other procedures are new.
1324The Guile core already contains the procedure @code{list->string} for
1325converting a list of characters into a string (@pxref{List/String
1326Conversion}).
1327
8f85c0c6 1328@deffn {Scheme Procedure} string->list str [start end]
a0e07ba4
NJ
1329Convert the string @var{str} into a list of characters.
1330@end deffn
1331
8f85c0c6 1332@deffn {Scheme Procedure} reverse-list->string chrs
a0e07ba4
NJ
1333An efficient implementation of @code{(compose string->list
1334reverse)}:
1335
1336@smalllisp
1337(reverse-list->string '(#\a #\B #\c)) @result{} "cBa"
1338@end smalllisp
1339@end deffn
1340
8f85c0c6 1341@deffn {Scheme Procedure} string-join ls [delimiter grammar]
a0e07ba4
NJ
1342Append the string in the string list @var{ls}, using the string
1343@var{delim} as a delimiter between the elements of @var{ls}.
1344@var{grammar} is a symbol which specifies how the delimiter is
1345placed between the strings, and defaults to the symbol
1346@code{infix}.
1347
1348@table @code
1349@item infix
1350Insert the separator between list elements. An empty string
1351will produce an empty list.
1352
1353@item string-infix
1354Like @code{infix}, but will raise an error if given the empty
1355list.
1356
1357@item suffix
1358Insert the separator after every list element.
1359
1360@item prefix
1361Insert the separator before each list element.
1362@end table
1363@end deffn
1364
1365
1366@c ===================================================================
1367
1368@node SRFI-13 Selection
1369@subsection Selection
1370
1371These procedures are called @dfn{selectors}, because they access
1372information about the string or select pieces of a given string.
1373
1374Additional selector procedures are documented in the Strings section
1375(@pxref{String Selection}), like @code{string-length} or
1376@code{string-ref}.
1377
1378@code{string-copy} is also available in core Guile, but this version
1379accepts additional start/end indices.
1380
8f85c0c6 1381@deffn {Scheme Procedure} string-copy str [start end]
a0e07ba4
NJ
1382Return a freshly allocated copy of the string @var{str}. If
1383given, @var{start} and @var{end} delimit the portion of
1384@var{str} which is copied.
1385@end deffn
1386
8f85c0c6 1387@deffn {Scheme Procedure} substring/shared str start [end]
a0e07ba4
NJ
1388Like @code{substring}, but the result may share memory with the
1389argument @var{str}.
1390@end deffn
1391
8f85c0c6 1392@deffn {Scheme Procedure} string-copy! target tstart s [start end]
a0e07ba4
NJ
1393Copy the sequence of characters from index range [@var{start},
1394@var{end}) in string @var{s} to string @var{target}, beginning
1395at index @var{tstart}. The characters are copied left-to-right
1396or right-to-left as needed - the copy is guaranteed to work,
1397even if @var{target} and @var{s} are the same string. It is an
1398error if the copy operation runs off the end of the target
1399string.
1400@end deffn
1401
8f85c0c6
NJ
1402@deffn {Scheme Procedure} string-take s n
1403@deffnx {Scheme Procedure} string-take-right s n
a0e07ba4
NJ
1404Return the @var{n} first/last characters of @var{s}.
1405@end deffn
1406
8f85c0c6
NJ
1407@deffn {Scheme Procedure} string-drop s n
1408@deffnx {Scheme Procedure} string-drop-right s n
a0e07ba4
NJ
1409Return all but the first/last @var{n} characters of @var{s}.
1410@end deffn
1411
8f85c0c6
NJ
1412@deffn {Scheme Procedure} string-pad s len [chr start end]
1413@deffnx {Scheme Procedure} string-pad-right s len [chr start end]
a0e07ba4
NJ
1414Take that characters from @var{start} to @var{end} from the
1415string @var{s} and return a new string, right(left)-padded by the
1416character @var{chr} to length @var{len}. If the resulting
1417string is longer than @var{len}, it is truncated on the right (left).
1418@end deffn
1419
8f85c0c6
NJ
1420@deffn {Scheme Procedure} string-trim s [char_pred start end]
1421@deffnx {Scheme Procedure} string-trim-right s [char_pred start end]
1422@deffnx {Scheme Procedure} string-trim-both s [char_pred start end]
a0e07ba4
NJ
1423Trim @var{s} by skipping over all characters on the left/right/both
1424sides of the string that satisfy the parameter @var{char_pred}:
1425
1426@itemize @bullet
1427@item
1428if it is the character @var{ch}, characters equal to
1429@var{ch} are trimmed,
1430
1431@item
1432if it is a procedure @var{pred} characters that
1433satisfy @var{pred} are trimmed,
1434
1435@item
1436if it is a character set, characters in that set are trimmed.
1437@end itemize
1438
1439If called without a @var{char_pred} argument, all whitespace is
1440trimmed.
1441@end deffn
1442
1443
1444@c ===================================================================
1445
1446@node SRFI-13 Modification
1447@subsection Modification
1448
1449The procedure @code{string-fill!} is extended from R5RS because it
1450accepts optional start/end indices. This bindings shadows the procedure
1451of the same name in the Guile core. The second modification procedure
1452@code{string-set!} is documented in the Strings section (@pxref{String
1453Modification}).
1454
8f85c0c6 1455@deffn {Scheme Procedure} string-fill! str chr [start end]
a0e07ba4
NJ
1456Stores @var{chr} in every element of the given @var{str} and
1457returns an unspecified value.
1458@end deffn
1459
1460
1461@c ===================================================================
1462
1463@node SRFI-13 Comparison
1464@subsection Comparison
1465
1466The procedures in this section are used for comparing strings in
1467different ways. The comparison predicates differ from those in R5RS in
1468that they do not only return @code{#t} or @code{#f}, but the mismatch
1469index in the case of a true return value.
1470
1471@code{string-hash} and @code{string-hash-ci} are for calculating hash
1472values for strings, useful for implementing fast lookup mechanisms.
1473
8f85c0c6
NJ
1474@deffn {Scheme Procedure} string-compare s1 s2 proc_lt proc_eq proc_gt [start1 end1 start2 end2]
1475@deffnx {Scheme Procedure} string-compare-ci s1 s2 proc_lt proc_eq proc_gt [start1 end1 start2 end2]
a0e07ba4
NJ
1476Apply @var{proc_lt}, @var{proc_eq}, @var{proc_gt} to the
1477mismatch index, depending upon whether @var{s1} is less than,
1478equal to, or greater than @var{s2}. The mismatch index is the
1479largest index @var{i} such that for every 0 <= @var{j} <
1480@var{i}, @var{s1}[@var{j}] = @var{s2}[@var{j}] - that is,
1481@var{i} is the first position that does not match. The
1482character comparison is done case-insensitively.
1483@end deffn
1484
8f85c0c6
NJ
1485@deffn {Scheme Procedure} string= s1 s2 [start1 end1 start2 end2]
1486@deffnx {Scheme Procedure} string<> s1 s2 [start1 end1 start2 end2]
1487@deffnx {Scheme Procedure} string< s1 s2 [start1 end1 start2 end2]
1488@deffnx {Scheme Procedure} string> s1 s2 [start1 end1 start2 end2]
1489@deffnx {Scheme Procedure} string<= s1 s2 [start1 end1 start2 end2]
1490@deffnx {Scheme Procedure} string>= s1 s2 [start1 end1 start2 end2]
a0e07ba4
NJ
1491Compare @var{s1} and @var{s2} and return @code{#f} if the predicate
1492fails. Otherwise, the mismatch index is returned (or @var{end1} in the
1493case of @code{string=}.
1494@end deffn
1495
8f85c0c6
NJ
1496@deffn {Scheme Procedure} string-ci= s1 s2 [start1 end1 start2 end2]
1497@deffnx {Scheme Procedure} string-ci<> s1 s2 [start1 end1 start2 end2]
1498@deffnx {Scheme Procedure} string-ci< s1 s2 [start1 end1 start2 end2]
1499@deffnx {Scheme Procedure} string-ci> s1 s2 [start1 end1 start2 end2]
1500@deffnx {Scheme Procedure} string-ci<= s1 s2 [start1 end1 start2 end2]
1501@deffnx {Scheme Procedure} string-ci>= s1 s2 [start1 end1 start2 end2]
a0e07ba4
NJ
1502Compare @var{s1} and @var{s2} and return @code{#f} if the predicate
1503fails. Otherwise, the mismatch index is returned (or @var{end1} in the
1504case of @code{string=}. These are the case-insensitive variants.
1505@end deffn
1506
8f85c0c6
NJ
1507@deffn {Scheme Procedure} string-hash s [bound start end]
1508@deffnx {Scheme Procedure} string-hash-ci s [bound start end]
a0e07ba4
NJ
1509Return a hash value of the string @var{s} in the range 0 @dots{}
1510@var{bound} - 1. @code{string-hash-ci} is the case-insensitive variant.
1511@end deffn
1512
1513
1514@c ===================================================================
1515
1516@node SRFI-13 Prefixes/Suffixes
1517@subsection Prefixes/Suffixes
1518
1519Using these procedures you can determine whether a given string is a
1520prefix or suffix of another string or how long a common prefix/suffix
1521is.
1522
8f85c0c6
NJ
1523@deffn {Scheme Procedure} string-prefix-length s1 s2 [start1 end1 start2 end2]
1524@deffnx {Scheme Procedure} string-prefix-length-ci s1 s2 [start1 end1 start2 end2]
1525@deffnx {Scheme Procedure} string-suffix-length s1 s2 [start1 end1 start2 end2]
1526@deffnx {Scheme Procedure} string-suffix-length-ci s1 s2 [start1 end1 start2 end2]
a0e07ba4
NJ
1527Return the length of the longest common prefix/suffix of the two
1528strings. @code{string-prefix-length-ci} and
1529@code{string-suffix-length-ci} are the case-insensitive variants.
1530@end deffn
1531
8f85c0c6
NJ
1532@deffn {Scheme Procedure} string-prefix? s1 s2 [start1 end1 start2 end2]
1533@deffnx {Scheme Procedure} string-prefix-ci? s1 s2 [start1 end1 start2 end2]
1534@deffnx {Scheme Procedure} string-suffix? s1 s2 [start1 end1 start2 end2]
1535@deffnx {Scheme Procedure} string-suffix-ci? s1 s2 [start1 end1 start2 end2]
a0e07ba4
NJ
1536Is @var{s1} a prefix/suffix of @var{s2}. @code{string-prefix-ci?} and
1537@code{string-suffix-ci?} are the case-insensitive variants.
1538@end deffn
1539
1540
1541@c ===================================================================
1542
1543@node SRFI-13 Searching
1544@subsection Searching
1545
1546Use these procedures to find out whether a string contains a given
1547character or a given substring, or a character from a set of characters.
1548
8f85c0c6
NJ
1549@deffn {Scheme Procedure} string-index s char_pred [start end]
1550@deffnx {Scheme Procedure} string-index-right s char_pred [start end]
a0e07ba4 1551Search through the string @var{s} from left to right (right to left),
85a9b4ed 1552returning the index of the first (last) occurrence of a character which
a0e07ba4
NJ
1553
1554@itemize @bullet
1555@item
1556equals @var{char_pred}, if it is character,
1557
1558@item
85a9b4ed 1559satisfies the predicate @var{char_pred}, if it is a
a0e07ba4
NJ
1560procedure,
1561
1562@item
1563is in the set @var{char_pred}, if it is a character set.
1564@end itemize
1565@end deffn
1566
8f85c0c6
NJ
1567@deffn {Scheme Procedure} string-skip s char_pred [start end]
1568@deffnx {Scheme Procedure} string-skip-right s char_pred [start end]
a0e07ba4 1569Search through the string @var{s} from left to right (right to left),
85a9b4ed 1570returning the index of the first (last) occurrence of a character which
a0e07ba4
NJ
1571
1572@itemize @bullet
1573@item
1574does not equal @var{char_pred}, if it is character,
1575
1576@item
85a9b4ed 1577does not satisfy the predicate @var{char_pred}, if it is
a0e07ba4
NJ
1578a procedure.
1579
1580@item
1581is not in the set if @var{char_pred} is a character set.
1582@end itemize
1583@end deffn
1584
8f85c0c6 1585@deffn {Scheme Procedure} string-count s char_pred [start end]
a0e07ba4
NJ
1586Return the count of the number of characters in the string
1587@var{s} which
1588
1589@itemize @bullet
1590@item
1591equals @var{char_pred}, if it is character,
1592
1593@item
85a9b4ed 1594satisfies the predicate @var{char_pred}, if it is a procedure.
a0e07ba4
NJ
1595
1596@item
1597is in the set @var{char_pred}, if it is a character set.
1598@end itemize
1599@end deffn
1600
8f85c0c6
NJ
1601@deffn {Scheme Procedure} string-contains s1 s2 [start1 end1 start2 end2]
1602@deffnx {Scheme Procedure} string-contains-ci s1 s2 [start1 end1 start2 end2]
a0e07ba4
NJ
1603Does string @var{s1} contain string @var{s2}? Return the index
1604in @var{s1} where @var{s2} occurs as a substring, or false.
1605The optional start/end indices restrict the operation to the
1606indicated substrings.
1607
1608@code{string-contains-ci} is the case-insensitive variant.
1609@end deffn
1610
1611
1612@c ===================================================================
1613
1614@node SRFI-13 Case Mapping
1615@subsection Alphabetic Case Mapping
1616
1617These procedures convert the alphabetic case of strings. They are
1618similar to the procedures in the Guile core, but are extended to handle
1619optional start/end indices.
1620
8f85c0c6
NJ
1621@deffn {Scheme Procedure} string-upcase s [start end]
1622@deffnx {Scheme Procedure} string-upcase! s [start end]
a0e07ba4
NJ
1623Upcase every character in @var{s}. @code{string-upcase!} is the
1624side-effecting variant.
1625@end deffn
1626
8f85c0c6
NJ
1627@deffn {Scheme Procedure} string-downcase s [start end]
1628@deffnx {Scheme Procedure} string-downcase! s [start end]
a0e07ba4
NJ
1629Downcase every character in @var{s}. @code{string-downcase!} is the
1630side-effecting variant.
1631@end deffn
1632
8f85c0c6
NJ
1633@deffn {Scheme Procedure} string-titlecase s [start end]
1634@deffnx {Scheme Procedure} string-titlecase! s [start end]
a0e07ba4
NJ
1635Upcase every first character in every word in @var{s}, downcase the
1636other characters. @code{string-titlecase!} is the side-effecting
1637variant.
1638@end deffn
1639
1640
1641@c ===================================================================
1642
1643@node SRFI-13 Reverse/Append
1644@subsection Reverse/Append
1645
1646One appending procedure, @code{string-append} is the same in R5RS and in
1647SRFI-13, so it is not redefined.
1648
8f85c0c6
NJ
1649@deffn {Scheme Procedure} string-reverse str [start end]
1650@deffnx {Scheme Procedure} string-reverse! str [start end]
a0e07ba4
NJ
1651Reverse the string @var{str}. The optional arguments
1652@var{start} and @var{end} delimit the region of @var{str} to
1653operate on.
1654
1655@code{string-reverse!} modifies the argument string and returns an
1656unspecified value.
1657@end deffn
1658
8f85c0c6 1659@deffn {Scheme Procedure} string-append/shared ls @dots{}
a0e07ba4
NJ
1660Like @code{string-append}, but the result may share memory
1661with the argument strings.
1662@end deffn
1663
8f85c0c6 1664@deffn {Scheme Procedure} string-concatenate ls
a0e07ba4
NJ
1665Append the elements of @var{ls} (which must be strings)
1666together into a single string. Guaranteed to return a freshly
1667allocated string.
1668@end deffn
1669
8f85c0c6 1670@deffn {Scheme Procedure} string-concatenate/shared ls
a0e07ba4
NJ
1671Like @code{string-concatenate}, but the result may share memory
1672with the strings in the list @var{ls}.
1673@end deffn
1674
8f85c0c6 1675@deffn {Scheme Procedure} string-concatenate-reverse ls final_string end
a0e07ba4
NJ
1676Without optional arguments, this procedure is equivalent to
1677
1678@smalllisp
1679(string-concatenate (reverse ls))
1680@end smalllisp
1681
1682If the optional argument @var{final_string} is specified, it is
1683consed onto the beginning to @var{ls} before performing the
1684list-reverse and string-concatenate operations. If @var{end}
1685is given, only the characters of @var{final_string} up to index
1686@var{end} are used.
1687
1688Guaranteed to return a freshly allocated string.
1689@end deffn
1690
8f85c0c6 1691@deffn {Scheme Procedure} string-concatenate-reverse/shared ls final_string end
a0e07ba4
NJ
1692Like @code{string-concatenate-reverse}, but the result may
1693share memory with the the strings in the @var{ls} arguments.
1694@end deffn
1695
1696
1697@c ===================================================================
1698
1699@node SRFI-13 Fold/Unfold/Map
1700@subsection Fold/Unfold/Map
1701
1702@code{string-map}, @code{string-for-each} etc. are for iterating over
1703the characters a string is composed of. The fold and unfold procedures
1704are list iterators and constructors.
1705
8f85c0c6 1706@deffn {Scheme Procedure} string-map proc s [start end]
a0e07ba4
NJ
1707@var{proc} is a char->char procedure, it is mapped over
1708@var{s}. The order in which the procedure is applied to the
1709string elements is not specified.
1710@end deffn
1711
8f85c0c6 1712@deffn {Scheme Procedure} string-map! proc s [start end]
a0e07ba4
NJ
1713@var{proc} is a char->char procedure, it is mapped over
1714@var{s}. The order in which the procedure is applied to the
1715string elements is not specified. The string @var{s} is
1716modified in-place, the return value is not specified.
1717@end deffn
1718
8f85c0c6
NJ
1719@deffn {Scheme Procedure} string-fold kons knil s [start end]
1720@deffnx {Scheme Procedure} string-fold-right kons knil s [start end]
a0e07ba4
NJ
1721Fold @var{kons} over the characters of @var{s}, with @var{knil} as the
1722terminating element, from left to right (or right to left, for
1723@code{string-fold-right}). @var{kons} must expect two arguments: The
1724actual character and the last result of @var{kons}' application.
1725@end deffn
1726
8f85c0c6
NJ
1727@deffn {Scheme Procedure} string-unfold p f g seed [base make_final]
1728@deffnx {Scheme Procedure} string-unfold-right p f g seed [base make_final]
a0e07ba4
NJ
1729These are the fundamental string constructors.
1730@itemize @bullet
1731@item @var{g} is used to generate a series of @emph{seed}
1732values from the initial @var{seed}: @var{seed}, (@var{g}
1733@var{seed}), (@var{g}^2 @var{seed}), (@var{g}^3 @var{seed}),
1734@dots{}
1735@item @var{p} tells us when to stop - when it returns true
1736when applied to one of these seed values.
12991fed 1737@item @var{f} maps each seed value to the corresponding
a0e07ba4
NJ
1738character in the result string. These chars are assembled into the
1739string in a left-to-right (right-to-left) order.
1740@item @var{base} is the optional initial/leftmost (rightmost)
1741 portion of the constructed string; it default to the empty string.
1742@item @var{make_final} is applied to the terminal seed
1743value (on which @var{p} returns true) to produce the final/rightmost
1744(leftmost) portion of the constructed string. It defaults to
1745@code{(lambda (x) "")}.
1746@end itemize
1747@end deffn
1748
8f85c0c6 1749@deffn {Scheme Procedure} string-for-each proc s [start end]
a0e07ba4
NJ
1750@var{proc} is mapped over @var{s} in left-to-right order. The
1751return value is not specified.
1752@end deffn
1753
1754
1755@c ===================================================================
1756
1757@node SRFI-13 Replicate/Rotate
1758@subsection Replicate/Rotate
1759
1760These procedures are special substring procedures, which can also be
1761used for replicating strings. They are a bit tricky to use, but
1762consider this code fragment, which replicates the input string
1763@code{"foo"} so often that the resulting string has a length of six.
1764
1765@lisp
1766(xsubstring "foo" 0 6)
1767@result{}
1768"foofoo"
1769@end lisp
1770
8f85c0c6 1771@deffn {Scheme Procedure} xsubstring s from [to start end]
a0e07ba4
NJ
1772This is the @emph{extended substring} procedure that implements
1773replicated copying of a substring of some string.
1774
1775@var{s} is a string, @var{start} and @var{end} are optional
1776arguments that demarcate a substring of @var{s}, defaulting to
17770 and the length of @var{s}. Replicate this substring up and
1778down index space, in both the positive and negative directions.
1779@code{xsubstring} returns the substring of this string
1780beginning at index @var{from}, and ending at @var{to}, which
1781defaults to @var{from} + (@var{end} - @var{start}).
1782@end deffn
1783
8f85c0c6 1784@deffn {Scheme Procedure} string-xcopy! target tstart s sfrom [sto start end]
a0e07ba4
NJ
1785Exactly the same as @code{xsubstring}, but the extracted text
1786is written into the string @var{target} starting at index
1787@var{tstart}. The operation is not defined if @code{(eq?
1788@var{target} @var{s})} or these arguments share storage - you
1789cannot copy a string on top of itself.
1790@end deffn
1791
1792
1793@c ===================================================================
1794
1795@node SRFI-13 Miscellaneous
1796@subsection Miscellaneous
1797
1798@code{string-replace} is for replacing a portion of a string with
1799another string and @code{string-tokenize} splits a string into a list of
1800strings, breaking it up at a specified character.
1801
8c24f46e 1802@deffn {Scheme Procedure} string-replace s1 s2 [start1 end1 start2 end2]
a0e07ba4
NJ
1803Return the string @var{s1}, but with the characters
1804@var{start1} @dots{} @var{end1} replaced by the characters
1805@var{start2} @dots{} @var{end2} from @var{s2}.
5519096e
KR
1806
1807For reference, note that SRFI-13 specifies @var{start1} and @var{end1}
1808as mandatory, but in Guile they are optional.
a0e07ba4
NJ
1809@end deffn
1810
c0ab7f13 1811@deffn {Scheme Procedure} string-tokenize s [token-set start end]
a0e07ba4 1812Split the string @var{s} into a list of substrings, where each
c0ab7f13
MV
1813substring is a maximal non-empty contiguous sequence of characters
1814from the character set @var{token_set}, which defaults to an
1815equivalent of @code{char-set:graphic}. If @var{start} or @var{end}
1816indices are provided, they restrict @code{string-tokenize} to
1817operating on the indicated substring of @var{s}.
a0e07ba4
NJ
1818@end deffn
1819
1820
1821@c ===================================================================
1822
1823@node SRFI-13 Filtering/Deleting
1824@subsection Filtering/Deleting
1825
1826@dfn{Filtering} means to remove all characters from a string which do
1827not match a given criteria, @dfn{deleting} means the opposite.
1828
8f85c0c6 1829@deffn {Scheme Procedure} string-filter s char_pred [start end]
a0e07ba4
NJ
1830Filter the string @var{s}, retaining only those characters that
1831satisfy the @var{char_pred} argument. If the argument is a
1832procedure, it is applied to each character as a predicate, if
1833it is a character, it is tested for equality and if it is a
1834character set, it is tested for membership.
1835@end deffn
1836
8f85c0c6 1837@deffn {Scheme Procedure} string-delete s char_pred [start end]
a0e07ba4
NJ
1838Filter the string @var{s}, retaining only those characters that
1839do not satisfy the @var{char_pred} argument. If the argument
1840is a procedure, it is applied to each character as a predicate,
1841if it is a character, it is tested for equality and if it is a
1842character set, it is tested for membership.
1843@end deffn
1844
1845
1846@node SRFI-14
1847@section SRFI-14 - Character-set Library
8742c48b 1848@cindex SRFI-14
a0e07ba4
NJ
1849
1850SRFI-14 defines the data type @dfn{character set}, and also defines a
1851lot of procedures for handling this character type, and a few standard
1852character sets like whitespace, alphabetic characters and others.
1853
1854All procedures from SRFI-14 (character-set library) are implemented in
1855the module @code{(srfi srfi-14)}, as well as the standard variables
1856@code{char-set:letter}, @code{char-set:digit} etc.
1857
1858@menu
1859* Loading SRFI-14:: How to make charsets available.
1860* SRFI-14 Character Set Data Type:: Underlying data type for charsets.
1861* SRFI-14 Predicates/Comparison:: Charset predicates.
1862* SRFI-14 Iterating Over Character Sets:: Enumerate charset elements.
85a9b4ed 1863* SRFI-14 Creating Character Sets:: Making new charsets.
a0e07ba4
NJ
1864* SRFI-14 Querying Character Sets:: Test charsets for membership etc.
1865* SRFI-14 Character-Set Algebra:: Calculating new charsets.
1866* SRFI-14 Standard Character Sets:: Variables containing predefined charsets.
1867@end menu
1868
1869
1870@node Loading SRFI-14
1871@subsection Loading SRFI-14
1872
1873When Guile is properly installed, SRFI-14 support can be loaded into a
1874running Guile by using the @code{(srfi srfi-14)} module.
1875
1876@example
1877$ guile
1878guile> (use-modules (srfi srfi-14))
1879guile> (char-set-union (char-set #\f #\o #\o) (string->char-set "bar"))
1880#<charset @{#\a #\b #\f #\o #\r@}>
1881guile>
1882@end example
1883
1884
1885@node SRFI-14 Character Set Data Type
1886@subsection Character Set Data Type
1887
1888The data type @dfn{charset} implements sets of characters
1889(@pxref{Characters}). Because the internal representation of character
1890sets is not visible to the user, a lot of procedures for handling them
1891are provided.
1892
1893Character sets can be created, extended, tested for the membership of a
1894characters and be compared to other character sets.
1895
1896The Guile implementation of character sets deals with 8-bit characters.
1897In the standard variables, only the ASCII part of the character range is
1898really used, so that for example @dfn{Umlaute} and other accented
1899characters are not considered to be letters. In the future, as Guile
1900may get support for international character sets, this will change, so
1901don't rely on these ``features''.
1902
1903
1904@c ===================================================================
1905
1906@node SRFI-14 Predicates/Comparison
1907@subsection Predicates/Comparison
1908
1909Use these procedures for testing whether an object is a character set,
1910or whether several character sets are equal or subsets of each other.
1911@code{char-set-hash} can be used for calculating a hash value, maybe for
1912usage in fast lookup procedures.
1913
8f85c0c6 1914@deffn {Scheme Procedure} char-set? obj
a0e07ba4
NJ
1915Return @code{#t} if @var{obj} is a character set, @code{#f}
1916otherwise.
1917@end deffn
1918
8f85c0c6 1919@deffn {Scheme Procedure} char-set= cs1 @dots{}
a0e07ba4
NJ
1920Return @code{#t} if all given character sets are equal.
1921@end deffn
1922
8f85c0c6 1923@deffn {Scheme Procedure} char-set<= cs1 @dots{}
a0e07ba4
NJ
1924Return @code{#t} if every character set @var{cs}i is a subset
1925of character set @var{cs}i+1.
1926@end deffn
1927
8f85c0c6 1928@deffn {Scheme Procedure} char-set-hash cs [bound]
a0e07ba4
NJ
1929Compute a hash value for the character set @var{cs}. If
1930@var{bound} is given and not @code{#f}, it restricts the
1931returned value to the range 0 @dots{} @var{bound - 1}.
1932@end deffn
1933
1934
1935@c ===================================================================
1936
1937@node SRFI-14 Iterating Over Character Sets
1938@subsection Iterating Over Character Sets
1939
1940Character set cursors are a means for iterating over the members of a
1941character sets. After creating a character set cursor with
1942@code{char-set-cursor}, a cursor can be dereferenced with
1943@code{char-set-ref}, advanced to the next member with
1944@code{char-set-cursor-next}. Whether a cursor has passed past the last
1945element of the set can be checked with @code{end-of-char-set?}.
1946
1947Additionally, mapping and (un-)folding procedures for character sets are
1948provided.
1949
8f85c0c6 1950@deffn {Scheme Procedure} char-set-cursor cs
a0e07ba4
NJ
1951Return a cursor into the character set @var{cs}.
1952@end deffn
1953
8f85c0c6 1954@deffn {Scheme Procedure} char-set-ref cs cursor
a0e07ba4
NJ
1955Return the character at the current cursor position
1956@var{cursor} in the character set @var{cs}. It is an error to
1957pass a cursor for which @code{end-of-char-set?} returns true.
1958@end deffn
1959
8f85c0c6 1960@deffn {Scheme Procedure} char-set-cursor-next cs cursor
a0e07ba4
NJ
1961Advance the character set cursor @var{cursor} to the next
1962character in the character set @var{cs}. It is an error if the
1963cursor given satisfies @code{end-of-char-set?}.
1964@end deffn
1965
8f85c0c6 1966@deffn {Scheme Procedure} end-of-char-set? cursor
a0e07ba4
NJ
1967Return @code{#t} if @var{cursor} has reached the end of a
1968character set, @code{#f} otherwise.
1969@end deffn
1970
8f85c0c6 1971@deffn {Scheme Procedure} char-set-fold kons knil cs
a0e07ba4
NJ
1972Fold the procedure @var{kons} over the character set @var{cs},
1973initializing it with @var{knil}.
1974@end deffn
1975
8f85c0c6
NJ
1976@deffn {Scheme Procedure} char-set-unfold p f g seed [base_cs]
1977@deffnx {Scheme Procedure} char-set-unfold! p f g seed base_cs
a0e07ba4
NJ
1978This is a fundamental constructor for character sets.
1979@itemize @bullet
12991fed 1980@item @var{g} is used to generate a series of ``seed'' values
a0e07ba4
NJ
1981from the initial seed: @var{seed}, (@var{g} @var{seed}),
1982(@var{g}^2 @var{seed}), (@var{g}^3 @var{seed}), @dots{}
1983@item @var{p} tells us when to stop -- when it returns true
12991fed 1984when applied to one of the seed values.
a0e07ba4
NJ
1985@item @var{f} maps each seed value to a character. These
1986characters are added to the base character set @var{base_cs} to
1987form the result; @var{base_cs} defaults to the empty set.
1988@end itemize
1989
1990@code{char-set-unfold!} is the side-effecting variant.
1991@end deffn
1992
8f85c0c6 1993@deffn {Scheme Procedure} char-set-for-each proc cs
a0e07ba4
NJ
1994Apply @var{proc} to every character in the character set
1995@var{cs}. The return value is not specified.
1996@end deffn
1997
8f85c0c6 1998@deffn {Scheme Procedure} char-set-map proc cs
a0e07ba4
NJ
1999Map the procedure @var{proc} over every character in @var{cs}.
2000@var{proc} must be a character -> character procedure.
2001@end deffn
2002
2003
2004@c ===================================================================
2005
2006@node SRFI-14 Creating Character Sets
2007@subsection Creating Character Sets
2008
2009New character sets are produced with these procedures.
2010
8f85c0c6 2011@deffn {Scheme Procedure} char-set-copy cs
a0e07ba4
NJ
2012Return a newly allocated character set containing all
2013characters in @var{cs}.
2014@end deffn
2015
8f85c0c6 2016@deffn {Scheme Procedure} char-set char1 @dots{}
a0e07ba4
NJ
2017Return a character set containing all given characters.
2018@end deffn
2019
8f85c0c6
NJ
2020@deffn {Scheme Procedure} list->char-set char_list [base_cs]
2021@deffnx {Scheme Procedure} list->char-set! char_list base_cs
a0e07ba4
NJ
2022Convert the character list @var{list} to a character set. If
2023the character set @var{base_cs} is given, the character in this
2024set are also included in the result.
2025
2026@code{list->char-set!} is the side-effecting variant.
2027@end deffn
2028
8f85c0c6
NJ
2029@deffn {Scheme Procedure} string->char-set s [base_cs]
2030@deffnx {Scheme Procedure} string->char-set! s base_cs
a0e07ba4
NJ
2031Convert the string @var{str} to a character set. If the
2032character set @var{base_cs} is given, the characters in this
2033set are also included in the result.
2034
2035@code{string->char-set!} is the side-effecting variant.
2036@end deffn
2037
8f85c0c6
NJ
2038@deffn {Scheme Procedure} char-set-filter pred cs [base_cs]
2039@deffnx {Scheme Procedure} char-set-filter! pred cs base_cs
a0e07ba4
NJ
2040Return a character set containing every character from @var{cs}
2041so that it satisfies @var{pred}. If provided, the characters
2042from @var{base_cs} are added to the result.
2043
2044@code{char-set-filter!} is the side-effecting variant.
2045@end deffn
2046
8f85c0c6
NJ
2047@deffn {Scheme Procedure} ucs-range->char-set lower upper [error? base_cs]
2048@deffnx {Scheme Procedure} uce-range->char-set! lower upper error? base_cs
a0e07ba4
NJ
2049Return a character set containing all characters whose
2050character codes lie in the half-open range
2051[@var{lower},@var{upper}).
2052
2053If @var{error} is a true value, an error is signalled if the
2054specified range contains characters which are not contained in
2055the implemented character range. If @var{error} is @code{#f},
85a9b4ed 2056these characters are silently left out of the resulting
a0e07ba4
NJ
2057character set.
2058
2059The characters in @var{base_cs} are added to the result, if
2060given.
2061
2062@code{ucs-range->char-set!} is the side-effecting variant.
2063@end deffn
2064
8f85c0c6 2065@deffn {Scheme Procedure} ->char-set x
a0e07ba4
NJ
2066Coerce @var{x} into a character set. @var{x} may be a string, a
2067character or a character set.
2068@end deffn
2069
2070
2071@c ===================================================================
2072
2073@node SRFI-14 Querying Character Sets
2074@subsection Querying Character Sets
2075
2076Access the elements and other information of a character set with these
2077procedures.
2078
8f85c0c6 2079@deffn {Scheme Procedure} char-set-size cs
a0e07ba4
NJ
2080Return the number of elements in character set @var{cs}.
2081@end deffn
2082
8f85c0c6 2083@deffn {Scheme Procedure} char-set-count pred cs
a0e07ba4
NJ
2084Return the number of the elements int the character set
2085@var{cs} which satisfy the predicate @var{pred}.
2086@end deffn
2087
8f85c0c6 2088@deffn {Scheme Procedure} char-set->list cs
a0e07ba4
NJ
2089Return a list containing the elements of the character set
2090@var{cs}.
2091@end deffn
2092
8f85c0c6 2093@deffn {Scheme Procedure} char-set->string cs
a0e07ba4
NJ
2094Return a string containing the elements of the character set
2095@var{cs}. The order in which the characters are placed in the
2096string is not defined.
2097@end deffn
2098
8f85c0c6 2099@deffn {Scheme Procedure} char-set-contains? cs char
a0e07ba4
NJ
2100Return @code{#t} iff the character @var{ch} is contained in the
2101character set @var{cs}.
2102@end deffn
2103
8f85c0c6 2104@deffn {Scheme Procedure} char-set-every pred cs
a0e07ba4
NJ
2105Return a true value if every character in the character set
2106@var{cs} satisfies the predicate @var{pred}.
2107@end deffn
2108
8f85c0c6 2109@deffn {Scheme Procedure} char-set-any pred cs
a0e07ba4
NJ
2110Return a true value if any character in the character set
2111@var{cs} satisfies the predicate @var{pred}.
2112@end deffn
2113
2114
2115@c ===================================================================
2116
2117@node SRFI-14 Character-Set Algebra
2118@subsection Character-Set Algebra
2119
2120Character sets can be manipulated with the common set algebra operation,
2121such as union, complement, intersection etc. All of these procedures
2122provide side-effecting variants, which modify their character set
2123argument(s).
2124
8f85c0c6
NJ
2125@deffn {Scheme Procedure} char-set-adjoin cs char1 @dots{}
2126@deffnx {Scheme Procedure} char-set-adjoin! cs char1 @dots{}
a0e07ba4
NJ
2127Add all character arguments to the first argument, which must
2128be a character set.
2129@end deffn
2130
8f85c0c6
NJ
2131@deffn {Scheme Procedure} char-set-delete cs char1 @dots{}
2132@deffnx {Scheme Procedure} char-set-delete! cs char1 @dots{}
a0e07ba4
NJ
2133Delete all character arguments from the first argument, which
2134must be a character set.
2135@end deffn
2136
8f85c0c6
NJ
2137@deffn {Scheme Procedure} char-set-complement cs
2138@deffnx {Scheme Procedure} char-set-complement! cs
a0e07ba4
NJ
2139Return the complement of the character set @var{cs}.
2140@end deffn
2141
8f85c0c6
NJ
2142@deffn {Scheme Procedure} char-set-union cs1 @dots{}
2143@deffnx {Scheme Procedure} char-set-union! cs1 @dots{}
a0e07ba4
NJ
2144Return the union of all argument character sets.
2145@end deffn
2146
8f85c0c6
NJ
2147@deffn {Scheme Procedure} char-set-intersection cs1 @dots{}
2148@deffnx {Scheme Procedure} char-set-intersection! cs1 @dots{}
a0e07ba4
NJ
2149Return the intersection of all argument character sets.
2150@end deffn
2151
8f85c0c6
NJ
2152@deffn {Scheme Procedure} char-set-difference cs1 @dots{}
2153@deffnx {Scheme Procedure} char-set-difference! cs1 @dots{}
a0e07ba4
NJ
2154Return the difference of all argument character sets.
2155@end deffn
2156
8f85c0c6
NJ
2157@deffn {Scheme Procedure} char-set-xor cs1 @dots{}
2158@deffnx {Scheme Procedure} char-set-xor! cs1 @dots{}
a0e07ba4
NJ
2159Return the exclusive-or of all argument character sets.
2160@end deffn
2161
8f85c0c6
NJ
2162@deffn {Scheme Procedure} char-set-diff+intersection cs1 @dots{}
2163@deffnx {Scheme Procedure} char-set-diff+intersection! cs1 @dots{}
a0e07ba4
NJ
2164Return the difference and the intersection of all argument
2165character sets.
2166@end deffn
2167
2168
2169@c ===================================================================
2170
2171@node SRFI-14 Standard Character Sets
2172@subsection Standard Character Sets
2173
2174In order to make the use of the character set data type and procedures
2175useful, several predefined character set variables exist.
2176
2177@defvar char-set:lower-case
2178All lower-case characters.
2179@end defvar
2180
2181@defvar char-set:upper-case
2182All upper-case characters.
2183@end defvar
2184
2185@defvar char-set:title-case
2186This is empty, because ASCII has no titlecase characters.
2187@end defvar
2188
2189@defvar char-set:letter
2190All letters, e.g. the union of @code{char-set:lower-case} and
2191@code{char-set:upper-case}.
2192@end defvar
2193
2194@defvar char-set:digit
2195All digits.
2196@end defvar
2197
2198@defvar char-set:letter+digit
2199The union of @code{char-set:letter} and @code{char-set:digit}.
2200@end defvar
2201
2202@defvar char-set:graphic
2203All characters which would put ink on the paper.
2204@end defvar
2205
2206@defvar char-set:printing
2207The union of @code{char-set:graphic} and @code{char-set:whitespace}.
2208@end defvar
2209
2210@defvar char-set:whitespace
2211All whitespace characters.
2212@end defvar
2213
2214@defvar char-set:blank
2215All horizontal whitespace characters, that is @code{#\space} and
2216@code{#\tab}.
2217@end defvar
2218
2219@defvar char-set:iso-control
2220The ISO control characters with the codes 0--31 and 127.
2221@end defvar
2222
2223@defvar char-set:punctuation
2224The characters @code{!"#%&'()*,-./:;?@@[\\]_@{@}}
2225@end defvar
2226
2227@defvar char-set:symbol
2228The characters @code{$+<=>^`|~}.
2229@end defvar
2230
2231@defvar char-set:hex-digit
2232The hexadecimal digits @code{0123456789abcdefABCDEF}.
2233@end defvar
2234
2235@defvar char-set:ascii
2236All ASCII characters.
2237@end defvar
2238
2239@defvar char-set:empty
2240The empty character set.
2241@end defvar
2242
2243@defvar char-set:full
2244This character set contains all possible characters.
2245@end defvar
2246
2247@node SRFI-16
2248@section SRFI-16 - case-lambda
8742c48b 2249@cindex SRFI-16
a0e07ba4
NJ
2250
2251@c FIXME::martin: Review me!
2252
8742c48b 2253@findex case-lambda
a0e07ba4
NJ
2254The syntactic form @code{case-lambda} creates procedures, just like
2255@code{lambda}, but has syntactic extensions for writing procedures of
2256varying arity easier.
2257
2258The syntax of the @code{case-lambda} form is defined in the following
2259EBNF grammar.
2260
2261@example
2262@group
2263<case-lambda>
2264 --> (case-lambda <case-lambda-clause>)
2265<case-lambda-clause>
2266 --> (<formals> <definition-or-command>*)
2267<formals>
2268 --> (<identifier>*)
2269 | (<identifier>* . <identifier>)
2270 | <identifier>
2271@end group
2272@end example
2273
2274The value returned by a @code{case-lambda} form is a procedure which
2275matches the number of actual arguments against the formals in the
2276various clauses, in order. @dfn{Formals} means a formal argument list
2277just like with @code{lambda} (@pxref{Lambda}). The first matching clause
2278is selected, the corresponding values from the actual parameter list are
2279bound to the variable names in the clauses and the body of the clause is
2280evaluated. If no clause matches, an error is signalled.
2281
2282The following (silly) definition creates a procedure @var{foo} which
2283acts differently, depending on the number of actual arguments. If one
2284argument is given, the constant @code{#t} is returned, two arguments are
2285added and if more arguments are passed, their product is calculated.
2286
2287@lisp
2288(define foo (case-lambda
2289 ((x) #t)
2290 ((x y) (+ x y))
2291 (z
2292 (apply * z))))
2293(foo 'bar)
2294@result{}
2295#t
2296(foo 2 4)
2297@result{}
22986
2299(foo 3 3 3)
2300@result{}
230127
2302(foo)
2303@result{}
23041
2305@end lisp
2306
2307The last expression evaluates to 1 because the last clause is matched,
2308@var{z} is bound to the empty list and the following multiplication,
2309applied to zero arguments, yields 1.
2310
2311
2312@node SRFI-17
2313@section SRFI-17 - Generalized set!
8742c48b 2314@cindex SRFI-17
a0e07ba4
NJ
2315
2316This is an implementation of SRFI-17: Generalized set!
2317
8742c48b 2318@findex getter-with-setter
a0e07ba4
NJ
2319It exports the Guile procedure @code{make-procedure-with-setter} under
2320the SRFI name @code{getter-with-setter} and exports the standard
2321procedures @code{car}, @code{cdr}, @dots{}, @code{cdddr},
2322@code{string-ref} and @code{vector-ref} as procedures with setters, as
2323required by the SRFI.
2324
2325SRFI-17 was heavily criticized during its discussion period but it was
2326finalized anyway. One issue was its concept of globally associating
2327setter @dfn{properties} with (procedure) values, which is non-Schemy.
2328For this reason, this implementation chooses not to provide a way to set
2329the setter of a procedure. In fact, @code{(set! (setter @var{proc})
2330@var{setter})} signals an error. The only way to attach a setter to a
2331procedure is to create a new object (a @dfn{procedure with setter}) via
2332the @code{getter-with-setter} procedure. This procedure is also
2333specified in the SRFI. Using it avoids the described problems.
2334
12991fed
TTN
2335
2336@node SRFI-19
2337@section SRFI-19 - Time/Date Library
8742c48b 2338@cindex SRFI-19
12991fed
TTN
2339
2340This is an implementation of SRFI-19: Time/Date Library
2341
2342It depends on SRFIs: 6 (@pxref{SRFI-6}), 8 (@pxref{SRFI-8}),
23439 (@pxref{SRFI-9}).
2344
2345This section documents constants and procedure signatures.
2346
2347@menu
2348* SRFI-19 Constants::
2349* SRFI-19 Current time and clock resolution::
2350* SRFI-19 Time object and accessors::
2351* SRFI-19 Time comparison procedures::
2352* SRFI-19 Time arithmetic procedures::
2353* SRFI-19 Date object and accessors::
2354* SRFI-19 Time/Date/Julian Day/Modified Julian Day converters::
2355* SRFI-19 Date to string/string to date converters::
2356@end menu
2357
2358@node SRFI-19 Constants
2359@subsection SRFI-19 Constants
2360
2361All these are bound to their symbol names:
2362
2363@example
2364 time-duration
2365 time-monotonic
2366 time-process
2367 time-tai
2368 time-thread
2369 time-utc
2370@end example
2371
2372@node SRFI-19 Current time and clock resolution
2373@subsection SRFI-19 Current time and clock resolution
2374
2375@example
2376 (current-date . tz-offset)
2377 (current-julian-day)
2378 (current-modified-julian-day)
2379 (current-time . clock-type)
2380 (time-resolution . clock-type)
2381@end example
2382
2383@node SRFI-19 Time object and accessors
2384@subsection SRFI-19 Time object and accessors
2385
2386@example
2387 (make-time type nanosecond second)
2388 (time? obj)
2389 (time-type time)
2390 (time-nanosecond time)
2391 (time-second time)
2392 (set-time-type! time type)
2393 (set-time-nanosecond! time nsec)
2394 (set-time-second! time sec)
2395 (copy-time time)
2396@end example
2397
2398@node SRFI-19 Time comparison procedures
2399@subsection SRFI-19 Time comparison procedures
2400
2401Args are all @code{time} values.
2402
2403@example
2404 (time<=? t1 t2)
2405 (time<? t1 t2)
2406 (time=? t1 t2)
2407 (time>=? t1 t2)
2408 (time>? t1 t2)
2409@end example
2410
2411@node SRFI-19 Time arithmetic procedures
2412@subsection SRFI-19 Time arithmetic procedures
2413
2414The @code{foo!} variants modify in place. Time difference
2415is expressed in @code{time-duration} values.
2416
2417@example
2418 (time-difference t1 t2)
2419 (time-difference! t1 t2)
2420 (add-duration time duration)
2421 (add-duration! time duration)
2422 (subtract-duration time duration)
2423 (subtract-duration! time duration)
2424 @end example
2425
2426@node SRFI-19 Date object and accessors
2427@subsection SRFI-19 Date object and accessors
2428
2429@example
2430 (make-date nsecs seconds minutes hours
2431 date month year offset)
2432 (date? obj)
2433 (date-nanosecond date)
2434 (date-second date)
2435 (date-minute date)
2436 (date-hour date)
2437 (date-day date)
2438 (date-month date)
2439 (date-year date)
2440 (date-zone-offset date)
2441 (date-year-day date)
2442 (date-week-day date)
2443 (date-week-number date day-of-week-starting-week)
2444@end example
2445
2446@node SRFI-19 Time/Date/Julian Day/Modified Julian Day converters
2447@subsection SRFI-19 Time/Date/Julian Day/Modified Julian Day converters
2448
2449@example
2450 (date->julian-day date)
2451 (date->modified-julian-day date)
2452 (date->time-monotonic date)
2453 (date->time-tai date)
2454 (date->time-utc date)
2455 (julian-day->date jdn . tz-offset)
2456 (julian-day->time-monotonic jdn)
2457 (julian-day->time-tai jdn)
2458 (julian-day->time-utc jdn)
2459 (modified-julian-day->date jdn . tz-offset)
2460 (modified-julian-day->time-monotonic jdn)
2461 (modified-julian-day->time-tai jdn)
2462 (modified-julian-day->time-utc jdn)
2463 (time-monotonic->date time . tz-offset)
2464 (time-monotonic->time-tai time-in)
2465 (time-monotonic->time-tai! time-in)
2466 (time-monotonic->time-utc time-in)
2467 (time-monotonic->time-utc! time-in)
2468 (time-tai->date time . tz-offset)
2469 (time-tai->julian-day time)
2470 (time-tai->modified-julian-day time)
2471 (time-tai->time-monotonic time-in)
2472 (time-tai->time-monotonic! time-in)
2473 (time-tai->time-utc time-in)
2474 (time-tai->time-utc! time-in)
2475 (time-utc->date time . tz-offset)
2476 (time-utc->julian-day time)
2477 (time-utc->modified-julian-day time)
2478 (time-utc->time-monotonic time-in)
2479 (time-utc->time-monotonic! time-in)
2480 (time-utc->time-tai time-in)
2481 (time-utc->time-tai! time-in)
2482@end example
2483
2484@node SRFI-19 Date to string/string to date converters
2485@subsection SRFI-19 Date to string/string to date converters
2486
2487@example
2488 (date->string date . format-string)
2489 (string->date input-string template-string)
2490@end example
2491
2492@c srfi-modules.texi ends here