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