Make bytevectors accessible using the generalized-vector API.
[bpt/guile.git] / libguile / vectors.c
1 /* Copyright (C) 1995,1996,1998,1999,2000,2001, 2006, 2008, 2009 Free Software Foundation, Inc.
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
17 */
18
19
20 \f
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include "libguile/_scm.h"
26 #include "libguile/eq.h"
27 #include "libguile/root.h"
28 #include "libguile/strings.h"
29 #include "libguile/lang.h"
30
31 #include "libguile/validate.h"
32 #include "libguile/vectors.h"
33 #include "libguile/unif.h"
34 #include "libguile/bytevectors.h"
35 #include "libguile/ramap.h"
36 #include "libguile/srfi-4.h"
37 #include "libguile/strings.h"
38 #include "libguile/srfi-13.h"
39 #include "libguile/dynwind.h"
40 #include "libguile/deprecation.h"
41
42 \f
43
44 #define VECTOR_MAX_LENGTH (SCM_T_BITS_MAX >> 8)
45
46 int
47 scm_is_vector (SCM obj)
48 {
49 if (SCM_I_IS_VECTOR (obj))
50 return 1;
51 if (SCM_I_ARRAYP (obj) && SCM_I_ARRAY_NDIM (obj) == 1)
52 {
53 SCM v = SCM_I_ARRAY_V (obj);
54 return SCM_I_IS_VECTOR (v);
55 }
56 return 0;
57 }
58
59 int
60 scm_is_simple_vector (SCM obj)
61 {
62 return SCM_I_IS_VECTOR (obj);
63 }
64
65 const SCM *
66 scm_vector_elements (SCM vec, scm_t_array_handle *h,
67 size_t *lenp, ssize_t *incp)
68 {
69 scm_generalized_vector_get_handle (vec, h);
70 if (lenp)
71 {
72 scm_t_array_dim *dim = scm_array_handle_dims (h);
73 *lenp = dim->ubnd - dim->lbnd + 1;
74 *incp = dim->inc;
75 }
76 return scm_array_handle_elements (h);
77 }
78
79 SCM *
80 scm_vector_writable_elements (SCM vec, scm_t_array_handle *h,
81 size_t *lenp, ssize_t *incp)
82 {
83 scm_generalized_vector_get_handle (vec, h);
84 if (lenp)
85 {
86 scm_t_array_dim *dim = scm_array_handle_dims (h);
87 *lenp = dim->ubnd - dim->lbnd + 1;
88 *incp = dim->inc;
89 }
90 return scm_array_handle_writable_elements (h);
91 }
92
93 SCM_DEFINE (scm_vector_p, "vector?", 1, 0, 0,
94 (SCM obj),
95 "Return @code{#t} if @var{obj} is a vector, otherwise return\n"
96 "@code{#f}.")
97 #define FUNC_NAME s_scm_vector_p
98 {
99 return scm_from_bool (scm_is_vector (obj));
100 }
101 #undef FUNC_NAME
102
103 SCM_GPROC (s_vector_length, "vector-length", 1, 0, 0, scm_vector_length, g_vector_length);
104 /* Returns the number of elements in @var{vector} as an exact integer. */
105 SCM
106 scm_vector_length (SCM v)
107 {
108 if (SCM_I_IS_VECTOR (v))
109 return scm_from_size_t (SCM_I_VECTOR_LENGTH (v));
110 else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1)
111 {
112 scm_t_array_dim *dim = SCM_I_ARRAY_DIMS (v);
113 return scm_from_size_t (dim->ubnd - dim->lbnd + 1);
114 }
115 else
116 SCM_WTA_DISPATCH_1 (g_vector_length, v, 1, NULL);
117 }
118
119 size_t
120 scm_c_vector_length (SCM v)
121 {
122 if (SCM_I_IS_VECTOR (v))
123 return SCM_I_VECTOR_LENGTH (v);
124 else
125 return scm_to_size_t (scm_vector_length (v));
126 }
127
128 SCM_REGISTER_PROC (s_list_to_vector, "list->vector", 1, 0, 0, scm_vector);
129 /*
130 "Return a newly created vector initialized to the elements of"
131 "the list @var{list}.\n\n"
132 "@lisp\n"
133 "(vector->list '#(dah dah didah)) @result{} (dah dah didah)\n"
134 "(list->vector '(dididit dah)) @result{} #(dididit dah)\n"
135 "@end lisp")
136 */
137 SCM_DEFINE (scm_vector, "vector", 0, 0, 1,
138 (SCM l),
139 "@deffnx {Scheme Procedure} list->vector l\n"
140 "Return a newly allocated vector composed of the\n"
141 "given arguments. Analogous to @code{list}.\n"
142 "\n"
143 "@lisp\n"
144 "(vector 'a 'b 'c) @result{} #(a b c)\n"
145 "@end lisp")
146 #define FUNC_NAME s_scm_vector
147 {
148 SCM res;
149 SCM *data;
150 long i, len;
151 scm_t_array_handle handle;
152
153 SCM_VALIDATE_LIST_COPYLEN (1, l, len);
154
155 res = scm_c_make_vector (len, SCM_UNSPECIFIED);
156 data = scm_vector_writable_elements (res, &handle, NULL, NULL);
157 i = 0;
158 while (scm_is_pair (l) && i < len)
159 {
160 data[i] = SCM_CAR (l);
161 l = SCM_CDR (l);
162 i += 1;
163 }
164
165 scm_array_handle_release (&handle);
166
167 return res;
168 }
169 #undef FUNC_NAME
170
171 SCM_GPROC (s_vector_ref, "vector-ref", 2, 0, 0, scm_vector_ref, g_vector_ref);
172
173 /*
174 "@var{k} must be a valid index of @var{vector}.\n"
175 "@samp{Vector-ref} returns the contents of element @var{k} of\n"
176 "@var{vector}.\n\n"
177 "@lisp\n"
178 "(vector-ref '#(1 1 2 3 5 8 13 21) 5) @result{} 8\n"
179 "(vector-ref '#(1 1 2 3 5 8 13 21)\n"
180 " (let ((i (round (* 2 (acos -1)))))\n"
181 " (if (inexact? i)\n"
182 " (inexact->exact i)\n"
183 " i))) @result{} 13\n"
184 "@end lisp"
185 */
186
187 SCM
188 scm_vector_ref (SCM v, SCM k)
189 #define FUNC_NAME s_vector_ref
190 {
191 return scm_c_vector_ref (v, scm_to_size_t (k));
192 }
193 #undef FUNC_NAME
194
195 SCM
196 scm_c_vector_ref (SCM v, size_t k)
197 {
198 if (SCM_I_IS_VECTOR (v))
199 {
200 if (k >= SCM_I_VECTOR_LENGTH (v))
201 scm_out_of_range (NULL, scm_from_size_t (k));
202 return (SCM_I_VECTOR_ELTS(v))[k];
203 }
204 else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1)
205 {
206 scm_t_array_dim *dim = SCM_I_ARRAY_DIMS (v);
207 SCM vv = SCM_I_ARRAY_V (v);
208 if (SCM_I_IS_VECTOR (vv))
209 {
210 if (k >= dim->ubnd - dim->lbnd + 1)
211 scm_out_of_range (NULL, scm_from_size_t (k));
212 k = SCM_I_ARRAY_BASE (v) + k*dim->inc;
213 return (SCM_I_VECTOR_ELTS (vv))[k];
214 }
215 scm_wrong_type_arg_msg (NULL, 0, v, "non-uniform vector");
216 }
217 else
218 SCM_WTA_DISPATCH_2 (g_vector_ref, v, scm_from_size_t (k), 2, NULL);
219 }
220
221 SCM_GPROC (s_vector_set_x, "vector-set!", 3, 0, 0, scm_vector_set_x, g_vector_set_x);
222
223 /* "@var{k} must be a valid index of @var{vector}.\n"
224 "@code{Vector-set!} stores @var{obj} in element @var{k} of @var{vector}.\n"
225 "The value returned by @samp{vector-set!} is unspecified.\n"
226 "@lisp\n"
227 "(let ((vec (vector 0 '(2 2 2 2) "Anna")))\n"
228 " (vector-set! vec 1 '("Sue" "Sue"))\n"
229 " vec) @result{} #(0 ("Sue" "Sue") "Anna")\n"
230 "(vector-set! '#(0 1 2) 1 "doe") @result{} @emph{error} ; constant vector\n"
231 "@end lisp"
232 */
233
234 SCM
235 scm_vector_set_x (SCM v, SCM k, SCM obj)
236 #define FUNC_NAME s_vector_set_x
237 {
238 scm_c_vector_set_x (v, scm_to_size_t (k), obj);
239 return SCM_UNSPECIFIED;
240 }
241 #undef FUNC_NAME
242
243 void
244 scm_c_vector_set_x (SCM v, size_t k, SCM obj)
245 {
246 if (SCM_I_IS_VECTOR (v))
247 {
248 if (k >= SCM_I_VECTOR_LENGTH (v))
249 scm_out_of_range (NULL, scm_from_size_t (k));
250 (SCM_I_VECTOR_WELTS(v))[k] = obj;
251 }
252 else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1)
253 {
254 scm_t_array_dim *dim = SCM_I_ARRAY_DIMS (v);
255 SCM vv = SCM_I_ARRAY_V (v);
256 if (SCM_I_IS_VECTOR (vv))
257 {
258 if (k >= dim->ubnd - dim->lbnd + 1)
259 scm_out_of_range (NULL, scm_from_size_t (k));
260 k = SCM_I_ARRAY_BASE (v) + k*dim->inc;
261 (SCM_I_VECTOR_WELTS (vv))[k] = obj;
262 }
263 else
264 scm_wrong_type_arg_msg (NULL, 0, v, "non-uniform vector");
265 }
266 else
267 {
268 if (SCM_UNPACK (g_vector_set_x))
269 scm_apply_generic (g_vector_set_x,
270 scm_list_3 (v, scm_from_size_t (k), obj));
271 else
272 scm_wrong_type_arg_msg (NULL, 0, v, "vector");
273 }
274 }
275
276 SCM_DEFINE (scm_make_vector, "make-vector", 1, 1, 0,
277 (SCM k, SCM fill),
278 "Return a newly allocated vector of @var{k} elements. If a\n"
279 "second argument is given, then each position is initialized to\n"
280 "@var{fill}. Otherwise the initial contents of each position is\n"
281 "unspecified.")
282 #define FUNC_NAME s_scm_make_vector
283 {
284 size_t l = scm_to_unsigned_integer (k, 0, VECTOR_MAX_LENGTH);
285
286 if (SCM_UNBNDP (fill))
287 fill = SCM_UNSPECIFIED;
288
289 return scm_c_make_vector (l, fill);
290 }
291 #undef FUNC_NAME
292
293
294 SCM
295 scm_c_make_vector (size_t k, SCM fill)
296 #define FUNC_NAME s_scm_make_vector
297 {
298 SCM v;
299 SCM *base;
300
301 if (k > 0)
302 {
303 unsigned long int j;
304
305 SCM_ASSERT_RANGE (1, scm_from_ulong (k), k <= VECTOR_MAX_LENGTH);
306
307 base = scm_gc_malloc (k * sizeof (SCM), "vector");
308 for (j = 0; j != k; ++j)
309 base[j] = fill;
310 }
311 else
312 base = NULL;
313
314 v = scm_cell ((k << 8) | scm_tc7_vector, (scm_t_bits) base);
315 scm_remember_upto_here_1 (fill);
316
317 return v;
318 }
319 #undef FUNC_NAME
320
321 SCM_DEFINE (scm_vector_copy, "vector-copy", 1, 0, 0,
322 (SCM vec),
323 "Return a copy of @var{vec}.")
324 #define FUNC_NAME s_scm_vector_copy
325 {
326 scm_t_array_handle handle;
327 size_t i, len;
328 ssize_t inc;
329 const SCM *src;
330 SCM *dst;
331
332 src = scm_vector_elements (vec, &handle, &len, &inc);
333 dst = scm_gc_malloc (len * sizeof (SCM), "vector");
334 for (i = 0; i < len; i++, src += inc)
335 dst[i] = *src;
336 scm_array_handle_release (&handle);
337
338 return scm_cell ((len << 8) | scm_tc7_vector, (scm_t_bits) dst);
339 }
340 #undef FUNC_NAME
341
342 void
343 scm_i_vector_free (SCM vec)
344 {
345 scm_gc_free (SCM_I_VECTOR_WELTS (vec),
346 SCM_I_VECTOR_LENGTH (vec) * sizeof(SCM),
347 "vector");
348 }
349
350 /* Allocate memory for a weak vector on behalf of the caller. The allocated
351 * vector will be of the given weak vector subtype. It will contain size
352 * elements which are initialized with the 'fill' object, or, if 'fill' is
353 * undefined, with an unspecified object.
354 */
355 SCM
356 scm_i_allocate_weak_vector (scm_t_bits type, SCM size, SCM fill)
357 {
358 size_t c_size;
359 SCM *base;
360 SCM v;
361
362 c_size = scm_to_unsigned_integer (size, 0, VECTOR_MAX_LENGTH);
363
364 if (c_size > 0)
365 {
366 size_t j;
367
368 if (SCM_UNBNDP (fill))
369 fill = SCM_UNSPECIFIED;
370
371 base = scm_gc_malloc (c_size * sizeof (SCM), "weak vector");
372 for (j = 0; j != c_size; ++j)
373 base[j] = fill;
374 }
375 else
376 base = NULL;
377
378 v = scm_double_cell ((c_size << 8) | scm_tc7_wvect,
379 (scm_t_bits) base,
380 type,
381 SCM_UNPACK (SCM_EOL));
382 scm_remember_upto_here_1 (fill);
383
384 return v;
385 }
386
387 SCM_DEFINE (scm_vector_to_list, "vector->list", 1, 0, 0,
388 (SCM v),
389 "Return a newly allocated list composed of the elements of @var{v}.\n"
390 "\n"
391 "@lisp\n"
392 "(vector->list '#(dah dah didah)) @result{} (dah dah didah)\n"
393 "(list->vector '(dididit dah)) @result{} #(dididit dah)\n"
394 "@end lisp")
395 #define FUNC_NAME s_scm_vector_to_list
396 {
397 SCM res = SCM_EOL;
398 const SCM *data;
399 scm_t_array_handle handle;
400 size_t i, count, len;
401 ssize_t inc;
402
403 data = scm_vector_elements (v, &handle, &len, &inc);
404 for (i = (len - 1) * inc, count = 0;
405 count < len;
406 i -= inc, count++)
407 res = scm_cons (data[i], res);
408
409 scm_array_handle_release (&handle);
410 return res;
411 }
412 #undef FUNC_NAME
413
414
415 SCM_DEFINE (scm_vector_fill_x, "vector-fill!", 2, 0, 0,
416 (SCM v, SCM fill),
417 "Store @var{fill} in every position of @var{vector}. The value\n"
418 "returned by @code{vector-fill!} is unspecified.")
419 #define FUNC_NAME s_scm_vector_fill_x
420 {
421 scm_t_array_handle handle;
422 SCM *data;
423 size_t i, len;
424 ssize_t inc;
425
426 data = scm_vector_writable_elements (v, &handle, &len, &inc);
427 for (i = 0; i < len; i += inc)
428 data[i] = fill;
429 scm_array_handle_release (&handle);
430 return SCM_UNSPECIFIED;
431 }
432 #undef FUNC_NAME
433
434
435 SCM
436 scm_i_vector_equal_p (SCM x, SCM y)
437 {
438 long i;
439 for (i = SCM_I_VECTOR_LENGTH (x) - 1; i >= 0; i--)
440 if (scm_is_false (scm_equal_p (SCM_I_VECTOR_ELTS (x)[i],
441 SCM_I_VECTOR_ELTS (y)[i])))
442 return SCM_BOOL_F;
443 return SCM_BOOL_T;
444 }
445
446
447 SCM_DEFINE (scm_vector_move_left_x, "vector-move-left!", 5, 0, 0,
448 (SCM vec1, SCM start1, SCM end1, SCM vec2, SCM start2),
449 "Copy elements from @var{vec1}, positions @var{start1} to @var{end1},\n"
450 "to @var{vec2} starting at position @var{start2}. @var{start1} and\n"
451 "@var{start2} are inclusive indices; @var{end1} is exclusive.\n\n"
452 "@code{vector-move-left!} copies elements in leftmost order.\n"
453 "Therefore, in the case where @var{vec1} and @var{vec2} refer to the\n"
454 "same vector, @code{vector-move-left!} is usually appropriate when\n"
455 "@var{start1} is greater than @var{start2}.")
456 #define FUNC_NAME s_scm_vector_move_left_x
457 {
458 scm_t_array_handle handle1, handle2;
459 const SCM *elts1;
460 SCM *elts2;
461 size_t len1, len2;
462 ssize_t inc1, inc2;
463 size_t i, j, e;
464
465 elts1 = scm_vector_elements (vec1, &handle1, &len1, &inc1);
466 elts2 = scm_vector_writable_elements (vec2, &handle2, &len2, &inc2);
467
468 i = scm_to_unsigned_integer (start1, 0, len1);
469 e = scm_to_unsigned_integer (end1, i, len1);
470 j = scm_to_unsigned_integer (start2, 0, len2 - (i-e));
471
472 i *= inc1;
473 e *= inc1;
474 j *= inc2;
475 for (; i < e; i += inc1, j += inc2)
476 elts2[j] = elts1[i];
477
478 scm_array_handle_release (&handle2);
479 scm_array_handle_release (&handle1);
480
481 return SCM_UNSPECIFIED;
482 }
483 #undef FUNC_NAME
484
485 SCM_DEFINE (scm_vector_move_right_x, "vector-move-right!", 5, 0, 0,
486 (SCM vec1, SCM start1, SCM end1, SCM vec2, SCM start2),
487 "Copy elements from @var{vec1}, positions @var{start1} to @var{end1},\n"
488 "to @var{vec2} starting at position @var{start2}. @var{start1} and\n"
489 "@var{start2} are inclusive indices; @var{end1} is exclusive.\n\n"
490 "@code{vector-move-right!} copies elements in rightmost order.\n"
491 "Therefore, in the case where @var{vec1} and @var{vec2} refer to the\n"
492 "same vector, @code{vector-move-right!} is usually appropriate when\n"
493 "@var{start1} is less than @var{start2}.")
494 #define FUNC_NAME s_scm_vector_move_right_x
495 {
496 scm_t_array_handle handle1, handle2;
497 const SCM *elts1;
498 SCM *elts2;
499 size_t len1, len2;
500 ssize_t inc1, inc2;
501 size_t i, j, e;
502
503 elts1 = scm_vector_elements (vec1, &handle1, &len1, &inc1);
504 elts2 = scm_vector_writable_elements (vec2, &handle2, &len2, &inc2);
505
506 i = scm_to_unsigned_integer (start1, 0, len1);
507 e = scm_to_unsigned_integer (end1, i, len1);
508 j = scm_to_unsigned_integer (start2, 0, len2 - (i-e));
509
510 i *= inc1;
511 e *= inc1;
512 j *= inc2;
513 while (i < e)
514 {
515 e -= inc1;
516 j -= inc2;
517 elts2[j] = elts1[e];
518 }
519
520 scm_array_handle_release (&handle2);
521 scm_array_handle_release (&handle1);
522
523 return SCM_UNSPECIFIED;
524 }
525 #undef FUNC_NAME
526
527 \f
528 /* Generalized vectors. */
529
530 int
531 scm_is_generalized_vector (SCM obj)
532 {
533 return (scm_is_vector (obj)
534 || scm_is_string (obj)
535 || scm_is_bitvector (obj)
536 || scm_is_uniform_vector (obj)
537 || scm_is_bytevector (obj));
538 }
539
540 SCM_DEFINE (scm_generalized_vector_p, "generalized-vector?", 1, 0, 0,
541 (SCM obj),
542 "Return @code{#t} if @var{obj} is a vector, string,\n"
543 "bitvector, or uniform numeric vector.")
544 #define FUNC_NAME s_scm_generalized_vector_p
545 {
546 return scm_from_bool (scm_is_generalized_vector (obj));
547 }
548 #undef FUNC_NAME
549
550 void
551 scm_generalized_vector_get_handle (SCM vec, scm_t_array_handle *h)
552 {
553 scm_array_get_handle (vec, h);
554 if (scm_array_handle_rank (h) != 1)
555 scm_wrong_type_arg_msg (NULL, 0, vec, "vector");
556 }
557
558 size_t
559 scm_c_generalized_vector_length (SCM v)
560 {
561 if (scm_is_vector (v))
562 return scm_c_vector_length (v);
563 else if (scm_is_string (v))
564 return scm_c_string_length (v);
565 else if (scm_is_bitvector (v))
566 return scm_c_bitvector_length (v);
567 else if (scm_is_uniform_vector (v))
568 return scm_c_uniform_vector_length (v);
569 else if (scm_is_bytevector (v))
570 return scm_c_bytevector_length (v);
571 else
572 scm_wrong_type_arg_msg (NULL, 0, v, "generalized vector");
573 }
574
575 SCM_DEFINE (scm_generalized_vector_length, "generalized-vector-length", 1, 0, 0,
576 (SCM v),
577 "Return the length of the generalized vector @var{v}.")
578 #define FUNC_NAME s_scm_generalized_vector_length
579 {
580 return scm_from_size_t (scm_c_generalized_vector_length (v));
581 }
582 #undef FUNC_NAME
583
584 SCM
585 scm_c_generalized_vector_ref (SCM v, size_t idx)
586 {
587 if (scm_is_vector (v))
588 return scm_c_vector_ref (v, idx);
589 else if (scm_is_string (v))
590 return scm_c_string_ref (v, idx);
591 else if (scm_is_bitvector (v))
592 return scm_c_bitvector_ref (v, idx);
593 else if (scm_is_uniform_vector (v))
594 return scm_c_uniform_vector_ref (v, idx);
595 else if (scm_is_bytevector (v))
596 return scm_from_uint8 (scm_c_bytevector_ref (v, idx));
597 else
598 scm_wrong_type_arg_msg (NULL, 0, v, "generalized vector");
599 }
600
601 SCM_DEFINE (scm_generalized_vector_ref, "generalized-vector-ref", 2, 0, 0,
602 (SCM v, SCM idx),
603 "Return the element at index @var{idx} of the\n"
604 "generalized vector @var{v}.")
605 #define FUNC_NAME s_scm_generalized_vector_ref
606 {
607 return scm_c_generalized_vector_ref (v, scm_to_size_t (idx));
608 }
609 #undef FUNC_NAME
610
611 void
612 scm_c_generalized_vector_set_x (SCM v, size_t idx, SCM val)
613 {
614 if (scm_is_vector (v))
615 scm_c_vector_set_x (v, idx, val);
616 else if (scm_is_string (v))
617 scm_c_string_set_x (v, idx, val);
618 else if (scm_is_bitvector (v))
619 scm_c_bitvector_set_x (v, idx, val);
620 else if (scm_is_uniform_vector (v))
621 scm_c_uniform_vector_set_x (v, idx, val);
622 else if (scm_is_bytevector (v))
623 scm_i_bytevector_generalized_set_x (v, idx, val);
624 else
625 scm_wrong_type_arg_msg (NULL, 0, v, "generalized vector");
626 }
627
628 SCM_DEFINE (scm_generalized_vector_set_x, "generalized-vector-set!", 3, 0, 0,
629 (SCM v, SCM idx, SCM val),
630 "Set the element at index @var{idx} of the\n"
631 "generalized vector @var{v} to @var{val}.")
632 #define FUNC_NAME s_scm_generalized_vector_set_x
633 {
634 scm_c_generalized_vector_set_x (v, scm_to_size_t (idx), val);
635 return SCM_UNSPECIFIED;
636 }
637 #undef FUNC_NAME
638
639 SCM_DEFINE (scm_generalized_vector_to_list, "generalized-vector->list", 1, 0, 0,
640 (SCM v),
641 "Return a new list whose elements are the elements of the\n"
642 "generalized vector @var{v}.")
643 #define FUNC_NAME s_scm_generalized_vector_to_list
644 {
645 if (scm_is_vector (v))
646 return scm_vector_to_list (v);
647 else if (scm_is_string (v))
648 return scm_string_to_list (v);
649 else if (scm_is_bitvector (v))
650 return scm_bitvector_to_list (v);
651 else if (scm_is_uniform_vector (v))
652 return scm_uniform_vector_to_list (v);
653 else
654 scm_wrong_type_arg_msg (NULL, 0, v, "generalized vector");
655 }
656 #undef FUNC_NAME
657
658
659 void
660 scm_init_vectors ()
661 {
662 scm_nullvect = scm_c_make_vector (0, SCM_UNDEFINED);
663
664 #include "libguile/vectors.x"
665 }
666
667
668 /*
669 Local Variables:
670 c-file-style: "gnu"
671 End:
672 */