Replace uses of scm_make_ra with scm_i_make_ra.
[bpt/guile.git] / libguile / ramap.c
1 /* Copyright (C) 1996,1998,2000,2001,2004 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
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18
19 /*
20 HWN:FIXME::
21 Someone should rename this to arraymap.c; that would reflect the
22 contents better. */
23 \f
24
25
26 \f
27
28 #include "libguile/_scm.h"
29 #include "libguile/strings.h"
30 #include "libguile/unif.h"
31 #include "libguile/smob.h"
32 #include "libguile/chars.h"
33 #include "libguile/eq.h"
34 #include "libguile/eval.h"
35 #include "libguile/feature.h"
36 #include "libguile/root.h"
37 #include "libguile/vectors.h"
38 #include "libguile/srfi-4.h"
39 #include "libguile/dynwind.h"
40
41 #include "libguile/validate.h"
42 #include "libguile/ramap.h"
43 \f
44
45 typedef struct
46 {
47 char *name;
48 SCM sproc;
49 int (*vproc) ();
50 } ra_iproc;
51
52
53 /* These tables are a kluge that will not scale well when more
54 * vectorized subrs are added. It is tempting to steal some bits from
55 * the SCM_CAR of all subrs (like those selected by SCM_SMOBNUM) to hold an
56 * offset into a table of vectorized subrs.
57 */
58
59 static ra_iproc ra_rpsubrs[] =
60 {
61 {"=", SCM_UNDEFINED, scm_ra_eqp},
62 {"<", SCM_UNDEFINED, scm_ra_lessp},
63 {"<=", SCM_UNDEFINED, scm_ra_leqp},
64 {">", SCM_UNDEFINED, scm_ra_grp},
65 {">=", SCM_UNDEFINED, scm_ra_greqp},
66 {0, 0, 0}
67 };
68
69 static ra_iproc ra_asubrs[] =
70 {
71 {"+", SCM_UNDEFINED, scm_ra_sum},
72 {"-", SCM_UNDEFINED, scm_ra_difference},
73 {"*", SCM_UNDEFINED, scm_ra_product},
74 {"/", SCM_UNDEFINED, scm_ra_divide},
75 {0, 0, 0}
76 };
77
78
79 #define GVREF scm_c_generalized_vector_ref
80 #define GVSET scm_c_generalized_vector_set_x
81
82 static unsigned long
83 cind (SCM ra, long *ve)
84 {
85 unsigned long i;
86 int k;
87 if (!SCM_ARRAYP (ra))
88 return *ve;
89 i = SCM_ARRAY_BASE (ra);
90 for (k = 0; k < SCM_ARRAY_NDIM (ra); k++)
91 i += (ve[k] - SCM_ARRAY_DIMS (ra)[k].lbnd) * SCM_ARRAY_DIMS (ra)[k].inc;
92 return i;
93 }
94
95
96 /* Checker for scm_array mapping functions:
97 return values: 4 --> shapes, increments, and bases are the same;
98 3 --> shapes and increments are the same;
99 2 --> shapes are the same;
100 1 --> ras are at least as big as ra0;
101 0 --> no match.
102 */
103
104 int
105 scm_ra_matchp (SCM ra0, SCM ras)
106 {
107 SCM ra1;
108 scm_t_array_dim dims;
109 scm_t_array_dim *s0 = &dims;
110 scm_t_array_dim *s1;
111 unsigned long bas0 = 0;
112 int i, ndim = 1;
113 int exact = 2 /* 4 */ ; /* Don't care about values >2 (yet?) */
114
115 if (scm_is_generalized_vector (ra0))
116 {
117 s0->lbnd = 0;
118 s0->inc = 1;
119 s0->ubnd = scm_c_generalized_vector_length (ra0) - 1;
120 }
121 else if (SCM_ARRAYP (ra0))
122 {
123 ndim = SCM_ARRAY_NDIM (ra0);
124 s0 = SCM_ARRAY_DIMS (ra0);
125 bas0 = SCM_ARRAY_BASE (ra0);
126 }
127 else
128 return 0;
129
130 while (SCM_NIMP (ras))
131 {
132 ra1 = SCM_CAR (ras);
133
134 if (scm_is_generalized_vector (ra1))
135 {
136 size_t length;
137
138 if (1 != ndim)
139 return 0;
140
141 length = scm_c_generalized_vector_length (ra1);
142
143 switch (exact)
144 {
145 case 4:
146 if (0 != bas0)
147 exact = 3;
148 case 3:
149 if (1 != s0->inc)
150 exact = 2;
151 case 2:
152 if ((0 == s0->lbnd) && (s0->ubnd == length - 1))
153 break;
154 exact = 1;
155 case 1:
156 if (s0->lbnd < 0 || s0->ubnd >= length)
157 return 0;
158 }
159 }
160 else if (SCM_ARRAYP (ra1) && ndim == SCM_ARRAY_NDIM (ra1))
161 {
162 s1 = SCM_ARRAY_DIMS (ra1);
163 if (bas0 != SCM_ARRAY_BASE (ra1))
164 exact = 3;
165 for (i = 0; i < ndim; i++)
166 switch (exact)
167 {
168 case 4:
169 case 3:
170 if (s0[i].inc != s1[i].inc)
171 exact = 2;
172 case 2:
173 if (s0[i].lbnd == s1[i].lbnd && s0[i].ubnd == s1[i].ubnd)
174 break;
175 exact = 1;
176 default:
177 if (s0[i].lbnd < s1[i].lbnd || s0[i].ubnd > s1[i].ubnd)
178 return (s0[i].lbnd <= s0[i].ubnd ? 0 : 1);
179 }
180 }
181 else
182 return 0;
183
184 ras = SCM_CDR (ras);
185 }
186
187 return exact;
188 }
189
190 /* array mapper: apply cproc to each dimension of the given arrays?.
191 int (*cproc) (); procedure to call on unrolled arrays?
192 cproc (dest, source list) or
193 cproc (dest, data, source list).
194 SCM data; data to give to cproc or unbound.
195 SCM ra0; destination array.
196 SCM lra; list of source arrays.
197 const char *what; caller, for error reporting. */
198 int
199 scm_ramapc (int (*cproc)(), SCM data, SCM ra0, SCM lra, const char *what)
200 {
201 SCM z;
202 SCM vra0, ra1, vra1;
203 SCM lvra, *plvra;
204 long *vinds;
205 int k, kmax;
206 switch (scm_ra_matchp (ra0, lra))
207 {
208 default:
209 case 0:
210 scm_misc_error (what, "array shape mismatch: ~S", scm_list_1 (ra0));
211 case 2:
212 case 3:
213 case 4: /* Try unrolling arrays */
214 kmax = (SCM_ARRAYP (ra0) ? SCM_ARRAY_NDIM (ra0) - 1 : 0);
215 if (kmax < 0)
216 goto gencase;
217 vra0 = scm_array_contents (ra0, SCM_UNDEFINED);
218 if (SCM_IMP (vra0)) goto gencase;
219 if (!SCM_ARRAYP (vra0))
220 {
221 size_t length = scm_c_generalized_vector_length (vra0);
222 vra1 = scm_i_make_ra (1, 0);
223 SCM_ARRAY_BASE (vra1) = 0;
224 SCM_ARRAY_DIMS (vra1)->lbnd = 0;
225 SCM_ARRAY_DIMS (vra1)->ubnd = length - 1;
226 SCM_ARRAY_DIMS (vra1)->inc = 1;
227 SCM_ARRAY_V (vra1) = vra0;
228 vra0 = vra1;
229 }
230 lvra = SCM_EOL;
231 plvra = &lvra;
232 for (z = lra; SCM_NIMP (z); z = SCM_CDR (z))
233 {
234 ra1 = SCM_CAR (z);
235 vra1 = scm_i_make_ra (1, 0);
236 SCM_ARRAY_DIMS (vra1)->lbnd = SCM_ARRAY_DIMS (vra0)->lbnd;
237 SCM_ARRAY_DIMS (vra1)->ubnd = SCM_ARRAY_DIMS (vra0)->ubnd;
238 if (!SCM_ARRAYP (ra1))
239 {
240 SCM_ARRAY_BASE (vra1) = 0;
241 SCM_ARRAY_DIMS (vra1)->inc = 1;
242 SCM_ARRAY_V (vra1) = ra1;
243 }
244 else if (!SCM_ARRAY_CONTP (ra1))
245 goto gencase;
246 else
247 {
248 SCM_ARRAY_BASE (vra1) = SCM_ARRAY_BASE (ra1);
249 SCM_ARRAY_DIMS (vra1)->inc = SCM_ARRAY_DIMS (ra1)[kmax].inc;
250 SCM_ARRAY_V (vra1) = SCM_ARRAY_V (ra1);
251 }
252 *plvra = scm_cons (vra1, SCM_EOL);
253 plvra = SCM_CDRLOC (*plvra);
254 }
255 return (SCM_UNBNDP (data) ? cproc(vra0, lvra) : cproc(vra0, data, lvra));
256 case 1:
257 gencase: /* Have to loop over all dimensions. */
258 vra0 = scm_i_make_ra (1, 0);
259 if (SCM_ARRAYP (ra0))
260 {
261 kmax = SCM_ARRAY_NDIM (ra0) - 1;
262 if (kmax < 0)
263 {
264 SCM_ARRAY_DIMS (vra0)->lbnd = 0;
265 SCM_ARRAY_DIMS (vra0)->ubnd = 0;
266 SCM_ARRAY_DIMS (vra0)->inc = 1;
267 }
268 else
269 {
270 SCM_ARRAY_DIMS (vra0)->lbnd = SCM_ARRAY_DIMS (ra0)[kmax].lbnd;
271 SCM_ARRAY_DIMS (vra0)->ubnd = SCM_ARRAY_DIMS (ra0)[kmax].ubnd;
272 SCM_ARRAY_DIMS (vra0)->inc = SCM_ARRAY_DIMS (ra0)[kmax].inc;
273 }
274 SCM_ARRAY_BASE (vra0) = SCM_ARRAY_BASE (ra0);
275 SCM_ARRAY_V (vra0) = SCM_ARRAY_V (ra0);
276 }
277 else
278 {
279 size_t length = scm_c_generalized_vector_length (ra0);
280 kmax = 0;
281 SCM_ARRAY_DIMS (vra0)->lbnd = 0;
282 SCM_ARRAY_DIMS (vra0)->ubnd = length - 1;
283 SCM_ARRAY_DIMS (vra0)->inc = 1;
284 SCM_ARRAY_BASE (vra0) = 0;
285 SCM_ARRAY_V (vra0) = ra0;
286 ra0 = vra0;
287 }
288 lvra = SCM_EOL;
289 plvra = &lvra;
290 for (z = lra; SCM_NIMP (z); z = SCM_CDR (z))
291 {
292 ra1 = SCM_CAR (z);
293 vra1 = scm_i_make_ra (1, 0);
294 SCM_ARRAY_DIMS (vra1)->lbnd = SCM_ARRAY_DIMS (vra0)->lbnd;
295 SCM_ARRAY_DIMS (vra1)->ubnd = SCM_ARRAY_DIMS (vra0)->ubnd;
296 if (SCM_ARRAYP (ra1))
297 {
298 if (kmax >= 0)
299 SCM_ARRAY_DIMS (vra1)->inc = SCM_ARRAY_DIMS (ra1)[kmax].inc;
300 SCM_ARRAY_V (vra1) = SCM_ARRAY_V (ra1);
301 }
302 else
303 {
304 SCM_ARRAY_DIMS (vra1)->inc = 1;
305 SCM_ARRAY_V (vra1) = ra1;
306 }
307 *plvra = scm_cons (vra1, SCM_EOL);
308 plvra = SCM_CDRLOC (*plvra);
309 }
310
311 scm_frame_begin (0);
312
313 vinds = scm_malloc (sizeof(long) * SCM_ARRAY_NDIM (ra0));
314 scm_frame_free (vinds);
315
316 for (k = 0; k <= kmax; k++)
317 vinds[k] = SCM_ARRAY_DIMS (ra0)[k].lbnd;
318 k = kmax;
319 do
320 {
321 if (k == kmax)
322 {
323 SCM y = lra;
324 SCM_ARRAY_BASE (vra0) = cind (ra0, vinds);
325 for (z = lvra; SCM_NIMP (z); z = SCM_CDR (z), y = SCM_CDR (y))
326 SCM_ARRAY_BASE (SCM_CAR (z)) = cind (SCM_CAR (y), vinds);
327 if (0 == (SCM_UNBNDP (data) ? cproc(vra0, lvra) : cproc(vra0, data, lvra)))
328 return 0;
329 k--;
330 continue;
331 }
332 if (vinds[k] < SCM_ARRAY_DIMS (ra0)[k].ubnd)
333 {
334 vinds[k]++;
335 k++;
336 continue;
337 }
338 vinds[k] = SCM_ARRAY_DIMS (ra0)[k].lbnd - 1;
339 k--;
340 }
341 while (k >= 0);
342
343 scm_frame_end ();
344 return 1;
345 }
346 }
347
348
349 SCM_DEFINE (scm_array_fill_x, "array-fill!", 2, 0, 0,
350 (SCM ra, SCM fill),
351 "Store @var{fill} in every element of @var{array}. The value returned\n"
352 "is unspecified.")
353 #define FUNC_NAME s_scm_array_fill_x
354 {
355 scm_ramapc (scm_array_fill_int, fill, ra, SCM_EOL, FUNC_NAME);
356 return SCM_UNSPECIFIED;
357 }
358 #undef FUNC_NAME
359
360 /* to be used as cproc in scm_ramapc to fill an array dimension with
361 "fill". */
362 int
363 scm_array_fill_int (SCM ra, SCM fill, SCM ignore SCM_UNUSED)
364 #define FUNC_NAME s_scm_array_fill_x
365 {
366 unsigned long i;
367 unsigned long n = SCM_ARRAY_DIMS (ra)->ubnd - SCM_ARRAY_DIMS (ra)->lbnd + 1;
368 long inc = SCM_ARRAY_DIMS (ra)->inc;
369 unsigned long base = SCM_ARRAY_BASE (ra);
370
371 ra = SCM_ARRAY_V (ra);
372
373 for (i = base; n--; i += inc)
374 GVSET (ra, i, fill);
375
376 return 1;
377 }
378 #undef FUNC_NAME
379
380
381
382 static int
383 racp (SCM src, SCM dst)
384 {
385 long n = (SCM_ARRAY_DIMS (src)->ubnd - SCM_ARRAY_DIMS (src)->lbnd + 1);
386 long inc_d, inc_s = SCM_ARRAY_DIMS (src)->inc;
387 unsigned long i_d, i_s = SCM_ARRAY_BASE (src);
388 dst = SCM_CAR (dst);
389 inc_d = SCM_ARRAY_DIMS (dst)->inc;
390 i_d = SCM_ARRAY_BASE (dst);
391 src = SCM_ARRAY_V (src);
392 dst = SCM_ARRAY_V (dst);
393
394 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
395 GVSET (dst, i_d, GVREF (src, i_s));
396 return 1;
397 }
398
399 SCM_REGISTER_PROC(s_array_copy_in_order_x, "array-copy-in-order!", 2, 0, 0, scm_array_copy_x);
400
401
402 SCM_DEFINE (scm_array_copy_x, "array-copy!", 2, 0, 0,
403 (SCM src, SCM dst),
404 "@deffnx {Scheme Procedure} array-copy-in-order! src dst\n"
405 "Copy every element from vector or array @var{source} to the\n"
406 "corresponding element of @var{destination}. @var{destination} must have\n"
407 "the same rank as @var{source}, and be at least as large in each\n"
408 "dimension. The order is unspecified.")
409 #define FUNC_NAME s_scm_array_copy_x
410 {
411 scm_ramapc (racp, SCM_UNDEFINED, src, scm_cons (dst, SCM_EOL), FUNC_NAME);
412 return SCM_UNSPECIFIED;
413 }
414 #undef FUNC_NAME
415
416 /* Functions callable by ARRAY-MAP! */
417
418
419 int
420 scm_ra_eqp (SCM ra0, SCM ras)
421 {
422 SCM ra1 = SCM_CAR (ras), ra2 = SCM_CAR (SCM_CDR (ras));
423 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
424 unsigned long i0 = SCM_ARRAY_BASE (ra0), i1 = SCM_ARRAY_BASE (ra1), i2 = SCM_ARRAY_BASE (ra2);
425 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
426 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
427 long inc2 = SCM_ARRAY_DIMS (ra1)->inc;
428 ra0 = SCM_ARRAY_V (ra0);
429 ra1 = SCM_ARRAY_V (ra1);
430 ra2 = SCM_ARRAY_V (ra2);
431
432 {
433 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
434 if (scm_is_true (scm_c_bitvector_ref (ra0, i0)))
435 if (!scm_is_eq (GVREF (ra1, i1), GVREF (ra2, i2)))
436 scm_c_bitvector_set_x (ra0, i0, SCM_BOOL_F);
437 }
438
439 return 1;
440 }
441
442 /* opt 0 means <, nonzero means >= */
443
444 static int
445 ra_compare (SCM ra0, SCM ra1, SCM ra2, int opt)
446 {
447 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
448 unsigned long i0 = SCM_ARRAY_BASE (ra0), i1 = SCM_ARRAY_BASE (ra1), i2 = SCM_ARRAY_BASE (ra2);
449 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
450 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
451 long inc2 = SCM_ARRAY_DIMS (ra1)->inc;
452 ra0 = SCM_ARRAY_V (ra0);
453 ra1 = SCM_ARRAY_V (ra1);
454 ra2 = SCM_ARRAY_V (ra2);
455
456 {
457 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
458 if (scm_is_true (scm_c_bitvector_ref (ra0, i0)))
459 if (opt ?
460 scm_is_true (scm_less_p (GVREF (ra1, i1), GVREF (ra2, i2))) :
461 scm_is_false (scm_less_p (GVREF (ra1, i1), GVREF (ra2, i2))))
462 scm_c_bitvector_set_x (ra0, i0, SCM_BOOL_F);
463 }
464
465 return 1;
466 }
467
468
469
470 int
471 scm_ra_lessp (SCM ra0, SCM ras)
472 {
473 return ra_compare (ra0, SCM_CAR (ras), SCM_CAR (SCM_CDR (ras)), 0);
474 }
475
476
477 int
478 scm_ra_leqp (SCM ra0, SCM ras)
479 {
480 return ra_compare (ra0, SCM_CAR (SCM_CDR (ras)), SCM_CAR (ras), 1);
481 }
482
483
484 int
485 scm_ra_grp (SCM ra0, SCM ras)
486 {
487 return ra_compare (ra0, SCM_CAR (SCM_CDR (ras)), SCM_CAR (ras), 0);
488 }
489
490
491 int
492 scm_ra_greqp (SCM ra0, SCM ras)
493 {
494 return ra_compare (ra0, SCM_CAR (ras), SCM_CAR (SCM_CDR (ras)), 1);
495 }
496
497
498 int
499 scm_ra_sum (SCM ra0, SCM ras)
500 {
501 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
502 unsigned long i0 = SCM_ARRAY_BASE (ra0);
503 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
504 ra0 = SCM_ARRAY_V (ra0);
505 if (!scm_is_null(ras))
506 {
507 SCM ra1 = SCM_CAR (ras);
508 unsigned long i1 = SCM_ARRAY_BASE (ra1);
509 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
510 ra1 = SCM_ARRAY_V (ra1);
511 switch (SCM_TYP7 (ra0) == SCM_TYP7 (ra1) ? SCM_TYP7 (ra0) : 0)
512 {
513 default:
514 {
515 for (; n-- > 0; i0 += inc0, i1 += inc1)
516 GVSET (ra0, i0, scm_sum (GVREF(ra0, i0), GVREF(ra1, i1)));
517 break;
518 }
519 }
520 }
521 return 1;
522 }
523
524
525
526 int
527 scm_ra_difference (SCM ra0, SCM ras)
528 {
529 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
530 unsigned long i0 = SCM_ARRAY_BASE (ra0);
531 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
532 ra0 = SCM_ARRAY_V (ra0);
533 if (scm_is_null (ras))
534 {
535 switch (SCM_TYP7 (ra0))
536 {
537 default:
538 {
539 for (; n-- > 0; i0 += inc0)
540 GVSET (ra0, i0, scm_difference (GVREF(ra0, i0), SCM_UNDEFINED));
541 break;
542 }
543 }
544 }
545 else
546 {
547 SCM ra1 = SCM_CAR (ras);
548 unsigned long i1 = SCM_ARRAY_BASE (ra1);
549 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
550 ra1 = SCM_ARRAY_V (ra1);
551 switch (SCM_TYP7 (ra0) == SCM_TYP7 (ra1) ? SCM_TYP7 (ra0) : 0)
552 {
553 default:
554 {
555 for (; n-- > 0; i0 += inc0, i1 += inc1)
556 GVSET (ra0, i0, scm_difference (GVREF (ra0, i0),
557 GVREF (ra1, i1)));
558 break;
559 }
560 }
561 }
562 return 1;
563 }
564
565
566
567 int
568 scm_ra_product (SCM ra0, SCM ras)
569 {
570 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
571 unsigned long i0 = SCM_ARRAY_BASE (ra0);
572 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
573 ra0 = SCM_ARRAY_V (ra0);
574 if (!scm_is_null (ras))
575 {
576 SCM ra1 = SCM_CAR (ras);
577 unsigned long i1 = SCM_ARRAY_BASE (ra1);
578 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
579 ra1 = SCM_ARRAY_V (ra1);
580 switch (SCM_TYP7 (ra0) == SCM_TYP7 (ra1) ? SCM_TYP7 (ra0) : 0)
581 {
582 default:
583 {
584 for (; n-- > 0; i0 += inc0, i1 += inc1)
585 GVSET (ra0, i0, scm_product (GVREF (ra0, i0),
586 GVREF (ra1, i1)));
587 }
588 }
589 }
590 return 1;
591 }
592
593
594 int
595 scm_ra_divide (SCM ra0, SCM ras)
596 {
597 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
598 unsigned long i0 = SCM_ARRAY_BASE (ra0);
599 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
600 ra0 = SCM_ARRAY_V (ra0);
601 if (scm_is_null (ras))
602 {
603 switch (SCM_TYP7 (ra0))
604 {
605 default:
606 {
607 for (; n-- > 0; i0 += inc0)
608 GVSET (ra0, i0, scm_divide (GVREF (ra0, i0), SCM_UNDEFINED));
609 break;
610 }
611 }
612 }
613 else
614 {
615 SCM ra1 = SCM_CAR (ras);
616 unsigned long i1 = SCM_ARRAY_BASE (ra1);
617 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
618 ra1 = SCM_ARRAY_V (ra1);
619 switch (SCM_TYP7 (ra0) == SCM_TYP7 (ra1) ? SCM_TYP7 (ra0) : 0)
620 {
621 default:
622 {
623 for (; n-- > 0; i0 += inc0, i1 += inc1)
624 {
625 SCM res = scm_divide (GVREF (ra0, i0),
626 GVREF (ra1, i1));
627 GVSET (ra0, i0, res);
628 }
629 break;
630 }
631 }
632 }
633 return 1;
634 }
635
636
637 int
638 scm_array_identity (SCM dst, SCM src)
639 {
640 return racp (SCM_CAR (src), scm_cons (dst, SCM_EOL));
641 }
642
643
644
645 static int
646 ramap (SCM ra0, SCM proc, SCM ras)
647 {
648 long i = SCM_ARRAY_DIMS (ra0)->lbnd;
649 long inc = SCM_ARRAY_DIMS (ra0)->inc;
650 long n = SCM_ARRAY_DIMS (ra0)->ubnd;
651 long base = SCM_ARRAY_BASE (ra0) - i * inc;
652 ra0 = SCM_ARRAY_V (ra0);
653 if (scm_is_null (ras))
654 for (; i <= n; i++)
655 GVSET (ra0, i*inc+base, scm_call_0 (proc));
656 else
657 {
658 SCM ra1 = SCM_CAR (ras);
659 SCM args;
660 unsigned long k, i1 = SCM_ARRAY_BASE (ra1);
661 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
662 ra1 = SCM_ARRAY_V (ra1);
663 ras = SCM_CDR (ras);
664 if (scm_is_null(ras))
665 ras = scm_nullvect;
666 else
667 ras = scm_vector (ras);
668
669 for (; i <= n; i++, i1 += inc1)
670 {
671 args = SCM_EOL;
672 for (k = scm_c_vector_length (ras); k--;)
673 args = scm_cons (GVREF (scm_c_vector_ref (ras, k), i), args);
674 args = scm_cons (GVREF (ra1, i1), args);
675 GVSET (ra0, i*inc+base, scm_apply_0 (proc, args));
676 }
677 }
678 return 1;
679 }
680
681
682 static int
683 ramap_dsubr (SCM ra0, SCM proc, SCM ras)
684 {
685 SCM ra1 = SCM_CAR (ras);
686 unsigned long i0 = SCM_ARRAY_BASE (ra0), i1 = SCM_ARRAY_BASE (ra1);
687 long inc0 = SCM_ARRAY_DIMS (ra0)->inc, inc1 = SCM_ARRAY_DIMS (ra1)->inc;
688 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra1)->lbnd + 1;
689 ra0 = SCM_ARRAY_V (ra0);
690 ra1 = SCM_ARRAY_V (ra1);
691 switch (SCM_TYP7 (ra0))
692 {
693 default:
694 for (; n-- > 0; i0 += inc0, i1 += inc1)
695 GVSET (ra0, i0, scm_call_1 (proc, GVREF (ra1, i1)));
696 break;
697 }
698 return 1;
699 }
700
701
702
703 static int
704 ramap_rp (SCM ra0, SCM proc, SCM ras)
705 {
706 SCM ra1 = SCM_CAR (ras), ra2 = SCM_CAR (SCM_CDR (ras));
707 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
708 unsigned long i0 = SCM_ARRAY_BASE (ra0), i1 = SCM_ARRAY_BASE (ra1), i2 = SCM_ARRAY_BASE (ra2);
709 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
710 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
711 long inc2 = SCM_ARRAY_DIMS (ra1)->inc;
712 ra0 = SCM_ARRAY_V (ra0);
713 ra1 = SCM_ARRAY_V (ra1);
714 ra2 = SCM_ARRAY_V (ra2);
715
716 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
717 if (scm_is_true (scm_c_bitvector_ref (ra0, i0)))
718 if (scm_is_false (SCM_SUBRF (proc) (GVREF (ra1, i1), GVREF (ra2, i2))))
719 scm_c_bitvector_set_x (ra0, i0, SCM_BOOL_F);
720
721 return 1;
722 }
723
724
725
726 static int
727 ramap_1 (SCM ra0, SCM proc, SCM ras)
728 {
729 SCM ra1 = SCM_CAR (ras);
730 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
731 unsigned long i0 = SCM_ARRAY_BASE (ra0), i1 = SCM_ARRAY_BASE (ra1);
732 long inc0 = SCM_ARRAY_DIMS (ra0)->inc, inc1 = SCM_ARRAY_DIMS (ra1)->inc;
733 ra0 = SCM_ARRAY_V (ra0);
734 ra1 = SCM_ARRAY_V (ra1);
735 if (scm_tc7_vector == SCM_TYP7 (ra0) || scm_tc7_wvect == SCM_TYP7 (ra0))
736 for (; n-- > 0; i0 += inc0, i1 += inc1)
737 GVSET (ra0, i0, SCM_SUBRF (proc) (GVREF (ra1, i1)));
738 else
739 for (; n-- > 0; i0 += inc0, i1 += inc1)
740 GVSET (ra0, i0, SCM_SUBRF (proc) (GVREF (ra1, i1)));
741 return 1;
742 }
743
744
745
746 static int
747 ramap_2o (SCM ra0, SCM proc, SCM ras)
748 {
749 SCM ra1 = SCM_CAR (ras);
750 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
751 unsigned long i0 = SCM_ARRAY_BASE (ra0), i1 = SCM_ARRAY_BASE (ra1);
752 long inc0 = SCM_ARRAY_DIMS (ra0)->inc, inc1 = SCM_ARRAY_DIMS (ra1)->inc;
753 ra0 = SCM_ARRAY_V (ra0);
754 ra1 = SCM_ARRAY_V (ra1);
755 ras = SCM_CDR (ras);
756 if (scm_is_null (ras))
757 {
758 for (; n-- > 0; i0 += inc0, i1 += inc1)
759 GVSET (ra0, i0, SCM_SUBRF (proc) (GVREF (ra1, i1), SCM_UNDEFINED));
760 }
761 else
762 {
763 SCM ra2 = SCM_CAR (ras);
764 unsigned long i2 = SCM_ARRAY_BASE (ra2);
765 long inc2 = SCM_ARRAY_DIMS (ra2)->inc;
766 ra2 = SCM_ARRAY_V (ra2);
767 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
768 GVSET (ra0, i0, SCM_SUBRF (proc) (GVREF (ra1, i1), GVREF (ra2, i2)));
769 }
770 return 1;
771 }
772
773
774
775 static int
776 ramap_a (SCM ra0, SCM proc, SCM ras)
777 {
778 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
779 unsigned long i0 = SCM_ARRAY_BASE (ra0);
780 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
781 ra0 = SCM_ARRAY_V (ra0);
782 if (scm_is_null (ras))
783 for (; n-- > 0; i0 += inc0)
784 GVSET (ra0, i0, SCM_SUBRF (proc) (GVREF (ra0, i0), SCM_UNDEFINED));
785 else
786 {
787 SCM ra1 = SCM_CAR (ras);
788 unsigned long i1 = SCM_ARRAY_BASE (ra1);
789 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
790 ra1 = SCM_ARRAY_V (ra1);
791 for (; n-- > 0; i0 += inc0, i1 += inc1)
792 GVSET (ra0, i0, SCM_SUBRF (proc) (GVREF (ra0, i0), GVREF (ra1, i1)));
793 }
794 return 1;
795 }
796
797
798 SCM_REGISTER_PROC(s_array_map_in_order_x, "array-map-in-order!", 2, 0, 1, scm_array_map_x);
799
800
801 SCM_DEFINE (scm_array_map_x, "array-map!", 2, 0, 1,
802 (SCM ra0, SCM proc, SCM lra),
803 "@deffnx {Scheme Procedure} array-map-in-order! ra0 proc . lra\n"
804 "@var{array1}, @dots{} must have the same number of dimensions as\n"
805 "@var{array0} and have a range for each index which includes the range\n"
806 "for the corresponding index in @var{array0}. @var{proc} is applied to\n"
807 "each tuple of elements of @var{array1} @dots{} and the result is stored\n"
808 "as the corresponding element in @var{array0}. The value returned is\n"
809 "unspecified. The order of application is unspecified.")
810 #define FUNC_NAME s_scm_array_map_x
811 {
812 SCM_VALIDATE_PROC (2, proc);
813 SCM_VALIDATE_REST_ARGUMENT (lra);
814 /* This is done as a test on lra, rather than an extra mandatory parameter
815 eval could check, so that the prototype for scm_array_map_x stays as it
816 was in the past. scm_array_map_x isn't actually documented, but did
817 get a mention in the NEWS file, so is best left alone. */
818 if (scm_is_null (lra))
819 SCM_WRONG_NUM_ARGS ();
820 switch (SCM_TYP7 (proc))
821 {
822 default:
823 gencase:
824 scm_ramapc (ramap, proc, ra0, lra, FUNC_NAME);
825 return SCM_UNSPECIFIED;
826 case scm_tc7_subr_1:
827 scm_ramapc (ramap_1, proc, ra0, lra, FUNC_NAME);
828 return SCM_UNSPECIFIED;
829 case scm_tc7_subr_2:
830 case scm_tc7_subr_2o:
831 scm_ramapc (ramap_2o, proc, ra0, lra, FUNC_NAME);
832 return SCM_UNSPECIFIED;
833 case scm_tc7_dsubr:
834 scm_ramapc (ramap_dsubr, proc, ra0, lra, FUNC_NAME);
835 return SCM_UNSPECIFIED;
836 case scm_tc7_rpsubr:
837 {
838 ra_iproc *p;
839 if (scm_is_false (scm_array_p (ra0, SCM_BOOL_T)))
840 goto gencase;
841 scm_array_fill_x (ra0, SCM_BOOL_T);
842 for (p = ra_rpsubrs; p->name; p++)
843 if (scm_is_eq (proc, p->sproc))
844 {
845 while (!scm_is_null (lra) && !scm_is_null (SCM_CDR (lra)))
846 {
847 scm_ramapc (p->vproc, SCM_UNDEFINED, ra0, lra, FUNC_NAME);
848 lra = SCM_CDR (lra);
849 }
850 return SCM_UNSPECIFIED;
851 }
852 while (!scm_is_null (lra) && !scm_is_null (SCM_CDR (lra)))
853 {
854 scm_ramapc (ramap_rp, proc, ra0, lra, FUNC_NAME);
855 lra = SCM_CDR (lra);
856 }
857 return SCM_UNSPECIFIED;
858 }
859 case scm_tc7_asubr:
860 if (scm_is_null (lra))
861 {
862 SCM fill = SCM_SUBRF (proc) (SCM_UNDEFINED, SCM_UNDEFINED);
863 scm_array_fill_x (ra0, fill);
864 }
865 else
866 {
867 SCM tail, ra1 = SCM_CAR (lra);
868 SCM v0 = (SCM_ARRAYP (ra0) ? SCM_ARRAY_V (ra0) : ra0);
869 ra_iproc *p;
870 /* Check to see if order might matter.
871 This might be an argument for a separate
872 SERIAL-ARRAY-MAP! */
873 if (scm_is_eq (v0, ra1)
874 || (SCM_ARRAYP (ra1) && scm_is_eq (v0, SCM_ARRAY_V (ra1))))
875 if (!scm_is_eq (ra0, ra1)
876 || (SCM_ARRAYP(ra0) && !SCM_ARRAY_CONTP(ra0)))
877 goto gencase;
878 for (tail = SCM_CDR (lra); !scm_is_null (tail); tail = SCM_CDR (tail))
879 {
880 ra1 = SCM_CAR (tail);
881 if (scm_is_eq (v0, ra1)
882 || (SCM_ARRAYP (ra1) && scm_is_eq (v0, SCM_ARRAY_V (ra1))))
883 goto gencase;
884 }
885 for (p = ra_asubrs; p->name; p++)
886 if (scm_is_eq (proc, p->sproc))
887 {
888 if (!scm_is_eq (ra0, SCM_CAR (lra)))
889 scm_ramapc (scm_array_identity, SCM_UNDEFINED, ra0, scm_cons (SCM_CAR (lra), SCM_EOL), FUNC_NAME);
890 lra = SCM_CDR (lra);
891 while (1)
892 {
893 scm_ramapc (p->vproc, SCM_UNDEFINED, ra0, lra, FUNC_NAME);
894 if (SCM_IMP (lra) || SCM_IMP (SCM_CDR (lra)))
895 return SCM_UNSPECIFIED;
896 lra = SCM_CDR (lra);
897 }
898 }
899 scm_ramapc (ramap_2o, proc, ra0, lra, FUNC_NAME);
900 lra = SCM_CDR (lra);
901 if (SCM_NIMP (lra))
902 for (lra = SCM_CDR (lra); SCM_NIMP (lra); lra = SCM_CDR (lra))
903 scm_ramapc (ramap_a, proc, ra0, lra, FUNC_NAME);
904 }
905 return SCM_UNSPECIFIED;
906 }
907 }
908 #undef FUNC_NAME
909
910
911 static int
912 rafe (SCM ra0, SCM proc, SCM ras)
913 {
914 long i = SCM_ARRAY_DIMS (ra0)->lbnd;
915 unsigned long i0 = SCM_ARRAY_BASE (ra0);
916 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
917 long n = SCM_ARRAY_DIMS (ra0)->ubnd;
918 ra0 = SCM_ARRAY_V (ra0);
919 if (scm_is_null (ras))
920 for (; i <= n; i++, i0 += inc0)
921 scm_call_1 (proc, GVREF (ra0, i0));
922 else
923 {
924 SCM ra1 = SCM_CAR (ras);
925 SCM args;
926 unsigned long k, i1 = SCM_ARRAY_BASE (ra1);
927 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
928 ra1 = SCM_ARRAY_V (ra1);
929 ras = SCM_CDR (ras);
930 if (scm_is_null(ras))
931 ras = scm_nullvect;
932 else
933 ras = scm_vector (ras);
934 for (; i <= n; i++, i0 += inc0, i1 += inc1)
935 {
936 args = SCM_EOL;
937 for (k = scm_c_vector_length (ras); k--;)
938 args = scm_cons (GVREF (scm_c_vector_ref (ras, k), i), args);
939 args = scm_cons2 (GVREF (ra0, i0), GVREF (ra1, i1), args);
940 scm_apply_0 (proc, args);
941 }
942 }
943 return 1;
944 }
945
946
947 SCM_DEFINE (scm_array_for_each, "array-for-each", 2, 0, 1,
948 (SCM proc, SCM ra0, SCM lra),
949 "Apply @var{proc} to each tuple of elements of @var{array0} @dots{}\n"
950 "in row-major order. The value returned is unspecified.")
951 #define FUNC_NAME s_scm_array_for_each
952 {
953 SCM_VALIDATE_PROC (1, proc);
954 SCM_VALIDATE_REST_ARGUMENT (lra);
955 scm_ramapc (rafe, proc, ra0, lra, FUNC_NAME);
956 return SCM_UNSPECIFIED;
957 }
958 #undef FUNC_NAME
959
960 SCM_DEFINE (scm_array_index_map_x, "array-index-map!", 2, 0, 0,
961 (SCM ra, SCM proc),
962 "Apply @var{proc} to the indices of each element of @var{array} in\n"
963 "turn, storing the result in the corresponding element. The value\n"
964 "returned and the order of application are unspecified.\n\n"
965 "One can implement @var{array-indexes} as\n"
966 "@lisp\n"
967 "(define (array-indexes array)\n"
968 " (let ((ra (apply make-array #f (array-shape array))))\n"
969 " (array-index-map! ra (lambda x x))\n"
970 " ra))\n"
971 "@end lisp\n"
972 "Another example:\n"
973 "@lisp\n"
974 "(define (apl:index-generator n)\n"
975 " (let ((v (make-uniform-vector n 1)))\n"
976 " (array-index-map! v (lambda (i) i))\n"
977 " v))\n"
978 "@end lisp")
979 #define FUNC_NAME s_scm_array_index_map_x
980 {
981 unsigned long i;
982 SCM_VALIDATE_PROC (2, proc);
983
984 if (scm_is_generalized_vector (ra))
985 {
986 size_t length = scm_c_generalized_vector_length (ra);
987 for (i = 0; i < length; i++)
988 GVSET (ra, i, scm_call_1 (proc, scm_from_ulong (i)));
989 return SCM_UNSPECIFIED;
990 }
991 else if (SCM_ARRAYP (ra))
992 {
993 SCM args = SCM_EOL;
994 int j, k, kmax = SCM_ARRAY_NDIM (ra) - 1;
995 long *vinds;
996
997 if (kmax < 0)
998 return scm_array_set_x (ra, scm_call_0 (proc), SCM_EOL);
999
1000 scm_frame_begin (0);
1001
1002 vinds = scm_malloc (sizeof(long) * SCM_ARRAY_NDIM (ra));
1003 scm_frame_free (vinds);
1004
1005 for (k = 0; k <= kmax; k++)
1006 vinds[k] = SCM_ARRAY_DIMS (ra)[k].lbnd;
1007 k = kmax;
1008 do
1009 {
1010 if (k == kmax)
1011 {
1012 vinds[k] = SCM_ARRAY_DIMS (ra)[k].lbnd;
1013 i = cind (ra, vinds);
1014 for (; vinds[k] <= SCM_ARRAY_DIMS (ra)[k].ubnd; vinds[k]++)
1015 {
1016 for (j = kmax + 1, args = SCM_EOL; j--;)
1017 args = scm_cons (scm_from_long (vinds[j]), args);
1018 GVSET (SCM_ARRAY_V (ra), i, scm_apply_0 (proc, args));
1019 i += SCM_ARRAY_DIMS (ra)[k].inc;
1020 }
1021 k--;
1022 continue;
1023 }
1024 if (vinds[k] < SCM_ARRAY_DIMS (ra)[k].ubnd)
1025 {
1026 vinds[k]++;
1027 k++;
1028 continue;
1029 }
1030 vinds[k] = SCM_ARRAY_DIMS (ra)[k].lbnd - 1;
1031 k--;
1032 }
1033 while (k >= 0);
1034
1035 scm_frame_end ();
1036 return SCM_UNSPECIFIED;
1037 }
1038 else
1039 scm_wrong_type_arg_msg (NULL, 0, ra, "array");
1040 }
1041 #undef FUNC_NAME
1042
1043
1044 static int
1045 raeql_1 (SCM ra0, SCM as_equal, SCM ra1)
1046 {
1047 unsigned long i0 = 0, i1 = 0;
1048 long inc0 = 1, inc1 = 1;
1049 unsigned long n;
1050 ra1 = SCM_CAR (ra1);
1051 if (SCM_ARRAYP(ra0))
1052 {
1053 n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
1054 i0 = SCM_ARRAY_BASE (ra0);
1055 inc0 = SCM_ARRAY_DIMS (ra0)->inc;
1056 ra0 = SCM_ARRAY_V (ra0);
1057 }
1058 else
1059 n = scm_c_generalized_vector_length (ra0);
1060
1061 if (SCM_ARRAYP (ra1))
1062 {
1063 i1 = SCM_ARRAY_BASE (ra1);
1064 inc1 = SCM_ARRAY_DIMS (ra1)->inc;
1065 ra1 = SCM_ARRAY_V (ra1);
1066 }
1067
1068 if (scm_is_generalized_vector (ra0))
1069 {
1070 for (; n--; i0 += inc0, i1 += inc1)
1071 {
1072 if (scm_is_false (as_equal))
1073 {
1074 if (scm_is_false (scm_array_equal_p (GVREF (ra0, i0), GVREF (ra1, i1))))
1075 return 0;
1076 }
1077 else if (scm_is_false (scm_equal_p (GVREF (ra0, i0), GVREF (ra1, i1))))
1078 return 0;
1079 }
1080 return 1;
1081 }
1082 else
1083 return 0;
1084 }
1085
1086
1087
1088 static int
1089 raeql (SCM ra0, SCM as_equal, SCM ra1)
1090 {
1091 SCM v0 = ra0, v1 = ra1;
1092 scm_t_array_dim dim0, dim1;
1093 scm_t_array_dim *s0 = &dim0, *s1 = &dim1;
1094 unsigned long bas0 = 0, bas1 = 0;
1095 int k, unroll = 1, vlen = 1, ndim = 1;
1096 if (SCM_ARRAYP (ra0))
1097 {
1098 ndim = SCM_ARRAY_NDIM (ra0);
1099 s0 = SCM_ARRAY_DIMS (ra0);
1100 bas0 = SCM_ARRAY_BASE (ra0);
1101 v0 = SCM_ARRAY_V (ra0);
1102 }
1103 else
1104 {
1105 s0->inc = 1;
1106 s0->lbnd = 0;
1107 s0->ubnd = scm_c_generalized_vector_length (v0) - 1;
1108 unroll = 0;
1109 }
1110 if (SCM_ARRAYP (ra1))
1111 {
1112 if (ndim != SCM_ARRAY_NDIM (ra1))
1113 return 0;
1114 s1 = SCM_ARRAY_DIMS (ra1);
1115 bas1 = SCM_ARRAY_BASE (ra1);
1116 v1 = SCM_ARRAY_V (ra1);
1117 }
1118 else
1119 {
1120 /*
1121 Huh ? Schizophrenic return type. --hwn
1122 */
1123 if (1 != ndim)
1124 return 0;
1125 s1->inc = 1;
1126 s1->lbnd = 0;
1127 s1->ubnd = scm_c_generalized_vector_length (v1) - 1;
1128 unroll = 0;
1129 }
1130 if (SCM_TYP7 (v0) != SCM_TYP7 (v1))
1131 return 0;
1132 for (k = ndim; k--;)
1133 {
1134 if (s0[k].lbnd != s1[k].lbnd || s0[k].ubnd != s1[k].ubnd)
1135 return 0;
1136 if (unroll)
1137 {
1138 unroll = (s0[k].inc == s1[k].inc);
1139 vlen *= s0[k].ubnd - s1[k].lbnd + 1;
1140 }
1141 }
1142 if (unroll && bas0 == bas1 && scm_is_eq (v0, v1))
1143 return 1;
1144 return scm_ramapc (raeql_1, as_equal, ra0, scm_cons (ra1, SCM_EOL), "");
1145 }
1146
1147
1148 SCM
1149 scm_raequal (SCM ra0, SCM ra1)
1150 {
1151 return scm_from_bool(raeql (ra0, SCM_BOOL_T, ra1));
1152 }
1153
1154 #if 0
1155 /* GJB:FIXME:: Why not use SCM_DEFINE1 for array-equal? */
1156 SCM_DEFINE1 (scm_array_equal_p, "array-equal?", scm_tc7_rpsubr,
1157 (SCM ra0, SCM ra1),
1158 "Return @code{#t} iff all arguments are arrays with the same\n"
1159 "shape, the same type, and have corresponding elements which are\n"
1160 "either @code{equal?} or @code{array-equal?}. This function\n"
1161 "differs from @code{equal?} in that a one dimensional shared\n"
1162 "array may be @var{array-equal?} but not @var{equal?} to a\n"
1163 "vector or uniform vector.")
1164 #define FUNC_NAME s_scm_array_equal_p
1165 {
1166 }
1167 #undef FUNC_NAME
1168 #endif
1169
1170 static char s_array_equal_p[] = "array-equal?";
1171
1172
1173 SCM
1174 scm_array_equal_p (SCM ra0, SCM ra1)
1175 {
1176 if (SCM_ARRAYP (ra0) || SCM_ARRAYP (ra1))
1177 return scm_from_bool(raeql (ra0, SCM_BOOL_F, ra1));
1178 return scm_equal_p (ra0, ra1);
1179 }
1180
1181
1182 static void
1183 init_raprocs (ra_iproc *subra)
1184 {
1185 for (; subra->name; subra++)
1186 {
1187 SCM sym = scm_from_locale_symbol (subra->name);
1188 SCM var =
1189 scm_sym2var (sym, scm_current_module_lookup_closure (), SCM_BOOL_F);
1190 if (var != SCM_BOOL_F)
1191 subra->sproc = SCM_VARIABLE_REF (var);
1192 else
1193 subra->sproc = SCM_BOOL_F;
1194 }
1195 }
1196
1197
1198 void
1199 scm_init_ramap ()
1200 {
1201 init_raprocs (ra_rpsubrs);
1202 init_raprocs (ra_asubrs);
1203 scm_c_define_subr (s_array_equal_p, scm_tc7_rpsubr, scm_array_equal_p);
1204 scm_smobs[SCM_TC2SMOBNUM (scm_tc16_array)].equalp = scm_raequal;
1205 #include "libguile/ramap.x"
1206 scm_add_feature (s_scm_array_for_each);
1207 }
1208
1209 /*
1210 Local Variables:
1211 c-file-style: "gnu"
1212 End:
1213 */