forked from scheme-requests-for-implementation/srfi-133
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrfi-133.html
2163 lines (2070 loc) · 69.3 KB
/
srfi-133.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- Non-indentation necessary for the commit check junk. -->
<title>SRFI 133: Vector Library (R7RS-compatible)</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="/srfi.css" type="text/css" />
<style type="text/css">
/* <![CDATA[ */
dt.ref {
font-weight: </i>;
}
dt.ref:before {
content: "[";
}
dt.ref:after {
content: "]";
}
dt.proc-index {
font-size: medium;
font-weight: </i>;
}
dt.type-spec {
font-family: monospace;
font-style: italic;
}
dt.proc-spec {
font-family: monospace;
}
code.example-call {
}
code.example-value {
}
code.example-value:before {
content: "=> "
}
/* ]]> */
</style>
</head>
<body>
<H1>Title</H1>
Vector Library (R7RS-compatible)
<H1>Author</H1>
<span class="srfi-author">John Cowan</span> (based on SRFI 43 by Taylor Campbell)
<h1>Issues</h1>
None at this time.
<h1 class="nonheader">Table of Contents</h1>
<ul class="outer">
<li>1. <a href="#Status">Status</a></li>
<li>2. <a href="#Abstract">Abstract</a></li>
<li>3. <a href="#Rationale">Rationale</a></li>
<li>4. <a href="#ProcIndex">Procedure Index</a></li>
<li>
5. <a href="#Procs">Procedures</a>
<ul>
<li>5.1. <a href="#Constructors">Constructors</a></li>
<li>5.2. <a href="#Predicates">Predicates</a></li>
<li>5.3. <a href="#Selectors">Selectors</a></li>
<li>5.4. <a href="#Iteration">Iteration</a></li>
<li>5.5. <a href="#Searching">Searching</a></li>
<li>5.6. <a href="#Mutators">Mutators</a></li>
<li>5.7. <a href="#Conversion">Conversion</a></li>
</ul>
</li>
<li>6. <a href="#SampImpl">Sample Implementation</a></li>
<li>7. <a href="#Acknowledgements">Acknowledgements</a></li>
<li>8. <a href="#References">References</a></li>
<li>9. <a href="#Copyright">Copyright</a></li>
</ul>
<h1 class="nonheader"><a name="Status">1. Status</a></h1>
<p>This SRFI is currently in <em><span class="srfi-status">final</span></em> status. Here is <a href="http://srfi.schemers.org/srfi-process.html">an explanation</a> of each status that a SRFI can hold. To provide input on this SRFI, please send email to <code><a href="mailto:srfi+minus+133+at+srfi+dotschemers+dot+org">srfi-133@<span class="antispam">nospam</span>srfi.schemers.org</a></code>. To subscribe to the list, follow <a href="http://srfi.schemers.org/srfi-list-subscribe.html">these instructions</a>. You can access previous messages via the mailing list <a href="http://srfi-email.schemers.org/srfi-133">archive</a>.</p>
<ul>
<li class="srfi-revision">Received: <time>2015/12/15</time></li>
<li class="srfi-revision">60-day deadline: <time>2016/2/14</time></li>
<li class="srfi-revision">Draft #1 published: <time>2015/12/16</time></li>
<li class="srfi-revision">Draft #2 published: <time>2016/1/24</time></li>
<li class="srfi-revision">Draft #3 published: <time>2016/1/31</time></li>
<li class="srfi-revision">Draft #4 published: <time>2016/3/12</time></li>
<li class="srfi-revision">Finalized: <time>2016/3/20</time></li>
<li>Revised to fix errata:
<ul>
<li class="srfi-revision"><time>2016/4/1</time> (Fixed description of <code>vector-unfold!</code>)</li>
<li class="srfi-revision"><time>2016/8/10</time> (Fixed typos.)</li>
<li class="srfi-revision"><time>2016/9/2</time> (Changed order of arguments to <code>vector-cumulate</code>
from <code>(vector-cumulate f vec knil)</code> to
<code>(vector-cumulate f knil vec)</code> to match the
argument order of <tt>vector-fold</tt>.)</li>
<li class="srfi-revision"><time>2017/6/5</time> (Added second return type of <code>vector-partition</code>.)</li>
<li class="srfi-revision"><time>2018/7/4</time> (Removed requirement that <code>elt=?</code>
argument be consistent with <code>eq?</code>.)</li>
<li class="srfi-revision"><time>2018/10/27</time> (Fixed typos.)</li></ul></ul>
<p><b>Post-finalization note</b>: The finalized version of this
SRFI required the equality operator used by the
<code>vector=</code> procedure to be consistent with
<code>eq?</code>. However, <code>=</code> is not consistent
with <code>eq?</code> in a Scheme which provides NaN values and
IEEE semantics for them, as <code>(eq? +nan.0 +nan.0)</code> may
return either <code>#t</code> or <code>#f</code> but <code>(=
+nan.0 +nan.0)</code> must return <code>#f. </code> This means
that the expected semantics of <code>=</code> when used with
<code>vector=</code> are violated. Therefore, the requirement
for consistency has been removed from this version, and the
sample implementation adjusted accordingly.</p>
<h1 class="nonheader"><a name="Abstract">2. Abstract</a></h1>
<p class="srfi-abstract">
This <a href="#SRFI">SRFI</a> proposes a comprehensive
library of vector operations accompanied by a freely
available and complete reference implementation. The reference
implementation is unencumbered by copyright, and useable with no
modifications on any Scheme system that is
<a href="#R5RS">R5RS</a>-compliant. It also provides several
hooks for implementation-specific optimization as well.
</p>
<h1 class="nonheader"><a name="Rationale">3. Rationale</a></h1>
<p>
<a href="#R5RS">R5RS</a> provides very few list-processing
procedures, for which reason <a href="#SRFI-1">SRFI 1</a> exists. However,
<a href="#R5RS">R5RS</a> provides even fewer vector operations
— while it provides mapping, appending, et cetera
operations for lists, it specifies only nine vector manipulation
operations:
</p>
<ul class="indented">
<li><tt><a href="#vector-p">vector?</a></tt></li>
<li><tt><a href="#make-vector">make-vector</a></tt></li>
<li><tt><a href="#vector">vector</a></tt></li>
<li><tt><a href="#vector-length">vector-length</a></tt></li>
<li><tt><a href="#vector-ref">vector-ref</a></tt></li>
<li><tt><a href="#vector-set-bang">vector-set!</a></tt></li>
<li><tt><a href="#vector-to-list">vector->list</a></tt></li>
<li><tt><a href="#list-to-vector">list->vector</a></tt></li>
<li><tt><a href="#vector-fill-bang">vector-fill!</a></tt></li>
</ul>
<p>
<a href="#R7RS-small">R7RS-small</a> added support for
<i>start</i> and <i>end</i> arguments to <code>vector->list</code>,
<code>list->vector</code> and <code>vector-fill!</code>. It also
provided seven additional vector procedures, bringing vectors
and lists to approximate parity:
</p>
<ul class="indented">
<li><tt><a href="#vector-copy">vector-copy</a></tt></li>
<li><tt><a href="#vector-copy-bang">vector-copy!</a></tt></li>
<li><tt><a href="#vector-append">vector-append</a></tt></li>
<li><tt><a href="#vector-map">vector-map</a></tt></li>
<li><tt><a href="#vector-for-each">vector-for-each</a></tt></li>
<li><tt><a href="#vector-to-string">vector->string</a></tt></li>
<li><tt><a href="#string-to-vector">string->vector</a></tt></li>
</ul>
<p>
<a href="#SRFI-43">SRFI 43</a> standardized more vector procedures,
all of which are included in this SRFI. Unfortunately, R7RS-small
and SRFI 43 placed irreconcileable requirements on the procedures
invoked by <tt>vector-map</tt> and <tt>vector-for-each</tt>.
This SRFI resolves that issue by changing these SRFI 43
procedures as well as <tt>vector-map!</tt>, <tt>vector-fold</tt>,
<tt>vector-fold-right</tt>, and <tt>vector-count</tt> to leave
out the <var>index</var> argument that is passed under SRFI 43's
definition.<p>
<p>In addition, the version of <code>vector-copy</code> in this SRFI
does not require support for a <var>fill</var> argument, which
makes it equivalent to the R7RS-small definition.</p>
<p>This SRFI also provides the following new procedures (some from
Python, some from other sources):
</p>
<ul class="indented">
<li><tt><a href="#vector-unfold-bang">vector-unfold!</a></tt></li>
<li><tt><a href="#vector-unfold-right-bang">vector-unfold-right!</a></tt></li>
<li><tt><a href="#vector-append-subvectors">vector-append-subvectors</a></tt></li>
<li><tt><a href="#vector-cumulate">vector-cumulate</a></tt></li>
<li><tt><a href="#vector-partition">vector-partition</a></tt></li>
</ul>
<p>
It should be noted that no vector sorting procedures are provided
by this SRFI, because there already are several SRFIs for that purpose.
</p>
<h1 class="nonheader">
<a name="ProcIndex">4. Procedure Index</a>
</h1>
<p>
Here is an index of the procedures provided by this package.
Those marked by <i>italics</i> are also provided in
<a href="#R7RS-small">R7RS-small</a>.
</p>
<dl>
<dt class="proc-index">
· <a href="#Constructors">Constructors</a>
<br />
<br />
</dt>
<dd>
<code>
<i><a href="#make-vector">make-vector</a></i>
<i><a href="#vector">vector</a></i>
<br />
<a href="#vector-unfold">vector-unfold</a>
<a href="#vector-unfold-right">vector-unfold-right</a>
<br />
<i><a href="#vector-copy">vector-copy</a></i>
<a href="#vector-reverse-copy">vector-reverse-copy</a>
<br />
<i><a href="#vector-append">vector-append</a></i>
<a href="#vector-concatenate">vector-concatenate</a>
<a href="#vector-append-subvectors">vector-append-subvectors</a>
<br />
<br />
</code>
</dd>
<dt class="proc-index">
· <a href="#Predicates">Predicates</a>
<br />
<br />
</dt>
<dd>
<code>
<i><a href="#vector-p">vector?</a></i>
<br />
<a href="#vector-empty-p">vector-empty?</a>
<br />
<a href="#vector-eq">vector=</a>
<br />
<br />
</code>
</dd>
<dt class="proc-index">
· <a href="#Selectors">Selectors</a>
<br />
<br />
</dt>
<dd>
<code>
<i><a href="#vector-ref">vector-ref</a></i>
<br />
<i><a href="#vector-length">vector-length</a></i>
<br />
<br />
</code>
</dd>
<dt class="proc-index">
· <a href="#Iteration">Iteration</a>
<br />
<br />
</dt>
<dd>
<code>
<a href="#vector-fold">vector-fold</a>
<a href="#vector-fold-right">vector-fold-right</a>
<br />
<i><a href="#vector-map">vector-map</a></i>
<a href="#vector-map-bang">vector-map!</a>
<br />
<i><a href="#vector-for-each">vector-for-each</a></i>
<a href="#vector-count">vector-count</a>
<br />
<a href="#vector-cumulate">vector-cumulate</a>
<br />
<br />
</code>
</dd>
<dt class="proc-index">
· <a href="#Searching">Searching</a>
<br />
<br />
</dt>
<dd>
<code>
<a href="#vector-index">vector-index</a>
<a href="#vector-index-right">vector-index-right</a>
<br />
<a href="#vector-skip">vector-skip</a>
<a href="#vector-skip-right">vector-skip-right</a>
<br />
<a href="#vector-binary-search">vector-binary-search</a>
<br />
<a href="#vector-any">vector-any</a>
<a href="#vector-every">vector-every</a>
<br />
<a href="#vector-partition">vector-partition</a>
<br />
<br />
</code>
</dd>
<dt class="proc-index">
· <a href="#Mutators">Mutators</a>
<br />
<br />
</dt>
<dd>
<code>
<i><a href="#vector-set-bang">vector-set!</a></i>
<a href="#vector-swap-bang">vector-swap!</a>
<br />
<i><a href="#vector-fill-bang">vector-fill!</a></i>
<a href="#vector-reverse-bang">vector-reverse!</a>
<br />
<i><a href="#vector-copy-bang">vector-copy!</a></i>
<a href="#vector-reverse-copy-bang">vector-reverse-copy!</a>
<br />
<a href="#vector-unfold-bang">vector-unfold!</a></i>
<a href="#vector-unfold-right-bang">vector-unfold-right!</a></i>
<br />
<br />
</code>
</dd>
<dt class="proc-index">
· <a href="#Conversion">Conversion</a>
<br />
<br />
</dt>
<dd>
<code>
<i><a href="#vector-to-list">vector->list</a></i>
<a href="#reverse-vector-to-list">reverse-vector->list</a>
<br />
<i><a href="#list-to-vector">list->vector</a></i>
<a href="#reverse-list-to-vector">reverse-list->vector</a>
<br />
<i><a href="#vector-to-string">vector->string</a></i>
<i><a href="#string-to-vector">string->vector</a></i>
</code>
</dd>
</dl>
<h1 class="nonheader"><a name="Procs">5. Procedures</a></h1>
<p>
In this section containing specifications of procedures, the
following notation is used to specify parameters and return
values:
</p>
<dl class="indented">
<dt class="type-spec">
(f arg<sub>1</sub> arg<sub>2</sub> ...)
-> something</dt>
<dd>
Indicates a function <tt><i>f</i></tt> takes the parameters
<tt><i>arg<sub>1</sub> arg<sub>2</sub>
...</i></tt> and returns a value of the
type <tt><i>something</i></tt>. If <tt><i>something</i></tt>
is <tt>unspecified</tt>, then <tt><i>f</i></tt> returns a single
implementation-dependent value; this SRFI does not specify what it
returns, and in order to write portable code, the return value
should be ignored.
<br />
<br />
</dd>
<dt class="type-spec">vec</dt>
<dd>
The argument in this place must be a vector, i.e. it must
satisfy the predicate
<tt><a href="#vector-p">vector?</a></tt>.
<br />
<br />
</dd>
<dt class="type-spec">i, j, start, size</dt>
<dd>
The argument in this place must be a exact nonnegative integer, i.e.
it must satisfy the predicates <tt>exact?</tt>, <tt>integer?</tt> and either
<tt>zero?</tt> or <tt>positive?</tt>. The third case of it
indicates the index at which traversal begins; the fourth case
of it indicates the size of a vector.
<br />
<br />
</dd>
<dt class="type-spec">end</dt>
<dd>
The argument in this place must be a exact positive integer, i.e. it
must satisfy the predicates <tt>exact?</tt>, <tt>integer?</tt> and
<tt>positive?</tt>. This indicates the index directly before
which traversal will stop — processing will occur until
the the index of the vector is <tt><i>end</i></tt>. It is the
closed right side of a range.
<br />
<br />
</dd>
<dt class="type-spec">f</dt>
<dd>
The argument in this place must be a function of one or more
arguments, which returns (except as noted otherwise) exactly one value.
<br />
<br />
</dd>
<dt class="type-spec">pred?</dt>
<dd>
The argument in this place must be a function of one or more
arguments that returns one value, which is treated as a
boolean.
<br />
<br />
</dd>
<dt class="type-spec">
x, y, z, seed, knil, fill, key, value
</dt>
<dd>
The argument in this place may be any Scheme value.
<br />
<br />
</dd>
<dt class="type-spec">[something]</dt>
<dd>
Indicates that <tt><i>something</i></tt> is an optional
argument; it needn't necessarily be applied.
<tt><i>Something</i></tt> needn't necessarily be one thing; for
example, this usage of it is perfectly valid:
<br />
<br />
<code>
[start [end]]
</code>
<br />
<br />
and is indeed used quite often.
<br />
<br />
</dd>
<dt class="type-spec">something ...</dt>
<dd>
Indicates that zero or more <tt><i>something</i></tt>s are
allowed to be arguments.
<br />
<br />
</dd>
<dt class="type-spec">
something<sub>1</sub> something<sub>2</sub>
...
</dt>
<dd>
Indicates that at least one <tt><i>something</i></tt> must be
arguments.
<br />
<br />
</dd>
<dt class="type-spec">
something<sub>1</sub> something<sub>2</sub>
...
something<sub>n</sub>
</dt>
<dd>
Exactly equivalent to the previous argument notation, but this
also indicates that <tt><i>n</i></tt> will be used later in the
procedure description.
<br />
<br />
</dd>
</dl>
<p>
It should be noted that all of the procedures that iterate across
multiple vectors in parallel stop iterating and produce the final
result when the end of the shortest vector is reached. The sole
exception is <tt><a href="#vector-eq">vector=</a></tt>, which
automatically returns <tt>#f</tt> if the vectors' lengths vary.
</p>
<h2><a name="Constructors">5.1. Constructors</a></h2>
<dl>
<dt class="proc-spec proc def">
<a name="make-vector">
(make-vector <i>size</i> [<i>fill</i>])
-> vector
</a>
</dt>
<dd>
[<a href="#R7RS-small"><i>R7RS-small</i></a>] Creates and returns a vector
of size <tt><i>size</i></tt>.
If <i>fill</i> is specified, all the elements of the vector
are initialized to <i>fill</i>. Otherwise, their contents
are indeterminate.
<br />
<br />
Example:
<br />
<br />
<code class="example-call">
(make-vector 5 3)
</code>
<br />
<code class="example-value">
#(3 3 3 3 3)
</code>
<br />
<br />
</dd>
<dt class="proc-spec proc def">
<a name="vector">
(vector <i>x ...</i>)
-> vector
</a>
</dt>
<dd>
[<a href="#R7RS-small"><i>R7RS-small</i></a>] Creates and returns a vector
whose elements are <tt><i>x ...</i></tt>.
<br />
<br />
Example:
<br />
<br />
<code class="example-call">
(vector 0 1 2 3 4)
</code>
<br />
<code class="example-value">
#(0 1 2 3 4)
</code>
<br />
<br />
</dd>
<dt class="proc-spec proc def">
<a name="vector-unfold">
(vector-unfold <i>f length initial-seed
...</i>)
-> vector
</a>
</dt>
<dd>
The fundamental vector constructor. Creates a vector whose
length is <tt><i>length</i></tt> and iterates across each index
<tt><i>k</i></tt> between <tt>0</tt> and
<tt><i>length</i></tt>, applying <tt><i>f</i></tt> at each
iteration to the current index and current seeds, in that
order, to receive <tt><i>n</i> + 1</tt> values: first, the
element to put in the <tt><i>k</i></tt>th slot of the new
vector and <tt><i>n</i></tt> new seeds for the next iteration.
It is an error for the number of seeds to vary between
iterations. Note that the termination condition is different from
the <code>unfold</code> procedure of <a href="#SRFI 1">SRFI 1</a>.
<br />
<br />
Examples:
<br />
<br />
<code class="example-call">
(vector-unfold (λ (i x) (values x (- x 1)))
<br />
10 0)
</code>
<br />
<code class="example-value">
#(0 -1 -2 -3 -4 -5 -6 -7 -8 -9)
</code>
<br />
<br />
Construct a vector of the sequence of integers in the range
[0,<tt><i>n</i></tt>).
<br />
<code class="example-call">
(vector-unfold values <tt><i>n</i></tt>)
</code>
<br />
<code class="example-value">
#(0 1 2 ... <i>n-2</i> <i>n-1</i>)
</code>
<br />
<br />
Copy <tt><i>vector</i></tt>.
<br />
<br />
<code class="example-call">
(vector-unfold (λ (i) (vector-ref <i>vector</i> i))
<br />
(vector-length <i>vector</i>))
</code>
<br />
<br />
</dd>
<dt class="proc-spec proc def">
<a name="vector-unfold-right">
(vector-unfold-right <i>f length initial-seed
...</i>)
-> vector
</a>
</dt>
<dd>
Like <tt><a href="#vector-unfold">vector-unfold</a></tt>, but
it uses <tt><i>f</i></tt> to generate elements from
right-to-left, rather than left-to-right.
The first index used is <i>length</i> - 1.
Note that the termination condition is different from
the <code>unfold-right</code> procedure of <a href="#SRFI 1">SRFI 1</a>.
<br />
<br />
Examples:
<br />
<br />
Construct a vector of pairs of non-negative integers whose
values sum to 4.
<br />
<br />
<code class="example-call">
(vector-unfold-right (λ (i x) (values (cons i x) (+ x 1))) 5 0)
</code>
<br />
<code class="example-value">
#((0 . 4) (1 . 3) (2 . 2) (3 . 1) (4 . 0))
</code>
<br />
<br />
Reverse <tt><i>vector</i></tt>.
<br />
<br />
<code class="example-call">
(vector-unfold-right (λ (i x)
(values (vector-ref <i>vector</i> x)
(+ x 1)))
<br />
(vector-length <i>vector</i>)
<br />
0)
</code>
<br />
<br />
</dd>
<!-- VECTOR-TABULATE has been flushed in favour of VECTOR-UNFOLD.
<dt class="proc-spec">
<a name="vector-tabulate">
(vector-tabulate <i>f size</i>)
-> vector
</a>
</dt>
<dd>
Creates a new vector whose size is <tt><i>size</i></tt> and
fills it by applying <tt><i>f</i></tt> to each index in the
vector, in an unspecified order.
<br />
<br />
Examples:
<br />
<br />
<code class="example-call">
(vector-tabulate - 5)
</code>
<br />
<code class="example-value">
#(0 -1 -2 -3 -4)
</code>
<br />
<br />
<code class="example-call">
(vector-tabulate (λ (x) (* x x)) 5)
</code>
<br />
<code class="example-value">
#(0 1 4 9 16)
</code>
<br />
<br />
</dd>
-->
<dt class="proc-spec proc def">
<a name="vector-copy">
(vector-copy <i>vec</i>
[<i>start</i> [<i>end</i>]])
-> vector
</a>
</dt>
<dd>
[<a href="#R7RS-small"><i>R7RS-small</i></a>]
Allocates a new vector whose length is <tt><i>end</i> -
<i>start</i></tt> and fills it with elements from
<tt><i>vec</i></tt>, taking elements from <tt><i>vec</i></tt>
starting at index <tt><i>start</i></tt> and stopping at index
<tt><i>end</i></tt>. <tt><i>Start</i></tt> defaults to
<tt>0</tt> and <tt><i>end</i></tt> defaults to the value of
<tt>(<a href="#vector-length">vector-length</a>
<i>vec</i>)</tt>.
SRFI 43 provides an optional <var>fill</var> argument to supply
values if <var>end</var> is greater than the length of <var>vec</var>.
Neither R7RS-small nor this SRFI requires support for this argument.
<br />
<br />
Examples:
<br />
<br />
<code class="example-call">
(vector-copy '#(a b c d e f g h i))
</code>
<br />
<code class="example-value">
#(a b c d e f g h i)
</code>
<br />
<br />
<code class="example-call">
(vector-copy '#(a b c d e f g h i) 6)
</code>
<br />
<code class="example-value">
#(g h i)
</code>
<br />
<br />
<code class="example-call">
(vector-copy '#(a b c d e f g h i) 3 6)
</code>
<br />
<code class="example-value">
#(d e f)
</code>
<br />
<br />
</dd>
<dt class="proc-spec proc def">
<a name="vector-reverse-copy">
(vector-reverse-copy <i>vec</i>
[<i>start</i> [<i>end</i>]])
-> vector
</a>
</dt>
<dd>
Like <tt><a href="#vector-copy">vector-copy</a></tt>, but it
copies the elements in the reverse order from
<tt><i>vec</i></tt>.
<br />
<br />
Example:
<br />
<br />
<code class="example-call">
(vector-reverse-copy '#(5 4 3 2 1 0) 1 5)
</code>
<br />
<code class="example-value">
#(1 2 3 4)
</code>
<br />
<br />
</dd>
<dt class="proc-spec proc def">
<a name="vector-append">
(vector-append <i>vec ...</i>)
-> vector
</a>
</dt>
<dd>
[<a href="#R7RS-small"><i>R7RS-small</i></a>]
Returns a newly allocated vector that contains all elements in
order from the subsequent locations in <tt><i>vec
...</i></tt>.
<br />
<br />
Examples:
<br />
<br />
<code class="example-call">
(vector-append '#(x) '#(y))
</code>
<br />
<code class="example-value">
#(x y)
</code>
<br />
<br />
<code class="example-call">
(vector-append '#(a) '#(b c d))
</code>
<br />
<code class="example-value">
#(a b c d)
</code>
<br />
<br />
<code class="example-call">
(vector-append '#(a #(b)) '#(#(c)))
</code>
<br />
<code class="example-value">
#(a #(b) #(c))
</code>
<br />
<br />
</dd>
<dt class="proc-spec proc def">
<a name="vector-concatenate">
(vector-concatenate <i>list-of-vectors</i>)
-> vector
</a>
</dt>
<dd>
Appends each vector in <tt><i>list-of-vectors</i></tt>. This
is equivalent to:
<br />
<br />
<code class="indented">
(apply <a href="#vector-append">vector-append</a>
<i>list-of-vectors</i>)
</code>
<br />
<br />
However, it may be implemented better.
<br />
<br />
Example:
<br />
<br />
<code class="example-call">
(vector-concatenate '(#(a b) #(c d)))
</code>
<br />
<code class="example-value">
#(a b c d)
</code>
<br />
<br />
</dd>
</dl>
<dt class="proc-spec proc def">
<a name="vector-append-subvectors">
(vector-append-subvectors [<i>vec start end] ...</i>)
-> vector
</a>
</dt>
<dd>
Returns a vector that contains every element of each <i>vec</i>
from <i>start</i> to <i>end</i> in the specified order.
This procedure is a generalization of <tt>vector-append</tt>.
<br />
<br />
Example:
<br />
<br />
<code class="example-call">
(vector-append-subvectors '#(a b c d e) 0 2 '#(f g h i j) 2 4)
</code>
<br />
<code class="example-value">
#(a b h i)
</code>
<br />
<br />
</dd>
<h2><a name="Predicates">5.2. Predicates</a></h2>
<dl>
<dt class="proc-spec proc def">
<a name="vector-p">
(vector? <i>x</i>)
-> boolean
</a>
</dt>
<dd>
[<a href="#R7RS-small"><i>R7RS-small</i></a>] Disjoint type predicate for
vectors: this returns <tt>#t</tt> if <tt><i>x</i></tt> is a
vector, and <tt>#f</tt> if otherwise.
<br />
<br />
Examples:
<br />
<br />
<code class="example-call">
(vector? '#(a b c))
</code>
<br />
<code class="example-value">
#t
</code>
<br />
<br />
<code class="example-call">
(vector? '(a b c))
</code>
<br />
<code class="example-value">
#f
</code>
<br />
<br />
<code class="example-call">
(vector? #t)
</code>
<br />
<code class="example-value">
#f
</code>
<br />
<br />
<code class="example-call">
(vector? '#())
</code>
<br />
<code class="example-value">
#t
</code>
<br />
<br />
<code class="example-call">
(vector? '())
</code>
<br />
<code class="example-value">
#f
</code>
<br />
<br />
</dd>
<dt class="proc-spec proc def">
<a name="vector-empty-p">
(vector-empty? <i>vec</i>)
-> boolean
</a>
</dt>
<dd>
Returns <tt>#t</tt> if <tt><i>vec</i></tt> is empty, i.e. its
length is <tt>0</tt>, and <tt>#f</tt> if not.
<br />
<br />
Examples:
<br />
<br />
<code class="example-call">
(vector-empty? '#(a))
</code>
<br />
<code class="example-value">
#f
</code>
<br />
<br />
<code class="example-call">
(vector-empty? '#(()))
</code>
<br />
<code class="example-value">
#f
</code>
<br />
<br />
<code class="example-call">
(vector-empty? '#(#()))
</code>
<br />
<code class="example-value">
#f
</code>
<br />
<br />
<code class="example-call">
(vector-empty? '#())
</code>
<br />
<code class="example-value">
#t