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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
|
<!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 43: Vector Library</title>
<meta http-equiv="Content-type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
/* <![CDATA[ */
body {
padding-right: 5%;
}
h2 {
padding-left: 6%;
}
/* Ugly hack to make the header work right */
h1.nonheader {
padding-left: 8.5%;
}
h1 {
margin-left: -4.5%;
}
div.header {
padding-left: 8%;
}
p, dl, code.indented {
padding-left: 8%;
}
ul.outer, dl.indented {
padding-left: 13%;
}
ul.indented {
padding-left: 18%;
}
dt.ref {
font-weight: bold;
}
dt.ref:before {
content: "[";
}
dt.ref:after {
content: "]";
}
dt.proc-index {
padding-left: 0.5%;
font-size: medium;
font-weight: bold;
}
dt.type-spec {
font-family: monospace;
font-style: italic;
}
dt.proc-spec {
font-family: monospace;
}
code.example-call {
padding-left: 3%;
}
code.example-value {
padding-left: 8%;
}
code.example-value:before {
content: "=> "
}
/* ]]> */
</style>
</head>
<body>
<div class="header">
<!--
Special SRFI header, formatted oddly due to the commit check script
for SRFI CVS.
-->
<H1>Title</H1>
Vector library
<H1>Author</H1>
Taylor Campbell
<H1>Status</H1>
This SRFI is currently in ``final'' status. To see an explanation of each status that a SRFI can hold, see <A HREF="http://srfi.schemers.org/srfi-process.html">here</A>.
You can access the discussion via <A HREF="http://srfi.schemers.org/srfi-43/mail-archive/maillist.html">the archive of the mailing list</A>.
<UL>
<LI>Received: 2003/03/26
<LI>Draft: 2003/04/03-2003/06/01
<LI>Revised: 2003/07/15
<LI>Revised: 2003/11/01
<LI>Revised: 2004/04/10
<LI>Revised: 2004/04/28
<LI>Revised: 2004/08/30
<LI>Final: 2004/10/26
</UL>
<!--
End special header.
-->
</div>
<h1 class="nonheader">Table of Contents</h1>
<ul class="outer">
<li>1. <a href="#Abstract">Abstract</a></li>
<li>2. <a href="#Rationale">Rationale</a></li>
<li>3. <a href="#ProcIndex">Procedure Index</a></li>
<li>
4. <a href="#Procs">Procedures</a>
<ul>
<li>4.1. <a href="#Constructors">Constructors</a></li>
<li>4.2. <a href="#Predicates">Predicates</a></li>
<li>4.3. <a href="#Selectors">Selectors</a></li>
<li>4.4. <a href="#Iteration">Iteration</a></li>
<li>4.5. <a href="#Searching">Searching</a></li>
<li>4.6. <a href="#Mutators">Mutators</a></li>
<li>4.7. <a href="#Conversion">Conversion</a></li>
</ul>
</li>
<li>5. <a href="#RefImpl">Reference Implementation</a></li>
<li>6. <a href="#Acknowledgements">Acknowledgements</a></li>
<li>7. <a href="#References">References</a></li>
<li>8. <a href="#Copyright">Copyright</a></li>
</ul>
<h1 class="nonheader"><a name="Abstract">1. Abstract</a></h1>
<p>
This <a href="#SRFI">SRFI</a> proposes a comprehensive and
complete 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>
<p>
Because this SRFI is more of a library or module specification
than a request for additions to readers or any other internal
implementation detail, in an implementation that supports a
module or structure or package or library or unit (et cetera)
systems, these procedures should be contained in a module /
structure / package / library / unit called <tt>vector-lib</tt>.
</p>
<h1 class="nonheader"><a name="Rationale">2. Rationale</a></h1>
<p>
<a href="#R5RS">R5RS</a> provides very few list-processing
procedures, for which reason <a href="#SRFI-1">SRFI 1
(<tt>list-lib</tt>)</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>
Many Scheme implementations provide several vector operations
beyond the miniscule set that R5RS defines (the typical
<tt><a href="#vector-append">vector-append</a></tt>,
<tt><a href="#vector-map">vector-map</a></tt>, et cetera), but
often these procedures have different names, take arguments in
different orders, don't take the same number of arguments, or
have some other flaw that makes them unportable. For this
reason, this SRFI is proposed.
</p>
<p>
It should be noted that no vector sorting procedures are provided
by this SRFI, because there already is a SRFI for such a purpose
(<a href="#SRFI-32">SRFI 32 (<tt>sort-lib</tt>)</a>), which
includes routines for sorting not only vectors but also lists.
</p>
<h1 class="nonheader">
<a name="ProcIndex">3. Procedure Index</a>
</h1>
<p>
Here is an index of the procedures provided by this package.
Those marked by <b>bold</b> are provided in
<a href="#R5RS">R5RS</a> and those marked by <b><i>bold
italic</i></b> are defined by <a href="#R5RS">R5RS</a> but are
modified from their original definitions.
</p>
<dl>
<dt class="proc-index">
· <a href="#Constructors">Constructors</a>
<br>
<br>
</dt>
<dd>
<code>
<b><a href="#make-vector">make-vector</a></b>
<b><a href="#vector">vector</a></b>
<br>
<a href="#vector-tabulate">vector-unfold</a>
<a href="#vector-unfold-right">vector-unfold-right</a>
<br>
<a href="#vector-copy">vector-copy</a>
<a href="#vector-reverse-copy">vector-reverse-copy</a>
<br>
<a href="#vector-append">vector-append</a>
<a href="#vector-concatenate">vector-concatenate</a>
<br>
<br>
</code>
</dd>
<dt class="proc-index">
· <a href="#Predicates">Predicates</a>
<br>
<br>
</dt>
<dd>
<code>
<b><a href="#vector-p">vector?</a></b>
<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>
<b><a href="#vector-ref">vector-ref</a></b>
<br>
<b><a href="#vector-length">vector-length</a></b>
<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>
<a href="#vector-map">vector-map</a>
<a href="#vector-map-bang">vector-map!</a>
<br>
<a href="#vector-for-each">vector-for-each</a>
<br>
<a href="#vector-count">vector-count</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>
<br>
</code>
</dd>
<dt class="proc-index">
· <a href="#Mutators">Mutators</a>
<br>
<br>
</dt>
<dd>
<code>
<b><a href="#vector-set-bang">vector-set!</a></b>
<a href="#vector-swap-bang">vector-swap!</a>
<br>
<b><i><a href="#vector-fill-bang">vector-fill!</a></i></b>
<br>
<a href="#vector-reverse-bang">vector-reverse!</a>
<br>
<a href="#vector-copy-bang">vector-copy!</a>
<a href="#vector-reverse-copy-bang">vector-reverse-copy!</a>
<br>
<br>
</code>
</dd>
<dt class="proc-index">
· <a href="#Conversion">Conversion</a>
<br>
<br>
</dt>
<dd>
<code>
<b><i><a href="#vector-to-list">vector->list</a></i></b>
<a href="#reverse-vector-to-list">reverse-vector->list</a>
<br>
<b><i><a href="#list-to-vector">list->vector</a></i></b>
<a href="#reverse-list-to-vector">reverse-list->vector</a>
</code>
</dd>
</dl>
<h1 class="nonheader"><a name="Procs">4. 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 what <tt><i>f</i></tt> returns is
implementation-dependant; 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 nonnegative integer, i.e.
it must satisfy the predicates <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 positive integer, i.e. it
must satisfy the predicates <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, returning 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">4.1. Constructors</a></h2>
<dl>
<dt class="proc-spec">
<a name="make-vector">
(make-vector <i>size</i> [<i>fill</i>])
-> vector
</a>
</dt>
<dd>
[<a href="#R5RS"><i>R5RS</i></a>] Creates and returns a vector
of size <tt><i>size</i></tt>, optionally filling it with
<tt><i>fill</i></tt>. The default value of
<tt><i>fill</i></tt> is unspecified.
<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">
<a name="vector">
(vector <i>x ···</i>)
-> vector
</a>
</dt>
<dd>
[<a href="#R5RS"><i>R5RS</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">
<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.
<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">
<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.
<br>
<br>
Examples:
<br>
<br>
Construct a vector in reverse of the integers in the range
[0,<tt><i>n</i></tt>).
<br>
<br>
<code class="example-call">
(vector-unfold-right (λ (i x) (values x (+ x 1))) <i>n</i> 0)
</code>
<br>
<code class="example-value">
#(<i>n-1</i> <i>n-2</i> ··· 2 1 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">
<a name="vector-copy">
(vector-copy <i>vec</i>
[<i>start</i> [<i>end</i> [<i>fill</i>]]])
-> vector
</a>
</dt>
<dd>
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>. If <tt><i>end</i></tt> extends beyond the
length of <tt><i>vec</i></tt>, the slots in the new vector that
obviously cannot be filled by elements from <tt><i>vec</i></tt>
are filled with <tt><i>fill</i></tt>, whose default value is
unspecified.
<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>
<code class="example-call">
(vector-copy '#(a b c d e f g h i) 6 12 'x)
</code>
<br>
<code class="example-value">
#(g h i x x x)
</code>
<br>
<br>
</dd>
<dt class="proc-spec">
<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">
<a name="vector-append">
(vector-append <i>vec ···</i>)
-> vector
</a>
</dt>
<dd>
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">
<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>
<h2><a name="Predicates">4.2. Predicates</a></h2>
<dl>
<dt class="proc-spec">
<a name="vector-p">
(vector? <i>x</i>)
-> boolean
</a>
</dt>
<dd>
[<a href="#R5RS"><i>R5RS</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">
<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
</code>
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-eq">
(vector= <i>elt=? vec ···</i>)
-> boolean
</a>
</dt>
<dd>
Vector structure comparator, generalized across user-specified
element comparators. Vectors <tt><i>a</i></tt> and
<tt><i>b</i></tt> are considered equal by <tt>vector=</tt> iff
their lengths are the same, and for each respective elements
<tt><i>E</i><sub>a</sub></tt> and
<tt><i>E</i><sub>b</sub></tt>, <tt>(<i>elt=? E</i><sub>a</sub>
<i>E</i><sub>b</sub>)</tt> returns a true value.
<tt><i>Elt=?</i></tt> is always applied to two arguments.
Element comparison must be consistent with <tt>eq</tt>; that
is, if <tt>(eq? <i>E</i><sub>a</sub> <i>E</i><sub>b</sub>)</tt>
results in a true value, then <tt>(<i>elt=? E</i><sub>a</sub>
<i>E</i><sub>b</sub>)</tt> must also result in a true value.
This may be exploited to avoid unnecessary element comparisons.
(The reference implementation does, but it does not consider
the situation where <tt><i>elt=?</i></tt> is in fact itself
<tt>eq?</tt> to avoid yet more unnecessary comparisons.)
<br>
<br>
If there are only zero or one vector arguments, <tt>#t</tt> is
automatically returned. The dynamic order in which comparisons
of elements and of vectors are performed is left completely
unspecified; do not rely on a particular order.
<br>
<br>
Examples:
<br>
<br>
<code class="example-call">
(vector= eq? '#(a b c d) '#(a b c d))
</code>
<br>
<code class="example-value">
#t
</code>
<br>
<br>
<code class="example-call">
(vector= eq? '#(a b c d) '#(a b d c))
</code>
<br>
<code class="example-value">
#f
</code>
<br>
<br>
<code class="example-call">
(vector= = '#(1 2 3 4 5) '#(1 2 3 4))
</code>
<br>
<code class="example-value">
#f
</code>
<br>
<br>
<code class="example-call">
(vector= = '#(1 2 3 4) '#(1 2 3 4))
</code>
<br>
<code class="example-value">
#t
</code>
<br>
<br>
The two trivial cases.
<br>
<br>
<code class="example-call">
(vector= eq?)
</code>
<br>
<code class="example-value">
#t
</code>
<br>
<br>
<code class="example-call">
(vector= eq? '#(a))
</code>
<br>
<code class="example-value">
#t
</code>
<br>
<br>
Note the fact that we don't use vector literals in the next two
— it is unspecified whether or not literal vectors with
the same external representation are <tt>eq?</tt>.
<br>
<br>
<code class="example-call">
(vector= eq? (vector (vector 'a)) (vector (vector 'a)))
</code>
<br>
<code class="example-value">
#f
</code>
<br>
<br>
<code class="example-call">
(vector= equal? (vector (vector 'a)) (vector (vector 'a)))
</code>
<br>
<code class="example-value">
#t
</code>
<br>
<br>
</dd>
</dl>
<h2><a name="Selectors">4.3. Selectors</a></h2>
<dl>
<dt class="proc-spec">
<a name="vector-ref">
(vector-ref <i>vec i</i>)
-> value
</a>
</dt>
<dd>
[<a href="#R5RS"><i>R5RS</i></a>] Vector element dereferencing:
returns the value that the location in <tt><i>vec</i></tt> at
<tt><i>i</i></tt> is mapped to in the store. Indexing is based
on zero. <tt><i>I</i></tt> must be within the range [0,
<tt>(<a href="#vector-length">vector-length</a>
<i>vec</i>)</tt>).
<br>
<br>
Example:
<br>
<br>
<code class="example-call">
(vector-ref '#(a b c d) 2)
</code>
<br>
<code class="example-value">
c
</code>
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-length">
(vector-length <i>vec</i>)
-> exact nonnegative integer
</a>
</dt>
<dd>
[<a href="#R5RS"><i>R5RS</i></a>] Returns the length of <tt><i>vec</i></tt>, the number of
locations reachable from <tt><i>vec</i></tt>. (The careful
word 'reachable' is used to allow for 'vector slices,' whereby
<tt><i>vec</i></tt> refers to a larger vector that contains
more locations that are unreachable from <tt><i>vec</i></tt>.
This SRFI does not define vector slices, but later SRFIs may.)
<br>
<br>
Example:
<br>
<br>
<code class="example-call">
(vector-length '#(a b c))
</code>
<br>
<code class="example-value">
3
</code>
<br>
<br>
</dd>
</dl>
<h2><a name="Iteration">4.4. Iteration</a></h2>
<dl>
<dt class="proc-spec">
<a name="vector-fold">
(vector-fold <i>kons knil vec<sub>1</sub> vec<sub>2</sub>
···</i>)
-> value
</a>
</dt>
<dd>
The fundamental vector iterator. <tt><i>Kons</i></tt> is
iterated over each index in all of the vectors, stopping at the
end of the shortest; <tt><i>kons</i></tt> is applied as
<tt>
(<i>kons</i> <i>i</i> <i>state</i>
(<a href="#vector-ref">vector-ref</a>
<i>vec<sub>1</sub></i> <i>i</i>)
(<a href="#vector-ref">vector-ref</a>
<i>vec<sub>2</sub></i> <i>i</i>)
···)
</tt>
where <tt><i>state</i></tt> is the current state value —
the current state value begins with <tt><i>knil</i></tt>, and
becomes whatever <tt><i>kons</i></tt> returned at the
respective iteration —, and <tt><i>i</i></tt> is the
current index.
<br>
<br>
The iteration is strictly left-to-right.
<br>
<br>
Examples:
<br>
<br>
Find the longest string's length in
<tt><i>vector-of-strings</i></tt>.
<br>
<code class="example-call">
(vector-fold (λ (index len str)
(max (string-length str) len))
<br>
0 <i>vector-of-strings</i>)
</code>
<br>
<br>
Produce a list of the reversed elements of
<tt><i>vec</i></tt>.
<br>
<code class="example-call">
(vector-fold (λ (index tail elt) (cons elt tail))
<br>
'() <i>vec</i>)
</code>
<br>
<br>
Count the number of even numbers in <tt><i>vec</i></tt>.
<br>
<code class="example-call">
(vector-fold (λ (index counter n)
<br>
(if (even? n) (+ counter 1) counter))
<br>
0 <i>vec</i>)
</code>
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-fold-right">
(vector-fold-right <i>kons knil
vec<sub>1</sub> vec<sub>2</sub>
···</i>)
-> value
</a>
</dt>
<dd>
Similar to <tt><a href="#vector-fold">vector-fold</a></tt>, but
it iterates right to left instead of left to right.
<br>
<br>
Example:
<br>
<br>
Convert a vector to a list.
<br>
<code class="example-call">
(vector-fold-right (λ (index tail elt)
(cons elt tail))
<br>
'() '#(a b c d))
</code>
<br>
<code class="example-value">
(a b c d)
</code>
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-map">
(vector-map <i>f vec<sub>1</sub> vec<sub>2</sub>
···</i>)
-> vector
</a>
</dt>
<dd>
Constructs a new vector of the shortest size of the vector
arguments. Each element at index <tt><i>i</i></tt> of the new
vector is mapped from the old vectors by
<tt>(<i>f</i> <i>i</i>
(<a href="#vector-ref">vector-ref</a>
<i>vec<sub>1</sub></i>
<i>i</i>)
(<a href="#vector-ref">vector-ref</a>
<i>vec<sub>2</sub></i>
<i>i</i>)
···)</tt>.
The dynamic order of application of <tt><i>f</i></tt> is
unspecified.
<br>
<br>
Examples:
<br>
<br>
<code class="example-call">
(vector-map (λ (i x) (* x x))
<br>
(<a href="#vector-unfold">vector-unfold</a>
(λ (i x) (values x (+ x 1)))
4 1))
</code>
<br>
<code class="example-value">
#(1 4 9 16)
</code>
<br>
<br>
<code class="example-call">
(vector-map (λ (i x y) (* x y))<br>
(<a href="#vector-unfold">vector-unfold</a>
(λ (i x) (values x (+ x 1)))
5 1)<br>
(<a href="#vector-unfold">vector-unfold</a>
(λ (i x) (values x (- x 1)))
5 5))
</code>
<br>
<code class="example-value">
#(5 8 9 8 5)
</code>
<br>
<br>
<code class="example-call">
(let ((count 0))
</code>
<br>
<code class="example-call">
(vector-map (λ (ignored-index ignored-elt)
</code>
<br>
<code class="example-call">
(set! count (+ count 1))
</code>
<br>
<code class="example-call">
count)
</code>
<br>
<code class="example-call">
'#(a b)))
</code>
<br>
<code class="example-value">
#(1 2) <i>OR</i> #(2 1)
</code>
<br>
<br>
<code class="example-call">
(vector-map (λ (i elt) (+ i elt)) '#(1 2 3 4))
</code>
<br>
<code class="example-value">
#(1 3 5 7)
</code>
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-map-bang">
(vector-map! <i>f vec<sub>1</sub> vec<sub>2</sub>
···</i>)
-> unspecified
</a>
</dt>
<dd>
Similar to <tt><a href="#vector-map">vector-map</a></tt>, but
rather than mapping the new elements into a new vector, the new
mapped elements are destructively inserted into
<tt><i>vec<sub>1</sub></i></tt>. Again, the dynamic order of
application of <tt><i>f</i></tt> unspecified, so it is
dangerous for <tt><i>f</i></tt> to apply either
<tt><a href="#vector-ref">vector-ref</a></tt> or
<tt><a href="#vector-set-bang">vector-set!</a></tt> to
<tt><i>vec<sub>1</sub></i></tt> in <tt><i>f</i></tt>.
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-for-each">
(vector-for-each <i>f vec<sub>1</sub> vec<sub>2</sub>
···</i>)
-> unspecified
</a>
</dt>
<dd>
Simple vector iterator: applies <tt><i>f</i></tt> to each index
in the range [0, <tt><i>length</i></tt>), where
<tt><i>length</i></tt> is the length of the smallest vector
argument passed, and the respective list of parallel elements
from <tt><i>vec<sub>1</sub> vec<sub>2</sub></i>
···</tt> at that index. In contrast with
<tt><a href="#vector-map">vector-map</a></tt>, <tt><i>f</i></tt>
is reliably applied to each subsequent elements, starting at
index 0, in the vectors.
<br>
<br>
Example:
<br>
<br>
<code class="example-call">
(vector-for-each (λ (i x) (display x) (newline))
</code>
<br>
<code class="example-call">
'#("foo" "bar" "baz" "quux" "zot"))
</code>
<br>
Displays:
<br>
<pre>
foo
bar
baz
quux
zot</pre>
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-count">
(vector-count <i>pred? vec<sub>1</sub> vec<sub>2</sub>
···</i>)
-> exact nonnegative integer
</a>
</dt>
<dd>
Counts the number of parallel elements in the vectors that
satisfy <tt><i>pred?</i></tt>, which is applied, for each index
<tt><i>i</i></tt> in the range [0, <tt><i>length</i></tt>)
— where <tt><i>length</i></tt> is the length of the
smallest vector argument —, to <tt><i>i</i></tt> and each
parallel element in the vectors at that index, in order.
<br>
<br>
Examples:
<br>
<br>
<code class="example-call">
(vector-count (λ (i elt) (even? elt))
'#(3 1 4 1 5 9 2 5 6))
</code>
<br>
<code class="example-value">
3
</code>
<br>
<br>
<code class="example-call">
(vector-count (λ (i x y) (< x y))
'#(1 3 6 9) '#(2 4 6 8 10 12))
</code>
<br>
<code class="example-value">
2
</code>
<br>
<br>
</dd>
</dl>
<h2><a name="Searching">4.5. Searching</a></h2>
<dl>
<dt class="proc-spec">
<a name="vector-index">
(vector-index <i>pred? vec<sub>1</sub> vec<sub>2</sub>
···</i>)
-> exact nonnegative integer or #f
</a>
</dt>
<dd>
Finds & returns the index of the first elements in
<tt><i>vec<sub>1</sub> vec<sub>2</sub>
···</i></tt> that satisfy
<tt><i>pred?</i></tt>. If no matching element is found by the
end of the shortest vector, <tt>#f</tt> is returned.
<br>
<br>
Examples:
<br>
<br>
<code class="example-call">
(vector-index even? '#(3 1 4 1 5 9))
</code>
<br>
<code class="example-value">
2
</code>
<br>
<br>
<code class="example-call">
(vector-index < '#(3 1 4 1 5 9 2 5 6) '#(2 7 1 8 2))
</code>
<br>
<code class="example-value">
1
</code>
<br>
<br>
<code class="example-call">
(vector-index = '#(3 1 4 1 5 9 2 5 6) '#(2 7 1 8 2))
</code>
<br>
<code class="example-value">
#f
</code>
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-index-right">
(vector-index-right <i>pred? vec<sub>1</sub> vec<sub>2</sub>
···</i>)
-> exact nonnegative integer or #f
</a>
</dt>
<dd>
Like <tt><a href="#vector-index">vector-index</a></tt>, but it
searches right-to-left, rather than left-to-right, and all of
the vectors <i>must</i> have the same length.
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-skip">
(vector-skip <i>pred? vec<sub>1</sub> vec<sub>2</sub>
···</i>)
-> exact nonnegative integer or #f
</a>
</dt>
<dd>
Finds & returns the index of the first elements in
<tt><i>vec<sub>1</sub> vec<sub>2</sub>
···</i></tt> that do <i>not</i> satisfy
<tt><i>pred?</i></tt>. If all the values in the vectors
satisfy <tt><i>pred?</i></tt> until the end of the shortest
vector, this returns <tt>#f</tt>. This is equivalent to:
<br>
<br>
<code class="indented">
(<a href="#vector-index">vector-index</a>
(λ (x<sub><i>1</i></sub> x<sub><i>2</i></sub>
<i>···</i>)
(not (<i>pred?</i> x<sub><i>1</i></sub>
x<sub><i>1</i></sub>
<i>···</i>)))
<br>
<i>vec<sub>1</sub> vec<sub>2</sub>
···</i>)
</code>
<br>
<br>
Example:
<br>
<br>
<code class="example-call">
(vector-skip number? '#(1 2 a b 3 4 c d))
</code>
<br>
<code class="example-value">
2
</code>
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-skip-right">
(vector-skip-right <i>pred? vec<sub>1</sub> vec<sub>2</sub>
···</i>)
-> exact nonnegative integer or #f
</a>
</dt>
<dd>
Like <tt><a href="#vector-skip">vector-skip</a></tt>, but it
searches for a non-matching element right-to-left, rather than
left-to-right, and all of the vectors <i>must</i> have the same
length. This is equivalent to:
<br>
<br>
<code class="indented">
(<a href="#vector-index">vector-index-right</a>
(λ (x<sub><i>1</i></sub> x<sub><i>2</i></sub>
<i>···</i>)
(not (<i>pred?</i> x<sub><i>1</i></sub>
x<sub><i>1</i></sub>
<i>···</i>)))
<br>
<i>vec<sub>1</sub> vec<sub>2</sub>
···</i>)
</code>
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-binary-search">
(vector-binary-search <i>vec value cmp</i>)
-> exact nonnegative integer or #f
</a>
</dt>
<dd>
Similar to <tt><a href="#vector-index">vector-index</a></tt>
and
<tt><a href="#vector-index-right">vector-index-right</a></tt>,
but instead of searching left to right or right to left, this
performs a binary search. <tt><i>cmp</i></tt> should be a
procedure of two arguments and return a negative integer, which
indicates that its first argument is less than its second,
zero, which indicates that they are equal, or a positive
integer, which indicates that the first argument is greater
than the second argument. An example <tt><i>cmp</i></tt> might
be:
<br>
<br>
<code class="indented">
(λ (<i>char<sub>1</sub></i> <i>char<sub>2</sub></i>)
</code>
<br>
<code class="indented">
(cond ((char<? <i>char<sub>1</sub>
char<sub>2</sub></i>)
-1)
</code>
<br>
<code class="indented">
((char=? <i>char<sub>1</sub>
char<sub>2</sub></i>)
0)
</code>
<br>
<code class="indented">
(else 1)))
</code>
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-any">
(vector-any <i>pred? vec<sub>1</sub> vec<sub>2</sub>
···</i>)
-> value or #f
</a>
</dt>
<dd>
Finds the first set of elements in parallel from
<tt><i>vec<sub>1</sub> vec<sub>2</sub>
···</i></tt> for which
<tt><i>pred?</i></tt> returns a true value. If such a parallel
set of elements exists, <tt>vector-any</tt> returns the value
that <tt><i>pred?</i></tt> returned for that set of elements.
The iteration is strictly left-to-right.
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-every">
(vector-every <i>pred? vec<sub>1</sub> vec<sub>2</sub>
···</i>)
-> value or #f
</a>
</dt>
<dd>
If, for every index <tt><i>i</i></tt> between 0 and the length
of the shortest vector argument, the set of elements
<tt>(<a href="#vector-ref">vector-ref</a> <i>vec<sub>1</sub></i>
<i>i</i>)
(<a href="#vector-ref">vector-ref</a> <i>vec<sub>2</sub></i>
<i>i</i>)
···</tt>
satisfies <tt><i>pred?</i></tt>, <tt>vector-every</tt> returns
the value that <tt><i>pred?</i></tt> returned for the last
set of elements, at the last index of the shortest vector. The
iteration is strictly left-to-right.
<br>
<br>
</dd>
</dl>
<h2><a name="Mutators">4.6. Mutators</a></h2>
<dl>
<dt class="proc-spec">
<a name="vector-set-bang">
(vector-set! <i>vec i value</i>)
-> unspecified
</a>
</dt>
<dd>
[<a href="#R5RS"><i>R5RS</i></a>] Assigns the contents of the location at <tt><i>i</i></tt> in
<tt><i>vec</i></tt> to <tt><i>value</i></tt>.
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-swap-bang">
(vector-swap! <i>vec i j</i>)
-> unspecified
</a>
</dt>
<dd>
Swaps or exchanges the values of the locations in
<tt><i>vec</i></tt> at <tt><i>i</i></tt> &
<tt><i>j</i></tt>.
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-fill-bang">
(vector-fill! <i>vec fill</i> [<i>start</i> [<i>end</i>]])
-> unspecified
</a>
</dt>
<dd>
[<a href="#R5RS"><i>R5RS</i></a>+] Assigns the value of every location in <tt><i>vec</i></tt>
between <tt><i>start</i></tt>, which defaults to <tt>0</tt> and
<tt><i>end</i></tt>, which defaults to the length of
<tt><i>vec</i></tt>, to <tt><i>fill</i></tt>.
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-reverse-bang">
(vector-reverse! <i>vec</i> [<i>start</i> [<i>end</i>]])
-> unspecified
</a>
</dt>
<dd>
Destructively reverses the contents of the sequence of
locations in <tt><i>vec</i></tt> between <tt><i>start</i></tt>
and <tt><i>end</i></tt>. <tt><i>Start</i></tt> defaults to
<tt>0</tt> and <tt><i>end</i></tt> defaults to the length of
<tt><i>vec</i></tt>. Note that this does not deeply reverse.
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-copy-bang">
(vector-copy! <i>target tstart source</i>
[<i>sstart</i> [<i>send</i>]])
-> unspecified
</a>
</dt>
<dd>
Copies a block of elements from <tt><i>source</i></tt> to
<tt><i>target</i></tt>, both of which must be vectors, starting
in <tt><i>target</i></tt> at <tt><i>tstart</i></tt> and
starting in <tt><i>source</i></tt> at <tt><i>sstart</i></tt>,
ending when <tt><i>send</i> - <i>sstart</i></tt> elements have
been copied. It is an error for <tt><i>target</i></tt> to have
a length less than <tt><i>tstart</i> + (<i>send</i> -
<i>sstart</i>)</tt>. <tt><i>Sstart</i></tt> defaults to
<tt>0</tt> and <tt><i>send</i></tt> defaults to the length of
<tt><i>source</i></tt>.
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="vector-reverse-copy-bang">
(vector-reverse-copy! <i>target tstart source</i>
[<i>sstart</i> [<i>send</i>]])
-> unspecified
</a>
</dt>
<dd>
Like <tt><a href="#vector-copy-bang">vector-copy!</a></tt>, but
this copies the elements in the reverse order. It is an error
if <tt><i>target</i></tt> and <tt><i>source</i></tt> are
identical vectors and the target & source ranges overlap;
however, if <tt><i>tstart</i> = <i>sstart</i></tt>,
<tt>vector-reverse-copy!</tt> behaves as
<tt>
(<a href="#vector-reverse-bang">vector-reverse!</a>
<i>target</i>
<i>tstart</i>
<i>send</i>)
</tt>
would.
<br>
<br>
</dd>
</dl>
<h2><a name="Conversion">4.7. Conversion</a></h2>
<dl>
<dt class="proc-spec">
<a name="vector-to-list">
(vector->list <i>vec</i> [<i>start</i> [<i>end</i>]])
-> proper-list
</a>
</dt>
<dd>
[<a href="#R5RS"><i>R5RS</i></a>+] Creates a list containing the elements in <tt><i>vec</i></tt>
between <tt><i>start</i></tt>, which defaults to <tt>0</tt>,
and <tt><i>end</i></tt>, which defaults to the length of
<tt><i>vec</i></tt>.
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="reverse-vector-to-list">
(reverse-vector->list <i>vec</i>
[<i>start</i> [<i>end</i>]])
-> proper-list
</a>
</dt>
<dd>
Like <tt><a href="#vector-to-list">vector->list</a></tt>,
but the resulting list contains the elements in reverse between
the the specified range.
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="list-to-vector">
(list->vector <i>proper-list</i>) -> vector
</a>
</dt>
<dd>
[<a href="#R5RS"><i>R5RS</i></a>+] Creates a vector of elements from <tt><i>proper-list</i></tt>.
<br>
<br>
</dd>
<dt class="proc-spec">
<a name="reverse-list-to-vector">
(reverse-list->vector <i>proper-list</i>) -> vector
</a>
</dt>
<dd>
Like <tt><a href="#list-to-vector">list->vector</a></tt>,
but the resulting list contains the elements in reverse of
<tt><i>proper-list</i></tt>.
<br>
<br>
</dd>
</dl>
<h1 class="nonheader">
<a name="RefImpl">5. Reference Implementation</a>
</h1>
<p>
With this SRFI comes a complete reference implementation. It is
licensed under a very open copyright with which no implementors
should have any legal issues.
<br>
<br>
The reference implementation has only one non-R5RS dependency:
<a href="#SRFI-23">SRFI 23</a>'s <tt>error</tt> procedure.
<br>
<br>
This reference implementation of all the procedures described in
this SRFI can be found <a href="#vector-lib.scm">here</a>.
</p>
<h1 class="nonheader">
<a name="Acknowledgements">6. Acknowledgements</a>
</h1>
<p>
Thanks to Olin Shivers for his wonderfully complete
<a href="#SRFI-1">list</a> and <a href="#SRFI-13">string</a>
packages; to all the members of the
<a href="http://scheme-irc.webhop.org/"><tt>#scheme</tt> IRC
channel</a> on <a href="http://www.freenode.net/">Freenode</a>
who nitpicked a great deal, but also helped quite a lot in
general, and helped test the reference implementation in various
Scheme systems; to Michael Burschik for his numerous comments; to
Sergei Egorov for helping to narrow down the procedures; to Mike
Sperber for putting up with an <i>extremely</i> overdue draft; to
Felix Winkelmann for continually bugging me about finishing up the
SRFI so that it would be only overdue and not withdrawn; and to
everyone else who gave questions, comments, thoughts, or merely
attention to the SRFI.
</p>
<h1 class="nonheader"><a name="References">7. References</a></h1>
<dl>
<dt class="ref"><a name="R5RS">R5RS</a></dt>
<dd>
<i>R5RS: The Revised<sup>5</sup> Report on Scheme</i>
<br>
R. Kelsey, W. Clinger, J. Rees (editors).
<br>
Higher-Order and Symbolic Computation, Vol. 11, No. 1,
September, 1998
<br>
and
<br>
ACM SIGPLAN Notices, Vol. 33, No. 9, October, 1998
<br>
Available at:
<a href="http://www.schemers.org/Documents/Standards/R5RS/">
http://www.schemers.org/Documents/Standards/R5RS/
</a>
<br>
<br>
</dd>
<dt class="ref"><a name="SRFI">SRFI</a></dt>
<dd>
<i>SRFI: Scheme Request for Implementation</i>
<br>
The SRFI website can be found at:
<a href="http://srfi.schemers.org/">
http://srfi.schemers.org/
</a>
<br>
The SRFIs mentioned in this document are described later.
<br>
<br>
</dd>
<dt class="ref"><a name="SRFI-1">SRFI 1</a></dt>
<dd>
<i>SRFI 1: List Library</i>
<br>
A SRFI of list processing procedures, written by Olin Shivers.
<br>
Available at:
<a href="http://srfi.schemers.org/srfi-1/">
http://srfi.schemers.org/srfi-1/
</a>
<br>
<br>
</dd>
<dt class="ref"><a name="SRFI-13">SRFI 13</a></dt>
<dd>
<i>SRFI 13: String Library</i>
<br>
A SRFI of string processing procedures, written by Olin
Shivers.
<br>
Available at:
<a href="http://srfi.schemers.org/srfi-13/">
http://srfi.schemers.org/srfi-13/
</a>
<br>
<br>
</dd>
<dt class="ref"><a name="SRFI-23">SRFI 23</a></dt>
<dd>
<i>SRFI 23: Error Reporting Mechanism</i>
<br>
A SRFI that defines a new primitive (<tt>error</tt>) for
reporting that an error occurred, written by Stephan Houben.
<br>
Available at:
<a href="http://srfi.schemers.org/srfi-23/">
http://srfi.schemers.org/srfi-23/
</a>
<br>
<br>
</dd>
<dt class="ref"><a name="SRFI-32">SRFI 32</a></dt>
<dd>
<i>SRFI 32: Sort Libraries (draft)</i>
<br>
A SRFI of list and vector sorting routines, written by Olin
Shivers.
<br>
Available at:
<a href="http://srfi.schemers.org/srfi-32/">
http://srfi.schemers.org/srfi-32/
</a>
</dd>
</dl>
<h1 class="nonheader"><a name="Copyright">8. Copyright</a></h1>
<p>
Copyright (C) Taylor Campbell (2003). All rights reserved.
</p>
<p>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
</p>
<p>
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
</p>
<p>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
</p>
<hr>
<address>Editor: <a href="mailto:srfi-editors@srfi.schemers.org">Mike Sperber</a></address>
</body>
</html>
|