Commit | Line | Data |
---|---|---|
a0e07ba4 NJ |
1 | @page |
2 | @node SRFI Support | |
3 | @chapter SRFI Support Modules | |
8742c48b | 4 | @cindex SRFI |
a0e07ba4 NJ |
5 | |
6 | SRFI is an acronym for Scheme Request For Implementation. The SRFI | |
7 | documents define a lot of syntactic and procedure extensions to standard | |
8 | Scheme as defined in R5RS. | |
9 | ||
10 | Guile has support for a number of SRFIs. This chapter gives an overview | |
11 | over the available SRFIs and some usage hints. For complete | |
12 | documentation, design rationales and further examples, we advise you to | |
13 | get 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 | ||
40 | SRFI support in Guile is currently implemented partly in the core | |
41 | library, and partly as add-on modules. That means that some SRFIs are | |
42 | automatically available when the interpreter is started, whereas the | |
43 | other SRFIs require you to use the appropriate support module | |
12991fed | 44 | explicitly. |
a0e07ba4 NJ |
45 | |
46 | There are several reasons for this inconsistency. First, the feature | |
47 | checking syntactic form @code{cond-expand} (@pxref{SRFI-0}) must be | |
48 | available immediately, because it must be there when the user wants to | |
49 | check for the Scheme implementation, that is, before she can know that | |
50 | it is safe to use @code{use-modules} to load SRFI support modules. The | |
51 | second reason is that some features defined in SRFIs had been | |
52 | implemented in Guile before the developers started to add SRFI | |
53 | implementations as modules (for example SRFI-6 (@pxref{SRFI-6})). In | |
54 | the future, it is possible that SRFIs in the core library might be | |
55 | factored out into separate modules, requiring explicit module loading | |
56 | when 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 | |
58 | you want, you can do that already. We have included the module | |
59 | @code{(srfi srfi-6)} in the distribution, which currently does nothing, | |
60 | but ensures that you can write future-safe code. | |
61 | ||
62 | Generally, support for a specific SRFI is made available by using | |
63 | modules named @code{(srfi srfi-@var{number})}, where @var{number} is the | |
64 | number of the SRFI needed. Another possibility is to use the command | |
65 | line option @code{--use-srfi}, which will load the necessary modules | |
66 | automatically (@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 | ||
75 | SRFI-0 defines a means for checking whether a Scheme implementation has | |
76 | support for a specified feature. The syntactic form @code{cond-expand}, | |
77 | which 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 | ||
96 | When evaluated, this form checks all clauses in order, until it finds | |
97 | one whose feature requirement is satisfied. Then the form expands into | |
98 | the commands or definitions in the clause. A requirement is tested as | |
99 | follows: | |
100 | ||
101 | @itemize @bullet | |
102 | @item | |
103 | If it is a symbol, it is satisfied if the feature identifier is | |
104 | supported. | |
105 | ||
106 | @item | |
107 | If it is an @code{and} form, all requirements must be satisfied. If no | |
108 | requirements are given, it is satisfied, too. | |
109 | ||
110 | @item | |
111 | If it is an @code{or} form, at least one of the requirements must be | |
112 | satisfied. If no requirements are given, it is not satisfied. | |
113 | ||
114 | @item | |
115 | If it is a @code{not} form, the feature requirement must @emph{not} be | |
116 | satisfied. | |
117 | ||
118 | @item | |
119 | If the feature requirement is the keyword @code{else} and it is the last | |
120 | clause, it is satisfied if no prior clause matched. | |
121 | @end itemize | |
122 | ||
123 | If no clause is satisfied, an error is signalled. | |
124 | ||
125 | Since @code{cond-expand} is needed to tell what a Scheme implementation | |
126 | provides, it must be accessible without using any | |
85a9b4ed | 127 | implementation-dependent operations, such as @code{use-modules} in |
a0e07ba4 NJ |
128 | Guile. Thus, it is not necessary to use any module to get access to |
129 | this form. | |
130 | ||
131 | Currently, the feature identifiers @code{guile}, @code{r5rs} and | |
132 | @code{srfi-0} are supported. The other SRFIs are not in that list by | |
133 | default, because the SRFI modules must be explicitly used before their | |
12991fed | 134 | exported bindings can be used. |
a0e07ba4 NJ |
135 | |
136 | So if a Scheme program wishes to use SRFI-8, it has two possibilities: | |
137 | First, it can check whether the running Scheme implementation is Guile, | |
138 | and 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 | ||
149 | The other possibility is to use the @code{--use-srfi} command line | |
150 | option when invoking Guile (@pxref{Invoking Guile}). When you do that, | |
151 | the specified SRFI support modules will be loaded and add their feature | |
152 | identifier to the list of symbols checked by @code{cond-expand}. | |
153 | ||
154 | So, if you invoke Guile like this: | |
155 | ||
156 | @example | |
157 | $ guile --use-srfi=8 | |
158 | @end example | |
159 | ||
160 | the 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 | ||
173 | The list library defined in SRFI-1 contains a lot of useful list | |
174 | processing procedures for construction, examining, destructuring and | |
175 | manipulating lists and pairs. | |
176 | ||
177 | Since SRFI-1 also defines some procedures which are already contained | |
178 | in R5RS and thus are supported by the Guile core library, some list | |
179 | and pair procedures which appear in the SRFI-1 document may not appear | |
180 | in this section. So when looking for a particular list/pair | |
181 | processing 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 | ||
202 | New lists can be constructed by calling one of the following | |
203 | procedures. | |
204 | ||
8f85c0c6 | 205 | @deffn {Scheme Procedure} xcons d a |
a0e07ba4 NJ |
206 | Like @code{cons}, but with interchanged arguments. Useful mostly when |
207 | passed to higher-order procedures. | |
208 | @end deffn | |
209 | ||
8f85c0c6 | 210 | @deffn {Scheme Procedure} list-tabulate n init-proc |
a0e07ba4 NJ |
211 | Return an @var{n}-element list, where each list element is produced by |
212 | applying the procedure @var{init-proc} to the corresponding list | |
213 | index. The order in which @var{init-proc} is applied to the indices | |
214 | is not specified. | |
215 | @end deffn | |
216 | ||
8f85c0c6 | 217 | @deffn {Scheme Procedure} circular-list elt1 elt2 @dots{} |
a0e07ba4 NJ |
218 | Return 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 |
223 | Return a list containing @var{count} elements, where each element is |
224 | calculated 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 | ||
237 | The procedures in this section test specific properties of lists. | |
238 | ||
8f85c0c6 | 239 | @deffn {Scheme Procedure} proper-list? obj |
a0e07ba4 NJ |
240 | Return @code{#t} if @var{obj} is a proper list, that is a finite list, |
241 | terminated with the empty list. Otherwise, return @code{#f}. | |
242 | @end deffn | |
243 | ||
8f85c0c6 | 244 | @deffn {Scheme Procedure} circular-list? obj |
a0e07ba4 NJ |
245 | Return @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 |
250 | Return @code{#t} if @var{obj} is a dotted list, return @code{#f} |
251 | otherwise. A dotted list is a finite list which is not terminated by | |
252 | the empty list, but some other value. | |
253 | @end deffn | |
254 | ||
8f85c0c6 | 255 | @deffn {Scheme Procedure} null-list? lst |
a0e07ba4 NJ |
256 | Return @code{#t} if @var{lst} is the empty list @code{()}, @code{#f} |
257 | otherwise. If something else than a proper or circular list is passed | |
85a9b4ed | 258 | as @var{lst}, an error is signalled. This procedure is recommended |
a0e07ba4 NJ |
259 | for checking for the end of a list in contexts where dotted lists are |
260 | not allowed. | |
261 | @end deffn | |
262 | ||
8f85c0c6 | 263 | @deffn {Scheme Procedure} not-pair? obj |
a0e07ba4 NJ |
264 | Return @code{#t} is @var{obj} is not a pair, @code{#f} otherwise. |
265 | This is shorthand notation @code{(not (pair? @var{obj}))} and is | |
266 | supposed to be used for end-of-list checking in contexts where dotted | |
267 | lists are allowed. | |
268 | @end deffn | |
269 | ||
8f85c0c6 | 270 | @deffn {Scheme Procedure} list= elt= list1 @dots{} |
a0e07ba4 NJ |
271 | Return @code{#t} if all argument lists are equal, @code{#f} otherwise. |
272 | List equality is determined by testing whether all lists have the same | |
273 | length and the corresponding elements are equal in the sense of the | |
274 | equality 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 |
294 | These are synonyms for @code{car}, @code{cadr}, @code{caddr}, @dots{}. |
295 | @end deffn | |
296 | ||
8f85c0c6 | 297 | @deffn {Scheme Procedure} car+cdr pair |
a0e07ba4 NJ |
298 | Return 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 |
303 | Return 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} | |
306 | in order to produce the result. | |
307 | @end deffn | |
308 | ||
8f85c0c6 | 309 | @deffn {Scheme Procedure} drop lst i |
a0e07ba4 NJ |
310 | Return 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 |
315 | Return 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 |
320 | Return 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 |
329 | Return two values, a list containing the first @var{i} elements of the |
330 | list @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 |
337 | Return 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 |
347 | Return the length of the argument list @var{lst}. When @var{lst} is a |
348 | circular 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 |
353 | Construct a list by appending all lists in @var{list-of-lists}. |
354 | ||
355 | @code{concatenate!} may modify the structure of the given lists in | |
356 | order 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 |
361 | Reverse @var{rev-head}, append @var{tail} and return the result. This |
362 | is equivalent to @code{(append (reverse @var{rev-head}) @var{tail})}, | |
363 | but more efficient. | |
364 | ||
365 | @code{append-reverse!} may modify @var{rev-head} in order to produce | |
366 | the result. | |
367 | @end deffn | |
368 | ||
8f85c0c6 | 369 | @deffn {Scheme Procedure} zip lst1 lst2 @dots{} |
a0e07ba4 NJ |
370 | Return a list as long as the shortest of the argument lists, where |
371 | each element is a list. The first list contains the first elements of | |
372 | the argument lists, the second list contains the second elements, and | |
373 | so 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 |
382 | first elements of each list, @code{unzip2} returns two lists, the | |
383 | first containing the first elements of each lists and the second | |
384 | containing the second elements of each lists, and so on. | |
385 | @end deffn | |
386 | ||
e508c863 KR |
387 | @deffn {Scheme Procedure} count pred lst1 @dots{} lstN |
388 | Return a count of the number of times @var{pred} returns true when | |
389 | called 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 | |
393 | corresponding @var{lst1} @dots{} @var{lstN}. The first call is with | |
394 | the first element of each list, the second with the second element | |
395 | from each, and so on. | |
396 | ||
397 | Counting stops when the end of the shortest list is reached. At least | |
398 | one 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 |
408 | Fold 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 | ||
414 | if @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 |
419 | Similar to @code{fold}, but applies @var{kons} in right-to-left order |
420 | to 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 |
427 | Like @code{fold}, but apply @var{kons} to the pairs of the list |
428 | instead of the list elements. | |
429 | @end deffn | |
430 | ||
8f85c0c6 | 431 | @deffn {Scheme Procedure} pair-fold-right kons knil lst1 lst2 @dots{} |
a0e07ba4 NJ |
432 | Like @code{fold-right}, but apply @var{kons} to the pairs of the list |
433 | instead 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 | 443 | This 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 | |
458 | Determines when to stop unfolding. | |
459 | ||
460 | @item f | |
461 | Maps each seed value to the corresponding list element. | |
462 | ||
463 | @item g | |
464 | Maps each seed value to next seed valu. | |
465 | ||
466 | @item seed | |
467 | The state value for the unfold. | |
468 | ||
469 | @item tail-gen | |
470 | Creates 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 | |
474 | elements by @var{f}. These elements are put into a list in | |
475 | left-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 |
479 | Construct 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 | |
490 | Determines when to stop unfolding. | |
491 | ||
492 | @item f | |
493 | Maps each seed value to the corresponding list element. | |
494 | ||
495 | @item g | |
496 | Maps each seed value to next seed valu. | |
497 | ||
498 | @item seed | |
499 | The state value for the unfold. | |
500 | ||
501 | @item tail-gen | |
502 | Creates 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 |
508 | Map the procedure over the list(s) @var{lst1}, @var{lst2}, @dots{} and |
509 | return a list containing the results of the procedure applications. | |
510 | This procedure is extended with respect to R5RS, because the argument | |
511 | lists may have different lengths. The result list will have the same | |
512 | length as the shortest argument lists. The order in which @var{f} | |
513 | will 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 |
517 | Apply the procedure @var{f} to each pair of corresponding elements of |
518 | the list(s) @var{lst1}, @var{lst2}, @dots{}. The return value is not | |
519 | specified. This procedure is extended with respect to R5RS, because | |
520 | the argument lists may have different lengths. The shortest argument | |
521 | list determines the number of times @var{f} is called. @var{f} will | |
85a9b4ed | 522 | be 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 | 528 | Equivalent to |
a0e07ba4 NJ |
529 | |
530 | @lisp | |
12991fed | 531 | (apply append (map f clist1 clist2 ...)) |
a0e07ba4 NJ |
532 | @end lisp |
533 | ||
12991fed | 534 | and |
a0e07ba4 NJ |
535 | |
536 | @lisp | |
12991fed | 537 | (apply append! (map f clist1 clist2 ...)) |
a0e07ba4 NJ |
538 | @end lisp |
539 | ||
540 | Map @var{f} over the elements of the lists, just as in the @code{map} | |
541 | function. However, the results of the applications are appended | |
542 | together 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 | ||
546 | The dynamic order in which the various applications of @var{f} are | |
547 | made is not specified. | |
548 | @end deffn | |
549 | ||
8f85c0c6 | 550 | @deffn {Scheme Procedure} map! f lst1 lst2 @dots{} |
a0e07ba4 NJ |
551 | Linear-update variant of @code{map} -- @code{map!} is allowed, but not |
552 | required, to alter the cons cells of @var{lst1} to construct the | |
553 | result list. | |
554 | ||
555 | The dynamic order in which the various applications of @var{f} are | |
556 | made 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 |
561 | Like @code{for-each}, but applies the procedure @var{f} to the pairs |
562 | from which the argument lists are constructed, instead of the list | |
563 | elements. The return value is not specified. | |
564 | @end deffn | |
565 | ||
8f85c0c6 | 566 | @deffn {Scheme Procedure} filter-map f lst1 lst2 @dots{} |
a0e07ba4 NJ |
567 | Like @code{map}, but only results from the applications of @var{f} |
568 | which 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 | ||
577 | Filtering means to collect all elements from a list which satisfy a | |
578 | specific condition. Partitioning a list means to make two groups of | |
579 | list elements, one which contains the elements satisfying a condition, | |
580 | and 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 |
584 | Return a list containing all elements from @var{lst} which satisfy the |
585 | predicate @var{pred}. The elements in the result list have the same | |
586 | order as in @var{lst}. The order in which @var{pred} is applied to | |
587 | the 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 |
594 | Return two lists, one containing all elements from @var{lst} which |
595 | satisfy the predicate @var{pred}, and one list containing the elements | |
596 | which do not satisfy the predicated. The elements in the result lists | |
597 | have the same order as in @var{lst}. The order in which @var{pred} is | |
598 | applied to the list elements is not specified. | |
599 | ||
600 | @code{partition!} is allowed, but not required to modify the structure of | |
601 | the input list. | |
602 | @end deffn | |
603 | ||
8f85c0c6 NJ |
604 | @deffn {Scheme Procedure} remove pred lst |
605 | @deffnx {Scheme Procedure} remove! pred lst | |
a0e07ba4 NJ |
606 | Return a list containing all elements from @var{lst} which do not |
607 | satisfy the predicate @var{pred}. The elements in the result list | |
608 | have the same order as in @var{lst}. The order in which @var{pred} is | |
609 | applied to the list elements is not specified. | |
610 | ||
611 | @code{remove!} is allowed, but not required to modify the structure of | |
612 | the input list. | |
613 | @end deffn | |
614 | ||
615 | ||
616 | @node SRFI-1 Searching | |
617 | @subsection Searching | |
618 | ||
619 | @c FIXME::martin: Review me! | |
620 | ||
621 | The procedures for searching elements in lists either accept a | |
622 | predicate or a comparison object for determining which elements are to | |
623 | be searched. | |
624 | ||
8f85c0c6 | 625 | @deffn {Scheme Procedure} find pred lst |
a0e07ba4 NJ |
626 | Return 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 |
631 | Return the first pair of @var{lst} whose @sc{car} satisfies the |
632 | predicate @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 |
637 | Return the longest initial prefix of @var{lst} whose elements all |
638 | satisfy the predicate @var{pred}. | |
639 | ||
640 | @code{take-while!} is allowed, but not required to modify the input | |
641 | list while producing the result. | |
642 | @end deffn | |
643 | ||
8f85c0c6 | 644 | @deffn {Scheme Procedure} drop-while pred lst |
a0e07ba4 NJ |
645 | Drop the longest initial prefix of @var{lst} whose elements all |
646 | satisfy 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 |
654 | whose elements all satisfy the predicate @var{pred}, and the remaining | |
655 | tail. @code{break} inverts the sense of the predicate. | |
656 | ||
657 | @code{span!} and @code{break!} are allowed, but not required to modify | |
658 | the structure of the input list @var{lst} in order to produce the | |
659 | result. | |
660 | @end deffn | |
661 | ||
8f85c0c6 | 662 | @deffn {Scheme Procedure} any pred lst1 lst2 @dots{} |
a0e07ba4 NJ |
663 | Apply @var{pred} across the lists and return a true value if the |
664 | predicate returns true for any of the list elements(s); return | |
665 | @code{#f} otherwise. The true value returned is always the result of | |
85a9b4ed | 666 | the first successful application of @var{pred}. |
a0e07ba4 NJ |
667 | @end deffn |
668 | ||
8f85c0c6 | 669 | @deffn {Scheme Procedure} every pred lst1 lst2 @dots{} |
a0e07ba4 NJ |
670 | Apply @var{pred} across the lists and return a true value if the |
671 | predicate returns true for every of the list elements(s); return | |
672 | @code{#f} otherwise. The true value returned is always the result of | |
85a9b4ed | 673 | the 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 |
677 | Return the index of the leftmost element that satisfies @var{pred}. |
678 | @end deffn | |
679 | ||
8f85c0c6 | 680 | @deffn {Scheme Procedure} member x lst [=] |
a0e07ba4 NJ |
681 | Return 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}. | |
683 | Equality 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 |
695 | Return a list containing the elements of @var{lst} but with those |
696 | equal to @var{x} deleted. The returned elements will be in the same | |
697 | order as they were in @var{lst}. | |
698 | ||
699 | Equality is determined by the @var{=} predicate, or @code{equal?} if | |
700 | not given. An equality call is made just once for each element, but | |
701 | the order in which the calls are made on the elements is unspecified. | |
a0e07ba4 | 702 | |
b6b9376a KR |
703 | The equality calls are always @code{(= x elem)}, ie. the given @var{x} |
704 | is first. This means for instance elements greater than 5 can be | |
705 | deleted with @code{(delete 5 lst <)}. | |
706 | ||
707 | @code{delete} does not modify @var{lst}, but the return might share a | |
708 | common tail with @var{lst}. @code{delete!} may modify the structure | |
709 | of @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 |
714 | Return a list containing the elements of @var{lst} but without |
715 | duplicates. | |
716 | ||
717 | When elements are equal, only the first in @var{lst} is retained. | |
718 | Equal elements can be anywhere in @var{lst}, they don't have to be | |
719 | adjacent. The returned list will have the retained elements in the | |
720 | same order as they were in @var{lst}. | |
721 | ||
722 | Equality is determined by the @var{=} predicate, or @code{equal?} if | |
723 | not given. Calls @code{(= x y)} are made with element @var{x} being | |
724 | before @var{y} in @var{lst}. A call is made at most once for each | |
725 | combination, but the sequence of the calls across the elements is | |
726 | unspecified. | |
727 | ||
728 | @code{delete-duplicates} does not modify @var{lst}, but the return | |
729 | might share a common tail with @var{lst}. @code{delete-duplicates!} | |
730 | may modify the structure of @var{lst} to construct its return. | |
731 | ||
732 | In the worst case, this is an @math{O(N^2)} algorithm because it must | |
733 | check each element against all those preceding it. For long lists it | |
734 | is 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 | ||
743 | Association lists are described in detail in section @ref{Association | |
744 | Lists}. The present section only documents the additional procedures | |
745 | for dealing with association lists defined by SRFI-1. | |
746 | ||
8f85c0c6 | 747 | @deffn {Scheme Procedure} assoc key alist [=] |
a0e07ba4 NJ |
748 | Return the pair from @var{alist} which matches @var{key}. Equality is |
749 | determined 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 |
754 | Equivalent to |
755 | ||
756 | @lisp | |
757 | (cons (cons @var{key} @var{datum}) @var{alist}) | |
758 | @end lisp | |
759 | ||
760 | This procedure is used to coons a new pair onto an existing | |
761 | association list. | |
762 | @end deffn | |
763 | ||
8f85c0c6 | 764 | @deffn {Scheme Procedure} alist-copy alist |
a0e07ba4 NJ |
765 | Return a newly allocated copy of @var{alist}, that means that the |
766 | spine 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 |
771 | Return a list containing the pairs of @var{alist}, but without the |
772 | pairs whose @sc{cars} are equal to @var{key}. Equality is determined | |
773 | by @var{=}, which defaults to @code{equal?} if not given. | |
774 | ||
775 | @code{alist-delete!} is allowed, but not required to modify the | |
776 | structure 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 | ||
785 | Lists can be used for representing sets of objects. The procedures | |
786 | documented in this section can be used for such set representations. | |
85a9b4ed | 787 | Man combining several sets or adding elements, they make sure that no |
a0e07ba4 NJ |
788 | object is contained more than once in a given list. Please note that |
789 | lists are not a too efficient implementation method for sets, so if | |
790 | you need high performance, you should think about implementing a | |
791 | custom data structure for representing sets, such as trees, bitsets, | |
792 | hash tables or something similar. | |
793 | ||
794 | All these procedures accept an equality predicate as the first | |
795 | argument. This predicate is used for testing the objects in the list | |
796 | sets for sameness. | |
797 | ||
8f85c0c6 | 798 | @deffn {Scheme Procedure} lset<= = list1 @dots{} |
a0e07ba4 NJ |
799 | Return @code{#t} if every @var{listi} is a subset of @var{listi+1}, |
800 | otherwise return @code{#f}. Returns @code{#t} if called with less | |
801 | than two arguments. @var{=} is used for testing element equality. | |
802 | @end deffn | |
803 | ||
8f85c0c6 | 804 | @deffn {Scheme Procedure} lset= = list1 list2 @dots{} |
a0e07ba4 NJ |
805 | Return @code{#t} if all argument lists are equal. @var{=} is used for |
806 | testing 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 |
811 | Add all @var{elts} to the list @var{list}, suppressing duplicates and |
812 | return the resulting list. @code{lset-adjoin!} is allowed, but not | |
813 | required to modify its first argument. @var{=} is used for testing | |
814 | element 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 |
819 | Return the union of all argument list sets. The union is the set of |
820 | all elements which appear in any of the argument sets. | |
821 | @code{lset-union!} is allowed, but not required to modify its first | |
822 | argument. @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 |
827 | Return the intersection of all argument list sets. The intersection |
828 | is the set containing all elements which appear in all argument sets. | |
829 | @code{lset-intersection!} is allowed, but not required to modify its | |
830 | first 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 |
835 | Return the difference of all argument list sets. The difference is |
836 | the the set containing all elements of the first list which do not | |
837 | appear in the other lists. @code{lset-difference!} is allowed, but | |
838 | not required to modify its first argument. @var{=} is used for testing | |
839 | element 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 |
844 | Return the set containing all elements which appear in the first |
845 | argument list set, but not in the second; or, more generally: which | |
846 | appear in an odd number of sets. @code{lset-xor!} is allowed, but | |
847 | not required to modify its first argument. @var{=} is used for testing | |
848 | element 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 |
853 | Return two values, the difference and the intersection of the argument |
854 | list 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 | |
857 | its first argument. @var{=} is used for testing element equality. You | |
858 | have to use some means to deal with the multiple values these | |
859 | procedures 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 |
870 | The syntactic form @code{and-let*} combines the conditional evaluation |
871 | form @code{and} with the binding form @var{let*}. Each argument | |
872 | expression will be evaluated sequentially, bound to a variable (if a | |
873 | variable name is given), but only as long as no expression returns | |
874 | the false value @code{#f}. | |
875 | ||
876 | Use @code{(use-modules (srfi srfi-2)} to access this syntax form. | |
877 | ||
878 | A 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 | |
880 | false, so evaluation of the form is stopped, and @code{#f} is returned. | |
881 | In 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 | |
883 | body of the @code{and-let*} expression is evaluated, which in this case | |
884 | returns 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{} |
892 | 1 | |
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 | ||
902 | SRFI-4 defines a set of datatypes for vectors whose elements are all | |
903 | of the same numeric type. Vectors for signed and unsigned exact | |
904 | integer or inexact real numbers in several precisions are available. | |
905 | ||
906 | Procedures similar to the vector procedures (@pxref{Vectors}) are | |
907 | provided for handling these homogeneous vectors, but they are distinct | |
908 | datatypes. | |
909 | ||
910 | The reason for providing this set of datatypes is that with the | |
911 | limitation (all elements must have the same type), it is possible to | |
912 | implement them much more memory-efficient than normal, heterogenous | |
913 | vectors. | |
914 | ||
915 | If you want to use these datatypes and the corresponding procedures, | |
916 | you have to use the module @code{(srfi srfi-4)}. | |
917 | ||
918 | Ten vector data types are provided: Unsigned and signed integer values | |
919 | with 8, 16, 32 and 64 bits and floating point values with 32 and 64 | |
920 | bits. 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 | |
923 | denoting 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 | ||
934 | Homogeneous numeric vectors have an external representation (read | |
935 | syntax) similar to normal Scheme vectors, but with an additional tag | |
936 | telling the vector's type. | |
937 | ||
938 | @lisp | |
939 | #u16(1 2 3) | |
940 | @end lisp | |
941 | ||
942 | denotes a homogeneous numeric vector of three elements, which are the | |
943 | values 1, 2 and 3, represented as 16-bit unsigned integers. | |
944 | Correspondingly, | |
945 | ||
946 | @lisp | |
947 | #f64(3.1415 2.71) | |
948 | @end lisp | |
949 | ||
950 | denotes a vector of two elements, which are the values 3.1415 and | |
951 | 2.71, represented as floating-point values of 64 bit precision. | |
952 | ||
953 | Please note that the read syntax for floating-point vectors conflicts | |
954 | with Standard Scheme, because there @code{#f} is defined to be the | |
955 | literal false value. That means, that with the loaded SRFI-4 module, | |
956 | it is not possible to enter some list like | |
957 | ||
958 | @lisp | |
959 | '(1 #f3) | |
960 | @end lisp | |
961 | ||
962 | and hope that it will be parsed as a three-element list with the | |
963 | elements 1, @code{#f} and 3. In normal use, this should be no | |
964 | problem, because people tend to terminate tokens sensibly when writing | |
965 | Scheme expressions. | |
966 | ||
967 | @node SRFI-4 - Procedures | |
968 | @subsection SRFI-4 Procedures | |
969 | ||
970 | The procedures listed in this section are provided for all homogeneous | |
971 | numeric vector datatypes. For brevity, they are not all documented, | |
972 | but a summary of the procedures is given. In the following | |
973 | descriptions, you can replace @code{TAG} by any of the datatype | |
974 | indicators @code{u8}, @code{s8}, @code{u16}, @code{s16}, @code{u32}, | |
975 | @code{s32}, @code{u64}, @code{s64}, @code{f32} and @code{f64}. | |
976 | ||
977 | For 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 |
982 | Return @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 |
987 | Create a newly allocated homogeneous numeric vector of type |
988 | @code{TAG}, which can hold @var{n} elements. If @var{value} is given, | |
989 | the vector is initialized with the value, otherwise, the contents of | |
990 | the returned vector is not specified. | |
991 | @end deffn | |
992 | ||
8f85c0c6 | 993 | @deffn {Scheme Procedure} TAGvector value1 @dots{} |
a0e07ba4 NJ |
994 | Create a newly allocated homogeneous numeric vector of type |
995 | @code{TAG}. The returned vector is as long as the number of arguments | |
996 | given, and is initialized with the argument values. | |
997 | @end deffn | |
998 | ||
8f85c0c6 | 999 | @deffn {Scheme Procedure} TAGvector-length TAGvec |
a0e07ba4 NJ |
1000 | Return the number of elements in @var{TAGvec}. |
1001 | @end deffn | |
1002 | ||
8f85c0c6 | 1003 | @deffn {Scheme Procedure} TAGvector-ref TAGvec i |
a0e07ba4 NJ |
1004 | Return 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 |
1008 | Set the element at index @var{i} in @var{TAGvec} to @var{value}. The |
1009 | return value is not specified. | |
1010 | @end deffn | |
1011 | ||
8f85c0c6 | 1012 | @deffn {Scheme Procedure} TAGvector->list TAGvec |
a0e07ba4 NJ |
1013 | Return a newly allocated list holding all elements of @var{TAGvec}. |
1014 | @end deffn | |
1015 | ||
8f85c0c6 | 1016 | @deffn {Scheme Procedure} list->TAGvector lst |
a0e07ba4 NJ |
1017 | Return a newly allocated homogeneous numeric vector of type @code{TAG}, |
1018 | initialized 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 | |
1026 | SRFI-6 defines the procedures @code{open-input-string}, | |
1027 | @code{open-output-string} and @code{get-output-string}. These | |
1028 | procedures are included in the Guile core, so using this module does not | |
1029 | make any difference at the moment. But it is possible that support for | |
1030 | SRFI-6 will be factored out of the core library in the future, so using | |
1031 | this 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 | |
1038 | procedures 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 | |
1045 | This is the SRFI way for defining record types. The Guile | |
1046 | implementation is a layer above Guile's normal record construction | |
1047 | procedures (@pxref{Records}). The nice thing about this kind of record | |
1048 | definition method is that no new names are implicitly created, all | |
1049 | constructor, accessor and predicates are explicitly given. This reduces | |
1050 | the risk of variable capture. | |
1051 | ||
1052 | The 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 | ||
1068 | Usage example: | |
1069 | ||
1070 | @example | |
1071 | guile> (use-modules (srfi srfi-9)) | |
12991fed | 1072 | guile> (define-record-type :foo (make-foo x) foo? |
a0e07ba4 NJ |
1073 | (x get-x) (y get-y set-y!)) |
1074 | guile> (define f (make-foo 1)) | |
1075 | guile> f | |
1076 | #<:foo x: 1 y: #f> | |
1077 | guile> (get-x f) | |
1078 | 1 | |
1079 | guile> (set-y! f 2) | |
1080 | 2 | |
1081 | guile> (get-y f) | |
1082 | 2 | |
1083 | guile> f | |
1084 | #<:foo x: 1 y: 2> | |
1085 | guile> (foo? f) | |
1086 | #t | |
1087 | guile> (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 #,() | |
1098 | The module @code{(srfi srfi-10)} implements the syntax extension | |
1099 | @code{#,()}, also called hash-comma, which is defined in SRFI-10. | |
1100 | ||
1101 | The support for SRFI-10 consists of the procedure | |
1102 | @code{define-reader-ctor} for defining new reader constructors and the | |
1103 | read syntax form | |
1104 | ||
1105 | @example | |
1106 | #,(@var{ctor} @var{datum} ...) | |
1107 | @end example | |
1108 | ||
1109 | where @var{ctor} must be a symbol for which a read constructor was | |
85a9b4ed | 1110 | defined previously, using @code{define-reader-ctor}. |
a0e07ba4 NJ |
1111 | |
1112 | Example: | |
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 | ||
1123 | Please note the quote before the @code{#,(file ...)} expression. This | |
1124 | is necessary because ports are not self-evaluating in Guile. | |
1125 | ||
8f85c0c6 | 1126 | @deffn {Scheme Procedure} define-reader-ctor symbol proc |
a0e07ba4 NJ |
1127 | Define @var{proc} as the reader constructor for hash-comma forms with a |
1128 | tag @var{symbol}. @var{proc} will be applied to the datum(s) following | |
1129 | the tag in the hash-comma expression after the complete form has been | |
1130 | read 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 |
1140 | This 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 | |
1143 | binding of the values returned by multiple-valued expressions. | |
1144 | ||
1145 | Write @code{(use-modules (srfi srfi-11))} to make the bindings | |
1146 | available. | |
1147 | ||
1148 | @lisp | |
1149 | (let-values (((x y) (values 1 2)) | |
1150 | ((z f) (values 3 4))) | |
1151 | (+ x y z f)) | |
1152 | @result{} | |
1153 | 10 | |
1154 | @end lisp | |
1155 | ||
1156 | @code{let-values} performs all bindings simultaneously, which means that | |
1157 | no expression in the binding clauses may refer to variables bound in the | |
1158 | same clause list. @code{let-values*}, on the other hand, performs the | |
1159 | bindings sequentially, just like @code{let*} does for single-valued | |
1160 | expressions. | |
1161 | ||
1162 | ||
1163 | @node SRFI-13 | |
1164 | @section SRFI-13 - String Library | |
8742c48b | 1165 | @cindex SRFI-13 |
a0e07ba4 NJ |
1166 | |
1167 | In this section, we will describe all procedures defined in SRFI-13 | |
1168 | (string library) and implemented by the module @code{(srfi srfi-13)}. | |
1169 | ||
1170 | Note that only the procedures from SRFI-13 are documented here which are | |
1171 | not already contained in Guile. For procedures not documented here | |
1172 | please refer to the relevant chapters in the Guile Reference Manual, for | |
1173 | example the documentation of strings and string procedures | |
1174 | (@pxref{Strings}). | |
1175 | ||
40f316d0 MG |
1176 | All of the procedures defined in SRFI-13, which are not already |
1177 | included in the Guile core library, are implemented in the module | |
1178 | @code{(srfi srfi-13)}. The procedures which are both in Guile and in | |
1179 | SRFI-13 are slightly extended in this module. Their bindings | |
1180 | overwrite those in the Guile core. | |
a0e07ba4 NJ |
1181 | |
1182 | The procedures which are defined in the section @emph{Low-level | |
1183 | procedures} of SRFI-13 for parsing optional string indices, substring | |
1184 | specification checking and Knuth-Morris-Pratt-Searching are not | |
1185 | implemented. | |
1186 | ||
1187 | The procedures @code{string-contains} and @code{string-contains-ci} are | |
1188 | not implemented very efficiently at the moment. This will be changed as | |
1189 | soon 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 | ||
1213 | When Guile is properly installed, SRFI-13 support can be loaded into a | |
1214 | running Guile by using the @code{(srfi srfi-13)} module. | |
1215 | ||
1216 | @example | |
1217 | $ guile | |
1218 | guile> (use-modules (srfi srfi-13)) | |
1219 | guile> | |
1220 | @end example | |
1221 | ||
1222 | When this step causes any errors, Guile is not properly installed. | |
1223 | ||
1224 | One possible reason is that Guile cannot find either the Scheme module | |
1225 | file @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 | |
1227 | Guile load path and that the latter is either installed in some default | |
1228 | location like @file{/usr/local/lib} or that the directory it was | |
1229 | installed to is in your @code{LTDL_LIBRARY_PATH}. The same applies to | |
1230 | @file{srfi-14.scm}. | |
1231 | ||
1232 | Now you can test whether the SRFI-13 procedures are working by calling | |
1233 | the @code{string-concatenate} procedure. | |
1234 | ||
1235 | @example | |
1236 | guile> (string-concatenate '("Hello" " " "World!")) | |
1237 | "Hello World!" | |
1238 | @end example | |
1239 | ||
1240 | @node SRFI-13 Predicates | |
12991fed | 1241 | @subsection Predicates |
a0e07ba4 NJ |
1242 | |
1243 | In addition to the primitives @code{string?} and @code{string-null?}, | |
1244 | which 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 |
1248 | Check if the predicate @var{pred} is true for any character in |
1249 | the string @var{s}, proceeding from left (index @var{start}) to | |
1250 | right (index @var{end}). If @code{string-any} returns true, | |
1251 | the returned true value is the one produced by the first | |
1252 | successful application of @var{pred}. | |
1253 | @end deffn | |
1254 | ||
8f85c0c6 | 1255 | @deffn {Scheme Procedure} string-every pred s [start end] |
a0e07ba4 NJ |
1256 | Check if the predicate @var{pred} is true for every character |
1257 | in the string @var{s}, proceeding from left (index @var{start}) | |
1258 | to right (index @var{end}). If @code{string-every} returns | |
1259 | true, the returned true value is the one produced by the final | |
1260 | application 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 | ||
1269 | SRFI-13 defines several procedures for constructing new strings. In | |
1270 | addition to @code{make-string} and @code{string} (available in the Guile | |
1271 | core 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 |
1275 | of size @var{len} by applying @var{proc} to each index to | |
1276 | produce 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 | ||
1286 | The procedure @code{string->list} is extended by SRFI-13, that is why it | |
1287 | is included in @code{(srfi srfi-13)}. The other procedures are new. | |
1288 | The Guile core already contains the procedure @code{list->string} for | |
1289 | converting a list of characters into a string (@pxref{List/String | |
1290 | Conversion}). | |
1291 | ||
8f85c0c6 | 1292 | @deffn {Scheme Procedure} string->list str [start end] |
a0e07ba4 NJ |
1293 | Convert the string @var{str} into a list of characters. |
1294 | @end deffn | |
1295 | ||
8f85c0c6 | 1296 | @deffn {Scheme Procedure} reverse-list->string chrs |
a0e07ba4 NJ |
1297 | An efficient implementation of @code{(compose string->list |
1298 | reverse)}: | |
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 |
1306 | Append 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 | |
1309 | placed between the strings, and defaults to the symbol | |
1310 | @code{infix}. | |
1311 | ||
1312 | @table @code | |
1313 | @item infix | |
1314 | Insert the separator between list elements. An empty string | |
1315 | will produce an empty list. | |
1316 | ||
1317 | @item string-infix | |
1318 | Like @code{infix}, but will raise an error if given the empty | |
1319 | list. | |
1320 | ||
1321 | @item suffix | |
1322 | Insert the separator after every list element. | |
1323 | ||
1324 | @item prefix | |
1325 | Insert 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 | ||
1335 | These procedures are called @dfn{selectors}, because they access | |
1336 | information about the string or select pieces of a given string. | |
1337 | ||
1338 | Additional 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 | |
1343 | accepts additional start/end indices. | |
1344 | ||
8f85c0c6 | 1345 | @deffn {Scheme Procedure} string-copy str [start end] |
a0e07ba4 NJ |
1346 | Return a freshly allocated copy of the string @var{str}. If |
1347 | given, @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 |
1352 | Like @code{substring}, but the result may share memory with the |
1353 | argument @var{str}. | |
1354 | @end deffn | |
1355 | ||
8f85c0c6 | 1356 | @deffn {Scheme Procedure} string-copy! target tstart s [start end] |
a0e07ba4 NJ |
1357 | Copy the sequence of characters from index range [@var{start}, |
1358 | @var{end}) in string @var{s} to string @var{target}, beginning | |
1359 | at index @var{tstart}. The characters are copied left-to-right | |
1360 | or right-to-left as needed - the copy is guaranteed to work, | |
1361 | even if @var{target} and @var{s} are the same string. It is an | |
1362 | error if the copy operation runs off the end of the target | |
1363 | string. | |
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 |
1368 | Return 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 |
1373 | Return 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 |
1378 | Take that characters from @var{start} to @var{end} from the |
1379 | string @var{s} and return a new string, right(left)-padded by the | |
1380 | character @var{chr} to length @var{len}. If the resulting | |
1381 | string 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 |
1387 | Trim @var{s} by skipping over all characters on the left/right/both |
1388 | sides of the string that satisfy the parameter @var{char_pred}: | |
1389 | ||
1390 | @itemize @bullet | |
1391 | @item | |
1392 | if it is the character @var{ch}, characters equal to | |
1393 | @var{ch} are trimmed, | |
1394 | ||
1395 | @item | |
1396 | if it is a procedure @var{pred} characters that | |
1397 | satisfy @var{pred} are trimmed, | |
1398 | ||
1399 | @item | |
1400 | if it is a character set, characters in that set are trimmed. | |
1401 | @end itemize | |
1402 | ||
1403 | If called without a @var{char_pred} argument, all whitespace is | |
1404 | trimmed. | |
1405 | @end deffn | |
1406 | ||
1407 | ||
1408 | @c =================================================================== | |
1409 | ||
1410 | @node SRFI-13 Modification | |
1411 | @subsection Modification | |
1412 | ||
1413 | The procedure @code{string-fill!} is extended from R5RS because it | |
1414 | accepts optional start/end indices. This bindings shadows the procedure | |
1415 | of the same name in the Guile core. The second modification procedure | |
1416 | @code{string-set!} is documented in the Strings section (@pxref{String | |
1417 | Modification}). | |
1418 | ||
8f85c0c6 | 1419 | @deffn {Scheme Procedure} string-fill! str chr [start end] |
a0e07ba4 NJ |
1420 | Stores @var{chr} in every element of the given @var{str} and |
1421 | returns an unspecified value. | |
1422 | @end deffn | |
1423 | ||
1424 | ||
1425 | @c =================================================================== | |
1426 | ||
1427 | @node SRFI-13 Comparison | |
1428 | @subsection Comparison | |
1429 | ||
1430 | The procedures in this section are used for comparing strings in | |
1431 | different ways. The comparison predicates differ from those in R5RS in | |
1432 | that they do not only return @code{#t} or @code{#f}, but the mismatch | |
1433 | index in the case of a true return value. | |
1434 | ||
1435 | @code{string-hash} and @code{string-hash-ci} are for calculating hash | |
1436 | values 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 |
1440 | Apply @var{proc_lt}, @var{proc_eq}, @var{proc_gt} to the |
1441 | mismatch index, depending upon whether @var{s1} is less than, | |
1442 | equal to, or greater than @var{s2}. The mismatch index is the | |
1443 | largest 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 | |
1446 | character 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 |
1455 | Compare @var{s1} and @var{s2} and return @code{#f} if the predicate |
1456 | fails. Otherwise, the mismatch index is returned (or @var{end1} in the | |
1457 | case 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 |
1466 | Compare @var{s1} and @var{s2} and return @code{#f} if the predicate |
1467 | fails. Otherwise, the mismatch index is returned (or @var{end1} in the | |
1468 | case 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 |
1473 | Return 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 | ||
1483 | Using these procedures you can determine whether a given string is a | |
1484 | prefix or suffix of another string or how long a common prefix/suffix | |
1485 | is. | |
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 |
1491 | Return the length of the longest common prefix/suffix of the two |
1492 | strings. @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 |
1500 | Is @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 | ||
1510 | Use these procedures to find out whether a string contains a given | |
1511 | character 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 | 1515 | Search through the string @var{s} from left to right (right to left), |
85a9b4ed | 1516 | returning the index of the first (last) occurrence of a character which |
a0e07ba4 NJ |
1517 | |
1518 | @itemize @bullet | |
1519 | @item | |
1520 | equals @var{char_pred}, if it is character, | |
1521 | ||
1522 | @item | |
85a9b4ed | 1523 | satisfies the predicate @var{char_pred}, if it is a |
a0e07ba4 NJ |
1524 | procedure, |
1525 | ||
1526 | @item | |
1527 | is 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 | 1533 | Search through the string @var{s} from left to right (right to left), |
85a9b4ed | 1534 | returning the index of the first (last) occurrence of a character which |
a0e07ba4 NJ |
1535 | |
1536 | @itemize @bullet | |
1537 | @item | |
1538 | does not equal @var{char_pred}, if it is character, | |
1539 | ||
1540 | @item | |
85a9b4ed | 1541 | does not satisfy the predicate @var{char_pred}, if it is |
a0e07ba4 NJ |
1542 | a procedure. |
1543 | ||
1544 | @item | |
1545 | is 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 |
1550 | Return the count of the number of characters in the string |
1551 | @var{s} which | |
1552 | ||
1553 | @itemize @bullet | |
1554 | @item | |
1555 | equals @var{char_pred}, if it is character, | |
1556 | ||
1557 | @item | |
85a9b4ed | 1558 | satisfies the predicate @var{char_pred}, if it is a procedure. |
a0e07ba4 NJ |
1559 | |
1560 | @item | |
1561 | is 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 |
1567 | Does string @var{s1} contain string @var{s2}? Return the index |
1568 | in @var{s1} where @var{s2} occurs as a substring, or false. | |
1569 | The optional start/end indices restrict the operation to the | |
1570 | indicated 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 | ||
1581 | These procedures convert the alphabetic case of strings. They are | |
1582 | similar to the procedures in the Guile core, but are extended to handle | |
1583 | optional 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 |
1587 | Upcase every character in @var{s}. @code{string-upcase!} is the |
1588 | side-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 |
1593 | Downcase every character in @var{s}. @code{string-downcase!} is the |
1594 | side-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 |
1599 | Upcase every first character in every word in @var{s}, downcase the |
1600 | other characters. @code{string-titlecase!} is the side-effecting | |
1601 | variant. | |
1602 | @end deffn | |
1603 | ||
1604 | ||
1605 | @c =================================================================== | |
1606 | ||
1607 | @node SRFI-13 Reverse/Append | |
1608 | @subsection Reverse/Append | |
1609 | ||
1610 | One appending procedure, @code{string-append} is the same in R5RS and in | |
1611 | SRFI-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 |
1615 | Reverse the string @var{str}. The optional arguments |
1616 | @var{start} and @var{end} delimit the region of @var{str} to | |
1617 | operate on. | |
1618 | ||
1619 | @code{string-reverse!} modifies the argument string and returns an | |
1620 | unspecified value. | |
1621 | @end deffn | |
1622 | ||
8f85c0c6 | 1623 | @deffn {Scheme Procedure} string-append/shared ls @dots{} |
a0e07ba4 NJ |
1624 | Like @code{string-append}, but the result may share memory |
1625 | with the argument strings. | |
1626 | @end deffn | |
1627 | ||
8f85c0c6 | 1628 | @deffn {Scheme Procedure} string-concatenate ls |
a0e07ba4 NJ |
1629 | Append the elements of @var{ls} (which must be strings) |
1630 | together into a single string. Guaranteed to return a freshly | |
1631 | allocated string. | |
1632 | @end deffn | |
1633 | ||
8f85c0c6 | 1634 | @deffn {Scheme Procedure} string-concatenate/shared ls |
a0e07ba4 NJ |
1635 | Like @code{string-concatenate}, but the result may share memory |
1636 | with 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 |
1640 | Without optional arguments, this procedure is equivalent to |
1641 | ||
1642 | @smalllisp | |
1643 | (string-concatenate (reverse ls)) | |
1644 | @end smalllisp | |
1645 | ||
1646 | If the optional argument @var{final_string} is specified, it is | |
1647 | consed onto the beginning to @var{ls} before performing the | |
1648 | list-reverse and string-concatenate operations. If @var{end} | |
1649 | is given, only the characters of @var{final_string} up to index | |
1650 | @var{end} are used. | |
1651 | ||
1652 | Guaranteed 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 |
1656 | Like @code{string-concatenate-reverse}, but the result may |
1657 | share 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 | |
1667 | the characters a string is composed of. The fold and unfold procedures | |
1668 | are 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 | |
1673 | string 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 | |
1679 | string elements is not specified. The string @var{s} is | |
1680 | modified 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 |
1685 | Fold @var{kons} over the characters of @var{s}, with @var{knil} as the |
1686 | terminating element, from left to right (or right to left, for | |
1687 | @code{string-fold-right}). @var{kons} must expect two arguments: The | |
1688 | actual 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 |
1693 | These are the fundamental string constructors. |
1694 | @itemize @bullet | |
1695 | @item @var{g} is used to generate a series of @emph{seed} | |
1696 | values 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 | |
1700 | when applied to one of these seed values. | |
12991fed | 1701 | @item @var{f} maps each seed value to the corresponding |
a0e07ba4 NJ |
1702 | character in the result string. These chars are assembled into the |
1703 | string 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 | |
1707 | value (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 |
1715 | return value is not specified. | |
1716 | @end deffn | |
1717 | ||
1718 | ||
1719 | @c =================================================================== | |
1720 | ||
1721 | @node SRFI-13 Replicate/Rotate | |
1722 | @subsection Replicate/Rotate | |
1723 | ||
1724 | These procedures are special substring procedures, which can also be | |
1725 | used for replicating strings. They are a bit tricky to use, but | |
1726 | consider 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 |
1736 | This is the @emph{extended substring} procedure that implements |
1737 | replicated copying of a substring of some string. | |
1738 | ||
1739 | @var{s} is a string, @var{start} and @var{end} are optional | |
1740 | arguments that demarcate a substring of @var{s}, defaulting to | |
1741 | 0 and the length of @var{s}. Replicate this substring up and | |
1742 | down index space, in both the positive and negative directions. | |
1743 | @code{xsubstring} returns the substring of this string | |
1744 | beginning at index @var{from}, and ending at @var{to}, which | |
1745 | defaults 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 |
1749 | Exactly the same as @code{xsubstring}, but the extracted text |
1750 | is 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 | |
1753 | cannot 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 | |
1763 | another string and @code{string-tokenize} splits a string into a list of | |
1764 | strings, breaking it up at a specified character. | |
1765 | ||
8f85c0c6 | 1766 | @deffn {Scheme Procedure} string-replace s1 s2 [start1 end1 start2 end2] |
a0e07ba4 NJ |
1767 | Return 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 | 1773 | Split the string @var{s} into a list of substrings, where each |
c0ab7f13 MV |
1774 | substring is a maximal non-empty contiguous sequence of characters |
1775 | from the character set @var{token_set}, which defaults to an | |
1776 | equivalent of @code{char-set:graphic}. If @var{start} or @var{end} | |
1777 | indices are provided, they restrict @code{string-tokenize} to | |
1778 | operating 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 | |
1788 | not match a given criteria, @dfn{deleting} means the opposite. | |
1789 | ||
8f85c0c6 | 1790 | @deffn {Scheme Procedure} string-filter s char_pred [start end] |
a0e07ba4 NJ |
1791 | Filter the string @var{s}, retaining only those characters that |
1792 | satisfy the @var{char_pred} argument. If the argument is a | |
1793 | procedure, it is applied to each character as a predicate, if | |
1794 | it is a character, it is tested for equality and if it is a | |
1795 | character set, it is tested for membership. | |
1796 | @end deffn | |
1797 | ||
8f85c0c6 | 1798 | @deffn {Scheme Procedure} string-delete s char_pred [start end] |
a0e07ba4 NJ |
1799 | Filter the string @var{s}, retaining only those characters that |
1800 | do not satisfy the @var{char_pred} argument. If the argument | |
1801 | is a procedure, it is applied to each character as a predicate, | |
1802 | if it is a character, it is tested for equality and if it is a | |
1803 | character 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 | |
1811 | SRFI-14 defines the data type @dfn{character set}, and also defines a | |
1812 | lot of procedures for handling this character type, and a few standard | |
1813 | character sets like whitespace, alphabetic characters and others. | |
1814 | ||
1815 | All procedures from SRFI-14 (character-set library) are implemented in | |
1816 | the 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 | ||
1834 | When Guile is properly installed, SRFI-14 support can be loaded into a | |
1835 | running Guile by using the @code{(srfi srfi-14)} module. | |
1836 | ||
1837 | @example | |
1838 | $ guile | |
1839 | guile> (use-modules (srfi srfi-14)) | |
1840 | guile> (char-set-union (char-set #\f #\o #\o) (string->char-set "bar")) | |
1841 | #<charset @{#\a #\b #\f #\o #\r@}> | |
1842 | guile> | |
1843 | @end example | |
1844 | ||
1845 | ||
1846 | @node SRFI-14 Character Set Data Type | |
1847 | @subsection Character Set Data Type | |
1848 | ||
1849 | The data type @dfn{charset} implements sets of characters | |
1850 | (@pxref{Characters}). Because the internal representation of character | |
1851 | sets is not visible to the user, a lot of procedures for handling them | |
1852 | are provided. | |
1853 | ||
1854 | Character sets can be created, extended, tested for the membership of a | |
1855 | characters and be compared to other character sets. | |
1856 | ||
1857 | The Guile implementation of character sets deals with 8-bit characters. | |
1858 | In the standard variables, only the ASCII part of the character range is | |
1859 | really used, so that for example @dfn{Umlaute} and other accented | |
1860 | characters are not considered to be letters. In the future, as Guile | |
1861 | may get support for international character sets, this will change, so | |
1862 | don't rely on these ``features''. | |
1863 | ||
1864 | ||
1865 | @c =================================================================== | |
1866 | ||
1867 | @node SRFI-14 Predicates/Comparison | |
1868 | @subsection Predicates/Comparison | |
1869 | ||
1870 | Use these procedures for testing whether an object is a character set, | |
1871 | or 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 | |
1873 | usage in fast lookup procedures. | |
1874 | ||
8f85c0c6 | 1875 | @deffn {Scheme Procedure} char-set? obj |
a0e07ba4 NJ |
1876 | Return @code{#t} if @var{obj} is a character set, @code{#f} |
1877 | otherwise. | |
1878 | @end deffn | |
1879 | ||
8f85c0c6 | 1880 | @deffn {Scheme Procedure} char-set= cs1 @dots{} |
a0e07ba4 NJ |
1881 | Return @code{#t} if all given character sets are equal. |
1882 | @end deffn | |
1883 | ||
8f85c0c6 | 1884 | @deffn {Scheme Procedure} char-set<= cs1 @dots{} |
a0e07ba4 NJ |
1885 | Return @code{#t} if every character set @var{cs}i is a subset |
1886 | of character set @var{cs}i+1. | |
1887 | @end deffn | |
1888 | ||
8f85c0c6 | 1889 | @deffn {Scheme Procedure} char-set-hash cs [bound] |
a0e07ba4 NJ |
1890 | Compute a hash value for the character set @var{cs}. If |
1891 | @var{bound} is given and not @code{#f}, it restricts the | |
1892 | returned 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 | ||
1901 | Character set cursors are a means for iterating over the members of a | |
1902 | character 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 | |
1906 | element of the set can be checked with @code{end-of-char-set?}. | |
1907 | ||
1908 | Additionally, mapping and (un-)folding procedures for character sets are | |
1909 | provided. | |
1910 | ||
8f85c0c6 | 1911 | @deffn {Scheme Procedure} char-set-cursor cs |
a0e07ba4 NJ |
1912 | Return a cursor into the character set @var{cs}. |
1913 | @end deffn | |
1914 | ||
8f85c0c6 | 1915 | @deffn {Scheme Procedure} char-set-ref cs cursor |
a0e07ba4 NJ |
1916 | Return the character at the current cursor position |
1917 | @var{cursor} in the character set @var{cs}. It is an error to | |
1918 | pass 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 |
1922 | Advance the character set cursor @var{cursor} to the next |
1923 | character in the character set @var{cs}. It is an error if the | |
1924 | cursor given satisfies @code{end-of-char-set?}. | |
1925 | @end deffn | |
1926 | ||
8f85c0c6 | 1927 | @deffn {Scheme Procedure} end-of-char-set? cursor |
a0e07ba4 NJ |
1928 | Return @code{#t} if @var{cursor} has reached the end of a |
1929 | character set, @code{#f} otherwise. | |
1930 | @end deffn | |
1931 | ||
8f85c0c6 | 1932 | @deffn {Scheme Procedure} char-set-fold kons knil cs |
a0e07ba4 NJ |
1933 | Fold the procedure @var{kons} over the character set @var{cs}, |
1934 | initializing 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 |
1939 | This 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 |
1942 | from 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 | 1945 | when applied to one of the seed values. |
a0e07ba4 NJ |
1946 | @item @var{f} maps each seed value to a character. These |
1947 | characters are added to the base character set @var{base_cs} to | |
1948 | form 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 |
1955 | Apply @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 |
1960 | Map 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 | ||
1970 | New character sets are produced with these procedures. | |
1971 | ||
8f85c0c6 | 1972 | @deffn {Scheme Procedure} char-set-copy cs |
a0e07ba4 NJ |
1973 | Return a newly allocated character set containing all |
1974 | characters in @var{cs}. | |
1975 | @end deffn | |
1976 | ||
8f85c0c6 | 1977 | @deffn {Scheme Procedure} char-set char1 @dots{} |
a0e07ba4 NJ |
1978 | Return 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 |
1983 | Convert the character list @var{list} to a character set. If |
1984 | the character set @var{base_cs} is given, the character in this | |
1985 | set 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 |
1992 | Convert the string @var{str} to a character set. If the |
1993 | character set @var{base_cs} is given, the characters in this | |
1994 | set 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 |
2001 | Return a character set containing every character from @var{cs} |
2002 | so that it satisfies @var{pred}. If provided, the characters | |
2003 | from @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 |
2010 | Return a character set containing all characters whose |
2011 | character codes lie in the half-open range | |
2012 | [@var{lower},@var{upper}). | |
2013 | ||
2014 | If @var{error} is a true value, an error is signalled if the | |
2015 | specified range contains characters which are not contained in | |
2016 | the implemented character range. If @var{error} is @code{#f}, | |
85a9b4ed | 2017 | these characters are silently left out of the resulting |
a0e07ba4 NJ |
2018 | character set. |
2019 | ||
2020 | The characters in @var{base_cs} are added to the result, if | |
2021 | given. | |
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 |
2027 | Coerce @var{x} into a character set. @var{x} may be a string, a |
2028 | character 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 | ||
2037 | Access the elements and other information of a character set with these | |
2038 | procedures. | |
2039 | ||
8f85c0c6 | 2040 | @deffn {Scheme Procedure} char-set-size cs |
a0e07ba4 NJ |
2041 | Return 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 |
2045 | Return 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 |
2050 | Return 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 |
2055 | Return a string containing the elements of the character set |
2056 | @var{cs}. The order in which the characters are placed in the | |
2057 | string is not defined. | |
2058 | @end deffn | |
2059 | ||
8f85c0c6 | 2060 | @deffn {Scheme Procedure} char-set-contains? cs char |
a0e07ba4 NJ |
2061 | Return @code{#t} iff the character @var{ch} is contained in the |
2062 | character set @var{cs}. | |
2063 | @end deffn | |
2064 | ||
8f85c0c6 | 2065 | @deffn {Scheme Procedure} char-set-every pred cs |
a0e07ba4 NJ |
2066 | Return 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 |
2071 | Return 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 | ||
2081 | Character sets can be manipulated with the common set algebra operation, | |
2082 | such as union, complement, intersection etc. All of these procedures | |
2083 | provide side-effecting variants, which modify their character set | |
2084 | argument(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 |
2088 | Add all character arguments to the first argument, which must |
2089 | be 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 |
2094 | Delete all character arguments from the first argument, which |
2095 | must 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 |
2100 | Return 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 |
2105 | Return 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 |
2110 | Return 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 |
2115 | Return 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 |
2120 | Return 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 |
2125 | Return the difference and the intersection of all argument |
2126 | character sets. | |
2127 | @end deffn | |
2128 | ||
2129 | ||
2130 | @c =================================================================== | |
2131 | ||
2132 | @node SRFI-14 Standard Character Sets | |
2133 | @subsection Standard Character Sets | |
2134 | ||
2135 | In order to make the use of the character set data type and procedures | |
2136 | useful, several predefined character set variables exist. | |
2137 | ||
2138 | @defvar char-set:lower-case | |
2139 | All lower-case characters. | |
2140 | @end defvar | |
2141 | ||
2142 | @defvar char-set:upper-case | |
2143 | All upper-case characters. | |
2144 | @end defvar | |
2145 | ||
2146 | @defvar char-set:title-case | |
2147 | This is empty, because ASCII has no titlecase characters. | |
2148 | @end defvar | |
2149 | ||
2150 | @defvar char-set:letter | |
2151 | All 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 | |
2156 | All digits. | |
2157 | @end defvar | |
2158 | ||
2159 | @defvar char-set:letter+digit | |
2160 | The union of @code{char-set:letter} and @code{char-set:digit}. | |
2161 | @end defvar | |
2162 | ||
2163 | @defvar char-set:graphic | |
2164 | All characters which would put ink on the paper. | |
2165 | @end defvar | |
2166 | ||
2167 | @defvar char-set:printing | |
2168 | The union of @code{char-set:graphic} and @code{char-set:whitespace}. | |
2169 | @end defvar | |
2170 | ||
2171 | @defvar char-set:whitespace | |
2172 | All whitespace characters. | |
2173 | @end defvar | |
2174 | ||
2175 | @defvar char-set:blank | |
2176 | All horizontal whitespace characters, that is @code{#\space} and | |
2177 | @code{#\tab}. | |
2178 | @end defvar | |
2179 | ||
2180 | @defvar char-set:iso-control | |
2181 | The ISO control characters with the codes 0--31 and 127. | |
2182 | @end defvar | |
2183 | ||
2184 | @defvar char-set:punctuation | |
2185 | The characters @code{!"#%&'()*,-./:;?@@[\\]_@{@}} | |
2186 | @end defvar | |
2187 | ||
2188 | @defvar char-set:symbol | |
2189 | The characters @code{$+<=>^`|~}. | |
2190 | @end defvar | |
2191 | ||
2192 | @defvar char-set:hex-digit | |
2193 | The hexadecimal digits @code{0123456789abcdefABCDEF}. | |
2194 | @end defvar | |
2195 | ||
2196 | @defvar char-set:ascii | |
2197 | All ASCII characters. | |
2198 | @end defvar | |
2199 | ||
2200 | @defvar char-set:empty | |
2201 | The empty character set. | |
2202 | @end defvar | |
2203 | ||
2204 | @defvar char-set:full | |
2205 | This 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 |
2215 | The syntactic form @code{case-lambda} creates procedures, just like |
2216 | @code{lambda}, but has syntactic extensions for writing procedures of | |
2217 | varying arity easier. | |
2218 | ||
2219 | The syntax of the @code{case-lambda} form is defined in the following | |
2220 | EBNF 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 | ||
2235 | The value returned by a @code{case-lambda} form is a procedure which | |
2236 | matches the number of actual arguments against the formals in the | |
2237 | various clauses, in order. @dfn{Formals} means a formal argument list | |
2238 | just like with @code{lambda} (@pxref{Lambda}). The first matching clause | |
2239 | is selected, the corresponding values from the actual parameter list are | |
2240 | bound to the variable names in the clauses and the body of the clause is | |
2241 | evaluated. If no clause matches, an error is signalled. | |
2242 | ||
2243 | The following (silly) definition creates a procedure @var{foo} which | |
2244 | acts differently, depending on the number of actual arguments. If one | |
2245 | argument is given, the constant @code{#t} is returned, two arguments are | |
2246 | added 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{} | |
2259 | 6 | |
2260 | (foo 3 3 3) | |
2261 | @result{} | |
2262 | 27 | |
2263 | (foo) | |
2264 | @result{} | |
2265 | 1 | |
2266 | @end lisp | |
2267 | ||
2268 | The last expression evaluates to 1 because the last clause is matched, | |
2269 | @var{z} is bound to the empty list and the following multiplication, | |
2270 | applied 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 | |
2277 | This is an implementation of SRFI-17: Generalized set! | |
2278 | ||
8742c48b | 2279 | @findex getter-with-setter |
a0e07ba4 NJ |
2280 | It exports the Guile procedure @code{make-procedure-with-setter} under |
2281 | the SRFI name @code{getter-with-setter} and exports the standard | |
2282 | procedures @code{car}, @code{cdr}, @dots{}, @code{cdddr}, | |
2283 | @code{string-ref} and @code{vector-ref} as procedures with setters, as | |
2284 | required by the SRFI. | |
2285 | ||
2286 | SRFI-17 was heavily criticized during its discussion period but it was | |
2287 | finalized anyway. One issue was its concept of globally associating | |
2288 | setter @dfn{properties} with (procedure) values, which is non-Schemy. | |
2289 | For this reason, this implementation chooses not to provide a way to set | |
2290 | the 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 | |
2292 | procedure is to create a new object (a @dfn{procedure with setter}) via | |
2293 | the @code{getter-with-setter} procedure. This procedure is also | |
2294 | specified 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 | |
2301 | This is an implementation of SRFI-19: Time/Date Library | |
2302 | ||
2303 | It depends on SRFIs: 6 (@pxref{SRFI-6}), 8 (@pxref{SRFI-8}), | |
2304 | 9 (@pxref{SRFI-9}). | |
2305 | ||
2306 | This 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 | ||
2322 | All 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 | ||
2362 | Args 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 | ||
2375 | The @code{foo!} variants modify in place. Time difference | |
2376 | is 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 |