*** 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
b6b9376a
KR
703The equality calls are always @code{(= x elem)}, ie. the given @var{x}
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
NJ
866
867@c FIXME::martin: Review me!
868
8742c48b 869@findex and-let*
a0e07ba4
NJ
870The syntactic form @code{and-let*} combines the conditional evaluation
871form @code{and} with the binding form @var{let*}. Each argument
872expression will be evaluated sequentially, bound to a variable (if a
873variable name is given), but only as long as no expression returns
874the false value @code{#f}.
875
876Use @code{(use-modules (srfi srfi-2)} to access this syntax form.
877
878A short example will demonstrate how it works. In the first expression,
879@var{x} will get bound to 1, but the next expression (@code{#f}) is
880false, so evaluation of the form is stopped, and @code{#f} is returned.
881In the next expression, @var{x} is bound to 1, @var{y} is bound to
882@code{#t} and since no expression in the binding section was false, the
883body of the @code{and-let*} expression is evaluated, which in this case
884returns the value of @var{x}.
885
886@lisp
887(and-let* ((x 1) (y #f)) 42)
888@result{}
889#f
12991fed 890(and-let* ((x 1) (y #t)) x)
a0e07ba4
NJ
891@result{}
8921
893@end lisp
894
895
896@node SRFI-4
897@section SRFI-4 - Homogeneous numeric vector datatypes.
8742c48b 898@cindex SRFI-4
a0e07ba4
NJ
899
900@c FIXME::martin: Review me!
901
902SRFI-4 defines a set of datatypes for vectors whose elements are all
903of the same numeric type. Vectors for signed and unsigned exact
904integer or inexact real numbers in several precisions are available.
905
906Procedures similar to the vector procedures (@pxref{Vectors}) are
907provided for handling these homogeneous vectors, but they are distinct
908datatypes.
909
910The reason for providing this set of datatypes is that with the
911limitation (all elements must have the same type), it is possible to
912implement them much more memory-efficient than normal, heterogenous
913vectors.
914
915If you want to use these datatypes and the corresponding procedures,
916you have to use the module @code{(srfi srfi-4)}.
917
918Ten vector data types are provided: Unsigned and signed integer values
919with 8, 16, 32 and 64 bits and floating point values with 32 and 64
920bits. In the following descriptions, the tags @code{u8}, @code{s8},
921@code{u16}, @code{s16}, @code{u32}, @code{s32}, @code{u64},
922@code{s64}, @code{f32}, @code{f64}, respectively, are used for
923denoting the various types.
924
925@menu
926* SRFI-4 - Read Syntax:: How to write homogeneous vector literals.
927* SRFI-4 - Procedures:: Available homogeneous vector procedures.
928@end menu
929
930
931@node SRFI-4 - Read Syntax
932@subsection SRFI-4 - Read Syntax
933
934Homogeneous numeric vectors have an external representation (read
935syntax) similar to normal Scheme vectors, but with an additional tag
936telling the vector's type.
937
938@lisp
939#u16(1 2 3)
940@end lisp
941
942denotes a homogeneous numeric vector of three elements, which are the
943values 1, 2 and 3, represented as 16-bit unsigned integers.
944Correspondingly,
945
946@lisp
947#f64(3.1415 2.71)
948@end lisp
949
950denotes a vector of two elements, which are the values 3.1415 and
9512.71, represented as floating-point values of 64 bit precision.
952
953Please note that the read syntax for floating-point vectors conflicts
954with Standard Scheme, because there @code{#f} is defined to be the
955literal false value. That means, that with the loaded SRFI-4 module,
956it is not possible to enter some list like
957
958@lisp
959'(1 #f3)
960@end lisp
961
962and hope that it will be parsed as a three-element list with the
963elements 1, @code{#f} and 3. In normal use, this should be no
964problem, because people tend to terminate tokens sensibly when writing
965Scheme expressions.
966
967@node SRFI-4 - Procedures
968@subsection SRFI-4 Procedures
969
970The procedures listed in this section are provided for all homogeneous
971numeric vector datatypes. For brevity, they are not all documented,
972but a summary of the procedures is given. In the following
973descriptions, you can replace @code{TAG} by any of the datatype
974indicators @code{u8}, @code{s8}, @code{u16}, @code{s16}, @code{u32},
975@code{s32}, @code{u64}, @code{s64}, @code{f32} and @code{f64}.
976
977For example, you can use the procedures @code{u8vector?},
978@code{make-s8vector}, @code{u16vector}, @code{u32vector-length},
979@code{s64vector-ref}, @code{f32vector-set!} or @code{f64vector->list}.
980
8f85c0c6 981@deffn {Scheme Procedure} TAGvector? obj
a0e07ba4
NJ
982Return @code{#t} if @var{obj} is a homogeneous numeric vector of type
983@code{TAG}.
984@end deffn
985
8f85c0c6 986@deffn {Scheme Procedure} make-TAGvector n [value]
a0e07ba4
NJ
987Create a newly allocated homogeneous numeric vector of type
988@code{TAG}, which can hold @var{n} elements. If @var{value} is given,
989the vector is initialized with the value, otherwise, the contents of
990the returned vector is not specified.
991@end deffn
992
8f85c0c6 993@deffn {Scheme Procedure} TAGvector value1 @dots{}
a0e07ba4
NJ
994Create a newly allocated homogeneous numeric vector of type
995@code{TAG}. The returned vector is as long as the number of arguments
996given, and is initialized with the argument values.
997@end deffn
998
8f85c0c6 999@deffn {Scheme Procedure} TAGvector-length TAGvec
a0e07ba4
NJ
1000Return the number of elements in @var{TAGvec}.
1001@end deffn
1002
8f85c0c6 1003@deffn {Scheme Procedure} TAGvector-ref TAGvec i
a0e07ba4
NJ
1004Return the element at index @var{i} in @var{TAGvec}.
1005@end deffn
1006
8f85c0c6 1007@deffn {Scheme Procedure} TAGvector-ref TAGvec i value
a0e07ba4
NJ
1008Set the element at index @var{i} in @var{TAGvec} to @var{value}. The
1009return value is not specified.
1010@end deffn
1011
8f85c0c6 1012@deffn {Scheme Procedure} TAGvector->list TAGvec
a0e07ba4
NJ
1013Return a newly allocated list holding all elements of @var{TAGvec}.
1014@end deffn
1015
8f85c0c6 1016@deffn {Scheme Procedure} list->TAGvector lst
a0e07ba4
NJ
1017Return a newly allocated homogeneous numeric vector of type @code{TAG},
1018initialized with the elements of the list @var{lst}.
1019@end deffn
1020
1021
1022@node SRFI-6
1023@section SRFI-6 - Basic String Ports
8742c48b 1024@cindex SRFI-6
a0e07ba4
NJ
1025
1026SRFI-6 defines the procedures @code{open-input-string},
1027@code{open-output-string} and @code{get-output-string}. These
1028procedures are included in the Guile core, so using this module does not
1029make any difference at the moment. But it is possible that support for
1030SRFI-6 will be factored out of the core library in the future, so using
1031this module does not hurt, after all.
1032
1033@node SRFI-8
1034@section SRFI-8 - receive
8742c48b 1035@cindex SRFI-8
a0e07ba4
NJ
1036
1037@code{receive} is a syntax for making the handling of multiple-value
1038procedures easier. It is documented in @xref{Multiple Values}.
1039
1040
1041@node SRFI-9
1042@section SRFI-9 - define-record-type
8742c48b 1043@cindex SRFI-9
a0e07ba4
NJ
1044
1045This is the SRFI way for defining record types. The Guile
1046implementation is a layer above Guile's normal record construction
1047procedures (@pxref{Records}). The nice thing about this kind of record
1048definition method is that no new names are implicitly created, all
1049constructor, accessor and predicates are explicitly given. This reduces
1050the risk of variable capture.
1051
1052The syntax of a record type definition is:
1053
1054@example
1055@group
1056<record type definition>
1057 -> (define-record-type <type name>
1058 (<constructor name> <field tag> ...)
1059 <predicate name>
1060 <field spec> ...)
1061<field spec> -> (<field tag> <accessor name>)
1062 -> (<field tag> <accessor name> <modifier name>)
1063<field tag> -> <identifier>
1064<... name> -> <identifier>
1065@end group
1066@end example
1067
1068Usage example:
1069
1070@example
1071guile> (use-modules (srfi srfi-9))
12991fed 1072guile> (define-record-type :foo (make-foo x) foo?
a0e07ba4
NJ
1073 (x get-x) (y get-y set-y!))
1074guile> (define f (make-foo 1))
1075guile> f
1076#<:foo x: 1 y: #f>
1077guile> (get-x f)
10781
1079guile> (set-y! f 2)
10802
1081guile> (get-y f)
10822
1083guile> f
1084#<:foo x: 1 y: 2>
1085guile> (foo? f)
1086#t
1087guile> (foo? 1)
1088#f
1089@end example
1090
1091
1092@node SRFI-10
1093@section SRFI-10 - Hash-Comma Reader Extension
8742c48b 1094@cindex SRFI-10
a0e07ba4
NJ
1095
1096@cindex hash-comma
1097@cindex #,()
1098The module @code{(srfi srfi-10)} implements the syntax extension
1099@code{#,()}, also called hash-comma, which is defined in SRFI-10.
1100
1101The support for SRFI-10 consists of the procedure
1102@code{define-reader-ctor} for defining new reader constructors and the
1103read syntax form
1104
1105@example
1106#,(@var{ctor} @var{datum} ...)
1107@end example
1108
1109where @var{ctor} must be a symbol for which a read constructor was
85a9b4ed 1110defined previously, using @code{define-reader-ctor}.
a0e07ba4
NJ
1111
1112Example:
1113
1114@lisp
4310df36 1115(use-modules (ice-9 rdelim)) ; for read-line
a0e07ba4
NJ
1116(define-reader-ctor 'file open-input-file)
1117(define f '#,(file "/etc/passwd"))
1118(read-line f)
1119@result{}
1120"root:x:0:0:root:/root:/bin/bash"
1121@end lisp
1122
1123Please note the quote before the @code{#,(file ...)} expression. This
1124is necessary because ports are not self-evaluating in Guile.
1125
8f85c0c6 1126@deffn {Scheme Procedure} define-reader-ctor symbol proc
a0e07ba4
NJ
1127Define @var{proc} as the reader constructor for hash-comma forms with a
1128tag @var{symbol}. @var{proc} will be applied to the datum(s) following
1129the tag in the hash-comma expression after the complete form has been
1130read in. The result of @var{proc} is returned by the Scheme reader.
1131@end deffn
1132
1133
1134@node SRFI-11
1135@section SRFI-11 - let-values
8742c48b 1136@cindex SRFI-11
a0e07ba4 1137
8742c48b
KR
1138@findex let-values
1139@findex let-values*
a0e07ba4
NJ
1140This module implements the binding forms for multiple values
1141@code{let-values} and @code{let-values*}. These forms are similar to
1142@code{let} and @code{let*} (@pxref{Local Bindings}), but they support
1143binding of the values returned by multiple-valued expressions.
1144
1145Write @code{(use-modules (srfi srfi-11))} to make the bindings
1146available.
1147
1148@lisp
1149(let-values (((x y) (values 1 2))
1150 ((z f) (values 3 4)))
1151 (+ x y z f))
1152@result{}
115310
1154@end lisp
1155
1156@code{let-values} performs all bindings simultaneously, which means that
1157no expression in the binding clauses may refer to variables bound in the
1158same clause list. @code{let-values*}, on the other hand, performs the
1159bindings sequentially, just like @code{let*} does for single-valued
1160expressions.
1161
1162
1163@node SRFI-13
1164@section SRFI-13 - String Library
8742c48b 1165@cindex SRFI-13
a0e07ba4
NJ
1166
1167In this section, we will describe all procedures defined in SRFI-13
1168(string library) and implemented by the module @code{(srfi srfi-13)}.
1169
1170Note that only the procedures from SRFI-13 are documented here which are
1171not already contained in Guile. For procedures not documented here
1172please refer to the relevant chapters in the Guile Reference Manual, for
1173example the documentation of strings and string procedures
1174(@pxref{Strings}).
1175
40f316d0
MG
1176All of the procedures defined in SRFI-13, which are not already
1177included in the Guile core library, are implemented in the module
1178@code{(srfi srfi-13)}. The procedures which are both in Guile and in
1179SRFI-13 are slightly extended in this module. Their bindings
1180overwrite those in the Guile core.
a0e07ba4
NJ
1181
1182The procedures which are defined in the section @emph{Low-level
1183procedures} of SRFI-13 for parsing optional string indices, substring
1184specification checking and Knuth-Morris-Pratt-Searching are not
1185implemented.
1186
1187The procedures @code{string-contains} and @code{string-contains-ci} are
1188not implemented very efficiently at the moment. This will be changed as
1189soon as possible.
1190
1191@menu
1192* Loading SRFI-13:: How to load SRFI-13 support.
1193* SRFI-13 Predicates:: String predicates.
1194* SRFI-13 Constructors:: String constructing procedures.
1195* SRFI-13 List/String Conversion:: Conversion from/to lists.
1196* SRFI-13 Selection:: Selection portions of strings.
85a9b4ed 1197* SRFI-13 Modification:: Modify strings in-place.
a0e07ba4
NJ
1198* SRFI-13 Comparison:: Compare strings.
1199* SRFI-13 Prefixes/Suffixes:: Detect common pre-/suffixes.
1200* SRFI-13 Searching:: Searching for substrings.
1201* SRFI-13 Case Mapping:: Mapping to lower-/upper-case.
1202* SRFI-13 Reverse/Append:: Reverse and append strings.
1203* SRFI-13 Fold/Unfold/Map:: Construct/deconstruct strings.
40f316d0 1204* SRFI-13 Replicate/Rotate:: Replicate and rotate portions of strings.
a0e07ba4
NJ
1205* SRFI-13 Miscellaneous:: Left-over string procedures.
1206* SRFI-13 Filtering/Deleting:: Filter and delete characters from strings.
1207@end menu
1208
1209
1210@node Loading SRFI-13
1211@subsection Loading SRFI-13
1212
1213When Guile is properly installed, SRFI-13 support can be loaded into a
1214running Guile by using the @code{(srfi srfi-13)} module.
1215
1216@example
1217$ guile
1218guile> (use-modules (srfi srfi-13))
1219guile>
1220@end example
1221
1222When this step causes any errors, Guile is not properly installed.
1223
1224One possible reason is that Guile cannot find either the Scheme module
1225file @file{srfi-13.scm}, or it cannot find the shared object file
1226@file{libguile-srfi-srfi-13-14.so}. Make sure that the former is in the
1227Guile load path and that the latter is either installed in some default
1228location like @file{/usr/local/lib} or that the directory it was
1229installed to is in your @code{LTDL_LIBRARY_PATH}. The same applies to
1230@file{srfi-14.scm}.
1231
1232Now you can test whether the SRFI-13 procedures are working by calling
1233the @code{string-concatenate} procedure.
1234
1235@example
1236guile> (string-concatenate '("Hello" " " "World!"))
1237"Hello World!"
1238@end example
1239
1240@node SRFI-13 Predicates
12991fed 1241@subsection Predicates
a0e07ba4
NJ
1242
1243In addition to the primitives @code{string?} and @code{string-null?},
1244which are already in the Guile core, the string predicates
1245@code{string-any} and @code{string-every} are defined by SRFI-13.
1246
8f85c0c6 1247@deffn {Scheme Procedure} string-any pred s [start end]
a0e07ba4
NJ
1248Check if the predicate @var{pred} is true for any character in
1249the string @var{s}, proceeding from left (index @var{start}) to
1250right (index @var{end}). If @code{string-any} returns true,
1251the returned true value is the one produced by the first
1252successful application of @var{pred}.
1253@end deffn
1254
8f85c0c6 1255@deffn {Scheme Procedure} string-every pred s [start end]
a0e07ba4
NJ
1256Check if the predicate @var{pred} is true for every character
1257in the string @var{s}, proceeding from left (index @var{start})
1258to right (index @var{end}). If @code{string-every} returns
1259true, the returned true value is the one produced by the final
1260application of @var{pred} to the last character of @var{s}.
1261@end deffn
1262
1263
1264@c ===================================================================
1265
1266@node SRFI-13 Constructors
1267@subsection Constructors
1268
1269SRFI-13 defines several procedures for constructing new strings. In
1270addition to @code{make-string} and @code{string} (available in the Guile
1271core library), the procedure @code{string-tabulate} does exist.
1272
8f85c0c6 1273@deffn {Scheme Procedure} string-tabulate proc len
a0e07ba4
NJ
1274@var{proc} is an integer->char procedure. Construct a string
1275of size @var{len} by applying @var{proc} to each index to
1276produce the corresponding string element. The order in which
1277@var{proc} is applied to the indices is not specified.
1278@end deffn
1279
1280
1281@c ===================================================================
1282
1283@node SRFI-13 List/String Conversion
1284@subsection List/String Conversion
1285
1286The procedure @code{string->list} is extended by SRFI-13, that is why it
1287is included in @code{(srfi srfi-13)}. The other procedures are new.
1288The Guile core already contains the procedure @code{list->string} for
1289converting a list of characters into a string (@pxref{List/String
1290Conversion}).
1291
8f85c0c6 1292@deffn {Scheme Procedure} string->list str [start end]
a0e07ba4
NJ
1293Convert the string @var{str} into a list of characters.
1294@end deffn
1295
8f85c0c6 1296@deffn {Scheme Procedure} reverse-list->string chrs
a0e07ba4
NJ
1297An efficient implementation of @code{(compose string->list
1298reverse)}:
1299
1300@smalllisp
1301(reverse-list->string '(#\a #\B #\c)) @result{} "cBa"
1302@end smalllisp
1303@end deffn
1304
8f85c0c6 1305@deffn {Scheme Procedure} string-join ls [delimiter grammar]
a0e07ba4
NJ
1306Append the string in the string list @var{ls}, using the string
1307@var{delim} as a delimiter between the elements of @var{ls}.
1308@var{grammar} is a symbol which specifies how the delimiter is
1309placed between the strings, and defaults to the symbol
1310@code{infix}.
1311
1312@table @code
1313@item infix
1314Insert the separator between list elements. An empty string
1315will produce an empty list.
1316
1317@item string-infix
1318Like @code{infix}, but will raise an error if given the empty
1319list.
1320
1321@item suffix
1322Insert the separator after every list element.
1323
1324@item prefix
1325Insert the separator before each list element.
1326@end table
1327@end deffn
1328
1329
1330@c ===================================================================
1331
1332@node SRFI-13 Selection
1333@subsection Selection
1334
1335These procedures are called @dfn{selectors}, because they access
1336information about the string or select pieces of a given string.
1337
1338Additional selector procedures are documented in the Strings section
1339(@pxref{String Selection}), like @code{string-length} or
1340@code{string-ref}.
1341
1342@code{string-copy} is also available in core Guile, but this version
1343accepts additional start/end indices.
1344
8f85c0c6 1345@deffn {Scheme Procedure} string-copy str [start end]
a0e07ba4
NJ
1346Return a freshly allocated copy of the string @var{str}. If
1347given, @var{start} and @var{end} delimit the portion of
1348@var{str} which is copied.
1349@end deffn
1350
8f85c0c6 1351@deffn {Scheme Procedure} substring/shared str start [end]
a0e07ba4
NJ
1352Like @code{substring}, but the result may share memory with the
1353argument @var{str}.
1354@end deffn
1355
8f85c0c6 1356@deffn {Scheme Procedure} string-copy! target tstart s [start end]
a0e07ba4
NJ
1357Copy the sequence of characters from index range [@var{start},
1358@var{end}) in string @var{s} to string @var{target}, beginning
1359at index @var{tstart}. The characters are copied left-to-right
1360or right-to-left as needed - the copy is guaranteed to work,
1361even if @var{target} and @var{s} are the same string. It is an
1362error if the copy operation runs off the end of the target
1363string.
1364@end deffn
1365
8f85c0c6
NJ
1366@deffn {Scheme Procedure} string-take s n
1367@deffnx {Scheme Procedure} string-take-right s n
a0e07ba4
NJ
1368Return the @var{n} first/last characters of @var{s}.
1369@end deffn
1370
8f85c0c6
NJ
1371@deffn {Scheme Procedure} string-drop s n
1372@deffnx {Scheme Procedure} string-drop-right s n
a0e07ba4
NJ
1373Return all but the first/last @var{n} characters of @var{s}.
1374@end deffn
1375
8f85c0c6
NJ
1376@deffn {Scheme Procedure} string-pad s len [chr start end]
1377@deffnx {Scheme Procedure} string-pad-right s len [chr start end]
a0e07ba4
NJ
1378Take that characters from @var{start} to @var{end} from the
1379string @var{s} and return a new string, right(left)-padded by the
1380character @var{chr} to length @var{len}. If the resulting
1381string is longer than @var{len}, it is truncated on the right (left).
1382@end deffn
1383
8f85c0c6
NJ
1384@deffn {Scheme Procedure} string-trim s [char_pred start end]
1385@deffnx {Scheme Procedure} string-trim-right s [char_pred start end]
1386@deffnx {Scheme Procedure} string-trim-both s [char_pred start end]
a0e07ba4
NJ
1387Trim @var{s} by skipping over all characters on the left/right/both
1388sides of the string that satisfy the parameter @var{char_pred}:
1389
1390@itemize @bullet
1391@item
1392if it is the character @var{ch}, characters equal to
1393@var{ch} are trimmed,
1394
1395@item
1396if it is a procedure @var{pred} characters that
1397satisfy @var{pred} are trimmed,
1398
1399@item
1400if it is a character set, characters in that set are trimmed.
1401@end itemize
1402
1403If called without a @var{char_pred} argument, all whitespace is
1404trimmed.
1405@end deffn
1406
1407
1408@c ===================================================================
1409
1410@node SRFI-13 Modification
1411@subsection Modification
1412
1413The procedure @code{string-fill!} is extended from R5RS because it
1414accepts optional start/end indices. This bindings shadows the procedure
1415of the same name in the Guile core. The second modification procedure
1416@code{string-set!} is documented in the Strings section (@pxref{String
1417Modification}).
1418
8f85c0c6 1419@deffn {Scheme Procedure} string-fill! str chr [start end]
a0e07ba4
NJ
1420Stores @var{chr} in every element of the given @var{str} and
1421returns an unspecified value.
1422@end deffn
1423
1424
1425@c ===================================================================
1426
1427@node SRFI-13 Comparison
1428@subsection Comparison
1429
1430The procedures in this section are used for comparing strings in
1431different ways. The comparison predicates differ from those in R5RS in
1432that they do not only return @code{#t} or @code{#f}, but the mismatch
1433index in the case of a true return value.
1434
1435@code{string-hash} and @code{string-hash-ci} are for calculating hash
1436values for strings, useful for implementing fast lookup mechanisms.
1437
8f85c0c6
NJ
1438@deffn {Scheme Procedure} string-compare s1 s2 proc_lt proc_eq proc_gt [start1 end1 start2 end2]
1439@deffnx {Scheme Procedure} string-compare-ci s1 s2 proc_lt proc_eq proc_gt [start1 end1 start2 end2]
a0e07ba4
NJ
1440Apply @var{proc_lt}, @var{proc_eq}, @var{proc_gt} to the
1441mismatch index, depending upon whether @var{s1} is less than,
1442equal to, or greater than @var{s2}. The mismatch index is the
1443largest index @var{i} such that for every 0 <= @var{j} <
1444@var{i}, @var{s1}[@var{j}] = @var{s2}[@var{j}] - that is,
1445@var{i} is the first position that does not match. The
1446character comparison is done case-insensitively.
1447@end deffn
1448
8f85c0c6
NJ
1449@deffn {Scheme Procedure} string= s1 s2 [start1 end1 start2 end2]
1450@deffnx {Scheme Procedure} string<> s1 s2 [start1 end1 start2 end2]
1451@deffnx {Scheme Procedure} string< s1 s2 [start1 end1 start2 end2]
1452@deffnx {Scheme Procedure} string> s1 s2 [start1 end1 start2 end2]
1453@deffnx {Scheme Procedure} string<= s1 s2 [start1 end1 start2 end2]
1454@deffnx {Scheme Procedure} string>= s1 s2 [start1 end1 start2 end2]
a0e07ba4
NJ
1455Compare @var{s1} and @var{s2} and return @code{#f} if the predicate
1456fails. Otherwise, the mismatch index is returned (or @var{end1} in the
1457case of @code{string=}.
1458@end deffn
1459
8f85c0c6
NJ
1460@deffn {Scheme Procedure} string-ci= s1 s2 [start1 end1 start2 end2]
1461@deffnx {Scheme Procedure} string-ci<> s1 s2 [start1 end1 start2 end2]
1462@deffnx {Scheme Procedure} string-ci< s1 s2 [start1 end1 start2 end2]
1463@deffnx {Scheme Procedure} string-ci> s1 s2 [start1 end1 start2 end2]
1464@deffnx {Scheme Procedure} string-ci<= s1 s2 [start1 end1 start2 end2]
1465@deffnx {Scheme Procedure} string-ci>= s1 s2 [start1 end1 start2 end2]
a0e07ba4
NJ
1466Compare @var{s1} and @var{s2} and return @code{#f} if the predicate
1467fails. Otherwise, the mismatch index is returned (or @var{end1} in the
1468case of @code{string=}. These are the case-insensitive variants.
1469@end deffn
1470
8f85c0c6
NJ
1471@deffn {Scheme Procedure} string-hash s [bound start end]
1472@deffnx {Scheme Procedure} string-hash-ci s [bound start end]
a0e07ba4
NJ
1473Return a hash value of the string @var{s} in the range 0 @dots{}
1474@var{bound} - 1. @code{string-hash-ci} is the case-insensitive variant.
1475@end deffn
1476
1477
1478@c ===================================================================
1479
1480@node SRFI-13 Prefixes/Suffixes
1481@subsection Prefixes/Suffixes
1482
1483Using these procedures you can determine whether a given string is a
1484prefix or suffix of another string or how long a common prefix/suffix
1485is.
1486
8f85c0c6
NJ
1487@deffn {Scheme Procedure} string-prefix-length s1 s2 [start1 end1 start2 end2]
1488@deffnx {Scheme Procedure} string-prefix-length-ci s1 s2 [start1 end1 start2 end2]
1489@deffnx {Scheme Procedure} string-suffix-length s1 s2 [start1 end1 start2 end2]
1490@deffnx {Scheme Procedure} string-suffix-length-ci s1 s2 [start1 end1 start2 end2]
a0e07ba4
NJ
1491Return the length of the longest common prefix/suffix of the two
1492strings. @code{string-prefix-length-ci} and
1493@code{string-suffix-length-ci} are the case-insensitive variants.
1494@end deffn
1495
8f85c0c6
NJ
1496@deffn {Scheme Procedure} string-prefix? s1 s2 [start1 end1 start2 end2]
1497@deffnx {Scheme Procedure} string-prefix-ci? s1 s2 [start1 end1 start2 end2]
1498@deffnx {Scheme Procedure} string-suffix? s1 s2 [start1 end1 start2 end2]
1499@deffnx {Scheme Procedure} string-suffix-ci? s1 s2 [start1 end1 start2 end2]
a0e07ba4
NJ
1500Is @var{s1} a prefix/suffix of @var{s2}. @code{string-prefix-ci?} and
1501@code{string-suffix-ci?} are the case-insensitive variants.
1502@end deffn
1503
1504
1505@c ===================================================================
1506
1507@node SRFI-13 Searching
1508@subsection Searching
1509
1510Use these procedures to find out whether a string contains a given
1511character or a given substring, or a character from a set of characters.
1512
8f85c0c6
NJ
1513@deffn {Scheme Procedure} string-index s char_pred [start end]
1514@deffnx {Scheme Procedure} string-index-right s char_pred [start end]
a0e07ba4 1515Search through the string @var{s} from left to right (right to left),
85a9b4ed 1516returning the index of the first (last) occurrence of a character which
a0e07ba4
NJ
1517
1518@itemize @bullet
1519@item
1520equals @var{char_pred}, if it is character,
1521
1522@item
85a9b4ed 1523satisfies the predicate @var{char_pred}, if it is a
a0e07ba4
NJ
1524procedure,
1525
1526@item
1527is in the set @var{char_pred}, if it is a character set.
1528@end itemize
1529@end deffn
1530
8f85c0c6
NJ
1531@deffn {Scheme Procedure} string-skip s char_pred [start end]
1532@deffnx {Scheme Procedure} string-skip-right s char_pred [start end]
a0e07ba4 1533Search through the string @var{s} from left to right (right to left),
85a9b4ed 1534returning the index of the first (last) occurrence of a character which
a0e07ba4
NJ
1535
1536@itemize @bullet
1537@item
1538does not equal @var{char_pred}, if it is character,
1539
1540@item
85a9b4ed 1541does not satisfy the predicate @var{char_pred}, if it is
a0e07ba4
NJ
1542a procedure.
1543
1544@item
1545is not in the set if @var{char_pred} is a character set.
1546@end itemize
1547@end deffn
1548
8f85c0c6 1549@deffn {Scheme Procedure} string-count s char_pred [start end]
a0e07ba4
NJ
1550Return the count of the number of characters in the string
1551@var{s} which
1552
1553@itemize @bullet
1554@item
1555equals @var{char_pred}, if it is character,
1556
1557@item
85a9b4ed 1558satisfies the predicate @var{char_pred}, if it is a procedure.
a0e07ba4
NJ
1559
1560@item
1561is in the set @var{char_pred}, if it is a character set.
1562@end itemize
1563@end deffn
1564
8f85c0c6
NJ
1565@deffn {Scheme Procedure} string-contains s1 s2 [start1 end1 start2 end2]
1566@deffnx {Scheme Procedure} string-contains-ci s1 s2 [start1 end1 start2 end2]
a0e07ba4
NJ
1567Does string @var{s1} contain string @var{s2}? Return the index
1568in @var{s1} where @var{s2} occurs as a substring, or false.
1569The optional start/end indices restrict the operation to the
1570indicated substrings.
1571
1572@code{string-contains-ci} is the case-insensitive variant.
1573@end deffn
1574
1575
1576@c ===================================================================
1577
1578@node SRFI-13 Case Mapping
1579@subsection Alphabetic Case Mapping
1580
1581These procedures convert the alphabetic case of strings. They are
1582similar to the procedures in the Guile core, but are extended to handle
1583optional start/end indices.
1584
8f85c0c6
NJ
1585@deffn {Scheme Procedure} string-upcase s [start end]
1586@deffnx {Scheme Procedure} string-upcase! s [start end]
a0e07ba4
NJ
1587Upcase every character in @var{s}. @code{string-upcase!} is the
1588side-effecting variant.
1589@end deffn
1590
8f85c0c6
NJ
1591@deffn {Scheme Procedure} string-downcase s [start end]
1592@deffnx {Scheme Procedure} string-downcase! s [start end]
a0e07ba4
NJ
1593Downcase every character in @var{s}. @code{string-downcase!} is the
1594side-effecting variant.
1595@end deffn
1596
8f85c0c6
NJ
1597@deffn {Scheme Procedure} string-titlecase s [start end]
1598@deffnx {Scheme Procedure} string-titlecase! s [start end]
a0e07ba4
NJ
1599Upcase every first character in every word in @var{s}, downcase the
1600other characters. @code{string-titlecase!} is the side-effecting
1601variant.
1602@end deffn
1603
1604
1605@c ===================================================================
1606
1607@node SRFI-13 Reverse/Append
1608@subsection Reverse/Append
1609
1610One appending procedure, @code{string-append} is the same in R5RS and in
1611SRFI-13, so it is not redefined.
1612
8f85c0c6
NJ
1613@deffn {Scheme Procedure} string-reverse str [start end]
1614@deffnx {Scheme Procedure} string-reverse! str [start end]
a0e07ba4
NJ
1615Reverse the string @var{str}. The optional arguments
1616@var{start} and @var{end} delimit the region of @var{str} to
1617operate on.
1618
1619@code{string-reverse!} modifies the argument string and returns an
1620unspecified value.
1621@end deffn
1622
8f85c0c6 1623@deffn {Scheme Procedure} string-append/shared ls @dots{}
a0e07ba4
NJ
1624Like @code{string-append}, but the result may share memory
1625with the argument strings.
1626@end deffn
1627
8f85c0c6 1628@deffn {Scheme Procedure} string-concatenate ls
a0e07ba4
NJ
1629Append the elements of @var{ls} (which must be strings)
1630together into a single string. Guaranteed to return a freshly
1631allocated string.
1632@end deffn
1633
8f85c0c6 1634@deffn {Scheme Procedure} string-concatenate/shared ls
a0e07ba4
NJ
1635Like @code{string-concatenate}, but the result may share memory
1636with the strings in the list @var{ls}.
1637@end deffn
1638
8f85c0c6 1639@deffn {Scheme Procedure} string-concatenate-reverse ls final_string end
a0e07ba4
NJ
1640Without optional arguments, this procedure is equivalent to
1641
1642@smalllisp
1643(string-concatenate (reverse ls))
1644@end smalllisp
1645
1646If the optional argument @var{final_string} is specified, it is
1647consed onto the beginning to @var{ls} before performing the
1648list-reverse and string-concatenate operations. If @var{end}
1649is given, only the characters of @var{final_string} up to index
1650@var{end} are used.
1651
1652Guaranteed to return a freshly allocated string.
1653@end deffn
1654
8f85c0c6 1655@deffn {Scheme Procedure} string-concatenate-reverse/shared ls final_string end
a0e07ba4
NJ
1656Like @code{string-concatenate-reverse}, but the result may
1657share memory with the the strings in the @var{ls} arguments.
1658@end deffn
1659
1660
1661@c ===================================================================
1662
1663@node SRFI-13 Fold/Unfold/Map
1664@subsection Fold/Unfold/Map
1665
1666@code{string-map}, @code{string-for-each} etc. are for iterating over
1667the characters a string is composed of. The fold and unfold procedures
1668are list iterators and constructors.
1669
8f85c0c6 1670@deffn {Scheme Procedure} string-map proc s [start end]
a0e07ba4
NJ
1671@var{proc} is a char->char procedure, it is mapped over
1672@var{s}. The order in which the procedure is applied to the
1673string elements is not specified.
1674@end deffn
1675
8f85c0c6 1676@deffn {Scheme Procedure} string-map! proc s [start end]
a0e07ba4
NJ
1677@var{proc} is a char->char procedure, it is mapped over
1678@var{s}. The order in which the procedure is applied to the
1679string elements is not specified. The string @var{s} is
1680modified in-place, the return value is not specified.
1681@end deffn
1682
8f85c0c6
NJ
1683@deffn {Scheme Procedure} string-fold kons knil s [start end]
1684@deffnx {Scheme Procedure} string-fold-right kons knil s [start end]
a0e07ba4
NJ
1685Fold @var{kons} over the characters of @var{s}, with @var{knil} as the
1686terminating element, from left to right (or right to left, for
1687@code{string-fold-right}). @var{kons} must expect two arguments: The
1688actual character and the last result of @var{kons}' application.
1689@end deffn
1690
8f85c0c6
NJ
1691@deffn {Scheme Procedure} string-unfold p f g seed [base make_final]
1692@deffnx {Scheme Procedure} string-unfold-right p f g seed [base make_final]
a0e07ba4
NJ
1693These are the fundamental string constructors.
1694@itemize @bullet
1695@item @var{g} is used to generate a series of @emph{seed}
1696values from the initial @var{seed}: @var{seed}, (@var{g}
1697@var{seed}), (@var{g}^2 @var{seed}), (@var{g}^3 @var{seed}),
1698@dots{}
1699@item @var{p} tells us when to stop - when it returns true
1700when applied to one of these seed values.
12991fed 1701@item @var{f} maps each seed value to the corresponding
a0e07ba4
NJ
1702character in the result string. These chars are assembled into the
1703string in a left-to-right (right-to-left) order.
1704@item @var{base} is the optional initial/leftmost (rightmost)
1705 portion of the constructed string; it default to the empty string.
1706@item @var{make_final} is applied to the terminal seed
1707value (on which @var{p} returns true) to produce the final/rightmost
1708(leftmost) portion of the constructed string. It defaults to
1709@code{(lambda (x) "")}.
1710@end itemize
1711@end deffn
1712
8f85c0c6 1713@deffn {Scheme Procedure} string-for-each proc s [start end]
a0e07ba4
NJ
1714@var{proc} is mapped over @var{s} in left-to-right order. The
1715return value is not specified.
1716@end deffn
1717
1718
1719@c ===================================================================
1720
1721@node SRFI-13 Replicate/Rotate
1722@subsection Replicate/Rotate
1723
1724These procedures are special substring procedures, which can also be
1725used for replicating strings. They are a bit tricky to use, but
1726consider this code fragment, which replicates the input string
1727@code{"foo"} so often that the resulting string has a length of six.
1728
1729@lisp
1730(xsubstring "foo" 0 6)
1731@result{}
1732"foofoo"
1733@end lisp
1734
8f85c0c6 1735@deffn {Scheme Procedure} xsubstring s from [to start end]
a0e07ba4
NJ
1736This is the @emph{extended substring} procedure that implements
1737replicated copying of a substring of some string.
1738
1739@var{s} is a string, @var{start} and @var{end} are optional
1740arguments that demarcate a substring of @var{s}, defaulting to
17410 and the length of @var{s}. Replicate this substring up and
1742down index space, in both the positive and negative directions.
1743@code{xsubstring} returns the substring of this string
1744beginning at index @var{from}, and ending at @var{to}, which
1745defaults to @var{from} + (@var{end} - @var{start}).
1746@end deffn
1747
8f85c0c6 1748@deffn {Scheme Procedure} string-xcopy! target tstart s sfrom [sto start end]
a0e07ba4
NJ
1749Exactly the same as @code{xsubstring}, but the extracted text
1750is written into the string @var{target} starting at index
1751@var{tstart}. The operation is not defined if @code{(eq?
1752@var{target} @var{s})} or these arguments share storage - you
1753cannot copy a string on top of itself.
1754@end deffn
1755
1756
1757@c ===================================================================
1758
1759@node SRFI-13 Miscellaneous
1760@subsection Miscellaneous
1761
1762@code{string-replace} is for replacing a portion of a string with
1763another string and @code{string-tokenize} splits a string into a list of
1764strings, breaking it up at a specified character.
1765
8f85c0c6 1766@deffn {Scheme Procedure} string-replace s1 s2 [start1 end1 start2 end2]
a0e07ba4
NJ
1767Return the string @var{s1}, but with the characters
1768@var{start1} @dots{} @var{end1} replaced by the characters
1769@var{start2} @dots{} @var{end2} from @var{s2}.
1770@end deffn
1771
c0ab7f13 1772@deffn {Scheme Procedure} string-tokenize s [token-set start end]
a0e07ba4 1773Split the string @var{s} into a list of substrings, where each
c0ab7f13
MV
1774substring is a maximal non-empty contiguous sequence of characters
1775from the character set @var{token_set}, which defaults to an
1776equivalent of @code{char-set:graphic}. If @var{start} or @var{end}
1777indices are provided, they restrict @code{string-tokenize} to
1778operating on the indicated substring of @var{s}.
a0e07ba4
NJ
1779@end deffn
1780
1781
1782@c ===================================================================
1783
1784@node SRFI-13 Filtering/Deleting
1785@subsection Filtering/Deleting
1786
1787@dfn{Filtering} means to remove all characters from a string which do
1788not match a given criteria, @dfn{deleting} means the opposite.
1789
8f85c0c6 1790@deffn {Scheme Procedure} string-filter s char_pred [start end]
a0e07ba4
NJ
1791Filter the string @var{s}, retaining only those characters that
1792satisfy the @var{char_pred} argument. If the argument is a
1793procedure, it is applied to each character as a predicate, if
1794it is a character, it is tested for equality and if it is a
1795character set, it is tested for membership.
1796@end deffn
1797
8f85c0c6 1798@deffn {Scheme Procedure} string-delete s char_pred [start end]
a0e07ba4
NJ
1799Filter the string @var{s}, retaining only those characters that
1800do not satisfy the @var{char_pred} argument. If the argument
1801is a procedure, it is applied to each character as a predicate,
1802if it is a character, it is tested for equality and if it is a
1803character set, it is tested for membership.
1804@end deffn
1805
1806
1807@node SRFI-14
1808@section SRFI-14 - Character-set Library
8742c48b 1809@cindex SRFI-14
a0e07ba4
NJ
1810
1811SRFI-14 defines the data type @dfn{character set}, and also defines a
1812lot of procedures for handling this character type, and a few standard
1813character sets like whitespace, alphabetic characters and others.
1814
1815All procedures from SRFI-14 (character-set library) are implemented in
1816the module @code{(srfi srfi-14)}, as well as the standard variables
1817@code{char-set:letter}, @code{char-set:digit} etc.
1818
1819@menu
1820* Loading SRFI-14:: How to make charsets available.
1821* SRFI-14 Character Set Data Type:: Underlying data type for charsets.
1822* SRFI-14 Predicates/Comparison:: Charset predicates.
1823* SRFI-14 Iterating Over Character Sets:: Enumerate charset elements.
85a9b4ed 1824* SRFI-14 Creating Character Sets:: Making new charsets.
a0e07ba4
NJ
1825* SRFI-14 Querying Character Sets:: Test charsets for membership etc.
1826* SRFI-14 Character-Set Algebra:: Calculating new charsets.
1827* SRFI-14 Standard Character Sets:: Variables containing predefined charsets.
1828@end menu
1829
1830
1831@node Loading SRFI-14
1832@subsection Loading SRFI-14
1833
1834When Guile is properly installed, SRFI-14 support can be loaded into a
1835running Guile by using the @code{(srfi srfi-14)} module.
1836
1837@example
1838$ guile
1839guile> (use-modules (srfi srfi-14))
1840guile> (char-set-union (char-set #\f #\o #\o) (string->char-set "bar"))
1841#<charset @{#\a #\b #\f #\o #\r@}>
1842guile>
1843@end example
1844
1845
1846@node SRFI-14 Character Set Data Type
1847@subsection Character Set Data Type
1848
1849The data type @dfn{charset} implements sets of characters
1850(@pxref{Characters}). Because the internal representation of character
1851sets is not visible to the user, a lot of procedures for handling them
1852are provided.
1853
1854Character sets can be created, extended, tested for the membership of a
1855characters and be compared to other character sets.
1856
1857The Guile implementation of character sets deals with 8-bit characters.
1858In the standard variables, only the ASCII part of the character range is
1859really used, so that for example @dfn{Umlaute} and other accented
1860characters are not considered to be letters. In the future, as Guile
1861may get support for international character sets, this will change, so
1862don't rely on these ``features''.
1863
1864
1865@c ===================================================================
1866
1867@node SRFI-14 Predicates/Comparison
1868@subsection Predicates/Comparison
1869
1870Use these procedures for testing whether an object is a character set,
1871or whether several character sets are equal or subsets of each other.
1872@code{char-set-hash} can be used for calculating a hash value, maybe for
1873usage in fast lookup procedures.
1874
8f85c0c6 1875@deffn {Scheme Procedure} char-set? obj
a0e07ba4
NJ
1876Return @code{#t} if @var{obj} is a character set, @code{#f}
1877otherwise.
1878@end deffn
1879
8f85c0c6 1880@deffn {Scheme Procedure} char-set= cs1 @dots{}
a0e07ba4
NJ
1881Return @code{#t} if all given character sets are equal.
1882@end deffn
1883
8f85c0c6 1884@deffn {Scheme Procedure} char-set<= cs1 @dots{}
a0e07ba4
NJ
1885Return @code{#t} if every character set @var{cs}i is a subset
1886of character set @var{cs}i+1.
1887@end deffn
1888
8f85c0c6 1889@deffn {Scheme Procedure} char-set-hash cs [bound]
a0e07ba4
NJ
1890Compute a hash value for the character set @var{cs}. If
1891@var{bound} is given and not @code{#f}, it restricts the
1892returned value to the range 0 @dots{} @var{bound - 1}.
1893@end deffn
1894
1895
1896@c ===================================================================
1897
1898@node SRFI-14 Iterating Over Character Sets
1899@subsection Iterating Over Character Sets
1900
1901Character set cursors are a means for iterating over the members of a
1902character sets. After creating a character set cursor with
1903@code{char-set-cursor}, a cursor can be dereferenced with
1904@code{char-set-ref}, advanced to the next member with
1905@code{char-set-cursor-next}. Whether a cursor has passed past the last
1906element of the set can be checked with @code{end-of-char-set?}.
1907
1908Additionally, mapping and (un-)folding procedures for character sets are
1909provided.
1910
8f85c0c6 1911@deffn {Scheme Procedure} char-set-cursor cs
a0e07ba4
NJ
1912Return a cursor into the character set @var{cs}.
1913@end deffn
1914
8f85c0c6 1915@deffn {Scheme Procedure} char-set-ref cs cursor
a0e07ba4
NJ
1916Return the character at the current cursor position
1917@var{cursor} in the character set @var{cs}. It is an error to
1918pass a cursor for which @code{end-of-char-set?} returns true.
1919@end deffn
1920
8f85c0c6 1921@deffn {Scheme Procedure} char-set-cursor-next cs cursor
a0e07ba4
NJ
1922Advance the character set cursor @var{cursor} to the next
1923character in the character set @var{cs}. It is an error if the
1924cursor given satisfies @code{end-of-char-set?}.
1925@end deffn
1926
8f85c0c6 1927@deffn {Scheme Procedure} end-of-char-set? cursor
a0e07ba4
NJ
1928Return @code{#t} if @var{cursor} has reached the end of a
1929character set, @code{#f} otherwise.
1930@end deffn
1931
8f85c0c6 1932@deffn {Scheme Procedure} char-set-fold kons knil cs
a0e07ba4
NJ
1933Fold the procedure @var{kons} over the character set @var{cs},
1934initializing it with @var{knil}.
1935@end deffn
1936
8f85c0c6
NJ
1937@deffn {Scheme Procedure} char-set-unfold p f g seed [base_cs]
1938@deffnx {Scheme Procedure} char-set-unfold! p f g seed base_cs
a0e07ba4
NJ
1939This is a fundamental constructor for character sets.
1940@itemize @bullet
12991fed 1941@item @var{g} is used to generate a series of ``seed'' values
a0e07ba4
NJ
1942from the initial seed: @var{seed}, (@var{g} @var{seed}),
1943(@var{g}^2 @var{seed}), (@var{g}^3 @var{seed}), @dots{}
1944@item @var{p} tells us when to stop -- when it returns true
12991fed 1945when applied to one of the seed values.
a0e07ba4
NJ
1946@item @var{f} maps each seed value to a character. These
1947characters are added to the base character set @var{base_cs} to
1948form the result; @var{base_cs} defaults to the empty set.
1949@end itemize
1950
1951@code{char-set-unfold!} is the side-effecting variant.
1952@end deffn
1953
8f85c0c6 1954@deffn {Scheme Procedure} char-set-for-each proc cs
a0e07ba4
NJ
1955Apply @var{proc} to every character in the character set
1956@var{cs}. The return value is not specified.
1957@end deffn
1958
8f85c0c6 1959@deffn {Scheme Procedure} char-set-map proc cs
a0e07ba4
NJ
1960Map the procedure @var{proc} over every character in @var{cs}.
1961@var{proc} must be a character -> character procedure.
1962@end deffn
1963
1964
1965@c ===================================================================
1966
1967@node SRFI-14 Creating Character Sets
1968@subsection Creating Character Sets
1969
1970New character sets are produced with these procedures.
1971
8f85c0c6 1972@deffn {Scheme Procedure} char-set-copy cs
a0e07ba4
NJ
1973Return a newly allocated character set containing all
1974characters in @var{cs}.
1975@end deffn
1976
8f85c0c6 1977@deffn {Scheme Procedure} char-set char1 @dots{}
a0e07ba4
NJ
1978Return a character set containing all given characters.
1979@end deffn
1980
8f85c0c6
NJ
1981@deffn {Scheme Procedure} list->char-set char_list [base_cs]
1982@deffnx {Scheme Procedure} list->char-set! char_list base_cs
a0e07ba4
NJ
1983Convert the character list @var{list} to a character set. If
1984the character set @var{base_cs} is given, the character in this
1985set are also included in the result.
1986
1987@code{list->char-set!} is the side-effecting variant.
1988@end deffn
1989
8f85c0c6
NJ
1990@deffn {Scheme Procedure} string->char-set s [base_cs]
1991@deffnx {Scheme Procedure} string->char-set! s base_cs
a0e07ba4
NJ
1992Convert the string @var{str} to a character set. If the
1993character set @var{base_cs} is given, the characters in this
1994set are also included in the result.
1995
1996@code{string->char-set!} is the side-effecting variant.
1997@end deffn
1998
8f85c0c6
NJ
1999@deffn {Scheme Procedure} char-set-filter pred cs [base_cs]
2000@deffnx {Scheme Procedure} char-set-filter! pred cs base_cs
a0e07ba4
NJ
2001Return a character set containing every character from @var{cs}
2002so that it satisfies @var{pred}. If provided, the characters
2003from @var{base_cs} are added to the result.
2004
2005@code{char-set-filter!} is the side-effecting variant.
2006@end deffn
2007
8f85c0c6
NJ
2008@deffn {Scheme Procedure} ucs-range->char-set lower upper [error? base_cs]
2009@deffnx {Scheme Procedure} uce-range->char-set! lower upper error? base_cs
a0e07ba4
NJ
2010Return a character set containing all characters whose
2011character codes lie in the half-open range
2012[@var{lower},@var{upper}).
2013
2014If @var{error} is a true value, an error is signalled if the
2015specified range contains characters which are not contained in
2016the implemented character range. If @var{error} is @code{#f},
85a9b4ed 2017these characters are silently left out of the resulting
a0e07ba4
NJ
2018character set.
2019
2020The characters in @var{base_cs} are added to the result, if
2021given.
2022
2023@code{ucs-range->char-set!} is the side-effecting variant.
2024@end deffn
2025
8f85c0c6 2026@deffn {Scheme Procedure} ->char-set x
a0e07ba4
NJ
2027Coerce @var{x} into a character set. @var{x} may be a string, a
2028character or a character set.
2029@end deffn
2030
2031
2032@c ===================================================================
2033
2034@node SRFI-14 Querying Character Sets
2035@subsection Querying Character Sets
2036
2037Access the elements and other information of a character set with these
2038procedures.
2039
8f85c0c6 2040@deffn {Scheme Procedure} char-set-size cs
a0e07ba4
NJ
2041Return the number of elements in character set @var{cs}.
2042@end deffn
2043
8f85c0c6 2044@deffn {Scheme Procedure} char-set-count pred cs
a0e07ba4
NJ
2045Return the number of the elements int the character set
2046@var{cs} which satisfy the predicate @var{pred}.
2047@end deffn
2048
8f85c0c6 2049@deffn {Scheme Procedure} char-set->list cs
a0e07ba4
NJ
2050Return a list containing the elements of the character set
2051@var{cs}.
2052@end deffn
2053
8f85c0c6 2054@deffn {Scheme Procedure} char-set->string cs
a0e07ba4
NJ
2055Return a string containing the elements of the character set
2056@var{cs}. The order in which the characters are placed in the
2057string is not defined.
2058@end deffn
2059
8f85c0c6 2060@deffn {Scheme Procedure} char-set-contains? cs char
a0e07ba4
NJ
2061Return @code{#t} iff the character @var{ch} is contained in the
2062character set @var{cs}.
2063@end deffn
2064
8f85c0c6 2065@deffn {Scheme Procedure} char-set-every pred cs
a0e07ba4
NJ
2066Return a true value if every character in the character set
2067@var{cs} satisfies the predicate @var{pred}.
2068@end deffn
2069
8f85c0c6 2070@deffn {Scheme Procedure} char-set-any pred cs
a0e07ba4
NJ
2071Return a true value if any character in the character set
2072@var{cs} satisfies the predicate @var{pred}.
2073@end deffn
2074
2075
2076@c ===================================================================
2077
2078@node SRFI-14 Character-Set Algebra
2079@subsection Character-Set Algebra
2080
2081Character sets can be manipulated with the common set algebra operation,
2082such as union, complement, intersection etc. All of these procedures
2083provide side-effecting variants, which modify their character set
2084argument(s).
2085
8f85c0c6
NJ
2086@deffn {Scheme Procedure} char-set-adjoin cs char1 @dots{}
2087@deffnx {Scheme Procedure} char-set-adjoin! cs char1 @dots{}
a0e07ba4
NJ
2088Add all character arguments to the first argument, which must
2089be a character set.
2090@end deffn
2091
8f85c0c6
NJ
2092@deffn {Scheme Procedure} char-set-delete cs char1 @dots{}
2093@deffnx {Scheme Procedure} char-set-delete! cs char1 @dots{}
a0e07ba4
NJ
2094Delete all character arguments from the first argument, which
2095must be a character set.
2096@end deffn
2097
8f85c0c6
NJ
2098@deffn {Scheme Procedure} char-set-complement cs
2099@deffnx {Scheme Procedure} char-set-complement! cs
a0e07ba4
NJ
2100Return the complement of the character set @var{cs}.
2101@end deffn
2102
8f85c0c6
NJ
2103@deffn {Scheme Procedure} char-set-union cs1 @dots{}
2104@deffnx {Scheme Procedure} char-set-union! cs1 @dots{}
a0e07ba4
NJ
2105Return the union of all argument character sets.
2106@end deffn
2107
8f85c0c6
NJ
2108@deffn {Scheme Procedure} char-set-intersection cs1 @dots{}
2109@deffnx {Scheme Procedure} char-set-intersection! cs1 @dots{}
a0e07ba4
NJ
2110Return the intersection of all argument character sets.
2111@end deffn
2112
8f85c0c6
NJ
2113@deffn {Scheme Procedure} char-set-difference cs1 @dots{}
2114@deffnx {Scheme Procedure} char-set-difference! cs1 @dots{}
a0e07ba4
NJ
2115Return the difference of all argument character sets.
2116@end deffn
2117
8f85c0c6
NJ
2118@deffn {Scheme Procedure} char-set-xor cs1 @dots{}
2119@deffnx {Scheme Procedure} char-set-xor! cs1 @dots{}
a0e07ba4
NJ
2120Return the exclusive-or of all argument character sets.
2121@end deffn
2122
8f85c0c6
NJ
2123@deffn {Scheme Procedure} char-set-diff+intersection cs1 @dots{}
2124@deffnx {Scheme Procedure} char-set-diff+intersection! cs1 @dots{}
a0e07ba4
NJ
2125Return the difference and the intersection of all argument
2126character sets.
2127@end deffn
2128
2129
2130@c ===================================================================
2131
2132@node SRFI-14 Standard Character Sets
2133@subsection Standard Character Sets
2134
2135In order to make the use of the character set data type and procedures
2136useful, several predefined character set variables exist.
2137
2138@defvar char-set:lower-case
2139All lower-case characters.
2140@end defvar
2141
2142@defvar char-set:upper-case
2143All upper-case characters.
2144@end defvar
2145
2146@defvar char-set:title-case
2147This is empty, because ASCII has no titlecase characters.
2148@end defvar
2149
2150@defvar char-set:letter
2151All letters, e.g. the union of @code{char-set:lower-case} and
2152@code{char-set:upper-case}.
2153@end defvar
2154
2155@defvar char-set:digit
2156All digits.
2157@end defvar
2158
2159@defvar char-set:letter+digit
2160The union of @code{char-set:letter} and @code{char-set:digit}.
2161@end defvar
2162
2163@defvar char-set:graphic
2164All characters which would put ink on the paper.
2165@end defvar
2166
2167@defvar char-set:printing
2168The union of @code{char-set:graphic} and @code{char-set:whitespace}.
2169@end defvar
2170
2171@defvar char-set:whitespace
2172All whitespace characters.
2173@end defvar
2174
2175@defvar char-set:blank
2176All horizontal whitespace characters, that is @code{#\space} and
2177@code{#\tab}.
2178@end defvar
2179
2180@defvar char-set:iso-control
2181The ISO control characters with the codes 0--31 and 127.
2182@end defvar
2183
2184@defvar char-set:punctuation
2185The characters @code{!"#%&'()*,-./:;?@@[\\]_@{@}}
2186@end defvar
2187
2188@defvar char-set:symbol
2189The characters @code{$+<=>^`|~}.
2190@end defvar
2191
2192@defvar char-set:hex-digit
2193The hexadecimal digits @code{0123456789abcdefABCDEF}.
2194@end defvar
2195
2196@defvar char-set:ascii
2197All ASCII characters.
2198@end defvar
2199
2200@defvar char-set:empty
2201The empty character set.
2202@end defvar
2203
2204@defvar char-set:full
2205This character set contains all possible characters.
2206@end defvar
2207
2208@node SRFI-16
2209@section SRFI-16 - case-lambda
8742c48b 2210@cindex SRFI-16
a0e07ba4
NJ
2211
2212@c FIXME::martin: Review me!
2213
8742c48b 2214@findex case-lambda
a0e07ba4
NJ
2215The syntactic form @code{case-lambda} creates procedures, just like
2216@code{lambda}, but has syntactic extensions for writing procedures of
2217varying arity easier.
2218
2219The syntax of the @code{case-lambda} form is defined in the following
2220EBNF grammar.
2221
2222@example
2223@group
2224<case-lambda>
2225 --> (case-lambda <case-lambda-clause>)
2226<case-lambda-clause>
2227 --> (<formals> <definition-or-command>*)
2228<formals>
2229 --> (<identifier>*)
2230 | (<identifier>* . <identifier>)
2231 | <identifier>
2232@end group
2233@end example
2234
2235The value returned by a @code{case-lambda} form is a procedure which
2236matches the number of actual arguments against the formals in the
2237various clauses, in order. @dfn{Formals} means a formal argument list
2238just like with @code{lambda} (@pxref{Lambda}). The first matching clause
2239is selected, the corresponding values from the actual parameter list are
2240bound to the variable names in the clauses and the body of the clause is
2241evaluated. If no clause matches, an error is signalled.
2242
2243The following (silly) definition creates a procedure @var{foo} which
2244acts differently, depending on the number of actual arguments. If one
2245argument is given, the constant @code{#t} is returned, two arguments are
2246added and if more arguments are passed, their product is calculated.
2247
2248@lisp
2249(define foo (case-lambda
2250 ((x) #t)
2251 ((x y) (+ x y))
2252 (z
2253 (apply * z))))
2254(foo 'bar)
2255@result{}
2256#t
2257(foo 2 4)
2258@result{}
22596
2260(foo 3 3 3)
2261@result{}
226227
2263(foo)
2264@result{}
22651
2266@end lisp
2267
2268The last expression evaluates to 1 because the last clause is matched,
2269@var{z} is bound to the empty list and the following multiplication,
2270applied to zero arguments, yields 1.
2271
2272
2273@node SRFI-17
2274@section SRFI-17 - Generalized set!
8742c48b 2275@cindex SRFI-17
a0e07ba4
NJ
2276
2277This is an implementation of SRFI-17: Generalized set!
2278
8742c48b 2279@findex getter-with-setter
a0e07ba4
NJ
2280It exports the Guile procedure @code{make-procedure-with-setter} under
2281the SRFI name @code{getter-with-setter} and exports the standard
2282procedures @code{car}, @code{cdr}, @dots{}, @code{cdddr},
2283@code{string-ref} and @code{vector-ref} as procedures with setters, as
2284required by the SRFI.
2285
2286SRFI-17 was heavily criticized during its discussion period but it was
2287finalized anyway. One issue was its concept of globally associating
2288setter @dfn{properties} with (procedure) values, which is non-Schemy.
2289For this reason, this implementation chooses not to provide a way to set
2290the setter of a procedure. In fact, @code{(set! (setter @var{proc})
2291@var{setter})} signals an error. The only way to attach a setter to a
2292procedure is to create a new object (a @dfn{procedure with setter}) via
2293the @code{getter-with-setter} procedure. This procedure is also
2294specified in the SRFI. Using it avoids the described problems.
2295
12991fed
TTN
2296
2297@node SRFI-19
2298@section SRFI-19 - Time/Date Library
8742c48b 2299@cindex SRFI-19
12991fed
TTN
2300
2301This is an implementation of SRFI-19: Time/Date Library
2302
2303It depends on SRFIs: 6 (@pxref{SRFI-6}), 8 (@pxref{SRFI-8}),
23049 (@pxref{SRFI-9}).
2305
2306This section documents constants and procedure signatures.
2307
2308@menu
2309* SRFI-19 Constants::
2310* SRFI-19 Current time and clock resolution::
2311* SRFI-19 Time object and accessors::
2312* SRFI-19 Time comparison procedures::
2313* SRFI-19 Time arithmetic procedures::
2314* SRFI-19 Date object and accessors::
2315* SRFI-19 Time/Date/Julian Day/Modified Julian Day converters::
2316* SRFI-19 Date to string/string to date converters::
2317@end menu
2318
2319@node SRFI-19 Constants
2320@subsection SRFI-19 Constants
2321
2322All these are bound to their symbol names:
2323
2324@example
2325 time-duration
2326 time-monotonic
2327 time-process
2328 time-tai
2329 time-thread
2330 time-utc
2331@end example
2332
2333@node SRFI-19 Current time and clock resolution
2334@subsection SRFI-19 Current time and clock resolution
2335
2336@example
2337 (current-date . tz-offset)
2338 (current-julian-day)
2339 (current-modified-julian-day)
2340 (current-time . clock-type)
2341 (time-resolution . clock-type)
2342@end example
2343
2344@node SRFI-19 Time object and accessors
2345@subsection SRFI-19 Time object and accessors
2346
2347@example
2348 (make-time type nanosecond second)
2349 (time? obj)
2350 (time-type time)
2351 (time-nanosecond time)
2352 (time-second time)
2353 (set-time-type! time type)
2354 (set-time-nanosecond! time nsec)
2355 (set-time-second! time sec)
2356 (copy-time time)
2357@end example
2358
2359@node SRFI-19 Time comparison procedures
2360@subsection SRFI-19 Time comparison procedures
2361
2362Args are all @code{time} values.
2363
2364@example
2365 (time<=? t1 t2)
2366 (time<? t1 t2)
2367 (time=? t1 t2)
2368 (time>=? t1 t2)
2369 (time>? t1 t2)
2370@end example
2371
2372@node SRFI-19 Time arithmetic procedures
2373@subsection SRFI-19 Time arithmetic procedures
2374
2375The @code{foo!} variants modify in place. Time difference
2376is expressed in @code{time-duration} values.
2377
2378@example
2379 (time-difference t1 t2)
2380 (time-difference! t1 t2)
2381 (add-duration time duration)
2382 (add-duration! time duration)
2383 (subtract-duration time duration)
2384 (subtract-duration! time duration)
2385 @end example
2386
2387@node SRFI-19 Date object and accessors
2388@subsection SRFI-19 Date object and accessors
2389
2390@example
2391 (make-date nsecs seconds minutes hours
2392 date month year offset)
2393 (date? obj)
2394 (date-nanosecond date)
2395 (date-second date)
2396 (date-minute date)
2397 (date-hour date)
2398 (date-day date)
2399 (date-month date)
2400 (date-year date)
2401 (date-zone-offset date)
2402 (date-year-day date)
2403 (date-week-day date)
2404 (date-week-number date day-of-week-starting-week)
2405@end example
2406
2407@node SRFI-19 Time/Date/Julian Day/Modified Julian Day converters
2408@subsection SRFI-19 Time/Date/Julian Day/Modified Julian Day converters
2409
2410@example
2411 (date->julian-day date)
2412 (date->modified-julian-day date)
2413 (date->time-monotonic date)
2414 (date->time-tai date)
2415 (date->time-utc date)
2416 (julian-day->date jdn . tz-offset)
2417 (julian-day->time-monotonic jdn)
2418 (julian-day->time-tai jdn)
2419 (julian-day->time-utc jdn)
2420 (modified-julian-day->date jdn . tz-offset)
2421 (modified-julian-day->time-monotonic jdn)
2422 (modified-julian-day->time-tai jdn)
2423 (modified-julian-day->time-utc jdn)
2424 (time-monotonic->date time . tz-offset)
2425 (time-monotonic->time-tai time-in)
2426 (time-monotonic->time-tai! time-in)
2427 (time-monotonic->time-utc time-in)
2428 (time-monotonic->time-utc! time-in)
2429 (time-tai->date time . tz-offset)
2430 (time-tai->julian-day time)
2431 (time-tai->modified-julian-day time)
2432 (time-tai->time-monotonic time-in)
2433 (time-tai->time-monotonic! time-in)
2434 (time-tai->time-utc time-in)
2435 (time-tai->time-utc! time-in)
2436 (time-utc->date time . tz-offset)
2437 (time-utc->julian-day time)
2438 (time-utc->modified-julian-day time)
2439 (time-utc->time-monotonic time-in)
2440 (time-utc->time-monotonic! time-in)
2441 (time-utc->time-tai time-in)
2442 (time-utc->time-tai! time-in)
2443@end example
2444
2445@node SRFI-19 Date to string/string to date converters
2446@subsection SRFI-19 Date to string/string to date converters
2447
2448@example
2449 (date->string date . format-string)
2450 (string->date input-string template-string)
2451@end example
2452
2453@c srfi-modules.texi ends here