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 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512
|
XLISP-PLUS: Another Object-oriented Lisp
Version 3.0
January 15, 1997
Tom Almy
almy@teleport.com
Portions of this manual and software are from XLISP which is Copyright (c)
1988, by David Michael Betz, all rights reserved. Mr. Betz grants
permission for unrestricted non-commercial use. Portions of XLISP-PLUS from
XLISP-STAT are Copyright (c) 1988, Luke Tierney. UNIXSTUF.C is from Winterp
1.0, Copyright 1989 Hewlett-Packard Company (by Niels Mayer). Other
enhancements and bug fixes are provided without restriction by Tom Almy,
Mikael Pettersson, Neal Holtz, Johnny Greenblatt, Ken Whedbee, Blake
McBride, Pete Yadlowsky, and Richard Zidlicky. See source code for details.
Table of Contents
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
XLISP COMMAND LOOP . . . . . . . . . . . . . . . . . . . . . . . . . . 2
BREAK COMMAND LOOP . . . . . . . . . . . . . . . . . . . . . . . . . . 4
DATA TYPES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
THE EVALUATOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
HOOK FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
LEXICAL CONVENTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . 10
8 BIT ASCII CHARACTERS . . . . . . . . . . . . . . . . . . . . . . . . 12
READTABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
SYMBOL CASE CONTROL . . . . . . . . . . . . . . . . . . . . . . . . . . 15
PACKAGES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
LAMBDA LISTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
GENERALIZED VARIABLES . . . . . . . . . . . . . . . . . . . . . . . . . 20
OBJECTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
SYMBOLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
EVALUATION FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . 27
MULTIPLE VALUE FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . 29
SYMBOL FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
GENERALIZED VARIABLE FUNCTIONS . . . . . . . . . . . . . . . . . . . . 33
PACKAGE FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
PROPERTY LIST FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . 39
HASH TABLE FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . 40
ARRAY FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
SEQUENCE FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . 42
LIST FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
DESTRUCTIVE LIST FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . 54
ARITHMETIC FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . 55
BITWISE LOGICAL FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . 60
XLISP-PLUS 3.0 Table of Contents
STRING FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
CHARACTER FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . 66
STRUCTURE FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . 68
OBJECT FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
PREDICATE FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . 72
CONTROL CONSTRUCTS . . . . . . . . . . . . . . . . . . . . . . . . . . 77
LOOPING CONSTRUCTS . . . . . . . . . . . . . . . . . . . . . . . . . . 80
THE PROGRAM FEATURE . . . . . . . . . . . . . . . . . . . . . . . . . . 81
INPUT/OUTPUT FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . 83
THE FORMAT FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . 86
FILE I/O FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . 89
STRING STREAM FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . 94
DEBUGGING AND ERROR HANDLING FUNCTIONS . . . . . . . . . . . . . . . . 95
SYSTEM FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
ADDITIONAL FUNCTIONS AND UTILITIES . . . . . . . . . . . . . . . . . . 104
COMPILATION OPTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . 109
BUG FIXES AND EXTENSIONS . . . . . . . . . . . . . . . . . . . . . . . 111
EXAMPLES: FILE I/O FUNCTIONS . . . . . . . . . . . . . . . . . . . . . 121
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
XLISP-PLUS 3.0 INTRODUCTION Page 1
INTRODUCTION
XLISP-PLUS is an enhanced version of David Michael Betz's XLISP to have
additional features of Common Lisp. XLISP-PLUS is distributed for the IBM-
PC family and for UNIX, but can be easily ported to other platforms.
Complete source code is provided (in "C") to allow easy modification and
extension.
Since XLISP-PLUS is based on XLISP, most XLISP programs will run on XLISP-
PLUS. Since XLISP-PLUS incorporates many more features of Common Lisp, many
small Common Lisp applications will run on XLISP-PLUS with little
modification. See the section starting on page 111 for details of the
differences between XLISP and XLISP-PLUS.
Many Common Lisp functions are built into XLISP-PLUS. In addition, XLISP
defines the objects 'Object' and 'Class' as primitives. 'Object' is the
only class that has no superclass and hence is the root of the class
heirarchy tree. 'Class' is the class of which all classes are instances (it
is the only object that is an instance of itself).
This document is a brief description of XLISP-PLUS. It assumes some
knowledge of LISP and some understanding of the concepts of object-oriented
programming.
You will probably also need a copy of "Common Lisp: The Language" by Guy L.
Steele, Jr., published by Digital Press to use as a reference for some of
the Common Lisp functions that are described only briefly in this document.
XLISP-PLUS has a number of compilation options to to eliminate groups of
functions and to tailor itself to various environments. Unless otherwise
indicated this manual assumes all options are enabled and the system
dependent code is as complete as that provided for the MS/DOS environment.
Assistance for using or porting XLISP-PLUS can be obtained on the USENET
newsgroup comp.lang.lisp.x, or by writing to Tom Almy at the Internet
address almy@teleport.com, http://www.teleport.com/~almy/xlisp.html.
You can also reach Tom by writing to him at 17830 SW Shasta Trail,
Tualatin, OR 97062, USA.
XLISP-PLUS 3.0 XLISP COMMAND LOOP Page 2
XLISP COMMAND LOOP
When XLISP is started, it first tries to load the workspace "xlisp.wks", or
an alternative file specified with the "-wfilename" option, from the
current directory. If that file doesn't exist, or the "-w" flag is in the
command line, XLISP builds an initial workspace, empty except for the
built-in functions and symbols.
Then, providing no workspace file was loaded, XLISP attempts to load
"init.lsp" from a path in XLPATH or the current directory. This file can be
modified to suit the user's requirements. It contains a number of
preference items.
If *startup-functions* is non-nil (default is nil), it is taken as a list
of functions with no arguments which are executed in sequence at this time.
This allows automatically starting applications stored in workspaces.
If the variable *load-file-arguments* is non-nil (default is "t"), it then
loads any files named as parameters on the command line (after appending
".lsp" to their names). If the "-v" flag is in the command line, then the
files are loaded verbosely.
The option "-tfilename" will open a transcript file of the name "filename".
At this time the top level command loop is entered. This is the function
TOP-LEVEL-LOOP, by default.
XLISP then issues the following prompt (unless standard input has been
redirected):
>
This indicates that XLISP is waiting for an expression to be typed. If the
current package is other than USER, the the package name is printed before
the ">".
When a complete expression has been entered, XLISP attempts to evaluate
that expression. If the expression evaluates successfully, XLISP prints the
result and then returns for another expression.
The following control characters can be used while XLISP is waiting for
input:
Backspace delete last character
Del delete last character
tab tabs over (treated as space by XLISP reader)
ctrl-C goto top level
ctrl-G cleanup and return one level
ctrl-Z end of file (returns one level or exits program)
ctrl-P proceed (continue)
ctrl-T print information
Under MS-DOS or OS/2 (at least) the following control characters can be
typed while XLISP is executing (providing standard input has not been
redirected away from the console):
XLISP-PLUS 3.0 XLISP COMMAND LOOP Page 3
ctrl-B BREAK -- enter break loop
ctrl-S Pause until another key is struck
ctrl-C go to top level
ctrl-T print information
Under MS-DOS if the global variable *dos-input* is set non-NIL, DOS is used
to read entire input lines. Operation this way is convenient if certain DOS
utilities, such as CED, are used, or if XLISP is run under an editor like
EPSILON. In this case, normal command line editing is available, but the
control keys will not work (in particular, ctrl-C will cause the program to
exit!). Use the XLISP functions top-level, clean-up, and continue instead
of ctrl-C, ctrl-G, and ctrl-P.
Under MS-DOS if the global variable *dos-input* is NIL, or under OS/2 or
Windows, a special internal line editor is used. In this case the last 20
lines are saved, and can be recalled and viewed using the up and down arrow
keys. Duplicate lines are not saved.
An additional feature is symbol name lookup. This command takes what
appears to be an incomplete symbol name to the left of the cursor and
prints all interned symbol names that match.
The control keys for the editor are:
Up Arrow Previous command in queue
Down Arrow Next command in queue
Left Arrow Move cursor to left
Right Arrow Move cursor to right
Home Move cursor to start of line
End Move cursor to end of line
Delete Delete character at cursor
Backspace Delete character to left of cursor
Escape Delete current line
Tab Look up partial symbol name to left of cursor
Characters are inserted at the current cursor position. Lines are limited
in length to the width of the display, and invalid keystrokes cause the
bell to ring.
XLISP-PLUS 3.0 BREAK COMMAND LOOP Page 4
BREAK COMMAND LOOP
When XLISP encounters an error while evaluating an expression, it attempts
to handle the error in the following way:
If the symbol '*breakenable*' is true, the message corresponding to the
error is printed. If the error is correctable, the correction message is
printed.
If the symbol '*tracenable*' is true, a trace back is printed. The number
of entries printed depends on the value of the symbol '*tracelimit*'. If
this symbol is set to something other than a number, the entire trace back
stack is printed.
XLISP then enters a read/eval/print loop to allow the user to examine the
state of the interpreter in the context of the error. This loop differs
from the normal top-level read/eval/print loop in that if the user invokes
the function 'continue', XLISP will continue from a correctable error. If
the user invokes the function 'clean-up', XLISP will abort the break loop
and return to the top level or the next lower numbered break loop. When in
a break loop, XLISP prefixes the break level to the normal prompt.
If the symbol '*breakenable*' is NIL, XLISP looks for a surrounding errset
function. If one is found, XLISP examines the value of the print flag. If
this flag is true, the error message is printed. In any case, XLISP causes
the errset function call to return NIL.
If there is no surrounding errset function, XLISP prints the error message
and returns to the top level.
If XLISP was invoked with the command line argument "-b" then XLISP assumes
it is running in batch mode. In batch mode any uncaught error will cause
XLISP to exit after printing the error message.
XLISP-PLUS 3.0 DATA TYPES Page 5
DATA TYPES
There are several different data types available to XLISP-PLUS programmers.
Typical implementation limits are shown for 32 bit word systems. Values in
square brackets apply to 16 bit MS-DOS and Windows implementations.
All data nodes are effectively cons cells consisting of two pointers and
one or two bytes of identification flags (9 or 10 bytes per cell). Node
space is managed and garbage collected by XLISP. Array and string storage
is either allocated by the C runtime or managed and garbaged collected by
XLISP (compilation option). If C does the allocation, memory fragmentation
can occur. Fragmentation can be eliminated by saving the image and
restarting XLISP-PLUS.
NIL
Unlike the original XLISP, NIL is a symbol (although not in the
*obarray*), to allowing setting its properties.
lists
Either NIL or a CDR-linked list of cons cells, terminated by a symbol
(typically NIL). Circular lists are allowable, but can cause problems
with some functions so they must be used with care.
arrays
The CDR field of an array points to the dynamically allocated data
array, while the CAR contains the integer length of the array.
Elements in the data array are pointers to other cells [Size limited
to about 16360].
character strings
Implemented like arrays, except string array is byte indexed and
contains the actual characters. Note that unlike the underlying C, the
null character (value 0) is valid. [Size limited to about 65500]
symbols
Implemented as a 4 element array. The elements are value cell,
function cell, property list, and print name (a character string
node). Print names are limited to 100 characters. There are also flags
for constant and special. Values bound to special symbols (declared
with DEFVAR or DEFPARAMETER) are always dynamically bound, rather than
being lexically bound.
fixnums (integers)
Small integers (> -129 and <256) are statically allocated and are thus
always EQ integers of the same value. The CAR field is used to hold
the value, which is a 32 bit signed integer.
bignums (integers)
Big integers which don't fit in fixnums are stored in a special
structure. Part of the bignum extension compilation option, when
absent fixnums will overflow into flonums. Fixnums and flonums are
collectively referred to as "integers". [size limit is about 65500
characters for printing or about 500000 bits for calculations].
XLISP-PLUS 3.0 DATA TYPES Page 6
ratios
The CAR field is used to hold the numerator while the CDR field is
used to hold the denominator. The numerator and denominator are stored
as either both bignums or both fixnums. All ratios results are
returned in reduced form, and are returned as integers if the
denominator is 1. Part of the bignums extension. Ratios and integers
are collectively referred to as rationals.
characters
All characters are statically allocated and are thus EQ characters of
the same value. The CAR field is used to hold the value. In XLISP
characters are "unsigned" and thus range in value from 0 to 255.
flonums (floating point numbers)
The CAR and CDR fields hold the value, which is typically a 64 bit
IEEE floating point number. Flonums and rational numbers are
collectively referred to as real numbers.
complex numbers
Part of the math extension compilation option. The CAR field is used
to hold the real part while the CDR field is used to hold the
imaginary part. The parts can be either both rationals (ratio or
integer) or both flonums. Any function which would return an integer
complex number with a zero imaginary part returns just the real
integer.
objects
Implemented as an array of instance variable count plus one elements.
The first element is the object's class, while the remaining arguments
are the instance variables.
streams (file)
The CAR and CDR fields are used in a system dependent way as a file
pointer.
streams (unnamed -- string)
Implemented as a tconc-style list of characters.
subrs (built-in functions)
The CAR field points to the actual code to execute, while the CDR
field is an internal pointer to the name of the function.
fsubrs (special forms)
Same implementation as subrs.
closures (user defined functions)
Implemented as an array of 11 elements:
1. name symbol or NIL
2. 'lambda or 'macro
3. list of required arguments
4. optional arguments as list of (<arg> <init> <specified-p>)
triples.
5. &rest argument
6. &key arguments as list of (<key> <arg> <init> <specified-p>)
quadruples.
7. &aux arguments as list of (<arg> <init>) pairs.
8. function body
9. value environment (see page 96 for format)
10. function environment
11. argument list (unprocessed)
structures
Implemented as an array with first element being a pointer to the
structure name string, and the remaining elements being the structure
elements.
XLISP-PLUS 3.0 DATA TYPES Page 7
hash-tables
Implemented as a structure of varying length with no generalized
accessing functions, but with a special print function (print
functions not available for standard structures).
random-states
Implemented as a structure with a single element which is the random
state (here a fixnum, but could change without impacting xlisp
programs).
packages
Implemented using a structure. Packages must only be manipulated with
the functions provided.
XLISP-PLUS 3.0 THE EVALUATOR Page 8
THE EVALUATOR
The process of evaluation in XLISP:
Strings, characters, numbers of any type, objects, arrays, structures,
streams, subrs, fsubrs and closures evaluate to themselves.
Symbols act as variables and are evaluated by retrieving the value
associated with their current binding.
Lists are evaluated by examining the first element of the list and then
taking one of the following actions:
If it is a symbol, the functional binding of the symbol is retrieved.
If it is a lambda expression, a closure is constructed for the
function described by the lambda expression.
If it is a subr, fsubr or closure, it stands for itself.
Any other value is an error.
Then, the value produced by the previous step is examined:
If it is a subr or closure, the remaining list elements are evaluated
and the subr or closure is applied to these evaluated expressions.
If it is an fsubr, the fsubr is called with the remaining list
elements as arguments (unevaluated).
If it is a macro, the macro is expanded with the remaining list
elements as arguments (unevaluated). The macro expansion is then
evaluated in place of the original macro call. If the symbol
*displace-macros* is not NIL, then the expanded macro will
(destructively) replace the original macro expression. This means that
the macro will only be expanded once, but the original code will be
lost. The displacement will not take place unless the macro expands
into a list. The standard XLISP practice is the macro will be expanded
each time the expression is evaluated, which negates some of the
advantages of using macros.
XLISP-PLUS 3.0 HOOK FUNCTIONS Page 9
HOOK FUNCTIONS
The evalhook and applyhook facility are useful for implementing debugging
programs or just observing the operation of XLISP. It is possible to
control evaluation of forms in any context.
If the symbol '*evalhook*' is bound to a function closure, then every call
of eval will call this function. The function takes two arguements, the
form to be evaluated and execution environment. During the execution of
this function, *evalhook* (and *applyhook*) are dynamically bound to NIL to
prevent undesirable recursion. This "hook" function returns the result of
the evaluation.
If the symbol '*applyhook*' is bound to a function, then every function
application within an eval will call this function (note that the function
apply, and others which do not use eval, will not invoke the apply hook
function). The function takes two arguments, the function closure and the
argument list (which is already evaluated). During execution of this hook
function, *applyhook* (and *evalhook*) are dynamically bound to NIL to
prevent undesired recursion. This function is to return the result of the
function application.
Note that the hook functions cannot reset *evalhook* or *applyhook* to NIL,
because upon exit these values will be reset. An excape mechanism is
provided -- execution of 'top-level', or any error that causes return to
the top level, will unhook the functions. Applications should bind these
values either via 'progv', 'evalhook', or 'applyhook'.
The functions 'evalhook' and 'applyhook' allowed for controlled application
of the hook functions. The form supplied as an argument to 'evalhook', or
the function application given to 'applyhook', are not hooked themselves,
but any subsidiary forms and applications are. In addition, by supplying
NIL values for the hook functions, 'evalhook' can be used to execute a form
within a specific environment passed as an argument.
An additional hook function exists for the garbage collector. If the symbol
'*gc-hook*' is bound to a function, then this function is called after
every garbage collection. The function has two arguments. The first is the
total number of nodes, and the second is the number of nodes free. The
return value is ignored. During the execution of the function, *gc-hook* is
dynamically bound to NIL to prevent undesirable recursion.
XLISP-PLUS 3.0 LEXICAL CONVENTIONS Page 10
LEXICAL CONVENTIONS
The following conventions must be followed when entering XLISP programs:
Comments in XLISP code begin with a semi-colon character and continue to
the end of the line.
Except when escape sequences are used, symbol names in XLISP can consist of
any sequence of non-blank printable characters except the terminating macro
characters:
( ) ' ` , " ;
and the escape characters:
\ |
In addition, the first character may not be '#' (non-terminating macro
character), nor may the symbol have identical syntax with a numeric
literal. Uppercase and lowercase characters are not distinguished within
symbol names because, by default, lowercase characters are mapped to
uppercase on input.
Any printing character, including whitespace, may be part of a symbol name
when escape characters are used. The backslash escapes the following
character, while multiple characters can be escaped by placing them between
vertical bars. At all times the backslash must be used to escape either
escape characters.
For semantic reasons, certain chararacter sequences should/can never be
used as symbols in XLISP. A single period is used to denote dotted lists.
The symbol T is also reserved for use as the truth value. The symbol NIL
represents an empty list.
Symbols starting with a colon are keywords, and will always evaluate to
themselves. When the package facility is compiled as part of XLISP, colons
have a special significance. Thus colons should not be used as part of a
symbol name, except for these special uses.
Integer literals consist of a sequence of digits optionally beginning with
a sign ('+' or '-'). Unless the bignum extension is used, the range of
values an integer can represent is limited by the size of a C 'long' on the
machine on which XLISP is running. The radix of the literal is determined
by the value of the variable *read-base* if it has an integer value within
the range 2 to 36. However the literal can end with a period '.' in which
case it is treated as a decimal number. It is generally not a good idea to
assign a value to *read-base* unless you are reading from a file of
integers in a non-decimal radix. Use the read macros instead to specify the
base explicitly.
Ratio literals consist of two integer literals separated by a slash
character ('/'). The second number, the denominator, must be positive.
Ratios are automatically reduced to their cannonical form; if they are
integral, then they are reduced to an integer.
XLISP-PLUS 3.0 LEXICAL CONVENTIONS Page 11
Flonum (floating point) literals consist of a sequence of digits optionally
beginning with a sign ('+' or '-') and including one or both of an embedded
(not trailing) decimal point or a trailing exponent. The optional exponent
is denoted by an 'E' or 'e' followed by an optional sign and one or more
digits. The range of values a floating point number can represent is
limited by the size of a C 'double' on most machines on which XLISP is
running.
Numeric literals cannot have embedded escape characters. If they do, they
are treated as symbols. Thus '12\3' is a symbol even though it would appear
to be identical to '123'. Conversely, symbols that could be interpreted as
numeric literals in the current radix must have escape characters.
Complex literals are constructed using a read-macro of the format #C(r i),
where r is the real part and i is the imaginary part. The numeric fields
can be any valid real number literal. If either field has a flonum literal,
then both values are converted to flonums. Rational (integer or ratio)
complex literals with a zero imaginary part are automatically reduced to
rationals.
Character literals are handled via the #\ read-macro construct:
#\<char> == the ASCII code of the printing character
#\newline == ASCII linefeed character
#\space == ASCII space character
#\rubout == ASCII rubout (DEL)
#\C-<char> == ASCII control character
#\M-<char> == ASCII character with msb set (Meta character)
#\M-C-<char> == ASCII control character with msb set
Literal strings are sequences of characters surrounded by double quotes
(the " read-macro). Within quoted strings the '\' character is used to
allow non-printable characters to be included. The codes
recognized are:
\\ means the character '\'
\n means newline
\t means tab
\r means return
\f means form feed
\nnn means the character whose octal code is nnn
XLISP-PLUS 3.0 8 BIT ASCII CHARACTERS Page 12
8 BIT ASCII CHARACTERS
When used in an IBM PC environment (or perhaps others), XLISP-PLUS is
compiled by default to allow the full use of the IBM 8 bit ASCII character
set, including all characters with diacritic marks. Note that using such
characters will make programs non-portable. XLISP-PLUS can be compiled for
standard 7 bit ASCII if desired for portability.
When 8 bit ASCII is enabled, the following system characteristics change:
Character codes 128 to 254 are marked as :constituent in the readtable.
This means that any of the new characters (except for the nonprinting
character 255) can be symbol constituent. Alphabetic characters which
appear in both cases, such as and , are considered to be alphabetical
for purposes of symbol case control, while characters such as that have
no coresponding upper case are not considered to be alphabetical.
The reader is extended for the character data type to allow all the
additional characters (except code 255) to be entered literally, for
instance "#\". These characters are also printed literally, rather than
using the "M-" construct. Code 255 must still be entered as, and will be
printed as, "#\M-Rubout".
Likewise strings do not need and will not use the backslash escape
mechanism for codes 128 to 254.
The functions alphanumericp, alpha-char-p, upper-case-p, and lower-case-p
perform as would be expected on the extended characters, treating the
diacritic characters as their unadorned counterparts. As per the Common
Lisp definition, both-case-p will only indicate T for characters available
in both cases.
XLISP-PLUS 3.0 READTABLES Page 13
READTABLES
The behaviour of the reader is controlled by a data structure called a
"readtable". The reader uses the symbol *readtable* to locate the current
readtable. This table controls the interpretation of input characters -- if
it is changed then the section LEXICAL CONVENTIONS may not apply. The
readtable is an array with 256 entries, one for each of the extended ASCII
character codes. Each entry contains one of the following values, with the
initial entries assigned to the values indicated:
:white-space A whitespace character - tab, cr, lf, ff, space
(:tmacro . fun) terminating readmacro - ( ) " , ; ' `
(:nmacro . fun) non-terminating readmacro - #
:sescape Single escape character - \
:mescape Multiple escape character - |
:constituent Indicating a symbol constituent (all printing
characters not listed above)
NIL Indicating an invalid character (everything else)
In the case of :TMACRO and :NMACRO, the "fun" component is a function. This
can either be a built-in readmacro function or a lambda expression. The
function takes two parameters. The first is the input stream and the second
is the character that caused the invocation of the readmacro. The readmacro
function should return NIL to indicate that the character should be treated
as white space or a value consed with NIL to indicate that the readmacro
should be treated as an occurance of the specified value. Of course, the
readmacro code is free to read additional characters from the input stream.
A :nmacro is a symbol constituent except as the first character of a
symbol.
As an example, the following read macro allows the square brackets to be
used as a more visibly appealing alternative to the SEND function:
(setf (aref *readtable* (char-int #\[)) ; #\[ table entry
(cons :tmacro
(lambda (f c &aux ex) ; second arg is not used
(do ()
((eq (peek-char t f) #\]))
(setf ex (append ex (list (read f)))))
(read-char f) ; toss the trailing #\]
(cons (cons 'send ex) NIL))))
(setf (aref *readtable* (char-int #\]))
(cons :tmacro
(lambda (f c)
(error "misplaced right bracket"))))
XLISP-PLUS 3.0 READTABLES Page 14
XLISP defines several useful read macros:
'<expr> == (quote <expr>)
`<expr> == (backquote <expr>)
,<expr> == (comma <expr>)
,@<expr> == (comma-at <expr>)
#'<expr> == (function <expr>)
#(<expr>...) == an array of the specified expressions
#S(<structtype> [<slotname> <value>]...)
== structure of specified type and initial values
#.<expr> == result of evaluating <expr>
#d<digits> == a decimal number (integer or ratio)
#x<hdigits> == a hexadecimal integer or ratio (0-9,A-F)
#o<odigits> == an octal integer or ratio (0-7)
#b<bdigits> == a binary integer or ratio (0-1)
#<base>r<digits> == an integer or ratio in base <base>, 2-36
#| |# == a comment
#:<symbol> == an uninterned symbol
#C(r i) == a complex number
#+<expr> == conditional on feature expression true
#-<expr> == conditional on feature expression false
A feature expression is either a symbol or a list where the first element
is AND, OR, or NOT and any remaining elements (NOT requires exactly one)
are feature expressions. A symbol is true if it is a member (by test
function EQ) of the list in global variable *FEATURES*. Init.lsp defines
one initial feature, :XLISP, and the features :TIMES, :GENERIC, :POSFCNS
(various position functions), :MATH (complex math), :BIGNUMS (bignums and
ratios), :PC8 (character set), :PACKAGES, and :MULVALS depending on the
coresponding feature having been compiled into the XLISP executable.
Utility files supplied with XLISP-PLUS generally add new features which are
EQ to the keyword made from their file names.
XLISP-PLUS 3.0 SYMBOL CASE CONTROL Page 15
SYMBOL CASE CONTROL
XLISP-PLUS uses two variables, *READTABLE-CASE* and *PRINT-CASE* to
determine case conversion during reading and printing of symbols.
*READTABLE-CASE* can have the values :UPCASE :DOWNCASE :PRESERVE or
:INVERT, while *PRINT-CASE* can have the values :UPCASE :DOWNCASE or
:CAPITALIZE. By default, or when other values have been specified, both are
:UPCASE.
When *READTABLE-CASE* is :UPCASE, all unescaped lowercase characters are
converted to uppercase when read. When it is :DOWNCASE, all unescaped
uppercase characters are converted to lowercase. This mode is not very
useful because the predefined symbols are all uppercase and would need to
be escaped to read them. When *READTABLE-CASE* is :PRESERVE, no conversion
takes place. This allows case sensitive input with predefined functions in
uppercase. The final choice, :INVERT, will invert the case of any symbol
that is not mixed case. This provides case sensitive input while making the
predefined functions and variables appear to be in lowercase.
The printing of symbols involves the settings of both *READTABLE-CASE* and
*PRINT-CASE*. When *READTABLE-CASE* is :UPCASE, lowercase characters are
escaped (unless PRINC is used), and uppercase characters are printed in the
case specified by *PRINT-CASE*. When *READTABLE-CASE* is :DOWNCASE,
uppercase characters are escaped (unless PRINC is used), and lowercase are
printed in the case specified by *PRINT-CASE*. The *PRINT-CASE* value of
:CAPITALIZE means that the first character of the symbol, and any character
in the symbol immediately following a non-alphabetical character are to be
in uppercase, while all other alphabetical characters are to be in
lowercase. The remaining *READTABLE-CASE* modes ignore *PRINT-CASE* and do
not escape alphabetic characters. :PRESERVE never changes the case of
characters while :INVERT inverts the case of any non mixed-case symbols.
There are five major useful combinations of these modes:
A: *READTABLE-CASE* :UPCASE *PRINT-CASE* :UPCASE
"Traditional" mode. Case insensitive input; must escape to put lowercase
characters in symbol names. Symbols print exactly as they are stored, with
lowercase characters escaped when PRIN1 is used.
B: *READTABLE-CASE* :UPCASE *PRINT-CASE* :DOWNCASE
"Eyesaver" mode. Case insensitive input; must escape to put lowercase
characters in symbol name. Symbols print entirely in lowercase except
symbols escaped when lowercase characters present with PRIN1.
C: *READTABLE-CASE* :PRESERVE
"Oldfashioned case sensitive" mode. Case sensitive input. Predefined
symbols must be typed in uppercase. No alpha quoting needed. Symbols print
exactly as stored.
XLISP-PLUS 3.0 SYMBOL CASE CONTROL Page 16
D: *READTABLE-CASE* :INVERT
"Modern case sensitive" mode. Case sensitive input. Predefined symbols must
be typed in lowercase. Alpha quoting should be avoided. Predefined symbols
print in lower case, other symbols print as they were entered.
E: *READTABLE-CASE* :UPCASE *PRINT-CASE* :CAPITALIZE
Like case B, except symbol names print capitalized.
As far as compatibility between these modes are concerned, data printed in
mode A can be read in A, B, C, or E. Data printed in mode B can be read in
A, B, D, or E. Data printed in mode C can be read in mode C, and if no
lowercase symbols in modes A, B and E as well. Data printed in mode D can
be read in mode D, and if no (internally) lowercase symbols in modes A, B,
and E as well. Data printed in mode E can be read in modes A, B, and E. In
addition, symbols containing characters requiring quoting are compatible
among all modes.
XLISP-PLUS 3.0 PACKAGES Page 17
PACKAGES
When compiled in, XLISP-PLUS provides the "Packages" name hiding facility
of Common Lisp. When in use, there are multiple object arrays (name
spaces). Each package has internal and external symbols. Internal symbols
can only normally be accessed while in that package, while external symbols
can be imported into the current package and used as though they are
members of the current package. There are three standard packages, XLISP,
KEYWORD, and USER. In addition, some of the utility programs are in package
TOOLS. Normally one is in package USER, which is initally empty. USER
imports all external symbols from XLISP, which contains all the functions
and variables described in the body of this document. Symbols which are not
imported into the current package, but are declared to be external in their
home package, can be referenced with the syntax "packageName:symbolName" to
identify symbol s_y_m_b_o_l_N_a_m_e_ in package p_a_c_k_a_g_e_N_a_m_e_. Those symbols which are
internal in their home package need the slightly more difficult syntax
"packageName::symbolName".
The KEYWORD package is referenced by a symbol name with a leading colon.
All keywords are in this package. All keywords are automatically marked
external, and are interned as constants with themselves as their values.
To build an application in a package (to avoid name clashes, for instance),
use MAKE-PACKAGE to create a new package (only if the package does not
already exist, use FIND-PACKAGE to test first), and then preceed the
application with the IN-PACKAGE command to set the package. Use the EXPORT
function to indicate the symbols that will be accessable from outside the
package.
To use an application in a package, either use IMPORT to make specific
symbols accessable as local internal symbols, use USE-PACKAGE to make them
all accessable, or explicitly reference the symbols with the colon syntax.
The file MAKEWKS.LSP shows how to build an initial XLISP workspace such
that all the tools are accessable.
For the subtleties of the package facility, read Common Lisp the Language,
second edition.
XLISP-PLUS 3.0 LAMBDA LISTS Page 18
LAMBDA LISTS
There are several forms in XLISP that require that a "lambda list" be
specified. A lambda list is a definition of the arguments accepted by a
function. There are four different types of arguments.
The lambda list starts with required arguments. Required arguments must be
specified in every call to the function.
The required arguments are followed by the &optional arguments. Optional
arguments may be provided or omitted in a call. An initialization
expression may be specified to provide a default value for an &optional
argument if it is omitted from a call. If no initialization expression is
specified, an omitted argument is initialized to NIL. It is also possible
to provide the name of a 'supplied-p' variable that can be used to
determine if a call provided a value for the argument or if the
initialization expression was used. If specified, the supplied-p variable
will be bound to T if a value was specified in the call and NIL if the
default value was used.
The &optional arguments are followed by the &rest argument. The &rest
argument gets bound to the remainder of the argument list after the
required and &optional arguments have been removed.
The &rest argument is followed by the &key arguments. When a keyword
argument is passed to a function, a pair of values appears in the argument
list. The first expression in the pair should evaluate to a keyword symbol
(a symbol that begins with a ':'). The value of the second expression is
the value of the keyword argument. Like &optional arguments, &key arguments
can have initialization expressions and supplied-p variables. It is
possible to specify the keyword to be used in a function call. If no
keyword is specified, the keyword obtained by adding a ':' to the beginning
of the keyword argument symbol is used. In other words, if the keyword
argument symbol is 'foo', the keyword will be ':foo'.
If identical keywords occur, those after the first are ignored. Extra
keywords will signal an error unless &allow-other-keys is present, in which
case the extra keywords are ignored. Also, if the keyword :allow-other-keys
is used in the function/macro call, and has a non-nil value, then
additional keys will be ignored.
The &key arguments are followed by the &aux variables. These are local
variables that are bound during the evaluation of the function body. It is
possible to have initialization expressions for the &aux variables.
XLISP-PLUS 3.0 LAMBDA LISTS Page 19
Here is the complete syntax for lambda lists:
(<rarg>...
[&optional [<oarg> | (<oarg> [<init> [<svar>]])]...]
[&rest <rarg>]
[&key
[<karg> | ([<karg> | (<key> <karg>)] [<init> [<svar>]])] ...
[&allow-other-keys]]
[&aux [<aux> | (<aux> [<init>])]...])
where:
<rarg> is a required argument symbol
<oarg> is an &optional argument symbol
<rarg> is the &rest argument symbol
<karg> is a &key argument symbol
<key> is a keyword symbol (starts with ':')
<aux> is an auxiliary variable symbol
<init> is an initialization expression
<svar> is a supplied-p variable symbol
XLISP-PLUS 3.0 GENERALIZED VARIABLES Page 20
GENERALIZED VARIABLES
Several XLISP functions support the concept of generalized variables. The
idea behind generalized variables is that variables have two operations,
access and update. Often two separate functions exist for the access and
update operations, such as SYMBOL-VALUE and SET for the dynamic symbol
value, or CAR and REPLACA for the car part of a cons cell. Code can be
simplified if only one such function, the access function, is necessary.
The function SETF is used to update. SETF takes a "place form" argument
which specifies where the data is to be stored. The place form is identical
to the function used for access. Thus we can use (setf (car x) 'y) instead
of (rplaca x 'y). Updates using place forms are "destructive" in that the
alter the data structure rather than rebuilding. Other functions which take
place forms include PSETF, GETF, REMF, PUSH, PUSHNEW, POP, INCF, and DECF.
XLISP has a number of place forms pre-defined in code. In addition, the
function DEFSETF can be used to define new place forms. Place forms and
functions that take them as arguments must be carefully defined so that no
expression is evaluated more than once, and evaluation proceeds from left
to right. The result of this is that these functions tend to be slow. If
multiple evaluation and execution order is not a concern, alternative
simpler functions can be un-commented in COMMON.LSP and COMMON2.LSP.
A place form may be one of the following:
A symbol (variable name). In this case note that (setf x y) is the
same as (setq x y)
A function call form of one of the following functions: CAR CDR NTH
AREF ELT GET GETF SYMBOL-VALUE SYMBOL-FUNCTION SYMBOL-PLIST GETHASH.
The function GETF itself has a place form which must aditionally be
valid. The file COMMON2.LSP define additional placeforms (using
DEFSETF) for LDB MASK-FIELD FIRST REST SECOND THIRD (through TENTH)
and CxR. When used as a place form, the second argument of LDB and
MASK-FIELD must be place forms and the number is not destructively
modified.
A macro form, which is expanded and re-evaluated as a place form.
(send <obj> :<ivar>) to set the instance variable of an object
(requires CLASSES.LSP be used).
(<sym>-<element> <struct>) to set the element, <element>, of structure
<struct> which is of type <sym>/
(<fieldsym> <args>) form name <fieldsym>, defined with DEFSETF or
manually, is used with the arguments. When used with SETF, the
function stored in property *setf* of symbol <fieldsym> is applied to
(<args> <setf expr>), or, alternatively, the function stored in
property *setf-lambda* is applied then the result is evaluated in the
current context.
XLISP-PLUS 3.0 OBJECTS Page 21
OBJECTS
Definitions:
selector - a symbol used to select an appropriate method
message - a selector and a list of actual arguments
method - the code that implements a message
Since XLISP was created to provide a simple basis for experimenting with
object-oriented programming, one of the primitive data types included is
'object'. In XLISP, an object consists of a data structure containing a
pointer to the object's class as well as an array containing the values of
the object's instance variables.
Officially, there is no way to see inside an object (look at the values of
its instance variables). The only way to communicate with an object is by
sending it a message.
You can send a message to an object using the 'send' function. This
function takes the object as its first argument, the message selector as
its second argument (which must be a symbol) and the message arguments as
its remaining arguments.
The 'send' function determines the class of the receiving object and
attempts to find a method corresponding to the message selector in the set
of messages defined for that class. If the message is not found in the
object's class and the class has a super-class, the search continues by
looking at the messages defined for the super-class. This process continues
from one super-class to the next until a method for the message is found.
If no method is found, an error occurs.
To perform a method lookup starting with the method's superclass rather
than the object's class, use the function 'send-super'. This allows a
subclass to invoke a standard method in its parent class even though it
overrides that method with its own specialized version.
When a method is found, the evaluator binds the receiving object to the
symbol 'self' and evaluates the method using the remaining elements of the
original list as arguments to the method. These arguments are always
evaluated prior to being bound to their corresponding formal arguments. The
result of evaluating the method becomes the result of the expression.
Two objects, both classes, are predefined: Object and Class. Both Object
and Class are of class Class. The superclass of Class is Object, while
Object has no superclass. Typical use is to create new classes (by sending
:new to Class) to represent application objects. Objects of these classes,
created by sending :new to the appropriate new class, are subclasses of
Object. The Object method :show can be used to view the contents of any
object.
XLISP-PLUS 3.0 OBJECTS Page 22
THE 'Object' CLASS
Object THE TOP OF THE CLASS HEIRARCHY
Messages:
:show SHOW AN OBJECT'S INSTANCE VARIABLES
returns the object
:class RETURN THE CLASS OF AN OBJECT
returns the class of the object
:prin1 [<stream>] PRINT THE OBJECT
<stream> T is *terminal-io*, NIL and default is *standard-
output*
returns the object
:isnew THE DEFAULT OBJECT INITIALIZATION ROUTINE
returns the object
:superclass GET THE SUPERCLASS OF THE OBJECT
returns NIL
(Defined in classes.lsp, see :superclass below)
:ismemberof <class> CLASS MEMBERSHIP
<class> class name
returns T if object member of class, else NIL
(defined in classes.lsp)
:iskindof <class> CLASS MEMBERSHIP
<class> class name
returns T if object member of class or subclass of class,
else NIL
(defined in classes.lsp)
:respondsto <sel> SELECTOR KNOWLEDGE
<sel> message selector
returns T if object responds to message selector, else
NIL.
(defined in classes.lsp)
:storeon READ REPRESENTATION
returns a list, that when executed will create a copy of
the object. Only works for members of classes
created with defclass.
(defined in classes.lsp)
XLISP-PLUS 3.0 OBJECTS Page 23
THE 'Class' CLASS
Class THE CLASS OF ALL OBJECT CLASSES (including itself)
Messages:
:new CREATE A NEW INSTANCE OF A CLASS
returns the new class object
:isnew <ivars> [<cvars> [<super>]] INITIALIZE A NEW CLASS
<ivars> the list of instance variable symbol
<cvars> the list of class variable symbols
<super> the superclass (default is Object)
returns the new class object
:answer <msg> <fargs> <code> ADD A MESSAGE TO A CLASS
<msg> the message symbol
<fargs> the formal argument list (lambda list)
<code> a list of executable expressions
returns the object
:superclass GET THE SUPERCLASS OF THE OBJECT
returns the superclass (of the class)
(defined in classes.lsp)
:messages GET THE LIST OF MESSAGES OF THE CLASS
returns association list of message selectors and closures
for messages.
(defined in classes.lsp)
:storeon READ REPRESENTATION
returns a list, that when executed will re-create the
class and its methods.
(defined in classes.lsp)
When a new instance of a class is created by sending the message ':new' to
an existing class, the message ':isnew' followed by whatever parameters
were passed to the ':new' message is sent to the newly created object.
Therefore, when a new class is created by sending ':new' to class 'Class'
the message ':isnew' is sent to Class automatically. To create a new class,
a function of the following format is used:
(setq <newclassname> (send Class :new <ivars> [<cvars> [<super>]]))
When a new class is created, an optional parameter may be specified
indicating the superclass of the new class. If this parameter is omitted,
the new class will be a subclass of 'Object'. A class inherits all instance
variables, and methods from its super-class. Only class variables of a
method's class are accessable.
XLISP-PLUS 3.0 OBJECTS Page 24
INSTANCE VARIABLES OF CLASS 'CLASS':
MESSAGES - An association list of message names and closures
implementing the messages.
IVARS - List of names of instance variables.
CVARS - List of names of class variables.
CVAL - Array of class variable values.
SUPERCLASS - The superclass of this class or NIL if no superclass
(only for class OBJECT).
IVARCNT - instance variables in this class (length of IVARS)
IVARTOTAL - total instance variables for this class and all
superclasses of this class.
PNAME - printname string for this class.
XLISP-PLUS 3.0 SYMBOLS Page 25
SYMBOLS
All values are initially NIL unless otherwise specified. All are special
variables unless indicated to be constants.
NIL - represents empty list and the boolean value for "false". The
value of NIL is NIL, and cannot be changed (it is a constant). (car
NIL) and (cdr NIL) are also defined to be NIL.
t - boolean value "true" is constant with value t.
self - within a method context, the current object (see page 21),
otherwise initially unbound.
object - constant, value is the class 'Object.'
class - constant, value is the class 'Class'.
internal-time-units-per-second - integer constant to divide returned
times by to get time in seconds.
pi - floating point aproximation of pi (constant defined when math
extension is compiled).
*obarray* - the object hash table. Length of array is a compilation
option. Objects are hashed using the hash function and are placed on a
list in the appropriate array slot. This variable does note exist when
the package feature is compiled in.
*package* - the current package. Do not alter. Part of the package
feature.
*terminal-io* - stream bound to keyboard and display. Do not alter.
*standard-input* - the standard input stream, initially stdin. If
stdin is not redirected on the command line, then *terminal-io* is
used so that all interactive i/o uses the same stream.
*standard-output* - the standard output stream, initially stdout. If
stdout is not redirected on the command line then *terminal-io* is
used so that all interactive i/o uses the same stream.
*error-output* - the error output stream (used by all error messages),
initially same as *terminal-io*.
*trace-output* - the trace output stream (used by the trace function),
initially same as *terminal-io*.
*debug-io* - the break loop i/o stream, initially same as
*terminal-io*. System messages (other than error messages) also print
out on this stream.
*breakenable* - flag controlling entering break loop on errors (see
page 4)
*tracelist* - list of names of functions to trace, as set by trace
function.
*tracenable* - enable trace back printout on errors (see page 4).
*tracelimit* - number of levels of trace back information (see page
4).
*evalhook* - user substitute for the evaluator function (see page 9,
and evalhook and applyhook functions).
*applyhook* - user substitute for function application (see page 9,
and evalhook and applyhook functions).
*readtable* - the current readtable (see page 13).
*gc-flag* - controls the printing of gc messages. When non-NIL, a
message is printed after each garbage collection giving the total
number of nodes and the number of nodes free.
*gc-hook* - function to call after garbage collection (see page 9).
XLISP-PLUS 3.0 SYMBOLS Page 26
*integer-format* - format for printing integers (when not bound to a
string, defaults to "%d" or "%ld" depending on implementation).
Variable not used when bignum extension installed.
*float-format* - format for printing floats (when not bound to a
string, defaults to "%g")
*readtable-case* - symbol read and output case. See page 15 for
details
*read-base* - When bound to a fixnum in the range 2 through 36,
determines the default radix used when reading rational numbers. Part
of bignum extension.
*print-base* - When bound to a fixnum in the range 2 through 36,
determines the radix used when printing rational numbers with prin1
and princ. Part of bignum extension.
*print-case* - symbol output case when printing. See page 15 for
details
*print-level* - When bound to a number, list levels beyond this value
are printed as '#'. Used by all printing functions. Good precaution to
avoid getting caught in circular lists.
*print-length* - When bound to a number, lists longer than this value
are printed as '...'. Used by all printing functions. Good precaution
to avoid getting caught in circular lists.
*dos-input* - When not NIL, uses dos line input function for read (see
page 3).
*displace-macros* - When not NIL, macros are replaced by their
expansions when exectuted (see page 8).
*random-state* - the default random-state used by the random function.
*features* - list of features, initially (:xlisp), used for #+ and #-
reader macros.
*startup-functions* - list of functions to be executed when workspace
started
*command-line* - the xlisp command line, in the form of a list of
strings, one string per argument.
*load-file-arguments* - When not NIL, file arguements are loaded at
startup.
*top-level-loop* - Top level loop to utilize, defaults to TOP-LEVEL-
LOOP. Note that this function can only be restarted by executing TOP-
LEVEL, and it never exits.
*read-suppress* - When not NIL, inhibits certain parts of reading.
Used by the #+ and #- macroes.
There are several symbols maintained by the read/eval/print loop. The
symbols '+', '++', and '+++' are bound to the most recent three input
expressions. The symbols '*', '**' and '***' are bound to the most recent
three results. The symbol '-' is bound to the expression currently being
evaluated. It becomes the value of '+' at the end of the evaluation.
XLISP-PLUS 3.0 EVALUATION FUNCTIONS Page 27
EVALUATION FUNCTIONS
(eval <expr>) EVALUATE AN XLISP EXPRESSION
<expr> the expression to be evaluated
returns the result of evaluating the expression
(apply <fun> <arg>...<args>) APPLY A FUNCTION TO A LIST OF ARGUMENTS
<fun> the function to apply (or function symbol). May not be macro
or fsubr.
<arg> initial arguments, which are CONSed to...
<args> the argument list
returns the result of applying the function to the arguments
(funcall <fun> <arg>...) CALL A FUNCTION WITH ARGUMENTS
<fun> the function to call (or function symbol). May not be macro
or fsubr.
<arg> arguments to pass to the function
returns the result of calling the function with the arguments
(quote <expr>) RETURN AN EXPRESSION UNEVALUATED
fsubr
<expr> the expression to be quoted (quoted)
returns <expr> unevaluated
(function <expr>) GET THE FUNCTIONAL INTERPRETATION
fsubr
<expr> the symbol or lambda expression (quoted)
returns the functional interpretation
(complement <fun>) MAKE A COMPLEMENTARY FUNCTION
This function is intended to eliminate the need for -IF-NOT functions
and :TEST-NOT keys by providing a way to make complementary functions.
<fun> the function or closure (not macro or fsubr)
returns a new function closure that returns NOT of the result of the
original function.
(identity <expr>) RETURN THE EXPRESSION
<expr> the expression
returns the expression
(backquote <expr>) FILL IN A TEMPLATE
fsubr. Note: an improved backquote facility, which works properly when
nested, is available by loading the file backquot.lsp.
<expr> the template (quoted)
returns a copy of the template with comma and comma-at expressions
expanded.
(comma <expr>) COMMA EXPRESSION
(Never executed) As the object of a backquote expansion, the
expression is evaluated and becomes an object in the enclosing list.
XLISP-PLUS 3.0 EVALUATION FUNCTIONS Page 28
(comma-at <expr>) COMMA-AT EXPRESSION
(Never executed) As the object of a backquote expansion, the
expression is evaluated (and must evaluate to a list) and is then
spliced into the enclosing list.
(lambda <args> <expr>...) MAKE A FUNCTION CLOSURE
fsubr
<args> formal argument list (lambda list) (quoted)
<expr> expressions of the function body (quoted)
returns the function closure
(get-lambda-expression <closure>) GET THE LAMBDA EXPRESSION
<closure> the closure
returns the original lambda expression, or NIL if not a closure.
Second return value is T if closure has a non-global
environment, and the third return value is the name of the
closure.
(macroexpand <form>) RECURSIVELY EXPAND MACRO CALLS
<form> the form to expand
returns the macro expansion
(macroexpand-1 <form>) EXPAND A MACRO CALL
<form> the macro call form
returns the macro expansion
XLISP-PLUS 3.0 MULTIPLE VALUE FUNCTIONS Page 29
MULTIPLE VALUE FUNCTIONS
XLISP-PLUS supports multiple return values (via a compilation option) as in
Common Lisp. Note that most FSUBR control structure functions will pass
back multiple return values, with the exceptions being PROG1 and PROG2.
(multiple-value-bind <varlist> <vform> [<form>...])
BIND RETURN VALUES INTO LOCAL CONTEXT
defined as macro in common.lsp
<vform> form to be evaluated
<varlist> list of variables to bind to return values of vform
<form> forms evaluated sequentially, as in LET, using local
bindings
returns values of last form evaluated, or NIL if no forms
(multiple-value-call <fun> <form> ...) COLLECT VALUES AND APPLY FUNCTION
fsubr
<fun> function to apply
<form> forms, which are evaluated, with result values collected
returns result of applying fun to all of the returned values of the
forms
(multiple-value-list <form>) COLLECT MULTIPLE RETURNED VALUES INTO A LIST
defined as macro in common.lsp
<form> form to be evaluated
returns list of returned values
(multiple-value-prog1 <form> [<form> ...]) RETURN VALUES OF FIRST FORM
fsubr
<form> one or more forms, which are evaluated sequentially
returns the result values of the first form
(multiple-value-setq <varlist> <form>) BIND RETURN VALUES TO VARIABLES
defined as macro in common.lsp
<form> form to be evaluated
<varlist> list of variables to bind to return values of form
returns (undefined, implementation dependent)
(nth-value <index> <form>) EXTRACT A RETURN VALUE
fsubr
<index> index into return values
<form> form which gets evaluated
returns the nth result value of exectuing the form
(values [<expr>]) RETURN MULTIPLE VALUES
<expr> expression(s) to be evaluated
returns each argument as a separate value
(values-list <list>) RETURN MULTIPLE VALUES FROM LIST
defined in common.lsp
<list> a list
returns each list element as a separate value
XLISP-PLUS 3.0 SYMBOL FUNCTIONS Page 30
SYMBOL FUNCTIONS
(set <sym> <expr>) SET THE GLOBAL VALUE OF A SYMBOL
You can also use (setf (symbol-value <sym>) <expr>)
<sym> the symbol being set
<expr> the new value
returns the new value
(setq [<sym> <expr>]...) SET THE VALUE OF A SYMBOL
fsubr. You can also use (setf <sym> <expr>)
<sym> the symbol being set (quoted)
<expr> the new value
returns the last new value or NIL if no arguments
(psetq [<sym> <expr>]...) PARALLEL VERSION OF SETQ
fsubr. All expressions are evaluated before any assignments are
made.
<sym> the symbol being set (quoted)
<expr> the new value
returns NIL
(defun <sym> <fargs> <expr>...) DEFINE A FUNCTION
(defmacro <sym> <fargs> <expr>...) DEFINE A MACRO
fsubr
<sym> symbol being defined (quoted)
<fargs> formal argument list (lambda list) (quoted)
<expr> expressions constituting the body of the function (quoted)
returns the function symbol
(gensym [<tag>]) GENERATE A SYMBOL
<tag> string or number
returns the new symbol, uninterned
(intern <pname> [<package>]) MAKE AN INTERNED SYMBOL
<pname> the symbol's print name string
<package> the package (defaults to current package)
returns the new symbol. A second value is returned which is NIL if
the symbol did not pre-exist, :internal if it is an internal
symbol, :external if it is an external symbol, or :inherited
if it inherited via USE-PACKAGE.
(make-symbol <pname>) MAKE AN UNINTERNED SYMBOL
<pname> the symbol's print name string
returns the new symbol
(symbol-name <sym>) GET THE PRINT NAME OF A SYMBOL
<sym> the symbol
returns the symbol's print name
(symbol-value <sym>) GET THE VALUE OF A SYMBOL
May be used as a place form.
<sym> the symbol
returns the symbol's value
XLISP-PLUS 3.0 SYMBOL FUNCTIONS Page 31
(symbol-function <sym>) GET THE FUNCTIONAL VALUE OF A SYMBOL
May be used as a place form.
<sym> the symbol
returns the symbol's functional value
(symbol-plist <sym>) GET THE PROPERTY LIST OF A SYMBOL
May be used as a place form.
<sym> the symbol
returns the symbol's property list
(hash <expr> <n>) COMPUTE THE HASH INDEX
<expr> the object to hash
<n> the table size (positive fixnum less than 32768)
returns the hash index (fixnum 0 to n-1)
(makunbound <sym>) MAKE A SYMBOL VALUE BE UNBOUND
You cannot unbind constants.
<sym> the symbol
returns the symbol
(fmakunbound <sym>) MAKE A SYMBOL FUNCTION BE UNBOUND
<sym> the symbol
returns the symbol
(unintern <sym> [<package>]) UNINTERN A SYMBOL
Defined in common.lsp if package extension not compiled.
<sym> the symbol
<package> the package to look in for the symbol
returns t if successful, NIL if symbol not interned
(defconstant <sym> <val> [<comment>]) DEFINE A CONSTANT
fsubr.
<sym> the symbol
<val> the value
<comment> optional comment string (ignored)
returns the value
(defparameter <sym> <val> [<comment>]) DEFINE A PARAMETER
fsubr.
<sym> the symbol (will be marked "special")
<val> the value
<comment> optional comment string (ignored)
returns the value
(defvar <sym> [<val> [<comment>]]) DEFINE A VARIABLE
fsubr. Variable only initialized if not previously defined.
<sym> the symbol (will be marked "special")
<val> the initial value, or NIL if absent.
<comment> optional comment string (ignored)
returns the current value
XLISP-PLUS 3.0 SYMBOL FUNCTIONS Page 32
(mark-as-special <sym> [<flag>]) SET SPECIAL ATTRIBUTE
Also see definition of PROCLAIM and DECLARE.
<sym> symbol to mark
<flag> non-nil to make into a constant
returns nil, with symbol marked as special and possibly as a
constant.
(declare [<declaration> ...]) DECLARE ARGUMENT ATTRIBUTES
Macro in common.lsp provided to assist in porting Common Lisp
applications to XLISP-PLUS.
<declaration> list of local variable and attributes
returns nil, produces an error message if attribute SPECIAL is used.
(proclaim <proc>) PROCLAIM GLOBAL SYMBOL ATTRIBUTES
Function in common.lsp provided to assist in porting Common Lisp
applications to XLISP-PLUS.
<proc> a list of symbols. If the CAR of the list is SPECIAL, then
the remaining symbols are marked as special variables.
(copy-symbol <sym> [<flag>]) MAKE A COPY OF A SYMBOL
Function in common2.lsp
<sym> symbol to copy
<flag> if present and non-nil, copy value, function binding, and
property list.
returns un-interned copy of <sym>
XLISP-PLUS 3.0 GENERALIZED VARIABLE FUNCTIONS Page 33
GENERALIZED VARIABLE FUNCTIONS
(setf [<place> <expr>]...) SET THE VALUE OF A FIELD
fsubr
<place> the field specifier
<expr> the new value
returns the last new value, or NIL if no arguments
(psetf [<place> <expr>]...) PARALLEL VERSION OF SETF
fsubr. All expressions are evaluated and macro place forms expanded
before any assignments are made.
<place> the field specifier
<expr> the new value
returns NIL
(defsetf <sym> <fcn>) DEFINE A SETF FIELD SPECIFIER
(defsetf <sym> <fargs> (<value>) <expr>...)
Defined as macro in common.lsp. Convenient, Common Lisp compatible
alternative to setting *setf* or *setf-lambda* property directly.
<sym> field specifier symbol (quoted)
<fcn> function to use (quoted symbol) which takes the same
arguments as the field specifier plus an additional argument
for the value. The value must be returned.
<fargs> formal argument list of unevaluated arguments (lambda list)
(quoted)
<value> symbol bound to value to store (quoted).
<expr> The last expression must an expression to evaluate in the
setf context.In this respect, defsetf works like a macro
definition.
returns the field specifier symbol
(push <expr> <place>) CONS TO A FIELD
Defined as macro in common.lsp. Only evaluates place form arguments
one time. It is recommended that *displace-macros* be non-NIL for best
performance.
<place> field specifier being modified (see setf)
<expr> value to cons to field
returns the new value which is (CONS <expr> <place>)
(pushnew <expr> <place> &key :test :test-not :key) CONS NEW TO A FIELD
Defined as macro in common.lsp. Only evaluates place form arguments
one time. It is recommended that *displace-macros* be non-NIL for best
performance.
<place> field specifier being modified (see setf)
<expr> value to cons to field, if not already MEMBER of field
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to test function list argument (defaults
to identity)
returns the new value which is (CONS <expr> <place>) or <place>
XLISP-PLUS 3.0 GENERALIZED VARIABLE FUNCTIONS Page 34
(pop <place>) REMOVE FIRST ELEMENT OF A FIELD
Defined as macro in common.lsp. Only evaluates place form arguments
one time. It is recommended that *displace-macros* be non-NIL for best
performance.
<place> the field being modified (see setf)
returns (CAR <place>), field changed to (CDR <place>)
(incf <place> [<value>]) INCREMENT A FIELD
(decf <place> [<value>]) DECREMENT A FIELD
Defined as macro in common.lsp. Only evaluates place form arguments
one time. It is recommended that *displace-macros* be non-NIL for best
performance.
<place> field specifier being modified (see setf)
<value> Numeric value (default 1)
returns the new value which is (+ <place> <value>) or (- <place>
<value>)
XLISP-PLUS 3.0 PACKAGE FUNCTIONS Page 35
PACKAGE FUNCTIONS
These functions are defined when the packages extension is compiled. The
<package> argument can be either a string, symbol, or package object. The
default when no package is given is the current package (as bound to
*package*), unless otherwise specified in the definition. The <symbols>
argument may be either a single symbol or a list of symbols. In case of
name conflicts, a correctable error occurs.
When the packages extension is not compiled, simplified versions of
apropos, apropos-list, and do-all-symbols are provided in common2.lsp. In
addition, init.lsp will define dummy versions of export and in-package.
(apropos <string> [<package>]) SEARCH SYMBOLS FOR NAME MATCH
(apropos-list <string> [<package>])
Functions in common.lsp.
<string> find symbols which contain this string as substring of print
name
<package> package to search, if absent, or NIL, search all packages
returns apropos-list returns list of symbols, apropos prints them,
along with some information, and returns nothing.
(defpackage <package> [<option>...]) (RE)DEFINE A PACKAGE
Macro in common.lsp. Use to define a package, or redefine a package.
<package> the name of the package to (re)define
<option> any one or more of the following, none evaluated, applied in
this order:
(:shadow <symbol>...)
one or more symbols to shadow, as in function SHADOW
(:shadowing-import-from <symbol>...)
one or more symbols to shadow, as in function
SHADOWING-IMPORT
(:use <package>...)
one or more packages to "use", as in function USE-PACKAGE
(:import-from <package> <symbol>...)
one or more symbols to import from the package, as in
function IMPORT
(:intern <symbol>...)
one or more symbols to be located or created in this
package, as in function INTERN
(:export <symbol>...)
one or more symbols to be exported from this package, as in
function EXPORT
returns the new or redefined package
(delete-package <package>) DELETE A PACKAGE
Deletes a package by uninterning all its symbols and removing the
package.
<package> package to delete
returns T if successful
XLISP-PLUS 3.0 PACKAGE FUNCTIONS Page 36
(do-symbols (<var> [<package> [<result>]]) <expr>...)) ITERATE OVER SYMBOLS
(do-external-symbols (<var> [<package> [<result>]]) <expr>...)
(do-all-symbols (<var> [<result>]) <expr>...)
Implemented as macros in common.lsp. DO-SYMBOLS iterates over all
symbols in a single package, DO-EXTERNAL-SYMBOLS iterates only over
the external symbols, and DO-ALL-SYMBOLS iterates over all symbols in
all packages.
<var> variable to bind to symbol
<package> the package to search
<result> a single result form
<expr> expressions to evaluate (implicit tag-body)
returns result of result form, or NIL if not specified
(export <symbols> [<package>]) DECLARE EXTERNAL SYMBOLS
<symbols> symbols to declare as external
<package> package symbol is in
returns T
(find-all-symbols <string>) FIND SYMBOLS WITH SPECIFIED NAME
<string> string or symbol (if latter, print name string is used)
returns list of all symbols having that print-name
(find-package <package>) FIND PACKAGE WITH SPECIFIED NAME
<package> package to find
returns package with name or nickname <package>, or NIL if not found
(find-symbol <string> [<package>]) LOOK UP A SYMBOL
<string> print name to search for
<package> package to search in
returns two values, the first being the symbol, and the second being
:internal if the symbol is internal in the package,
:external if it is external, or :inherited if it is
inherited via USE-PACKAGE. If the symbol was not found, then
both return values are NIL.
(import <symbols> [<package>]) IMPORT SYMBOLS INTO A PACKAGE
<symbols> symbols to import (fully qualified names)
<package> package to import symbols into
returns T
(in-package <package>) SET CURRENT PACKAGE
FSUBR which sets the current package until next call or end of current
LOAD.
<package> the package to enter
returns the package
(list-all-packages) GET ALL PACKAGE NAMES
returns list of all currently existing packages
(make-package <package> &key :nicknames :use) MAKE A NEW PACKAGE
<package> name of new package to create
:nicknames list of package nicknames
:use list of packages to use (as in USE-PACKAGE)
returns the new package
XLISP-PLUS 3.0 PACKAGE FUNCTIONS Page 37
(package-name <package>) GET PACKAGE NAME STRING
<package> package name
returns package name string
(package-nicknames <package>) GET PACKAGE NICKNAME STRINGS
<package> package name
returns list of package nickname strings
(package-obarray <package> [<external>]) GET AN OBARRAY
<package> package to use
<external> non-nil for external obarray (default), else
internal obarray
returns the obarray (array of lists of symbols in package)
(package-shadowing-symbols <package>) GET LIST OF SHADOWING SYMBOLS
<package> the package
returns list of shadowing symbols in package
(package-use-list <package>) GET PACKAGES USED BY A PACKAGE
<package> the package
returns list of packages used by this package (as in USE-PACKAGE)
(package-used-by-list <package>) GET PACKAGES THAT USE THIS PACKAGE
<package> the package
returns list of packages that use this package (as in USE-PACKAGE)
(package-valid-p <package>) IS THIS A GOOD PACKAGE?
<package> object to check
returns T if a valid package, else NIL
(rename-package <package> <new> [<nick>]) RENAME A PACKAGE
<package> original package
<new> new package name (may be same as original name)
<nick> list of new package nicknames
returns the new package
(shadow <symbols> [<package>]) MAKE SHADOWING SYMBOLS
If a symbol is not already in the package, it is interned. The symbol
is placed in the shadowing symbols list for the package.
<symbols> the symbol or symbols to shadow
<package> package to put symbols in
returns T
(shadowing-import <symbols> [<package>]) IMPORT SYMBOLS AND SHADOW
If a symbol exists in the package, it is first uninterned. The symbol
is imported, and then made shadowing.
<symbols> the symbol or symbols to import and shadow
<package> package to put symbols in
returns T
(symbol-package <symbol>) FIND THE PACKAGE OF A SYMBOL
<symbol> the symbol
returns the home package of the symbol, or NIL if none
XLISP-PLUS 3.0 PACKAGE FUNCTIONS Page 38
(unexport <symbols> [<package>]) MAKE SYMBOLS INTERNAL TO PACKAGE
<symbols> symbol or symbols to make internal
<package> package for symbols
returns T
(unuse-package <pkgs> [<package>]) REMOVE PACKAGES FROM USE LIST
<pkgs> A single package or list of packages
<package> Package in which to un-use packages (default is current
package)
returns T
(use-package <pkgs> [<package>]) ADD PACKAGES TO USE LIST
<pkgs> A single package or list of packages
<package> Package in which to use packages in (default is current
package)
returns T
XLISP-PLUS 3.0 PROPERTY LIST FUNCTIONS Page 39
PROPERTY LIST FUNCTIONS
Note that property names are not limited to symbols. All functions handle a
symbol's property lists except for GETF and REMF which work with any
property list.
(get <sym> <prop> [<dflt>]) GET THE VALUE OF A SYMBOL'S PROPERTY
Use as a place form (with SETF) to add or change properties.
<sym> the symbol
<prop> the property name
<dflt> value to return if property not found, default is NIL
returns the property value or <dflt> if property doesn't exist.
(getf <place> <prop> [<dflt>]) GET THE VALUE OF A PROPERTY
Use GETF as a place form with SETF to add or change properties. (NOTE-
-when used with SETF, <place> must be a valid place form. It gets
executed twice, contrary to Common Lisp standard.)
<place> where the property list is stored
<prop> the property name
<dflt> value to return if property not found, default is NIL
returns the property value or <dflt> if property doesn't exist.
(putprop <sym> <val> <prop>) PUT A PROPERTY ONTO A PROPERTY LIST
Modern practice is to use (SETF (GET...)...) rather than PUTPROP.
<sym> the symbol
<val> the property value
<prop> the property name
returns the property value
(remf <place> <prop>) DELETE A PROPERTY
Defined as a macro in COMMON.LSP
<place> where the property list is stored
<prop> the property name
returns T if property existed, else NIL
(remprop <sym> <prop>) DELETE A SYMBOL'S PROPERTY
<sym> the symbol
<prop> the property name
returns NIL
XLISP-PLUS 3.0 HASH TABLE FUNCTIONS Page 40
HASH TABLE FUNCTIONS
A hash table is implemented as an structure of type hash-table. No general
accessing functions are provided, and hash tables print out using the angle
bracket convention (not readable by READ). The first element is the
comparison function. The remaining elements contain association lists of
keys (that hash to the same value) and their data.
(make-hash-table &key :size :test) MAKE A HASH TABLE
:size fixnum size of hash table -- should be a prime number.
Default is 31.
:test comparison function. Defaults to eql.
returns the hash table
(gethash <key> <table> [<def>]) EXTRACT FROM HASH TABLE
May be used as place form.
<key> hash key
<table> hash table
<def> value to return on no match (default is NIL)
returns associated data, if found, or <def> if not found.
(remhash <key> <table>) DELETE FROM HASH TABLE
<key> hash key
<table> hash table
returns T if deleted, NIL if not in table
(clrhash <table>) CLEAR THE HASH TABLE
<table> hash table
returns NIL, all entries cleared from table
(hash-table-count <table>) NUMBER OF ENTRIES IN HASH TABLE
<table> hash table
returns integer number of entries in table
(maphash <fcn> <table>) MAP FUNCTION OVER TABLE ENTRIES
<fcn> the function or function name, a function of two arguments,
the first is bound to the key, and the second the value of
each table entry in turn.
<table> hash table
returns NIL
XLISP-PLUS 3.0 ARRAY FUNCTIONS Page 41
ARRAY FUNCTIONS
Note that sequence functions also work on arrays.
(aref <array> <n>) GET THE NTH ELEMENT OF AN ARRAY
May be used as a place form
<array> the array (or string)
<n> the array index (fixnum, zero based)
returns the value of the array element
(make-array <size> &key :initial-element :initial-contents) MAKE A NEW ARRAY
<size> the size of the new array (fixnum)
:initial-element
value to initialize all array elements, default NIL
:initial-contents
sequence used to initialize all array elements, consecutive
sequence elements are used for each array element. The
length of the sequence must be the same as the size of the
array
returns the new array
(vector <expr>...) MAKE AN INITIALIZED VECTOR
<expr> the vector elements
returns the new vector
XLISP-PLUS 3.0 SEQUENCE FUNCTIONS Page 42
SEQUENCE FUNCTIONS
These functions work on sequences -- lists, arrays, or strings.
(concatenate <type> <expr> ...) CONCATENATE SEQUENCES
If result type is string, sequences must contain only characters.
<type> result type, one of CONS, LIST, ARRAY, or STRING
<expr> zero or more sequences to concatenate
returns a sequence which is the concatenation of the arguement
sequences
(elt <expr> <n>) GET THE NTH ELEMENT OF A SEQUENCE
May be used as a place form
<expr> the sequence
<n> the index of element to return
returns the element if the index is in bounds, otherwise error
(map <type> <fcn> <expr> ...) APPLY FUNCTION TO SUCCESSIVE ELEMENTS
(map-into <target> <fcn> [<expr> ...])
<type> result type, one of CONS, LIST, ARRAY, STRING, or NIL
<target> destination sequence to modify
<fcn> the function or function name
<expr> a sequence for each argument of the function
returns a new sequence of type <type> for MAP, and <target> for
MAP-INTO.
(every <fcn> <expr> ...) APPLY FUNCTION TO ELEMENTS UNTIL FALSE
(notevery <fcn> <expr> ...)
<fcn> the function or function name
<expr> a sequence for each argument of the function
returns every returns last evaluated function result
notevery returns T if there is a NIL function result, else
NIL
(some <fcn> <expr> ...) APPLY FUNCTION TO ELEMENTS UNTIL TRUE
(notany <fcn> <expr> ...)
<fcn> the function or function name
<expr> a sequence for each argument of the function
returns some returns first non-NIL function result, or NIL
notany returns NIL if there is a non-NIL function result,
else T
(length <expr>) FIND THE LENGTH OF A SEQUENCE
Note that a circular list causes an error. To detect a circular list,
use LIST-LENGTH.
<expr> the list, vector or string
returns the length of the list, vector or string
(reverse <expr>) REVERSE A SEQUENCE
(nreverse <expr>) DESTRUCTIVELY REVERSE A SEQUENCE
<expr> the sequence to reverse
returns a new sequence in the reverse order
XLISP-PLUS 3.0 SEQUENCE FUNCTIONS Page 43
(subseq <seq> <start> [<end>]) EXTRACT A SUBSEQUENCE
<seq> the sequence
<start> the starting position (zero origin)
<end> the ending position + 1 (defaults to end) or NIL for end of
sequence
returns the sequence between <start> and <end>
(sort <seq> <test> &key :key) DESTRUCTIVELY SORT A SEQUENCE
(stable-sort <seq> <test> &key :key) STABLE DESTRUCTIVE SORT
<seq> the sequence to sort
<test> the comparison function, must return T only if its first
argument is strictly to the left of its second argument.
:key function to apply to comparison function arguments (defaults
to identity)
returns the sorted sequence
(search <seq1> <seq2> &key :test :test-not :key :start1 :end1 :start2
:end2)
SEARCH FOR SEQUENCE
<seq1> the sequence to search for
<seq2> the sequence to search in
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to test function arguments (defaults to
identity)
:start1 starting index in <seq1>
:end1 index of end+1 in <seq1> or NIL for end of sequence
:start2 starting index in <seq2>
:end2 index of end+1 in <seq2> or NIL for end of sequence
returns position of first match
(remove <expr> <seq> &key :test :test-not :key :start :end :count
:from-end)
REMOVE ELEMENTS FROM A SEQUENCE
(remove-if <test> <seq> &key :key :start :end :count :from-end)
REMOVE ELEMENTS THAT PASS TEST
(remove-if-not <test> <seq> &key :key :start :end :count :from-end)
REMOVE ELEMENTS THAT FAIL TEST
<expr> the element to remove
<test> the test predicate, applied to each <seq> element in turn
<seq> the sequence
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to each <seq> element (defaults to
identity)
:start starting index
:end index of end+1, or NIL for (length <seq>)
:count maximum number of elements to remove, negative values
treated as zero, NIL same as default -- unlimited.
:from-end if non-nil, behaves as though elements are removed from
right end. This only has an affect when :count is used.
returns copy of sequence with matching/non-matching expressions
removed
XLISP-PLUS 3.0 SEQUENCE FUNCTIONS Page 44
(count <expr> <seq> &key :test :test-not :key :start :end :from-end)
COUNT MATCHING ELEMENTS IN A SEQUENCE
(count-if <test> <seq> &key :key :start :end :from-end)
COUNT ELEMENTS THAT PASS TEST
(count-if-not <test> <seq> &key :key :start :end :from-end)
COUNT ELEMENTS THAT FAIL TEST
<expr> element to count
<test> the test predicate, applied to each <seq> element in turn
<seq> the sequence
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to each <seq> element (defaults to
identity)
:start starting index
:end index of end+1, or NIL for (length <seq>)
:from-end this argument is ignored
returns count of matching/non-matching elements
(find <expr> <seq> &key :test :test-not :key :start :end :from-end)
FIND FIRST MATCHING ELEMENT IN SEQUENCE
(find-if <test> <seq> &key :key :start :end :from-end)
FIND FIRST ELEMENT THAT PASSES TEST
(find-if-not <test> <seq> &key :key :start :end :from-end)
FIND FIRST ELEMENT THAT FAILS TEST
<expr> element to search for
<test> the test predicate, applied to each <seq> element in turn
<seq> the sequence
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to each <seq> element (defaults to
identity)
:start starting index
:end index of end+1, or NIL for (length <seq>)
:from-end if non-nil search is done for last element
returns first matching/non-matching element of sequence, or NIL
(position <expr> <seq> &key :test :test-not :key :start :end :from-end)
FIND POSITION OF FIRST MATCHING ELEMENT IN SEQUENCE
(position-if <test> <seq> &key :key :start :end :from-end)
FIND POSITION OF FIRST ELEMENT THAT PASSES TEST
(position-if-not <test> <seq> &key :key :start :end :from-end)
FIND POSITION OF FIRST ELEMENT THAT FAILS TEST
<expr> element to search for
<test> the test predicate, applied to each <seq> element in turn
<seq> the sequence
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to each <seq> element (defaults to
identity)
:start starting index
:end index of end+1, or NIL for (length <seq>)
:from-end if non-nil search is made for last element
returns position of first matching/non-matching element of sequence,
or NIL
XLISP-PLUS 3.0 SEQUENCE FUNCTIONS Page 45
(delete <expr> <seq> &key :key :test :test-not :start :end :count
:from-end)
DELETE ELEMENTS FROM A SEQUENCE
(delete-if <test> <seq> &key :key :start :end :count :from-end)
DELETE ELEMENTS THAT PASS TEST
(delete-if-not <test> <seq> &key :key :start :end :count :from-end)
DELETE ELEMENTS THAT FAIL TEST
<expr> the element to delete
<test> the test predicate, applied to each <seq> element in turn
<seq> the sequence
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to each <seq> element (defaults to
identity)
:start starting index
:end index of end+1, or NIL for (length <seq>)
:count maximum number of elements to remove, negative values
treated as zero, NIL same as default -- unlimited.
:from-end if non-nil, behaves as though elements are removed from
right end. This only has an affect when :count is used.
returns <seq> with the matching/non-matching expressions deleted
(substitute <r> <e> <s> &key :key :test :test-not :start :end :count :from-
end)
SUBSTITUTE ELEMENTS IN A SEQUENCE
(substitute-if <r> <test> <s> &key :key :start :end :count :from-end)
SUBSTITUTE ELEMENTS THAT PASS TEST
(substitute-if-not <r> <test> <s> &key :key :start :end :count :from-end)
SUBSTITUTE ELEMENTS THAT FAIL TEST
<r> the replacement expression
<e> the element to replace
<test> the test predicate, applied to each <s> element in turn
<s> the sequence
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to each <s> element (defaults to identity)
:start starting index
:end index of end+1, or NIL for (length <s>)
:count maximum number of elements to remove, negative values
treated as zero, NIL same as default -- unlimited.
:from-end if non-nil, behaves as though elements are removed from
right end. This only has an affect when :count is used.
returns copy of <s> with the matching/non-matching expressions
substituted
XLISP-PLUS 3.0 SEQUENCE FUNCTIONS Page 46
(nsubstitute <r> <e> <s> &key :key :test :test-not :start :end :count
:from-end)
DESTRUCTIVELY SUBSTITUTE ELEMENTS IN A SEQUENCE
(nsubstitute-if <r> <test> <s> &key :key :start :end :count :from-end)
DESTRUCTIVELY SUBSTITUTE ELEMENTS THAT PASS TEST
(nsubstitute-if-not <r> <test> <s> &key :key :start :end :count :from-end)
DESTRUCTIVELY SUBSTITUTE ELEMENTS THAT FAIL TEST
<r> the replacement expression
<e> the element to replace
<test> the test predicate, applied to each <s> element in turn
<s> the sequence
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to each <s> element (defaults to identity)
:start starting index
:end index of end+1, or NIL for (length <s>)
:count maximum number of elements to remove, negative values
treated as zero, NIL same as default -- unlimited.
:from-end if non-nil, behaves as though elements are removed from
right end. This only has an affect when :count is used.
returns <s> with the matching/non-matching expressions substituted
(reduce <fcn> <seq> &key :initial-value :start :end)
REDUCE SEQUENCE TO SINGLE VALUE
<fcn> function (of two arguments) to apply to result of previous
function application (or first element) and each member of
sequence.
<seq> the sequence
:initial-value value to use as first argument in first function
application rather than using the first element of
the sequence.
:start starting index
:end index of end+1, or NIL for (length <seq>)
returns if sequence is empty and there is no initial value, returns
result of applying function to zero arguements. If there is
a single element, returns the element. Otherwise returns the
result of the last function application.
(remove-duplicates <seq> &key :test :test-not :key :start :end)
MAKE SEQUENCE WITH DUPLICATES REMOVED
(delete-duplicates <seq> &key :test :test-not :key :start :end)
DELETE DUPLICATES FROM SEQUENCE
Delete-duplicates defined in common2.lsp.
<seq> the sequence
:test comparison function (default eql)
:test-not comparison function (sense inverted)
:key function to apply to test function arguments (defaults to
identity)
:start starting index
:end index of end+1, or NIL for (length <seq>)
returns copy of sequence with duplicates removed, or <seq> with
duplicates deleted (destructive).
XLISP-PLUS 3.0 SEQUENCE FUNCTIONS Page 47
(fill <seq> <expr> &key :start :end) REPLACE ITEMS IN SEQUENCE
Defined in common.lsp
<seq> the sequence
<expr> new value to place in sequence
:start starting index
:end index of end+1, or NIL for (length <seq>)
returns sequence with items replaced with new item
(replace <seq1> <seq2> &key :start1 :end1 :start2 :end2)
REPLACE ITEMS IN SEQUENCE FROM SEQUENCE
Defined in common.lsp
<seq1> the sequence to modify
<seq2> sequence with new items
:start1 starting index in <seq1>
:end1 index of end+1 in <seq1> or NIL for end of sequence
:start2 starting index in <seq2>
:end2 index of end+1 in <seq2> or NIL for end of sequence
returns first sequence with items replaced
(make-sequence <type> <size> &key :initial-element) MAKE A SEQUENCE
Defined in common2.lsp.
<type> type of sequence to create: CONS LIST ARRAY or STRING
<size> size of sequence (non-negative integer)
:initial-element
initial value of all elements in sequence
returns the new sequence
(copy-seq <seq>) COPY A SEQUENCE
Defined in common2.lsp
<seq> sequence to copy
returns copy of the sequence, sequence elements are eq those in the
original sequence.
(merge <type> <seq1> <seq2> <pred> &key :key) MERGE TWO SEQUENCES
Defined in common2.lsp. Non-destructive, although may be destructive
in Common Lisp.
<type> type of result sequence: CONS LIST ARRAY or STRING
<seq1> first sequence to merge
<seq2> second sequence to merge
<pred> function of two arguments which returns true if its first
argument should precede its second
:key optional function to apply to each sequence element before
applying predicate function (defaults to identity)
returns new sequence containing all the elements of seq1 (in order)
merged with all the elements of seq2, according to the
predicate function
XLISP-PLUS 3.0 SEQUENCE FUNCTIONS Page 48
(mismatch <s1> <s2> &key :test :test-not :key :start1 :end1 :start2 :end2)
FIND DIFFERENCE BETWEEN TWO SEQUENCES
Defined in common2.lsp.
<s1> first sequence
<s2> second sequence
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to to each sequence element before
applying test function (defaults to identity)
:start1 starting index in <s1>
:end1 index of end+1 in <s1> or NIL for end of sequence
:start2 starting index in <s2>
:end2 index of end+1 in <s2> or NIL for end of sequence
returns integer index of first mismatch in s1, or NIL if no mismatch
XLISP-PLUS 3.0 LIST FUNCTIONS Page 49
LIST FUNCTIONS
(car <expr>) RETURN THE CAR OF A LIST NODE
May be used as a place form.
<expr> the list node
returns the car of the list node
(cdr <expr>) RETURN THE CDR OF A LIST NODE
May be used as a place form.
<expr> the list node
returns the cdr of the list node
(cxxr <expr>) ALL CxxR COMBINATIONS
(cxxxr <expr>) ALL CxxxR COMBINATIONS
(cxxxxr <expr>) ALL CxxxxR COMBINATIONS
May be used as place forms when COMMON2.LSP loaded.
(first <expr>) A SYNONYM FOR CAR
(second <expr>) A SYNONYM FOR CADR
(third <expr>) A SYNONYM FOR CADDR
(fourth <expr>) A SYNONYM FOR CADDDR
(fifth <expr>) FIFTH LIST ELEMENT
(sixth <expr>) SIXTH LIST ELEMENT
(seventh <expr>) SEVENTH LIST ELEMENT
(eighth <expr>) EIGHTH LIST ELEMENT
(ninth <expr>) NINTH LIST ELEMENT
(tenth <expr>) TENTH LIST ELEMENT
(rest <expr>) A SYNONYM FOR CDR
May be used as place forms when COMMON2.LSP loaded. fifth through
tenth defined in COMMON2.LSP.
(cons <expr1> <expr2>) CONSTRUCT A NEW LIST NODE
<expr1> the car of the new list node
<expr2> the cdr of the new list node
returns the new list node
(acons <expr1> <expr2> <alist>) ADD TO FRONT OF ASSOC LIST
defined in common.lsp
<expr1> key of new association
<expr2> value of new association
<alist> association list
returns new association list, which is (cons (cons <expr1> <expr2>)
<expr3>))
(list <expr>...) CREATE A LIST OF VALUES
(list* <expr> ... <list>)
<expr> expressions to be combined into a list
returns the new list
(append <expr>...) APPEND LISTS
<expr> lists whose elements are to be appended
returns the new list
XLISP-PLUS 3.0 LIST FUNCTIONS Page 50
(revappend <expr1> <expr2>) APPEND REVERSE LIST
Defined in common2.lsp
<expr1> first list
<expr2> second list
returns new list comprised of reversed first list appended to second
list
(list-length <list>) FIND THE LENGTH OF A LIST
<list> the list
returns the length of the list or NIL if the list is circular
(last <list>) RETURN THE LAST LIST NODE OF A LIST
<list> the list
returns the last list node in the list
(tailp <sublist> <list>) IS ONE LIST A SUBLIST OF ANOTHER?
Defined in common2.lsp
<sublist> list to search for
<list> list to search in
returns T if sublist is EQ one of the top level conses of list
(butlast <list> [<n>]) RETURN COPY OF ALL BUT LAST OF LIST
(nbutlast <list> [<n>]) DELETE LAST ELEMENTS OF LIST
nbutlast defined in common2.lsp
<list> the list
<n> count of elements to omit (default 1)
returns copy of list with last element(s) absent, or, for nbutlast,
the list with the last elements deleted (destructive).
(nth <n> <list>) RETURN THE NTH ELEMENT OF A LIST
May be used as a place form
<n> the number of the element to return (zero origin)
<list> the list
returns the nth element or NIL if the list isn't that long
(nthcdr <n> <list>) RETURN THE NTH CDR OF A LIST
<n> the number of the element to return (zero origin)
<list> the list
returns the nth cdr or NIL if the list isn't that long
(member <expr> <list> &key :test :test-not :key)
FIND AN EXPRESSION IN A LIST
(member-if <test> <list> &key :key) FIND ELEMENT PASSING TEST
(member-if-not <test> <list> &key :key) FIND ELEMENT FAILING TEST
Functions member-if and member-if-not defined in common2.lsp
<expr> the expression to find
<test> the test predicate
<list> the list to search
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to test function list argument (defaults
to identity)
returns the remainder of the list starting with the expression or
element passing/failing the test predicate
XLISP-PLUS 3.0 LIST FUNCTIONS Page 51
(assoc <expr> <alist> &key :test :test-not :key)
FIND AN EXPRESSION IN AN A-LIST
(assoc-if <test> <alist> &key :key) FIND ELEMENT IN A-LIST PASSING TEST
(assoc-if-not <test> <alist> &key :key) FIND ELEMENT IN A-LIST FAILING TEST
(rassoc <expr> <alist> &key :test :test-not :key)
FIND AN EXPRESSION IN AN A-LIST
(rassoc-if <test> <alist> &key :key) FIND ELEMENT IN A-LIST PASSING TEST
(rassoc-if-not <test> <alist> &key :key)FIND ELEMENT IN A-LIST FAILING TEST
All functions but assoc defined in common2.lsp. The rassoc functions
match the cdrs of the a-list elements while the assoc functions match
the cars.
<expr> the expression to find
<test> the test predicate
<alist> the association list
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to a-list argument (defaults to identity)
returns the alist entry or NIL
(mapc <fcn> <list1> <list>...) APPLY FUNCTION TO SUCCESSIVE CARS
(mapcar <fcn> <list1> <list>...) APPLY FUNCTION TO SUCCESSIVE CARS
(mapcan <fcn> <list1> <list>...) APPLY FUNCTION TO SUCCESSIVE CARS
(mapl <fcn> <list1> <list>...) APPLY FUNCTION TO SUCCESSIVE CDRS
(maplist <fcn> <list1> <list>...) APPLY FUNCTION TO SUCCESSIVE CDRS
(mapcon <fcn> <list1> <list>...) APPLY FUNCTION TO SUCCESSIVE CDRS
<fcn> the function or function name
<listn> a list for each argument of the function
returns the first list of arguments (mapc or mapl), a list of the
values returned (mapcar or maplist), or list or returned
values nconc'd together (mapcan or mapcon).
(subst <to> <from> <expr> &key :test :test-not :key)
(nsubst <to> <from> <expr> &key :test :test-not :key)
(nsubst-if <to> <test> <expr> &key :key)
(nsubst-if-not <to> <test> <expr> &key :key)
SUBSTITUTE EXPRESSIONS
SUBST does minimum copying as required by Common Lisp. NSUBST is the
destructive version.
<to> the new expression
<from> the old expression (match to part of <expr> using test
function
<test> test predicate
<expr> the expression in which to do the substitutions
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to subtree test function expression
argument (defaults to identity)
returns the expression with substitutions
XLISP-PLUS 3.0 LIST FUNCTIONS Page 52
(sublis <alist> <expr> &key :test :test-not :key)
(nsublis <alist> <expr> &key :test :test-not :key)
SUBSTITUTE WITH AN A-LIST
SUBLIS does minimum copying as required by Common Lisp. NSUBLIS is the
destructive version.
<alist> the association list
<expr> the expression in which to do the substitutions
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to subtree test function expression
argument (defaults to identity)
returns the expression with substitutions
(pairlis <keys> <values> [<alist>]) BUILD AN A-LIST FROM TWO LISTS
In file common.lsp
<keys> list of association keys
<values> list of association values, same length as keys
<alist> existing association list, default NIL
returns new association list
(make-list <size> &key :initial-element) MAKE A LIST
In file common2.lsp
<size> size of list (non-negative integer)
:initial-element
initial value for each element, default NIL
returns the new list
(copy-list <list>) COPY THE TOP LEVEL OF A LIST
In file common.lsp
<list> the list
returns a copy of the list (new cons cells in top level)
(copy-alist <alist>) COPY AN ASSOCIATION LIST
In file common.lsp
<alist> the association list
returns a copy of the association list (keys and values not copies)
(copy-tree <tree>) COPY A TREE
In file common.lsp
<tree> a tree structure of cons cells
returns a copy of the tree structure
XLISP-PLUS 3.0 LIST FUNCTIONS Page 53
(intersection <list1> <list2> &key :test :test-not :key) SET FUNCTIONS
(union <list1> <list2> &key :test :test-not :key)
(set-difference <list1> <list2> &key :test :test-not :key)
(set-exclusive-or <list1> <list2> &key :test :test-not :key)
(nintersection <list1> <list2> &key :test :test-not :key)
(nunion <list1> <list2> &key :test :test-not :key)
(nset-difference <list1> <list2> &key :test :test-not :key)
(nset-exclusive-or <list1> <list2> &key :test :test-not :key)
set-exclusive-or and nset-exclusive-or defined in common.lsp. nunion,
nintersection, and nset-difference are aliased to their
non-destructive counterparts in common.lsp.
<list1> first list
<list2> second list
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:key function to apply to test function arguments (defaults to
identity)
returns intersection: list of all elements in both lists
union: list of all elements in either list
set-diference: list of all elements in first list but not in
second list
set-exclusive-or: list of all elements in only one list
"n" versions are potentially destructive.
(adjoin <expr> <list> :test :test-not :key) ADD UNIQUE TO LIST
<expr> new element to add
<list> the list
:test the test function (defaults to eql)
:test-not the test function <sense inverted)
:key function to apply to test function arguments (defaults to
identity)
returns if element not in list then (cons <expr> <list>), else
<list>.
(ldiff <list> <sublist>) GET INITIAL ELEMENTS OF LIST
In file common2.lsp
<list> list to get elements of
<sublist> list to search for in <list> (uses tailp)
returns copy of list up to match with sublist.
XLISP-PLUS 3.0 DESTRUCTIVE LIST FUNCTIONS Page 54
DESTRUCTIVE LIST FUNCTIONS
Destructive functions that have non-desctructive equivalents are listed in
other sections. See also sort, map-into, nreverse, delete, delete-if,
delete-if-not, fill, and replace under SEQUENCE FUNCTIONS, setf under
SYMBOL FUNCTIONS, and mapcan, mapcon, nbutlast, nsubst, nsubst-if,
nsubst-if-not, nsublis, nintersection, nunion, nset-difference, and
nset-exclusive-or under LIST FUNCTIONS. Also, setf is a destructive
function.
(rplaca <list> <expr>) REPLACE THE CAR OF A LIST NODE
Modern practice is to use (setf (car <list>) <expr>)
<list> the list node
<expr> the new value for the car of the list node
returns the list node after updating the car
(rplacd <list> <expr>) REPLACE THE CDR OF A LIST NODE
Modern practice is to use (setf (cdr <list>) <expr>)
<list> the list node
<expr> the new value for the cdr of the list node
returns the list node after updating the cdr
(nconc <list>...) DESTRUCTIVELY CONCATENATE LISTS
<list> lists to concatenate
returns the result of concatenating the lists
(nreconc <list1> <list2>) DESTRUCTIVELY CONCATENATE LISTS
Defined in common2.lsp
<list1> first list
<list2> second list
returns second list concantenated to the end of the first list,
which has been destructively reversed.
XLISP-PLUS 3.0 ARITHMETIC FUNCTIONS Page 55
ARITHMETIC FUNCTIONS
Warning: integer calculations that overflow become floating point values as
part of the math extension, but give no error in the base-line Xlisp.
Integer calculations cannot overflow when the bignum extension is compiled.
On systems with IEEE floating point, the values +INF and -INF result from
overflowing floating point calculations.
The math extension option adds complex numbers, new functions, and
additional functionality to some existing functions. The bignum extension,
in addition, adds ratios, bignums, new functions and additional
functionality to some existing functions. Because of the size of the
extensions, and the performance loss they entail, some users may not wish
to include bignums, or bignums and math. This section documents the math
functions both with and without the extensions.
Functions that are described as having floating point arguments (SIN COS
TAN ASIN ACOS ATAN EXPT EXP SQRT) will take arguments of any type (real or
complex) when the math extension is used. In the descriptions, "rational
number" means integer or ratio (bignum extension) only, and "real number"
means floating point number or rational only.
Any rational results are reduced to canonical form (the gcd of the
numerator and denominator is 1, the denominator is positive); integral
results are reduced to integers. Rational complex numbers with zero
imaginary parts are reduced to integers.
(truncate <expr> <denom>) TRUNCATES TOWARD ZERO
(round <expr> <denom>) ROUNDS TOWARD NEAREST EVEN INTEGER
(floor <expr> <denom>) TRUNCATES TOWARD NEGATIVE INFINITY
(ceiling <expr> <denom>) TRUNCATES TOWARD INFINITY
Round, floor, and ceiling, and the second argument of truncate, are
part of the math extension. Integers are returned as is.
<expr> the real number
<denom> real number to divide <expr> by before converting
returns the integer result of converting the number, and, as a
second return value, the remainder of the operation, defined
as expr - result*denom. The type is flonum if either
argument is flonum, otherwise it is rational.
(float <expr>) CONVERTS AN INTEGER TO A FLOATING POINT NUMBER
<expr> the real number
returns the number as a flonum
(rational <expr>) CONVERTS A REAL NUMBER TO A RATIONAL
Rational numbers are returned as is. Part of the bignum extension.
<expr> the real number
returns the number as a ratio or integer.
(+ [<expr>...]) ADD A LIST OF NUMBERS
With no arguments returns addition identity, 0 (integer)
<expr> the numbers
returns the result of the addition
XLISP-PLUS 3.0 ARITHMETIC FUNCTIONS Page 56
(- <expr>...) SUBTRACT A LIST OF NUMBERS OR NEGATE A SINGLE NUMBER
<expr> the numbers
returns the result of the subtraction
(* [<expr>...]) MULTIPLY A LIST OF NUMBERS
With no arguments returns multiplication identity, 1
<expr> the numbers
returns the result of the multiplication
(/ <expr>...) DIVIDE A LIST OF NUMBERS OR INVERT A SINGLE NUMBER
With the bignum extension, division of integer numbers results in a
rational quotient, rather than integer. To perform integer division,
use TRUNCATE.
<expr> the numbers
returns the result of the division
(1+ <expr>) ADD ONE TO A NUMBER
<expr> the number
returns the number plus one
(1- <expr>) SUBTRACT ONE FROM A NUMBER
<expr> the number
returns the number minus one
(rem <expr>...) REMAINDER OF A LIST OF NUMBERS
With the math extension, only two arguments allowed.
<expr> the real numbers (must be integers, without math extension)
returns the result of the remainder operation (remainder with
truncating division)
(mod <expr1> <expr2>) NUMBER MODULO ANOTHER NUMBER
Part of math extension.
<expr1> real number
<expr2> real number divisor (may not be zero)
returns the remainder after dividing <expr1> by <expr2> using
flooring division, thus there is no discontinuity in the
function around zero.
(min <expr>...) THE SMALLEST OF A LIST OF NUMBERS
<expr> the real numbers
returns the smallest number in the list
(max <expr>...) THE LARGEST OF A LIST OF NUMBERS
<expr> the real numbers
returns the largest number in the list
(abs <expr>) THE ABSOLUTE VALUE OF A NUMBER
<expr> the number
returns the absolute value of the number, which is the floating
point magnitude for complex numbers.
XLISP-PLUS 3.0 ARITHMETIC FUNCTIONS Page 57
(signum <expr>) GET THE SIGN OF A NUMBER
Defined in common.lsp
<expr> the number
returns zero if number is zero, one if positive, or negative one if
negative. Numeric type is same as number. For a complex
number, returns unit magnitude but same phase as number.
(float-sign <expr1> [<expr2>]) APPLY SIGN TO A NUMBER
Defined in common2.lsp
<expr1> the real number
<expr2> another real number, defaults to 1.0
returns the number <expr2> with the sign of <expr1>
(gcd [<n>...]) COMPUTE THE GREATEST COMMON DIVISOR
With no arguments returns 0, with one argument returns the argument.
<n> The number(s) (integer)
returns the greatest common divisor
(lcm <n>...) COMPUTE THE LEAST COMMON MULTIPLE
Part of math extension. A result which would be larger than the
largest integer causes an error.
<n> The number(s) (integer)
returns the least common multiple
(random <n> [<state>]) COMPUTE A PSEUDO-RANDOM NUMBER
<n> the real number upper bound
<state> a random-state (default is *random-state*)
returns a random number in range [0,n)
(make-random-state [<state>]) CREATE A RANDOM-STATE
<state> a random-state, t, or NIL (default NIL). NIL means
*random-state*
returns If <state> is t, a random random-state, otherwise a copy of
<state>
(sin <expr>) COMPUTE THE SINE OF A NUMBER
(cos <expr>) COMPUTE THE COSINE OF A NUMBER
(tan <expr>) COMPUTE THE TANGENT OF A NUMBER
(asin <expr>) COMPUTE THE ARC SINE OF A NUMBER
(acos <expr>) COMPUTE THE ARC COSINE OF A NUMBER
<expr> the floating point number
returns the sine, cosine, tangent, arc sine, or arc cosine of the
number
(atan <expr> [<expr2>]) COMPUTE THE ARC TANGENT OF A NUMBER
<expr> the floating point number (numerator)
<expr2> the denominator, default 1. May only be specified if math
extension installed
returns the arc tangent of <expr>/<expr2>
XLISP-PLUS 3.0 ARITHMETIC FUNCTIONS Page 58
(sinh <expr>) COMPUTE THE HYPERBOLIC SINE OF A NUMBER
(cosh <expr>) COMPUTE THE HYPERBOLIC COSINE OF A NUMBER
(tanh <expr>) COMPUTE THE HYPERBOLIC TANGENT OF A NUMBER
(asinh <expr>) COMPUTE THE HYPERBOLIC ARC SINE OF A NUMBER
(acosh <expr>) COMPUTE THE HYPERBOLIC ARC COSINE OF A NUMBER
(atanh <expr>) COMPUTE THE HYPERBOLIC ARC TANGENT OF A NUMBER
Defined in common.lsp
<expr> the number
returns the hyperbolic sine, cosine, tangent, arc sine, arc cosine,
or arc tangent of the number.
(expt <x-expr> <y-expr>) COMPUTE X TO THE Y POWER
<x-expr> the number
<y-expr> the exponent
returns x to the y power. If y is an integer, then the result type
is the same as the type of x.
(exp <x-expr>) COMPUTE E TO THE X POWER
<x-expr> the floating point number
returns e to the x power
(cis <x-expr>) COMPUTE COSINE + I SINE
Defined in common.lsp
<x-expr> the number
returns e to the ix power
(log <expr> [<base>]) COMPUTE THE LOGRITHM
Part of the math extension
<expr> the number
<base> the base, default is e
returns log base <base> of <expr>
(sqrt <expr>) COMPUTE THE SQUARE ROOT OF A NUMBER
<expr> the number
returns the square root of the number
(isqrt <expr>) COMPUTER THE INTEGER SQUARE ROOT OF A NUMBER
Defined in common2.lsp
<expr> non-negative integer
returns the integer square root, either exact or the largest integer
less than the exact value.
(numerator <expr>) GET THE NUMERATOR OF A NUMBER
Part of bignum extension
<expr> rational number
returns numerator of number (number if integer)
(denominator <expr>) GET THE DENOMINATOR OF A NUMBER
Part of bignum extension
<expr> rational number
returns denominator of number (1 if integer)
XLISP-PLUS 3.0 ARITHMETIC FUNCTIONS Page 59
(complex <real> [<imag>]) CONVERT TO COMPLEX NUMBER
Part of math extension
<real> real number real part
<imag> real number imaginary part (default 0)
returns the complex number
(realpart <expr>) GET THE REAL PART OF A NUMBER
Part of the math extension
<expr> the number
returns the real part of a complex number, or the number itself if a
real number
(imagpart <expr>) GET THE IMAGINARY PART OF A NUMBER
Part of the math extension
<expr> the number
returns the imaginary part of a complex number, or zero of the type
of the number if a real number.
(conjugate <expr>) GET THE CONJUGATE OF A NUMBER
Part of the math extension
<expr> the number
returns the conjugate of a complex number, or the number itself if a
real number.
(phase <expr>) GET THE PHASE OF A NUMBER
Part of the math extension
<expr> the number
returns the phase angle, equivalent to (atan (imagpart <expr>)
(realpart <expr>))
(< <n1> <n2>...) TEST FOR LESS THAN
(<= <n1> <n2>...) TEST FOR LESS THAN OR EQUAL TO
(= <n1> <n2>...) TEST FOR EQUAL TO
(/= <n1> <n2>...) TEST FOR NOT EQUAL TO
(>= <n1> <n2>...) TEST FOR GREATER THAN OR EQUAL TO
(> <n1> <n2>...) TEST FOR GREATER THAN
<n1> the first real number to compare
<n2> the second real number to compare
returns the result of comparing <n1> with <n2>...
XLISP-PLUS 3.0 BITWISE LOGICAL FUNCTIONS Page 60
BITWISE LOGICAL FUNCTIONS
Integers are treated as two's complement, which can cause what appears to
be strange results when negative numbers are supplied as arguments.
(logand [<expr>...]) THE BITWISE AND OF A LIST OF INTEGERS
With no arguments returns identity -1
<expr> the integers
returns the result of the and operation
(logior [<expr>...]) THE BITWISE INCLUSIVE OR OF A LIST OF INTEGERS
With no arguments returns identity 0
<expr> the integers
returns the result of the inclusive or operation
(logxor [<expr>...]) THE BITWISE EXCLUSIVE OR OF A LIST OF INTEGERS
With no arguments returns identity 0
<expr> the integers
returns the result of the exclusive or operation
(logeqv [<expr>...]) THE BITWISE EQUIVALENCE OF A LIST OF INTEGERS
With no arguments returns identity -1
<expr> the integers
returns the result of the equivalence operation
(lognand <expr1> <expr2>) BITWISE LOGICAL FUNCTIONS
(logandc1 <expr1> <expr2>)
(logandc2 <expr1> <expr2>)
(lognor <expr1> <expr2>)
(logorc1 <expr1> <expr2>)
(logorc2 <expr1> <expr2>)
Part of the bignums extension, the remaining logical functions of two
integers.
<expr1> the first integer
<expr2> the second integer
returns lognand: (lognot (logand <expr1> <expr2>))
logandc1: (logand (lognot <expr1>) <expr2>)
logandc2: (logand <expr1> (lognot <expr2>))
lognor: (lognot (logor <expr1> <expr2>))
logorc1: (logor (lognot <expr1>) <expr2>)
logorc2: (logor <expr1> (lognot <expr2>))
(lognot <expr>) THE BITWISE NOT OF A INTEGER
<expr> the integer
returns the bitwise inversion of integer
(logtest <expr1> <expr2>) TEST BITWISE AND OF TWO INTEGERS
Defined in common.lsp when bignum extension not loaded
<expr1> the first integer
<expr2> the second integer
returns T if the result of the and operation is non-zero, else NIL
XLISP-PLUS 3.0 BITWISE LOGICAL FUNCTIONS Page 61
(logbitp <pos> <expr>) TEST BIT OF INTEGER
Part of bignums extension
<pos> non-negative fixnum bit position, as in (expt 2 <pos>)
<expr> integer to test
returns T if the bit is "1", else NIL.
(logcount <expr>) COUNT BITS IN AN INTEGER
Part of bignums extension
<expr> integer
returns if <expr> is negative, returns the number of 0 bits, else
returns the number of 1 bits
(integer-length <expr>) CALCULATE LENGTH OF AN INTEGER
Part of bignums extension
<expr> integer
returns the minimum number of bits necessary to represent the
integer, excluding any sign bit.
(ash <expr1> <expr2>) ARITHMETIC SHIFT
Part of math extension
<expr1> integer to shift
<expr2> number of bit positions to shift (positive is to left)
returns shifted integer
(byte <size> <pos>) CREATE A BYTE SPECIFIER
(byte-size <spec>) GET SPECIFIER SIZE FIELD
(byte-position <spec>) GET SPECIFIER POSITION FIELD
Defined in common2.lsp. A "byte specifier" is implemented as a CONS
cell with the CAR being the size and the CDR being the position. These
functions are aliases for CONS, CAR, and CDR, respectively.
<size> size of byte field (non-negative integer)
<pos> starting position of byte field (non-negative integer),
which is position with least bit weight
<spec> byte specifier (a CONS cell)
returns BYTE returns the specifier, BYTE-SIZE returns the size
field, and BYTE-POSITION returns the starting position
(ldb <spec> <int>) LOAD BYTE
Defined in common2.lsp. LDB can be used with SETF, in which case it
performs a STB followed by a SETF into the field.
<spec> specifier of byte to extract
<int> integer to extract byte from
returns the extracted byte, a non-negative integer
(ldb-test <spec> <int>) TEST A BYTE
Defined in common2.lsp
<spec> specifier of byte to test
<int> integer containing byte to test
returns T if byte is zero, else NIL
XLISP-PLUS 3.0 BITWISE LOGICAL FUNCTIONS Page 62
(mask-field <spec> <int>) EXTRACT UNDER MASK
Defined in common2.lsp. MASK-FIELD can be used with SETF, in which
case it performs a DEPOSIT-FIELD followed by a SETF into the field.
<spec> specified byte to extract
<int> integer to extract byte from
returns the extracted byte in the same bit position as it was in
<int>
(dpb <new> <spec> <int>) DEPOSIT BYTE
Defined in common2.lsp
<new> integer byte to insert
<spec> specifier of position and size of byte
<int> integer to insert byte into
returns <int> with <new> in the bit positions specified by <spec>
(deposit-field <new> <spec> <int>) INSERT UNDER MASK
Defined in common2.lsp
<new> integer containing byte field to insert
<spec> specifier of position and size of byte
<int> integer to insert byte into
returns <new> at <spec> replacing bits at <spec> in <int>
XLISP-PLUS 3.0 STRING FUNCTIONS Page 63
STRING FUNCTIONS
Note: functions with names starting "string" will also accept a symbol, in
which case the symbol's print name is used.
(string <expr>) MAKE A STRING FROM AN INTEGER ASCII VALUE
<expr> an integer (which is first converted into its ASCII
character value), string, character, or symbol
returns the string representation of the argument
(string-trim <bag> <str>) TRIM BOTH ENDS OF A STRING
<bag> a string containing characters to trim
<str> the string to trim
returns a trimed copy of the string
(string-left-trim <bag> <str>) TRIM THE LEFT END OF A STRING
<bag> a string containing characters to trim
<str> the string to trim
returns a trimed copy of the string
(string-right-trim <bag> <str>) TRIM THE RIGHT END OF A STRING
<bag> a string containing characters to trim
<str> the string to trim
returns a trimed copy of the string
(string-upcase <str> &key :start :end) CONVERT TO UPPERCASE
<str> the string
:start the starting offset
:end the ending offset + 1 or NIL for end of string
returns a converted copy of the string
(string-downcase <str> &key :start :end) CONVERT TO LOWERCASE
<str> the string
:start the starting offset
:end the ending offset + 1 or NIL for end of string
returns a converted copy of the string
(string-capitalize <str> &key :start :end) CAPITALIZE STRING
<str> the string
:start the starting offset
:end the ending offset + 1 or NIL for end of string
returns a converted copy of the string with each word having an
initial uppercase letter and following lowercase letters
(nstring-upcase <str> &key :start :end) CONVERT TO UPPERCASE
<str> the string
:start the starting offset
:end the ending offset + 1 or NIL for end of string
returns the converted string (not a copy)
XLISP-PLUS 3.0 STRING FUNCTIONS Page 64
(nstring-downcase <str> &key :start :end) CONVERT TO LOWERCASE
<str> the string
:start the starting offset
:end the ending offset + 1 or NIL for end of string
returns the converted string (not a copy)
(nstring-capitalize <str> &key :start :end) CAPITALIZE STRING
<str> the string
:start the starting offset
:end the ending offset + 1 or NIL for end of string
returns the string with each word having an initial uppercase letter
and following lowercase letters (not a copy)
(make-string <size> &key :initial-element) MAKE A STRING
Defined in common2.lsp.
<size> size of string (non-negative integer)
:initial-element
initial value of all characters in the string
returns the new string
(strcat <expr>...) CONCATENATE STRINGS
Macro in init.lsp, to maintain compatibility with XLISP.
See CONCATENATE for preferred function.
<expr> the strings to concatenate
returns the result of concatenating the strings
(string< <str1> <str2> &key :start1 :end1 :start2 :end2)
(string<= <str1> <str2> &key :start1 :end1 :start2 :end2)
(string= <str1> <str2> &key :start1 :end1 :start2 :end2)
(string/= <str1> <str2> &key :start1 :end1 :start2 :end2)
(string>= <str1> <str2> &key :start1 :end1 :start2 :end2)
(string> <str1> <str2> &key :start1 :end1 :start2 :end2)
<str1> the first string to compare
<str2> the second string to compare
:start1 first substring starting offset
:end1 first substring ending offset + 1 or NIL for end of string
:start2 second substring starting offset
:end2 second substring ending offset + 1 or NIL for end of string
returns string=: t if predicate is true, NIL otherwise
others: If predicate is true then number of initial matching
characters, else NIL
Note: case is significant with these comparison functions.
XLISP-PLUS 3.0 STRING FUNCTIONS Page 65
(string-lessp <str1> <str2> &key :start1 :end1 :start2 :end2)
(string-not-greaterp <str1> <str2> &key :start1 :end1 :start2 :end2)
(string-equal <str1> <str2> &key :start1 :end1 :start2 :end2)
(string-not-equal <str1> <str2> &key :start1 :end1 :start2 :end2)
(string-not-lessp <str1> <str2> &key :start1 :end1 :start2 :end2)
(string-greaterp <str1> <str2> &key :start1 :end1 :start2 :end2)
<str1> the first string to compare
<str2> the second string to compare
:start1 first substring starting offset
:end1 first substring ending offset + 1 or NIL for end of string
:start2 second substring starting offset
:end2 second substring ending offset + 1 or NIL for end of string
returns string-equal: t if predicate is true, NIL otherwise
others: If predicate is true then number of initial matching
characters, else NIL
Note: case is not significant with these comparison functions -- all
uppercase characters are converted to lowercase before being compared.
XLISP-PLUS 3.0 CHARACTER FUNCTIONS Page 66
CHARACTER FUNCTIONS
(char <string> <index>) EXTRACT A CHARACTER FROM A STRING
<string> the string
<index> the string index (zero relative)
returns the ascii code of the character
(alphanumericp <chr>) IS THIS CHARACTER ALPHANUMERIC?
<chr> the character
returns true if the character is alphabetic or numeric, NIL
otherwise
(upper-case-p <chr>) IS THIS AN UPPER CASE CHARACTER?
<chr> the character
returns true if the character is upper case, NIL otherwise
(lower-case-p <chr>) IS THIS A LOWER CASE CHARACTER?
<chr> the character
returns true if the character is lower case, NIL otherwise
(alpha-char-p <chr>) IS THIS AN ALPHABETIC CHARACTER?
<chr> the character
returns true if the character is alphabetic, NIL otherwise
(both-case-p <chr>) IS THIS AN ALPHABETIC (EITHER CASE) CHARACTER?
<chr> the character
returns true if the character is available in both cases, NIL
otherwise
(digit-char-p <chr>[<radix>]) IS THIS A DIGIT CHARACTER?
<chr> the character
<radix> the radix (default 10)
returns the digit weight if character is a digit, NIL otherwise
(char-code <chr>) GET THE ASCII CODE OF A CHARACTER
<chr> the character
returns the ASCII character code (integer, parity bit stripped)
(code-char <code>) GET THE CHARACTER WITH A SPECFIED ASCII CODE
<code> the ASCII code (integer, range 0-127)
returns the character with that code or NIL
(char-upcase <chr>) CONVERT A CHARACTER TO UPPER CASE
<chr> the character
returns the upper case version of the character, if one exists,
otherwise returns the character
(char-downcase <chr>) CONVERT A CHARACTER TO LOWER CASE
<chr> the character
returns the lower case version of the character, if one exists,
otherwise returns the character
XLISP-PLUS 3.0 CHARACTER FUNCTIONS Page 67
(digit-char <n>[<radix>]) CONVERT A DIGIT WEIGHT TO A DIGIT
<n> the digit weight (integer)
<radix> the radix (default 10)
returns the digit character or NIL
(char-int <chr>) CONVERT A CHARACTER TO AN INTEGER
<chr> the character
returns the ASCII character code (range 0-255)
(int-char <int>) CONVERT AN INTEGER TO A CHARACTER
<int> the ASCII character code (treated modulo 256)
returns the character with that code
(character <expr>) CREATE A CHARACTER
Defined in common2.lsp
<expr> single character symbol, string, or integer
returns <expr> converted into a character
(char-name <chr>) CHARACTER PRINT NAME
Defined in common2.lsp
<chr> the character
returns string which is the name of the character, or NIL if no name
(char< <chr1> <chr2>...)
(char<= <chr1> <chr2>...)
(char= <chr1> <chr2>...)
(char/= <chr1> <chr2>...)
(char>= <chr1> <chr2>...)
(char> <chr1> <chr2>...)
<chr1> the first character to compare
<chr2> the second character(s) to compare
returns t if predicate is true, NIL otherwise
Note: case is significant with these comparison functions.
(char-lessp <chr1> <chr2>...)
(char-not-greaterp <chr1> <chr2>...)
(char-equal <chr1> <chr2>...)
(char-not-equal <chr1> <chr2>...)
(char-not-lessp <chr1> <chr2>...)
(char-greaterp <chr1> <chr2>...)
<chr1> the first string to compare
<chr2> the second string(s) to compare
returns t if predicate is true, NIL otherwise
Note: case is not significant with these comparison functions -- all
uppercase characters are converted to lowercase before the comparison.
XLISP-PLUS 3.0 STRUCTURE FUNCTIONS Page 68
STRUCTURE FUNCTIONS
XLISP provides a subset of the Common Lisp structure definition facility.
No slot options are allowed, but slots can have default initialization
expressions.
(defstruct name [<comment>] <slot-desc>...)
or
(defstruct (name <option>...) [<comment>] <slot-desc>...)
fsubr
<name> the structure name symbol (quoted)
<option> option description (quoted)
<comment> comment string (ignored)
<slot-desc> slot descriptions (quoted)
returns the structure name
The recognized options are:
(:conc-name name)
(:include name [<slot-desc>...])
(:print-function <function>)
Note that if :CONC-NAME appears, it should be before :INCLUDE.
Each slot description takes the form:
<name>
or
(<name> <defexpr>)
If the default initialization expression is not specified, the slot will be
initialized to NIL if no keyword argument is passed to the creation
function.
The optional :PRINT-FUNCTION overrides the default #S notation. The
function must take three arguments, the structure instance, the stream, and
the current printing depth.
DEFSTRUCT causes access functions to be created for each of the slots and
also arranges that SETF will work with those access functions. The access
function names are constructed by taking the structure name, appending a
'-' and then appending the slot name. This can be overridden by using the
:CONC-NAME option.
DEFSTRUCT also makes a creation function called MAKE-<structname>, a copy
function called COPY-<structname> and a predicate function called
<structname>-P. The creation function takes keyword arguments for each of
the slots. Structures can be created using the #S( read macro, as well.
The property *struct-slots* is added to the symbol that names the
structure. This property consists of an association list of slot names and
closures that evaluate to the initial values (NIL if no initial value
expression).
XLISP-PLUS 3.0 STRUCTURE FUNCTIONS Page 69
For instance:
(defstruct foo bar (gag 2))
creates the following functions:
(foo-bar <expr>)
(setf (foo-bar <expr>) <value>)
(foo-gag <expr>)
place form (foo-gag <expr>)
(make-foo &key :bar :gag)
(copy-foo <expr>)
(foo-p <expr>)
XLISP-PLUS 3.0 OBJECT FUNCTIONS Page 70
OBJECT FUNCTIONS
Note that the functions provided in classes.lsp are useful but not
necessary.
Messages defined for Object and Class are listed starting on page 22.
(send <object> <message> [<args>...]) SEND A MESSAGE
<object> the object to receive the message
<message> message sent to object
<args> arguments to method (if any)
returns the result of the method
(send-super <message> [<args>]) SEND A MESSAGE TO SUPERCLASS
valid only in method context
<message> message sent to method's superclass
<args> arguments to method (if any)
returns the result of the method
(defclass <sym> <ivars> [<cvars> [<super>]]) DEFINE A NEW CLASS
defined in class.lsp as a macro
<sym> symbol whose value is to be bound to the class object
(quoted)
<ivars> list of instance variables (quoted). Instance variables
specified either as <ivar> or (<ivar> <init>) to specify
non-NIL default initial value.
<cvars> list of class variables (quoted)
<super> superclass, or Object if absent.
This function sends :SET-PNAME (defined in classes.lsp) to the new
class to set the class' print name instance variable.
Methods defined for classes defined with defclass:
(send <object> :<ivar>)
Returns the specified instance variable
(send <object> :SET-IVAR <ivar> <value>)
Used to set an instance variable, typically with setf via
(setf (send <object> :<ivar>) <value>).
(send <sym> :NEW {:<ivar> <init>})
Actually definition for :ISNEW. Creates new object
initializing instance variables as specified in keyword
arguments, or to their default if keyword argument is
missing. Returns the object.
returns the new class object
(defmethod <class> <sym> <fargs> <expr> ...) DEFINE A NEW METHOD
defined in class.lsp as a macro
<class> Class which will respond to message
<sym> Message selector name (quoted)
<fargs> Formal argument list. Leading "self" is implied (quoted)
<expr> Expressions constituting body of method (quoted)
returns the class object.
XLISP-PLUS 3.0 OBJECT FUNCTIONS Page 71
(definst <class> <sym> [<args>...]) DEFINE A NEW GLOBAL INSTANCE
defined in class.lsp as a macro
<class> Class of new object
<sym> Symbol whose value will be set to new object
<args> Arguments passed to :NEW (typically initial values for
instance variables)
returns the instance object
(tracemethod <class> [<sel>]) ADD A METHOD TO THE TRACE LIST
defined in class.lsp
<class> Class containing method to trace
<sel> Message selector of method to trace, if absent then trace
all methods defined in <class>.
returns the trace list
(untracemethod [<class> [<sel>]])) REMOVE A METHOD FROM THE TRACE LIST
defined in class.lsp
<class> Class containing method to remove, if absent remove all
methods of all classes.
<sel> Message selector of method to remove, if absent then remove
all methods of <class>.
returns the trace list
XLISP-PLUS 3.0 PREDICATE FUNCTIONS Page 72
PREDICATE FUNCTIONS
(atom <expr>) IS THIS AN ATOM?
<expr> the expression to check
returns t if the value is an atom, NIL otherwise
(symbolp <expr>) IS THIS A SYMBOL?
<expr> the expression to check
returns t if the expression is a symbol, NIL otherwise
(numberp <expr>) IS THIS A NUMBER?
<expr> the expression to check
returns t if the expression is a number, NIL otherwise
(null <expr>) IS THIS AN EMPTY LIST?
<expr> the list to check
returns t if the list is empty, NIL otherwise
(not <expr>) IS THIS FALSE?
<expr> the expression to check
return t if the value is NIL, NIL otherwise
(listp <expr>) IS THIS A LIST?
<expr> the expression to check
returns t if the value is a cons or NIL, NIL otherwise
(endp <list>) IS THIS THE END OF A LIST?
<list> the list
returns t if the value is NIL, NIL otherwise
(consp <expr>) IS THIS A NON-EMPTY LIST?
<expr> the expression to check
returns t if the value is a cons, NIL otherwise
(constantp <expr>) IS THIS A CONSTANT?
<expr> the expression to check
returns t if the value is a constant (basically, would EVAL <expr>
repeatedly return the same thing?), NIL otherwise.
(specialp <expr>) IS THIS A SPECIAL SYMBOL?
<expr> the expression to check
returns t if the value is a symbol which is SPECIAL, NIL otherwise.
(integerp <expr>) IS THIS AN INTEGER?
<expr> the expression to check
returns t if the value is an integer, NIL otherwise
(floatp <expr>) IS THIS A FLOAT?
<expr> the expression to check
returns t if the value is a float, NIL otherwise
XLISP-PLUS 3.0 PREDICATE FUNCTIONS Page 73
(rationalp <expr>) IS THIS A RATIONAL NUMBER?
Part of bignum extension.
<expr> the expression to check
returns t if the value is rational (integer or ratio), NIL otherwise
(realp <expr>) IS THIS A REAL NUMBER?
Defined in common2.lsp
<expr> the expression to check
returns t if the value is rational or float, NIL otherwise
(complexp <expr>) IS THIS A COMPLEX NUMBER?
Part of math extension.
<expr> the expression to check
returns t if the value is a complex number, NIL otherwise
(stringp <expr>) IS THIS A STRING?
<expr> the expression to check
returns t if the value is a string, NIL otherwise
(characterp <expr>) IS THIS A CHARACTER?
<expr> the expression to check
returns t if the value is a character, NIL otherwise
(arrayp <expr>) IS THIS AN ARRAY?
<expr> the expression to check
returns t if the value is an array, NIL otherwise
(array-in-bounds-p <expr> <index>) IS ARRAY INDEX IN BOUNDS?
Defined in common2.lsp
<expr> the array
<index> index to check
returns t if index is in bounds for the array, NIL otherwise
(streamp <expr>) IS THIS A STREAM?
<expr> the expression to check
returns t if the value is a stream, NIL otherwise
(open-stream-p <stream>) IS STREAM OPEN?
<stream> the stream
returns t if the stream is open, NIL otherwise
(input-stream-p <stream>) IS STREAM READABLE?
<stream> the stream
returns t if stream is readable, NIL otherwise
(output-stream-p <stream>) IS STREAM WRITABLE?
<stream> the stream
returns t if stream is writable, NIL otherwise
(objectp <expr>) IS THIS AN OBJECT?
<expr> the expression to check
returns t if the value is an object, NIL otherwise
XLISP-PLUS 3.0 PREDICATE FUNCTIONS Page 74
(classp <expr>) IS THIS A CLASS OBJECT?
<expr> the expression to check
returns t if the value is a class object, NIL otherwise
(hash-table-p <expr>) IS THIS A HASH TABLE?
Defined in common2.lsp
<expr> the expression to check
returns t if the value is a hash table, NIL otherwise
(keywordp <expr>) IS THIS A KEYWORD?
Defined in common2.lsp
<expr> the expression to check
returns t if the value is a keyword symbol, NIL otherwise
(packagep <expr>) IS THIS A PACKAGE?
Defined in common2.lsp
<expr> the expression to check
returns t if the value is a package, NIL otherwise
(boundp <sym>) IS A VALUE BOUND TO THIS SYMBOL?
<sym> the symbol
returns t if a value is bound to the symbol, NIL otherwise
(fboundp <sym>) IS A FUNCTIONAL VALUE BOUND TO THIS SYMBOL?
<sym> the symbol
returns t if a functional value is bound to the symbol, NIL
otherwise
(functionp <sym>) IS THIS A FUNCTION?
Defined in common.lsp
<expr> the expression to check
returns t if the value is a function -- that is, can it be applied
to arguments. This is true for any symbol (even those with
no function binding), list with car being lambda, a closure,
or subr. Otherwise returns NIL.
(minusp <expr>) IS THIS NUMBER NEGATIVE?
<expr> the number to test
returns t if the number is negative, NIL otherwise
(zerop <expr>) IS THIS NUMBER ZERO?
<expr> the number to test
returns t if the number is zero, NIL otherwise
(plusp <expr>) IS THIS NUMBER POSITIVE?
<expr> the number to test
returns t if the number is positive, NIL otherwise
(evenp <expr>) IS THIS INTEGER EVEN?
<expr> the integer to test
returns t if the integer is even, NIL otherwise
(oddp <expr>) IS THIS INTEGER ODD?
<expr> the integer to test
returns t if the integer is odd, NIL otherwise
XLISP-PLUS 3.0 PREDICATE FUNCTIONS Page 75
(subsetp <list1> <list2> &key :test :test-not :key) IS SET A SUBSET?
<list1> the first list
<list2> the second list
:test test function (defaults to eql)
:test-not test function (sense inverted)
:key function to apply to test function arguments (defaults to
identity)
returns t if every element of the first list is in the second list,
NIL otherwise
(eq <expr1> <expr2>) ARE THE EXPRESSIONS EQUAL?
(eql <expr1> <expr2>)
(equal <expr1> <expr2>)
(equalp <expr1> <expr2>)
equalp defined in common.lsp
<expr1> the first expression
<expr2> the second expression
returns t if equal, NIL otherwise. Each is progressively more
liberal in what is "equal":
eq: identical pointers -- works with characters, symbols,
and arbitrarily small integers
eql: works with all numbers, if same type (see also = on
page 59)
equal: lists and strings
equalp: case insensitive characters (and strings), numbers
of differing types, arrays (which can be equalp to
string containing same elements)
XLISP-PLUS 3.0 PREDICATE FUNCTIONS Page 76
(typep <expr> <type>) IS THIS A SPECIFIED TYPE?
<expr> the expression to test
<type> the type specifier. Symbols can either be one of those
listed under type-of (on page 100) or one of:
ATOM any atom
NULL NIL
LIST matches NIL or any cons cell
STREAM any stream
NUMBER any numeric type
REAL flonum or rational number
INTEGER fixnum or bignum
RATIONAL fixnum or ratio
STRUCT any structure (except hash-table)
FUNCTION any function, as defined by functionp (page 74)
The specifer can also be a form (which can be nested). All
form elements are quoted. Valid form cars:
or any of the cdr type specifiers must be true
and all of the cdr type specifiers must be true
not the single cdr type specifier must be false
satisfies the result of applying the cdr predicate function
to <expr>
member <expr> must be eql to one of the cdr values
object <expr> must be an object, of class specified by
the single cdr value. The cdr value can be a
symbol which must evaluate to a class.
Note that everything is of type T, and nothing is of type
NIL.
returns t if <expr> is of type <type>, NIL otherwise.
XLISP-PLUS 3.0 CONTROL CONSTRUCTS Page 77
CONTROL CONSTRUCTS
(cond <pair>...) EVALUATE CONDITIONALLY
fsubr
<pair> pair consisting of:
(<pred> <expr>...)
where
<pred> is a predicate expression
<expr> evaluated if the predicate is not NIL
returns the value of the first expression whose predicate is not NIL
(and <expr>...) THE LOGICAL AND OF A LIST OF EXPRESSIONS
fsubr
<expr> the expressions to be ANDed
returns NIL if any expression evaluates to NIL, otherwise the value
of the last expression (evaluation of expressions stops
after the first expression that evaluates to NIL)
(or <expr>...) THE LOGICAL OR OF A LIST OF EXPRESSIONS
fsubr
<expr> the expressions to be ORed
returns NIL if all expressions evaluate to NIL, otherwise the value
of the first non-NIL expression (evaluation of expressions
stops after the first expression that does not evaluate to
NIL)
(if <texpr> <expr1> [<expr2>]) EVALUATE EXPRESSIONS CONDITIONALLY
fsubr
<texpr> the test expression
<expr1> the expression to be evaluated if texpr is non-NIL
<expr2> the expression to be evaluated if texpr is NIL
returns the value of the selected expression
(when <texpr> <expr>...) EVALUATE ONLY WHEN A CONDITION IS TRUE
fsubr
<texpr> the test expression
<expr> the expression(s) to be evaluted if texpr is non-NIL
returns the value of the last expression or NIL
(unless <texpr> <expr>...) EVALUATE ONLY WHEN A CONDITION IS FALSE
fsubr
<texpr> the test expression
<expr> the expression(s) to be evaluated if texpr is NIL
returns the value of the last expression or NIL
XLISP-PLUS 3.0 CONTROL CONSTRUCTS Page 78
(case <expr> <case>...[(t <expr>)]) SELECT BY CASE
fsubr
<expr> the selection expression
<case> pair consisting of:
(<value> <expr>...)
where:
<value> is a single expression or a list of expressions
(unevaluated)
<expr> are expressions to execute if the case matches
(t <expr>) default case (no previous matching)
returns the value of the last expression of the matching case
(typecase <expr> <case>...[(t <expr>)]) SELECT BY TYPE
macro defined in common2.lsp
<expr> the selection expression
<case> pair consisting of:
(<type> <expr>...)
where:
<type> type specifier as in function TYPEP (page 76)
<expr> are expressions to execute if the case matches
(t <expr>) default case (no previous matching)
returns the value of the last expression of the matching case
(let (<binding>...) <expr>...) CREATE LOCAL BINDINGS
(let* (<binding>...) <expr>...) LET WITH SEQUENTIAL BINDING
fsubr
<binding> the variable bindings each of which is either:
1) a symbol (which is initialized to NIL)
2) a list whose car is a symbol and whose cadr is an
initialization expression
<expr> the expressions to be evaluated
returns the value of the last expression
(flet (<binding>...) <expr>...) CREATE LOCAL FUNCTIONS
(labels (<binding>...) <expr>...) FLET WITH RECURSIVE FUNCTIONS
(macrolet (<binding>...) <expr>...) CREATE LOCAL MACROS
fsubr
<binding> the function bindings each of which is:
(<sym> <fargs> <expr>...)
where:
<sym> the function/macro name
<fargs> formal argument list (lambda list)
<expr> expressions constituting the body of the
function/macro
<expr> the expressions to be evaluated
returns the value of the last expression
(catch <sym> <expr>...) EVALUATE EXPRESSIONS AND CATCH THROWS
fsubr
<sym> the catch tag
<expr> expressions to evaluate
returns the value of the last expression or the throw expression
XLISP-PLUS 3.0 CONTROL CONSTRUCTS Page 79
(throw <sym> [<expr>]) THROW TO A CATCH
fsubr
<sym> the catch tag
<expr> the value for the catch to return (defaults to NIL)
returns never returns
(unwind-protect <expr> <cexpr>...) PROTECT EVALUATION OF AN EXPRESSION
fsubr
<expr> the expression to protect
<cexpr> the cleanup expressions
returns the value of the expression
Note: unwind-protect guarantees to execute the cleanup expressions
even if a non-local exit terminates the evaluation of the protected
expression
XLISP-PLUS 3.0 LOOPING CONSTRUCTS Page 80
LOOPING CONSTRUCTS
(loop <expr>...) BASIC LOOPING FORM
fsubr
<expr> the body of the loop
returns never returns (must use non-local exit, such as RETURN)
(do (<binding>...) (<texpr> <rexpr>...) <expr>...) GENERAL LOOPING FORM
(do* (<binding>...) (<texpr> <rexpr>...) <expr>...)
fsubr. do binds simultaneously, do* binds sequentially
<binding> the variable bindings each of which is either:
1) a symbol (which is initialized to NIL)
2) a list of the form: (<sym> <init> [<step>])
where:
<sym> is the symbol to bind
<init> the initial value of the symbol
<step> a step expression
<texpr> the termination test expression
<rexpr> result expressions (the default is NIL)
<expr> the body of the loop (treated like an implicit prog)
returns the value of the last result expression
(dolist (<sym> <expr> [<rexpr>]) <expr>...) LOOP THROUGH A LIST
fsubr
<sym> the symbol to bind to each list element
<expr> the list expression
<rexpr> the result expression (the default is NIL)
<expr> the body of the loop (treated like an implicit prog)
returns the result expression
(dotimes (<sym> <expr> [<rexpr>]) <expr>...) LOOP FROM ZERO TO N-1
fsubr
<sym> the symbol to bind to each value from 0 to n-1
<expr> the number of times to loop (a fixnum)
<rexpr> the result expression (the default is NIL)
<expr> the body of the loop (treated like an implicit prog)
returns the result expression
XLISP-PLUS 3.0 THE PROGRAM FEATURE Page 81
THE PROGRAM FEATURE
(prog (<binding>...) <expr>...) THE PROGRAM FEATURE
(prog* (<binding>...) <expr>...) PROG WITH SEQUENTIAL BINDING
fsubr -- equivalent to (let () (block NIL (tagbody ...)))
<binding> the variable bindings each of which is either:
1) a symbol (which is initialized to NIL)
2) a list whose car is a symbol and whose cadr is an
initialization expression
<expr> expressions to evaluate or tags (symbols)
returns NIL or the argument passed to the return function
(block <name> <expr>...) NAMED BLOCK
fsubr
<name> the block name (quoted symbol)
<expr> the block body
returns the value of the last expression
(return [<expr>]) CAUSE A PROG CONSTRUCT TO RETURN A VALUE
fsubr
<expr> the value (defaults to NIL)
returns never returns
(return-from <name> [<value>]) RETURN FROM A NAMED BLOCK OR FUNCTION
fsubr. In traditional Xlisp, the names are dynamically scoped. A
compilation option (default) uses lexical scoping like Common Lisp.
<name> the block or function name (quoted symbol). If name is NIL,
use function RETURN.
<value> the value to return (defaults to NIL)
returns never returns
(tagbody <expr>...) BLOCK WITH LABELS
fsubr
<expr> expression(s) to evaluate or tags (symbols)
returns NIL
(go <sym>) GO TO A TAG WITHIN A TAGBODY
fsubr. In traditional Xlisp, tags are dynamically scoped. A
compilation option (default) uses lexical scoping like Common Lisp.
<sym> the tag (quoted)
returns never returns
(progv <slist> <vlist> <expr>...) DYNAMICALLY BIND SYMBOLS
fsubr
<slist> list of symbols (evaluated)
<vlist> list of values to bind to the symbols (evaluated)
<expr> expression(s) to evaluate
returns the value of the last expression
(prog1 <expr1> <expr>...) EXECUTE EXPRESSIONS SEQUENTIALLY
fsubr
<expr1> the first expression to evaluate
<expr> the remaining expressions to evaluate
returns the value of the first expression
XLISP-PLUS 3.0 THE PROGRAM FEATURE Page 82
(prog2 <expr1> <expr2> <expr>...) EXECUTE EXPRESSIONS SEQUENTIALLY
fsubr
<expr1> the first expression to evaluate
<expr2> the second expression to evaluate
<expr> the remaining expressions to evaluate
returns the value of the second expression
(progn <expr>...) EXECUTE EXPRESSIONS SEQUENTIALLY
fsubr
<expr> the expressions to evaluate
returns the value of the last expression (or NIL)
XLISP-PLUS 3.0 INPUT/OUTPUT FUNCTIONS Page 83
INPUT/OUTPUT FUNCTIONS
Note that when printing objects, printing is accomplished by sending the
message :prin1 to the object.
(read [<stream> [<eofp> [<eof> [<rflag>]]]]) READ AN EXPRESSION
NOTE: there has been an incompatible change in arguments from prior
versions.
<stream> the input stream (default, or NIL, is *standard-input*, T is
*terminal-io*)
<eofp> When T, signal an error on end of file, when NIL return
<eof> (default is T)
<eof> the value to return on end of file (default is NIL)
<rflag> recursive read flag. The value is ignored
returns the expression read
(set-macro-character <ch> <fcn> [ T ]) MODIFY READ TABLE
defined in init.lsp
<ch> character to define
<fcn> function to bind to character (see page 13)
T if TMACRO rather than NMACRO
(get-macro-character <ch>) EXAMINE READ TABLE
defined in init.lsp
<ch> character
returns function bound to character
(print <expr> [<stream>]) PRINT AN EXPRESSION ON A NEW LINE
The expression is printed using prin1, then current line is terminated
(Note: this is backwards from Common Lisp).
<expr> the expression to be printed
<stream> the output stream (default, or NIL, is *standard-output*, T
is *terminal-io*)
returns the expression
(prin1 <expr> [<stream>]) PRINT AN EXPRESSION
symbols, cons cells (without circularities), arrays, strings, numbers,
and characters are printed in a format generally acceptable to the
read function. Printing format can be affected by the global
formatting variables: *print-level* and *print-length* for lists and
arrays, *print-base* for rationals, *integer-format* for fixnums,
*float-format* for flonums, *ratio-format* for ratios, and
*print-case* and *readtable-case* for symbols.
<expr> the expression to be printed
<stream> the output stream (default, or NIL, is *standard-output*, T
is *terminal-io*)
returns the expression
XLISP-PLUS 3.0 INPUT/OUTPUT FUNCTIONS Page 84
(princ <expr> [<stream>]) PRINT AN EXPRESSION WITHOUT QUOTING
Like PRIN1 except symbols (including uninterned), strings, and
characters are printed without using any quoting mechanisms.
<expr> the expressions to be printed
<stream> the output stream (default, or NIL, is *standard-output*, T
is *terminal-io*)
returns the expression
(pprint <expr> [<stream>]) PRETTY PRINT AN EXPRESSION
Uses prin1 for printing.
<expr> the expressions to be printed
<stream> the output stream (default, or NIL, is *standard-output*, T
is *terminal-io*)
returns the expression
(terpri [<stream>]) TERMINATE THE CURRENT PRINT LINE
<stream> the output stream (default, or NIL, is *standard-output*, T
is *terminal-io*)
returns NIL
(fresh-line [<stream>]) START A NEW LINE
<stream> the output stream (default, or NIL, is *standard-output*, T
is *terminal-io*)
returns t if a new list was started, NIL if already at the start of
a line.
(flatsize <expr>) LENGTH OF PRINTED REPRESENTATION USING PRIN1
<expr> the expression
returns the length
(flatc <expr>) LENGTH OF PRINTED REPRESENTATION USING PRINC
<expr> the expression
returns the length
(y-or-n-p [<fmt> [<arg>...]]) ASK A YES OR NO QUESTION
(yes-or-no-p [<fmt> [<arg>...]])
defined in common.lsp. Uses *terminal-io* stream for interaction.
y-or-n-p strives for a single character answer, using get-key if
defined.
<fmt> optional format string for question (see page 86)
<arg> arguments, if any, for format string
returns T for yes, NIL for no.
(prin1-to-string <expr>) PRINT TO A STRING
(princ-to-string <expr>)
defined in common2.lsp. Uses prin1 or princ conventions, respectively.
<expr> the expression to print
returns the string containing the "printed" expression
XLISP-PLUS 3.0 INPUT/OUTPUT FUNCTIONS Page 85
(read-from-string <str> [<eofp> [<eof>]] &key :start :end)
READ AN EXPRESSION
defined in common2.lsp.
<str> the input string
<eofp> When T, signal an error on end of string, when NIL return
<eof> (default is T)
<eof> the value to return on end of string (default is NIL)
:start starting index of <str>, default 0
:end ending index of <str>, default NIL (end of string)
returns two values: the expression read and index of character after
last one used
XLISP-PLUS 3.0 THE FORMAT FUNCTION Page 86
THE FORMAT FUNCTION
(format <stream> <fmt> [<arg>...]) DO FORMATTED OUTPUT
<stream> the output stream (T is *standard-output*)
<fmt> the format string
<arg> the format arguments
returns output string if <stream> is NIL, NIL otherwise
The format string can contain characters that should be copied directly to
the output and formatting directives. The formatting directives are:
~? use next argument as recursive format string
~( ~) process format string with case conversion
~{ ~} process format string repetitively
~* skip arguments
~% start a new line
~& start a new line if not on a new line
~\n ignore return and following whitespace
~| start a new page
~~ print a tilde character
~A or ~a print next argument using princ
~B or ~b print next argument as binary integer (bignum extension)
~D or ~d print next argument as decimal integer
~E or ~e print next argument in exponential form
~F or ~f print next argument in fixed point form
~G or ~g print next argument using either ~E or ~F depending on
magnitude
~O or ~o print next argument as octal integer
~R or ~r print next number in any radix (bignum extension)
~S or ~s print next argument using prin1
~T or ~t go to a specified column
~X or ~x print next argument as hexidecimal integer
~[ ~; ~] process format string conditionally
The format directives can contain optional prefix and optional colon (:) or
at-sign (@) modifiers between the tilde and directive character. Prefix
characters are unsigned integers, the character '#' which represents the
remaining number of arguments, the character 'v' to indicate the number is
taken from the next argument, or a single quote (') followed by a single
character for those parameters that should be a single character.
For ~A and ~S the full form is:
~mincol,colinc,minpad,padchar:@A (or S)
If : is given, NIL will print as "()" rather than "NIL". The string is
padded on the right (or left, if @ is given) with at least "minpad" copies
of the "padchar". Padding characters are then inserted "colinc" characters
at a time until the total width is at least "mincol". The defaults are 0
for mincol and minpad, 1 for colinc, and #\space for padchar. For example:
~15,,2,'.@A
XLISP-PLUS 3.0 THE FORMAT FUNCTION Page 87
The output is padded on the left with at least 2 periods until the output
is at least 15 characters wide.
For ~D, ~B, ~O, and ~X the full form is ("D" shown):
~mincol,padchar@D
If the data to print is not an integer, then the format "~mincolA" is used.
If "mincol" is specified then the number is padded on the left to be at
least that many characters long using "padchar". "padchar" defaults to
#\space. If @ is used and the value is positive, then a leading plus sign
is printed before the first digit.
For ~R, the full form is:
~radix,mincol,padchar@R
The radix must be in the range 2 through 36. Other arguments are as in ~D,
above. Unlike Common Lisp, English text and Roman numeral output is not
supported.
For ~E ~F and ~G the full form is:
~mincol,round,padchar@E (or F or G)
(This implementation is not Common Lisp compatible.) If the argument is not
a real number (FIXNUM, RATIO, or FLONUM), then the format
"~mincol,padcharD" is used. The number is printed using the C language e,
f, or g formats. If the number could potentially take more than 100 digits
to print, then F format is forced to E format, although some C libraries
will do this at a lower number of digits. If "round" is specified, than
that is the number of digits to the right of the decimal point that will be
printed, otherwise six digits (or whatever is necessary in G format) are
printed. In G format, trailing zeroes are deleted and exponential notation
is used if the exponent of the number is greater than the precision or less
than -4. If the @ modifier is used, a leading plus sign is printed before
positive values. If "mincol" is specified, the number is padded on the left
to be at least "mincol" characters long using "padchar". "padchar" defaults
to #\space.
For ~%, ~|, and ~~, the full form is ~n%, ~n|, or ~n~. "n" copies
(default=1) of the character are output.
For ~&, the full form is ~n&. ~0& does nothing. Otherwise enough new line
characters are emited to move down to the "n"th new line (default=1).
For ~?, the next argument is taken as a format string, upon completion
execution resumes in the current format string. The argument after is taken
as the list of arguments used for the new format string unless the @
modifier is used, in which case the current argument list is used.
For ~(, the full form is ~(string~). The string is processed as a format
string, however case conversion is performed on the output. If no modifiers
are used, the string is converted to lowercase. If the colon modifier is
used alone then all words are capitalized. If the @ modifier is used alone
XLISP-PLUS 3.0 THE FORMAT FUNCTION Page 88
then the first character is converted to upper case and all remaining to
lowercase. If both modifiers are used, all characters are converted to
uppercase.
For ~{, the full form is ~n{string~}. Repeatedly processes string as a
format string, or if the string is zero length, takes the next argument as
the string. Iteration stops when processing has occured n times or no
arguments remain. If the colon modifier is used on the ~} command, and n is
non-zero then the string will be processed at least once. If no modifiers
are used on ~{, then the arguments are taken from the next argument (like
in ~?). If the colon modifier is used, the arguments are taken from the
next argument which must be a list of sublists -- the sublists are used in
turn to provide arguments on each iteration. In either case, the @ modifier
will cause the current arguement list to be used rather than a single list
argument.
For ~[, there are three formats. The first form is
~n[clause0~;clause1...~;clausen~]. Only one clause string is used,
depending on the value of n. When n is absent, its value is taken from the
argument list (as though 'v' had been used.) The last clause is treated as
an "otherwise" clause if a colon modifier is used in its leading ~;
command. The second form is ~:[clausenil~;clauset~]. The next argument is
examined (and also consumed), and if nil clausenil is used, otherwise
clauset is used. The third form is ~@[string~]. If then next argument is
non-nil, then it is not used up and the format string is used, otherwise
the argument is used up and the string is not used.
For ~*, the full form is ~n*. The count, n, defaults to 1 and is the number
of arguments to skip. If the colon modifier is used, n is negated and
skipping is backwards. The @ modifier causes n to be an absolute argument
position (with default of 0), where the first argument is argument 0.
Attempts to position before the first argument will position at the first
argument, while attempts to position after the last argument signals an
error.
For ~T, the full form is:
~count,tabwidth@T
The cursor is moved to column "count" (default 1). If the cursor is
initially at count or beyond, then the cursor is moved forward to the next
position that is a multiple of "tabwidth" (default 1) columns beyond count.
When the @ modifier is used, then positioning is relative. "count" spaces
are printed, then additional spaces are printed to make the column number
be a multiple of "tabwidth". Note that column calcuations will be incorrect
if ASCII tab characters or ANSI cursor positioning sequences are used.
For ~\n, if the colon modifier is used, then the format directive is
ignored (allowing embedded returns in the source for enhanced readability).
If the at-sign modifier is used, then a carriage return is emitted, and
following whitespace is ignored.
XLISP-PLUS 3.0 FILE I/O FUNCTIONS Page 89
FILE I/O FUNCTIONS
Note that initially, when starting XLISP-PLUS, there are six system stream
symbols which are associated with three streams. *TERMINAL-IO* is a special
stream that is bound to the keyboard and display, and allows for
interactive editing. *STANDARD-INPUT* is bound to standard input or to
*TERMINAL-IO* if not redirected. *STANDARD-OUTPUT* is bound to standard
output or to *TERMINAL-IO* if not redirected. *ERROR-OUTPUT* (error message
output), *TRACE-OUTPUT* (for TRACE and TIME functions), and *DEBUG-IO*
(break loop i/o, and messages) are all bound to *TERMINAL-IO*. Standard
input and output can be redirected on most systems.
File streams are printed using the #< format that cannot be read by the
reader. Console, standard input, standard output, and closed streams are
explicitly indicated. Other file streams will typically indicate the name
of the attached file.
When the transcript is active (either -t on the command line or the DRIBBLE
function), all characters that would be sent to the display via
*TERMINAL-IO* are also placed in the transcript file.
*TERMINAL-IO* should not be changed. Any other system streams that are
changed by an application should be restored to their original values.
(read-char [<stream>[<eofp>[<eof>]]]) READ A CHARACTER FROM A STREAM
NOTE: New eof arguments are incompatible with older XLISP versions.
<stream> the input stream (default, or NIL, is *standard-input*, T is
*terminal-io*)
<eofp> When T, signal an error on end of file, when NIL return
<eof> (default is T)
<eof> the value to return on end of file (default is NIL)
returns the character or <eof> at end of file
(peek-char [<flag> [<stream> [<eofp> [<eof>]]]])
PEEK AT THE NEXT CHARACTER
<flag> flag for skipping white space (default is NIL)
<stream> the input stream (default, or NIL, is *standard-input*, T is
*terminal-io*)
<eofp> When T, signal an error on end of file, when NIL return
<eof> (default is T)
<eof> the value to return on end of file (default is NIL)
returns the character or <eof> at end of file
(write-char <ch> [<stream>]) WRITE A CHARACTER TO A STREAM
<ch> the character to write
<stream> the output stream (default, or NIL, is *standard-output*, T
is *terminal-io*)
returns the character
XLISP-PLUS 3.0 FILE I/O FUNCTIONS Page 90
(read-line [<stream>[<eofp>[<eof>]]]) READ A LINE FROM A STREAM
NOTE: New eof arguments are incompatible with older XLISP versions.
<stream> the input stream (default, or NIL, is *standard-input*, T is
*terminal-io*)
<eofp> When T, signal an error on end of file, when NIL return
<eof> (default is T)
<eof> the value to return on end of file (default is NIL)
returns the string excluding the #\newline, or <eof> at end of file
XLISP-PLUS 3.0 FILE I/O FUNCTIONS Page 91
(open <fname> &key :direction :element-type :if-exists :if-does-not-exist)
OPEN A FILE STREAM
The function OPEN has been significantly enhanced over original XLISP.
The original function only had the :direction keyword argument, which
could only have the values :input or :output. When used with the
:output keyword, it was equivalent to (open <fname> :direction :output
:if-exists :supersede). A maximum of ten files can be open at any one
time, including any files open via the LOAD, DRIBBLE, SAVE and RESTORE
commands. The open command may force a garbage collection to reclaim
file slots used by unbound file streams.
<fname> the file name string, symbol, or file stream created
via OPEN. In the last case, the name is used to open a
second stream on the same file -- this can cause
problems if one or more streams is used for writing.
:direction Read and write permission for stream (default is
:input).
:input Open file for read operations only.
:probe Open file for reading, then close it (use to test for
file existance)
:output Open file for write operations only.
:io Like :output, but reading also allowed.
:element-type FIXNUM or CHARACTER (default is CHARACTER), as returned
by type-of function (on page 100), or UNSIGNED-BYTE,
SIGNED-BYTE, (UNSIGNED-BYTE <size>), or (SIGNED-BYTE
<size>) with the bignum extension. CHARACTER (the
default) is for text files, the other types are for
binary files and can only be used with READ-BYTE and
WRITE-BYTE. FIXNUM is a vestige of older XLISP-PLUS
releases and is identical to (UNSIGNED-BYTE 8). If no
size is given, then size defaults to 8. Size must be a
multiple of 8.
:if-exists action to take if file exists. Argument ignored for
:input (file is positioned at start) or :probe (file is
closed)
:error give error message
:rename rename file to generated backup name, then open a new
file of the original name. This is the default action
:new-version same as :rename
:overwrite file is positioned to start, original data intact
:append file is positioned to end
:supersede delete original file and open new file of the same name
:rename-and-delete same as :supersede
NIL close file and return NIL
:if-does-not-exist action to take if file does not exist.
:error give error message (default for :input, or :overwrite
or :append)
:create create a new file (default for :output or :io when not
:overwrite or :append)
NIL return NIL (default for :probe)
returns a file stream, or sometimes NIL
XLISP-PLUS 3.0 FILE I/O FUNCTIONS Page 92
(close <stream>) CLOSE A FILE STREAM
The stream becomes a "closed stream." Note that unbound file streams
are closed automatically during a garbage collection.
<stream> the stream, which may be a string stream
returns t if stream closed, NIL if terminal (cannot be closed) or
already closed.
(probe-file <fname>) CHECK FOR EXISTANCE OF A FILE
Defined in common2.lsp
<fname> file name string or symbol
returns t if file exists, else NIL
(delete-file <fname>) DELETE A FILE
<fname> file name string, symbol or a stream opened with OPEN
returns t if file does not exist or is deleted. If <fname> is a
stream, the stream is closed before the file is deleted. An
error occurs if the file cannot be deleted.
(truename <fname>) OBTAIN THE FILE PATH NAME
<fname> file name string, symbol, or a stream opened with OPEN
returns string representing the true file name (absolute path to
file).
(with-open-file (<var> <fname> [<karg>...]) [<expr>...])
EVALUATE USING A FILE
(with-open-stream (<var> <stream>) [<expr>...])
EVALUATE USING AN OPENED STREAM
Defined in common.lsp and common2.lsp, respectively, as macros. Stream
will always be closed upon completion
<var> symbol name to bind stream to while evaluating expresssions
(quoted)
<fname> file name string or symbol
<stream> a file or string stream
<karg> keyword arguments for the implicit open command
<expr> expressions to evaluate while file is open (implicit progn)
returns value of last <expr>.
(read-byte <stream>[<eofp>[<eof>]]) READ A BYTE FROM A STREAM
NOTE: New eof arguments are incompatible with older XLISP versions.
Stream argument used to be optional. Number of system bytes read
depend on :element-type specified in the open command.
<stream> the input stream
<eofp> When T, signal an error on end of file, when NIL return
<eof> (default is T)
<eof> the value to return on end of file (default is NIL)
returns the byte (integer) or <eof> at end of file
(write-byte <byte> <stream>) WRITE A BYTE TO A STREAM
NOTE: Stream argument used to be optional. Number of system bytes
writen depend on :element-type specified in open command. No checks
are made for overflow, however negative values cannot be written to
unsigned-byte streams.
<byte> the byte to write (integer)
<stream> the output stream
returns the byte (integer)
XLISP-PLUS 3.0 FILE I/O FUNCTIONS Page 93
(file-length <stream>) GET LENGTH OF FILE
For a CHARACTER file, the length reported may be larger than the
number of characters read or written because of CR conversion.
<stream> the file stream (should be disk file)
returns length of file, or NIL if cannot be determined.
(file-position <stream> [<expr>]) GET OR SET FILE POSITION
For a CHARACTER file, the file position may not be the same as the
number of characters read or written because of CR conversion. It will
be correct when using file-position to position a file at a location
earlier reported by file-position.
<stream> the file stream (should be a disk file)
<expr> desired file position, if setting position. Can also be
:start for start of file or :end for end of file.
returns if setting position, and successful, then T; if getting
position and successful then the position; otherwise NIL
XLISP-PLUS 3.0 STRING STREAM FUNCTIONS Page 94
STRING STREAM FUNCTIONS
These functions operate on unnamed streams. An unnamed output stream
collects characters sent to it when it is used as the destination of any
output function. The functions 'get-output-stream' string and list return a
sting or list of the characters.
An unnamed input stream is setup with the 'make-string-input-stream'
function and returns each character of the string when it is used as the
source of any input function.
Note that there is no difference between unnamed input and output streams.
Unnamed input streams may be written to by output functions, in which case
the characters are appended to the tail end of the stream. Unnamed output
streams may also be (destructively) read by any input function as well as
the get-output-stream functions.
(make-string-input-stream <str> [<start> [<end>]])
<str> the string
<start> the starting offset
<end> the ending offset + 1 or NIL for end of string
returns an unnamed stream that reads from the string
(make-string-output-stream)
returns an unnamed output stream
(get-output-stream-string <stream>)
The output stream is emptied by this function
<stream> the output stream
returns the output so far as a string
(get-output-stream-list <stream>)
The output stream is emptied by this function
<stream> the output stream
returns the output so far as a list
(with-input-from-string (<var> <str> &key :start :end :index) [<expr>...])
Defined in common.lsp as a macro
<var> symbol that stream is bound to during execution of
expressions (quoted)
<str> the string
:start starting offset into string (default 0)
:end ending offset + 1 (default, or NIL, is end of string)
:index setf place form which gets final index into string after
last expression is executed (quoted)
<expr> expressions to evaluate (implicit progn)
returns the value of the last <expr>
(with-output-to-string (<var>) [<expr>...])
Defined in common.lsp as a macro
<var> symbol that stream is bound to during execution of
expressions (quoted)
<expr> expressions to evaluate (implicit progn)
returns contents of stream, as a string
XLISP-PLUS 3.0 DEBUGGING AND ERROR HANDLING Page 95
DEBUGGING AND ERROR HANDLING FUNCTIONS
(trace [<sym>...]) ADD A FUNCTION TO THE TRACE LIST
fsubr
<sym> the function(s) to add (quoted)
returns the trace list
(untrace [<sym>...]) REMOVE A FUNCTION FROM THE TRACE LIST
fsubr. If no functions given, all functions are removed from the trace
list.
<sym> the function(s) to remove (quoted)
returns the trace list
(error <emsg> {<arg>}) SIGNAL A NON-CORRECTABLE ERROR
Note that the definition of this function has changed from 2.1e and
earlier so to match Common Lisp.
<emsg> the error message string, which is processed by FORMAT
<arg> optional argument{s} for FORMAT
returns never returns
(cerror <cmsg> <emsg> {<arg>}) SIGNAL A CORRECTABLE ERROR
Note that the definition of this function has changed from 2.1e and
earlier so to match Common Lisp.
<cmsg> the continue message string, which is processed by FORMAT
<emsg> the error message string, which is processed by FORMAT
<arg> optional argument(s) for both FORMATs (arguments are useable
twice)
returns NIL when continued from the break loop
(break <bmsg> {<arg>}) ENTER A BREAK LOOP
Note that the definition of this function has changed from 2.1e and
earlier so to match Common Lisp.
<bmsg> the break message string, which is processed by FORMAT
<arg> optional argument(s) for FORMAT
returns NIL when continued from the break loop
(clean-up) CLEAN-UP AFTER AN ERROR
returns never returns
(top-level) CLEAN-UP AFTER AN ERROR AND RETURN TO THE TOP LEVEL
Runs the function in variable *top-level-loop* (ususally TOP-LEVEL-
LOOP)
returns never returns
(continue) CONTINUE FROM A CORRECTABLE ERROR
returns never returns
(errset <expr> [<pflag>]) TRAP ERRORS
fsubr
<expr> the expression to execute
<pflag> flag to control printing of the error message (default t)
returns the value of the last expression consed with NIL or NIL on
error
XLISP-PLUS 3.0 DEBUGGING AND ERROR HANDLING Page 96
(baktrace [<n>]) PRINT N LEVELS OF TRACE BACK INFORMATION
<n> the number of levels (defaults to all levels)
returns NIL
(evalhook <expr> <ehook> <ahook> [<env>]) EVALUATE WITH HOOKS
<expr> the expression to evaluate. <ehook> is not used at the top
level.
<ehook> the value for *evalhook*
<ahook> the value for *applyhook*
<env> the environment (default is NIL). The format is a dotted
pair of value (car) and function (cdr) binding lists. Each
binding list is a list of level binding a-lists, with the
innermost a-list first. The level binding a-list associates
the bound symbol with its value.
returns the result of evaluating the expression
(applyhook <fun> <arglist> <ehook> <ahook>) APPLY WITH HOOKS
<fun> The function closure. <ahook> is not used for this function
application.
<arglist> The list of arguments.
<ehook> the value for *evalhook*
<ahook> the value for *applyhook*
returns the result of applying <fun> to <arglist>
(debug) ENABLE DEBUG BREAKS
(nodebug) DISABLE DEBUG BREAKS
Defined in init.lsp
(ecase <expr> <case>...) SELECT BY CASE
(ccase <expr> <case>...)
Defined in common2.lsp as macros. ECASE signals a non-continuable
error if there are no case matches, while CCASE signals a continuable
error and allows changing the value of <expr>.
<expr> the selection expression
<case> pair consisting of:
(<value> <expr>...)
where:
<value> is a single expression or a list of expressions
(unevaluated)
<expr> are expressions to execute if the case matches
returns the value of the last expression of the matching case
(etypecase <expr> <case>...) SELECT BY TYPE
(ctypecase <expr> <case>...)
Defined in common2.lsp as macros. ETYPECASE signals a non-continuable
error if there are no case matches, while CTYPECASE signals a
continuable error and allows changing the value of <expr>.
<expr> the selection expression
<case> pair consisting of:
(<type> <expr>...)
where:
<type> type specifier as in function TYPEP (page 76)
<expr> are expressions to execute if the case matches
returns the value of the last expression of the matching case
XLISP-PLUS 3.0 DEBUGGING AND ERROR HANDLING Page 97
(check-type <place> <type> [<string>]) VERIFY DATA TYPE
Defined in common2.lsp as a macro. If value stored at <place> is not
of type <type> then a continuable error is signaled which allows
changing the value at <place>.
<place> a valid field specifier (generalized variable)
<type> a valid type specifier as in function TYPEP (page 76)
<string> string to print as the error message
returns NIL
(assert <test> [([<place>...]) [<string> [<args>...]]]) MAKE AN ASSERTION
Defined in common2.lsp. If value of <test> is NIL then a continuable
error is signaled which allows changing the place values.
<test> assertion test
<place> zero or more valid field specifiers
<string> error message printed using FORMAT (evaluated only if
assertion fails)
<args> arguments for FORMAT (evaluated only if assertion fails)
returns NIL
XLISP-PLUS 3.0 SYSTEM FUNCTIONS Page 98
SYSTEM FUNCTIONS
(load <fname> &key :verbose :print) LOAD A SOURCE FILE
An implicit ERRSET exists in this function so that if error occurs
during loading, and *breakenable* is NIL, then the error message will
be printed and NIL will be returned. The OS environmental variable
XLPATH is used as a search path for files in this function. If the
filename does not contain path separators ('/' for UNIX, and either
'/' or '\' for MS-DOS) and XLPATH is defined, then each pathname in
XLPATH is tried in turn until a matching file is found. If no file is
found, then one last attempt is made in the current directory. The
pathnames are separated by either a space or semicolon, and a trailing
path separator character is optional.
<fname> the filename string, symbol, or a file stream created with
OPEN. The extension "lsp" is assumed.
:verbose the verbose flag (default is t)
:print the print flag (default is NIL)
returns t if successful, else NIL
(restore <fname>) RESTORE WORKSPACE FROM A FILE
The OS environmental variable XLPATH is used as a search path for
files in this function. See the note under function "load", above. The
standard system streams are restored to the defaults as of when
XLISP-PLUS was started. Files streams are restored in the same mode
they were created, if possible, and are positioned where they were at
the time of the save. If the files have been altered or moved since
the time of the save, the restore will not be completely successful.
Memory allocation will not be the same as the current settings of
ALLOC are used. Execution proceeds at the top-level read-eval-print
loop. The state of the transcript logging is not affected by this
function.
<fname> the filename string, symbol, or a file stream created with
OPEN. The extension "wks" is assumed.
returns NIL on failure, otherwise never returns
(save <fname>) SAVE WORKSPACE TO A FILE
You cannot save from within a load. Not all of the state may be saved
-- see "restore", above. By saving a workspace with the name "xlisp",
that workspace will be loaded automatically when you invoke
XLISP-PLUS.
<fname> the filename string, symbol, or a file stream created with
OPEN. The extension "wks" is assumed.
returns t if workspace was written, NIL otherwise
(savefun <fcn>) SAVE FUNCTION TO A FILE
defined in init.lsp
<fcn> function name (saves it to file of same name, with extension
".lsp")
returns t if successful
(dribble [<fname>]) CREATE A FILE WITH A TRANSCRIPT OF A SESSION
<fname> file name string, symbol, or file stream created with OPEN
(if missing, close current transcript)
returns t if the transcript is opened, NIL if it is closed
XLISP-PLUS 3.0 SYSTEM FUNCTIONS Page 99
(gc) FORCE GARBAGE COLLECTION
returns NIL
(expand [<num>]) EXPAND MEMORY BY ADDING SEGMENTS
<num> the (fixnum) number of segments to add, default 1
returns the (fixnum) number of segments added
(alloc <num> [<num2> [<num3>]]) CHANGE SEGMENT SIZE
<num> the (fixnum) number of nodes to allocate
<num2> the (fixnum) number of pointer elements to allocate in an
array segment (when dynamic array allocation compiled).
Default is no change.
<num3> the <fixnum> ideal ratio of free to used vector space
(versions of XLISP using dldmem.c). Default is 1. Increase
if extensive time is spent in garbage collection in bignum
math intensive programs.
returns the old number of nodes to allocate
(room) SHOW MEMORY ALLOCATION STATISTICS
Statistics (which are sent to *STANDARD-OUTPUT*) include:
Nodes - number of nodes, free and used
Free nodes - number of free nodes
Segments - number of node segments, including those reserved
for characters and small integers.
Allocate - number of nodes to allocate in any new node
segments
Total - total memory bytes allocated for node segments,
arrays, and strings
Collections - number of garbage collections
Time - time spent performing garbage collections (in
seconds)
When dynamic array allocation is compiled, the following additional
statistics are printed:
Vector nodes - total vector space (pointers and string, in
pointer sized units)
Vector free - free space in vector area (may be fragmented
across segments)
Vector segs - number of vector segments. Increases and
decreases as needed.
Vec allocate - number of pointer elements to allocate in any
new vector segment
Vec collect - number of garbage collections instigated by
vector space exhaustion
returns NIL
(time <expr>) MEASURE EXECUTION TIME
fsubr.
<expr> the expression to evaluate
returns the result of the expression. The execution time is printed
to *TRACE-OUTPUT*
(sleep <expr>) TIME DELAY
defined in common2.lsp
<expr> time in seconds
returns NIL, after <expr> seconds delay
XLISP-PLUS 3.0 SYSTEM FUNCTIONS Page 100
(get-internal-real-time) GET ELAPSED CLOCK TIME
(get-internal-run-time) GET ELAPSED EXECUTION TIME
returns integer time in system units (see
internal-time-units-per-second on page 25). meaning of
absolute values is system dependent.
(coerce <expr> <type>) FORCE EXPRESSION TO DESIGNATED TYPE
Sequences can be coerced into other sequences, single character
strings or symbols with single character printnames can be coerced
into characters, integers can be coerced into characters or flonums.
Ratios can be coerced into flonums. Flonums can be coerced into
complex.
<expr> the expression to coerce
<type> desired type, as returned by type-of (see page 100)
returns <expr> if type is correct, or converted object.
(type-of <expr>) RETURNS THE TYPE OF THE EXPRESSION
It is recommended that typep be used instead, as it is more general.
In the original XLISP, the value NIL was returned for NIL.
<expr> the expression to return the type of
returns One of the symbols:
LIST for NIL (lists, conses return CONS)
SYMBOL for symbols
OBJECT for objects
CONS for conses
SUBR for built-in functions
FSUBR for special forms
CLOSURE for defined functions
STRING for strings
FIXNUM for integers
BIGNUM for large integers
RATIO for ratios
FLONUM for floating point numbers
COMPLEX for complex numbers
CHARACTER for characters
FILE-STREAM for file pointers
UNNAMED-STREAM for unnamed streams
ARRAY for arrays
HASH-TABLE for hash tables
sym for structures of type "sym"
(peek <addrs>) PEEK AT A LOCATION IN MEMORY
<addrs> the address to peek at (fixnum)
returns the value at the specified address (integer)
(poke <addrs> <value>) POKE A VALUE INTO MEMORY
<addrs> the address to poke (fixnum)
<value> the value to poke into the address (fixnum)
returns the value
(address-of <expr>) GET THE ADDRESS OF AN XLISP NODE
<expr> the node
returns the address of the node (fixnum)
XLISP-PLUS 3.0 SYSTEM FUNCTIONS Page 101
(get-key) READ A KEYSTROKE FROM CONSOLE
OS dependent.
returns integer value of key (no echo)
(system <command>) EXECUTE A SYSTEM COMMAND
OS dependent -- not always available.
<command> Command string, if 0 length then spawn OS shell
returns T if successful (note that MS/DOS command.com always returns
success)
(set-stack-mark <size>) SET SYSTEM STACK WARNING POINT
OS dependent -- not always available. The system will perform a
continuable error when the amount of remaining system stack passes
below this setting. The trap is reset at the top-level. This function
is useful for debugging runaway recursive functions.
<size> Remaining stack, in bytes. Minimum value is fixed at the
value that causes the system stack overflow error, while the
maximum value is limitied to somewhat less than the current
remaining stack space. Use "0" to turn the warnings off.
returns the previous value.
(top-level-loop) DEFAULT TOP LEVEL LOOP
Runs the XLISP top level read-eval-print loop, described earlier.
Never returns.
(reset-system) FLUSH INPUT BUFFERS
Used by user-implemented top level loops to flush the input buffer
returns NIL
(exit) EXIT XLISP
returns never returns
(generic <expr>) CREATE A GENERIC TYPED COPY OF THE EXPRESSION
Note: added function, Tom Almy's creation for debugging xlisp.
<expr> the expression to copy
returns NIL if value is NIL and NILSYMBOL compilation option not
declared, otherwise if type is:
SYMBOL copy as an ARRAY
OBJECT copy as an ARRAY
CONS (CONS (CAR <expr>)(CDR <expr>))
CLOSURE copy as an ARRAY
STRING copy of the string
FIXNUM value
FLONUM value
RATIO value
CHARACTER value
UNNAMED-STREAM copy as a CONS
ARRAY copy of the array
COMPLEX copy as an ARRAY
HASH-TABLE copy as an ARRAY
BIGNUM copy as a string
structure copy as an ARRAY
XLISP-PLUS 3.0 SYSTEM FUNCTIONS Page 102
(eval-when <condition> <body> ...)
Macro defined in common.lsp, and provided to assist in porting Common
Lisp applications to XLISP-PLUS.
<condition> List of conditions
<body> expressions which are evaluated if one of the conditions is
EXECUTE or LOAD.
returns result of last body expression
The following graphic and display functions represent an extension by Tom
Almy:
(cls) CLEAR DISPLAY
Clear the display and position cursor at upper left corner.
returns nil
(cleol) CLEAR TO END OF LINE
Clears current line to end.
returns nil
(goto-xy [<column> <row>]) GET OR SET CURSOR POSITION
Cursor is repositioned if optional arguments are specified.
Coordinates are clipped to actual size of display.
<column> 0-based column (x coordinate)
<row> 0-based row (y coordinate)
returns list of original column and row positions
(mode <ax> [<bx> <width> <height>) SET DISPLAY MODE
Standard modes require only <ax> argument. Extended modes are "Super-
VGA" or "Super-EGA" and are display card specific. Not all XLISP
versions support all modes.
<ax> Graphic mode (value passed in register AX)
Common standard Modes:
0,1 - 40x25 text
2,3 - 80x25 text
4,5 - 320x200 4 color graphics (CGA)
6 - 640x200 monchrome graphics (CGA)
13 - 320x200 16 color graphics (EGA)
14 - 640x200 16 color graphics (EGA)
16 - 640x350 16 color graphics (EGA)
18 - 640x480 16 color graphics (VGA)
19 - 320x200 256 color graphics (VGA)
<bx> BX value for some extended graphic modes
<width> width for extended graphic modes
<height> height for extended graphic modes
returns a list of the number of columns, number of lines (1 for
CGA), maximum X graphic coordinate (-1 for text modes), and
the maximum Y graphic coordinate (-1 for text modes), or NIL
if fails
(color <value>) SET DRAWING COLOR
<value> Drawing color (not checked for validity)
returns <value>
XLISP-PLUS 3.0 ADDITIONAL FUNCTIONS Page 103
(move <x1> <y1> [<x2> <y2> ...]) ABSOLUTE MOVE
(moverel <x1> <y2> [<x2> <y2> ...]) RELATIVE MOVE
For moverel, all coordinates are relative to the preceeding point.
<x1> <y1> Moves to point x1,y1 in anticipation of draw.
<x2> <y2> Draws to points specified in additional arguments.
returns T if succeeds, else NIL
(draw [<x1> <y1> ...]) ABSOLUTE DRAW
(drawrel [<x1> <y1> ...]) RELATIVE DRAW
For drawrel, all coordinates are relative to the preceeding point.
<x1> <y1> Point(s) drawn to, in order.
returns T if succeeds, else NIL
XLISP-PLUS 3.0 ADDITIONAL FUNCTIONS Page 104
ADDITIONAL FUNCTIONS AND UTILITIES
STEP.LSP
This file contains a simple Lisp single-step debugger. It started as an
implementation of the "hook" example in chapter 20 of Steele's "Common
Lisp". This version was brought up on Xlisp 1.7 for the Amiga, and then on
VAXLISP.
When the package feature is compiled in, the debugger is in the TOOLS
package.
To invoke: (step (whatever-form with args))
For each list (interpreted function call), the stepper prints the
environment and the list, then enters a read-eval-print loop. At this point
the available commands are:
(a list)<CR> evaluate the list in the current environment, print the
result, and repeat.
<CR> step into the called function
anything_else<CR> step over the called function.
If the stepper comes to a form that is not a list it prints the form and
the value, and continues on without stopping.
Note that stepper commands are executed in the current environment. Since
this is the case, the stepper commands can change the current environment.
For example, a SETF will change an environment variable and thus can alter
the course of execution.
Global variables - newline, *hooklevel*
Functions/macros - while step eval-hool-function step-spaces step-flush
Note -- an even more powerful stepper package is in stepper.lsp (documented
in stepper.doc).
XLISP-PLUS 3.0 ADDITIONAL FUNCTIONS Page 105
PP.LSP
In addition to the pretty-printer itself, this file contains a few
functions that illustrate some simple but useful applications.
When the package feature is compiled in, these funtions are in the TOOLS
package.
(pp <object> [<stream>]) PRETTY PRINT EXPRESSION
(pp-def <funct> [<stream>]) PRETTY PRINT FUNCTION/MACRO
(pp-file <file> [<stream>]) PRETTY PRINT FILE
<object> The expression to print
<funct> Function to print (as DEFUN or DEFMACRO)
<file> File to print (specify either as string or quoted symbol)
<stream> Output stream (default is *standard-output*)
returns T
Global variables: tabsize maxsize miser-size min-miser-car max-normal-car
Functions/Macros: sym-function pp-file pp-def make-def pp pp1 moveto spaces
pp-rest-across pp-rest printmacrop pp-binding-form pp-do-form
pp-defining-form pp-pair-form
See the source file for more information.
XLISP-PLUS 3.0 ADDITIONAL FUNCTIONS Page 106
DOCUMENT.LSP
This file provides the documentation feature of Common Lisp. When loaded,
glossary descriptions of system functions and variables are installed from
the file GLOS.TXT. References are made directly to the file so that the
size of the XLISP image will not increase. The following functions are
implemented:
(documentation <symbol> <doctype>) GET DOCUMENTATION STRING
Use with SETF to alter documentation string.
<symbol> Symbol of interest
<doctype> Documentation type, one of FUNCTION, VARIABLE, STRUCTURE,
SETF, or TYPE.
returns Documentation string
(glos <symbol> [T]) GET DOCUMENTATION
Defined in package TOOLS.
<symbol> Either the symbol for which the documentation is requested,
or a string which will match all symbol names containing
that string.
T Flag saying to treat symbol as a string, and match all
related names.
returns nothing
Documentation can be added via the DEFCONSTANT, DEFPARAMETER, DEFVAR,
DEFUN, DEFMACRO, and DEFSTRUCT functions as well as via DOCUMENTATION.
Documentation is stored in the property list in properties %DOC-FUNCTION,
%DOC-STRUCTURE, %DOC-VARIABLE, %DOC-SETF, and %DOC-TYPE. The latter two are
not currently used. These properties either contain the documentation
string or the offset into the GLOS.TXT file.
XLISP-PLUS 3.0 ADDITIONAL FUNCTIONS Page 107
INSPECT.LSP
INSPECT.LSP contains an XLISP editor/inspector. When the package feature is
compiled in, the editor is in the TOOLS package. Two functions, INSPECT and
DESCRIBE, are part of Common Lisp and are in the XLISP package.
(ins <symbol>) INSPECT A SYMBOL
(inspect <expr>) INSPECTOR
(insf <symbol>) INSPECT FUNCTION BINDING
INS and INSF are macros defined in package TOOLS. INSF edits the
function binding and allows changing the argument list or type (MACRO
or LAMBDA).
<symbol> Symbol to inspect (quoted)
<expr> Expression to inspect
returns Symbol or expression
(describe <expr>) DESCRIBE
Tells what <expr> is, but doesn't allow editing. Use INSPECT to edit.
<expr> Expression to describe
returns The expression
The editor alters the current selection by copying so that aborting all
changes is generally posible; the exception is when editing a closure, if
the closure is backed out of, the change is permanent. Also, naturally,
changing the values of structure elements, instance variables, or symbols
cannot be undone.
For all commands taking a numeric argument, the first element of the
selection is the 0th (as in NTH function).
Do not create new closures, because the environment will be incorrect.
Closures become LAMBDA or MACRO expressions as the selection. Only the
closure body may be changed; the argument list cannot be successfully
modified, nor can the environment.
For class objects, the class variables, methods and message names can be
modified. For instance objects, instance variables can be examined (if the
object under-stands the message :<ivar> for the particular ivar), and
changed (if :SET-IVAR is defined for that class, as it is if CLASSES.LSP is
used). Structure elements can be examined and changed.
(command list on next page)
XLISP-PLUS 3.0 ADDITIONAL FUNCTIONS Page 108
COMMANDS (all "hot keyed and case sensitive"):
? List available commands
A select the CAR of the current selection.
D select the CDR of the current selection.
e n select ("Edit") element n
r n x Replaces element n with x.
X eXit, saving all changes
Q Quit, without saving changes
b go Back one level (backs up A, D or e commands)
B n go Back n levels.
l List selection using pprint; if selection is symbol, give
short description
v Verbosity toggle
. n change maximum print length (default 10)
# n change maximum print depth (default 3)
! x evaluates x and prints result, the symbol tools:@ is bound
to the selection
R x Replaces the selection with evaluated x, the symbol tools:@
is bound to the selection
ADDITIONAL COMMANDS (selection is a list or array):
( n m inserts parenthesis starting with the nth element, for m
elements.
) n removes parenthesis surrounding nth element of selection,
which may be array or list
[ n m as in (, but makes elements into an array
i n x Inserts x before nth element in selection.
d n Deletes nth element in selection.
S x y Substitute all occurances of y with x in selection (which
must be a list). EQUAL is used for the comparison.
XLISP-PLUS 3.0 COMPILATION OPTIONS Page 109
COMPILATION OPTIONS
XLISP PLUS has many compilation options to optimize the executable for
specific tasks. These are the most useful:
1. Available Functions (all turned on by default)
- SRCHFCN supplies SEARCH
- MAPFCNS supplies SOME EVERY NOTANY NOTEVERY and MAP
- POSFCNS supplies POSITION-* COUNT-* and FIND-* functions
- REMDUPS supplies REMOVE-DUPLICATES
- REDUCE supplies REDUCE
- SUBSTITUTE supplies SUBSTITUTE-* and NSUBSTITUTE-*
- ADDEDTAA supplies GENERIC
- TIMES supplies TIME GET-INTERNAL-RUN-TIME GET-INTERNAL-REAL-TIME
and the constant INTERNAL-TIME-UNITS-PER-SECOND
- RANDOM supplies RANDOM-NUMBER-STATE type, *RANDOM-STATE*, and the
function MAKE-RANDOM-STATE. Requires TIMES.
- HASHFCNS supplies SETHASH MAKE-HASH-TABLE REMHASH MAPHASH CLRHASH
and HASH-TABLE-COUNT
- SETS supplies ADJOIN UNION INTERSECTION SET-DIFFERENCE and
SUBSETP
- SAVERESTORE supplies SAVE and RESTORE
- GRAPHICS supplies graphic functions (when available)
2. Features (all turned on by default)
- COMPLX adds complex number support including math functions
COMPLEX COMPLEXP IMAGPART REALPART CONJUGATE PHASE LOG FLOOR
CEILING ROUND PI LCM and ASH
- BIGNUMS adds bignum, ratio, and read/print radix support.
Requires COMPLX.
- NOOVFIXNUM Check for fixnum overflow, and convert to flonum (only
applies if BIGNUMS not used)
- PACKAGES uses the packages implementation. Some people find XLISP
PLUS easier to use if this is not defined.
- MULVALS multiple value returns
- FILETABLE files referenced via a table -- allows saving and
restoring open files (in WKS files), and is required by Microsoft
Windows versions. Also allows functions TRUENAME and DELETE-FILE.
- KEYARG adds :key keyword option to functions having it
- FROMEND adds the :from-end and :count keywords to functions
having them
- AOKEY makes &allow-other-keys functional. Without this option,
all functions behave as though &allow-other-keys is always
specified.
- APPLYHOOK adds applyhook support
3. Backwards compatibility
- OLDERRORS makes CERROR and ERROR work as in XLISP-PLUS 2.1e or
earlier, which is not compatible with more recent versions (or
Common Lisp)
- LEXBIND lexical tag scoping for TAGBODY/GO and BLOCK/RETURN, as
in Common Lisp. If not defined, then the original dynamic scoping
is used.
4. Environmental options
XLISP-PLUS 3.0 COMPILATION OPTIONS Page 110
- ASCII8 eight bit ASCII character support
- ANSI8 used in addition to ASCII8 for MS Windows character code
page
- READTABLECASE adds *readtable-case* and its functionality
- PATHNAMES allows environment variable to specify search path for
RESTORE and LOAD functions
- BIGENDIANFILE binary files use "bigendian" orientation. Normally
this option is defined when BIGENDIAN (required on bigendian
systems) is defined, but this has been made a separate option to
allow file portability between systems.
5. Performance options
- JMAC increases performance slightly, except on 16 bit DOS
environments.
- GENERIC use generic bignum to float conversion. Required for
bigendian or non IEEE floating point systems (such as Macs).
Using this selection decreases precision and increases execution
time.
In addition, there are options for various stack sizes, static fixnum
values, and various allocation sizes that can be altered. They have been
set optimally for each compiler/environment and "typical" applications.
XLISP-PLUS 3.0 BUG FIXES AND EXTENSIONS Page 111
BUG FIXES AND EXTENSIONS
In this section, CL means "Common Lisp compatible to the extent possible".
CX means "now works with complex numbers". CR means "now works with
ratios". * means "implemented in LISP rather than C". # means
"implementation moved from LISP to C".
Bug Fixes
RESTORE did not work -- several bugs for 80x86 systems. Only one restore
would work per session -- all systems.
:downcase for variable *printcase* did not work with some compilers.
Modifications to make the source acceptable to ANSI C compilers.
Values for ADEPTH and EDEPTH changed to more reasonable values -- before
this change the processor stack would overflow first, causing a crash.
On systems with 16 bit integers: STRCAT crashes when aggregate size of
argument strings were greater than 32k. MAKE-ARRAY crashes on too-large
arrays. DOTIMES, AREF, AREF and NTH place forms of SETF,
MAKE-STRING-INPUT-STREAM and GET-OUTPUT-STREAM-STRING treat numeric
argument modulo 65536. MAKE-STRING-INPUT-STREAM did not check for
start>end.
Strings containing nulls could not be read or printed.
NTH and NTHCDR failed for zero length lists.
Unnamed streams did not survive garbage collections.
(format nil ...) did not protect from garbage collection the unnamed stream
it creates.
SORT did not protect some pointers from garbage collection.
SYMBOL-NAME SYMBOL-VALUE SYMBOL-PLIST BOUNDP and FBOUNDP failed with symbol
NIL as argument.
LAST returned wrong value when its argument list ended with a dotted pair.
*gc-hook* was not rebound to NIL during execution of gchook function,
causing potential infinite recursion and crash.
Executing RETURN from within a DOLIST or DOTIMES caused the environment to
be wrong.
When errors occured during loading, which were not caught, the file would
be left open. EVAL and LOAD did not use global environment. EVALHOOK's
default environment was not global.
XLISP-PLUS 3.0 BUG FIXES AND EXTENSIONS Page 112
Invalid symbols (those containing control characters, for instance), can no
longer be created with intern and make-symbol.
The key T, meaning "otherwise" in the CASE function used to be allowed in
any position. Now it only means "otherwise" when used as the last case.
The lexical and functional environment of send of :answer (which defines a
new method) are now used during the method's evaluation, rather than the
global environment.
Signatures added for WKS files so that invalid ones will be rejected.
Checks added for file names and identifier names being too long.
Indexing code fixed to allow almost 64k long strings in 16 bit systems. It
is no longer possible to allocate arrays or strings that are too long for
the underlying system.
Circularity checks added to PRINT LAST BUTLAST LENGTH MEMBER and MAP
functions. An error is produced for all but MEMBER, which will execute
correctly.
Code for SETF modified so that a Common Lisp compatible DEFSETF could be
used.
Circularity checks added to EQUAL.
Check for even number of arguments to SETQ, SETF, and PSETQ added. PSETQ
changed to return NIL rather than result of first assignment (really now!).
User Interface Changes
-w command line argument to specify alternate or no workspace.
-b command line argument for batch operation.
-? command line argument gives usage message.
init.lsp not loaded if workspace loaded.
Search path can be provided for workspaces and .lsp files.
Standard input and output can be redirected. *TERMINAL-IO* stream added
which is always bound to console (stderr).
Non-error messages are sent to *DEBUG-IO* so they don't clutter
*STANDARD-OUTPUT*
Results of evaluations are printed on a fresh line rather than at the end
of the preceeding line (if any). This enhances readability.
Display writes are buffered.
Character literals available for all 256 values. CL
XLISP-PLUS 3.0 BUG FIXES AND EXTENSIONS Page 113
Uninterned symbols print with leading #:. CL
PRIN1 generates appropriate escape sequences for control and meta
characters in strings. CL
Read macro #. added. CL
Lisp code for nested backquote macros added. CL
Read macro #C added for complex numbers. CL
Semantics for #S read macro changed so that it can read in structures
written by PRINT. CL
PRINT of file streams shows file name, or "closed" if a closed file stream.
*PRINT-CASE* now applies to PRINC. CL
Added *READTABLE-CASE* to control case conversion on input and output,
allowing case sensitive code. CL-like
Reader macros #+ and #- added, along with global variable *FEATURES*. CL
Added optional and OS dependent checking of system stack overflow, with
checks in READ, PRINT, EVAL, and in the garbage collector. Added a new
function SET-STACK-MARK which performs a continuable error when the
remaining stack space drops below a preset amount.
Improved command line editing, symbol name lookup, and history (command
recall) for MS-DOS.
*PRINT-CASE* can now be :CAPITALIZE. CL
Packages added.
Reader macro #nR added. Added *READ-BASE* to control default read radix.
Numeric input is now Common Lisp compliant.
New/Changed Data Types
NIL -- was treated as a special case, now just a normal symbol.
symbols -- value binding can optionally be constant or special. "*unbound*"
is no longer a symbol so does not have to be specially treated.
ratio numbers -- new type.
complex numbers -- new type, can be rational or real. (Older versions
allowed fixnum or real.)
bignums -- new type.
character strings -- The ASCII NUL (code 0) is now a valid character.
objects -- objects of class Class have a new instance variable which is the
print name of the class.
hash-table -- new type, close to CL
random-state -- new type, CL
Property list properties are no longer limited to just symbols CL
Multiple value returns added where appropriate
Packages added where appropriate
XLISP-PLUS 3.0 BUG FIXES AND EXTENSIONS Page 114
New Variables and Constants
*apply-hook* Now activated
*command-line*
*displace-macros* Macros are replaced with their expansions when possible
*dos-input* MSDOS only, uses DOS interface to interact with user.
Allows recall of earlier command(s).
*load-file-arguments*
*print-level* CL
*print-length* CL
*random-state* CL
*ratio-format*
*readtable-case* CL-like
*startup-functions*
*terminal-io* CL
*top-level-loop*
internal-time-units-per-second CL
pi CL
*read-base*
*print-base*
New functions
ACONS CL*
ACOSH CL*
ADJOIN CL
ALPHA-CHAR-P CL
APPLYHOOK CL
APROPOS CL*
APROPOS-LIST CL*
ASH CL
ASINH CL*
ATANH CL*
BUTLAST CL
CEILING CL
CIS CL*
CLREOL (clear to end of line -- MS/DOS only)
CLRHASH CL
CLS (clear screen -- MS/DOS only)
COERCE CL
COLOR (graphics -- MS/DOS only)
COMPLEMENT CL
COMPLEX CL
COMPLEXP CL
CONCATENATE CL
CONJUGATE CL
CONSTANTP CL
COPY-ALIST CL*
COPY-LIST CL*
COPY-TREE CL*
COSH CL*
COUNT-IF CL
COUNT-IF-NOT CL
DECF CL*
DECLARE *
XLISP-PLUS 3.0 BUG FIXES AND EXTENSIONS Page 115
DEFCLASS * (define a new class)
DEFINST * (define a new instance)
DEFMETHOD * (define a new method)
DEFPACKAGE CL*
DEFSETF CL*
DELETE-FILE CL
DELETE-PACKAGE CL
DENOMINATOR CL
DESCRIBE CL*
DO-ALL-SYMBOLS CL*
DO-EXTERNAL-SYMBOLS CL*
DO-SYMBOLS CL*
DOCUMENTATION CL*
DRAW (graphics -- MS/DOS only)
DRAWREL (graphics -- MS/DOS only)
ELT CL
EQUALP CL*
EVAL-WHEN *
EVERY CL
EXPORT CL
FILE-LENGTH CL
FILE-POSITION CL
FILL CL*
FIND-ALL-SYMBOLS CL
FIND-IF CL
FIND-IF-NOT CL
FIND-PACKAGE CL
FLOOR CL
FRESH-LINE CL
FUNCTIONP CL*
GENERIC (implementation debugging function)
GET-INTERNAL-REAL-TIME CL
GET-INTERNAL-RUN-TIME CL
GETF CL
GETHASH CL
GOTO-XY (position cursor -- MS/DOS only)
HASH-TABLE-COUNT CL
IDENTITY CL
IMAGPART CL
IMPORT CL
INCF CL*
IN-PACKAGE CL
INPUT-STREAM-P CL
INSPECT CL*
INTEGER-LENGTH CL
INTERSECTION CL
LCM CL
LIST* CL
LIST-ALL-PACKAGES CL
LIST-LENGTH CL
LOG CL
LOGANDC1 CL
LOGANDC2 CL
LOGBITP CL
LOGCOUNT CL
XLISP-PLUS 3.0 BUG FIXES AND EXTENSIONS Page 116
LOGEQV CL
LOGNAND CL
LOGNOR CL
LOGORC1 CL
LOGORC2 CL
LOGTEST CL
MAKE-HASK-TABLE CL
MAKE-PACKAGE CL
MAKE-RANDOM-STATE CL
MAP CL
MAP-INTO CL
MAPHASH CL
MARK-AS-SPECIAL
MODE (graphics -- MS/DOS only)
MOVE (graphics -- MS/DOS only)
MOVEREL (graphics -- MS/DOS only)
MULTIPLE-VALUE-BIND CL*
MULTIPLE-VALUE-CALL CL
MULTIPLE-VALUE-LIST CL*
MULTIPLE-VALUE-PROG1 CL
MULTIPLE-VALUE-SETQ CL*
NINTERSECTION CL*
NTH-VALUE
NOTANY CL
NOTEVERY CL
NREVERSE CL
NSET-DIFFERENCE CL*
NSET-EXCLUSIVE-OR CL*
NSTRING-CAPITALIZE CL
NSUBSTITUTE CL
NSUBSTITUTE-IF CL
NSUBSTITUTE-IF-NOT CL
NUMERATOR CL
NUNION CL*
OPEN-STREAM-P CL
OUTPUT-STREAM-P CL
PACKAGE-NAME CL
PACKAGE-NICKNAMES CL
PACKAGE-OBARRAY
PACKAGE-SHADOWING-SYMBOLS CL
PACKAGE-USED-BY-LIST CL
PACKAGE-USE-LIST CL
PACKAGE-VALID-P
PAIRLIS CL*
PHASE CL
POP CL*
POSITION-IF CL
POSITION-IF-NOT CL
PROCLAIM *
PSETF CL
PUSH CL*
PUSHNEW CL*
RATIONAL CL
RATIONALP CL
REALPART CL
XLISP-PLUS 3.0 BUG FIXES AND EXTENSIONS Page 117
REDUCE CL except no :from-end
REMF CL*
REMHASH CL
REMOVE-DUPLICATES CL except no :from-end
RENAME-PACKAGE CL
REPLACE CL*
RESET-SYSTEM
ROUND CL
SEARCH CL except no :from-end
SET-DIFFERENCE CL
SET-EXCLUSIVE-OR CL*
SET-STACK-MARK
SETF Placeform ELT CL
SETF Placeform GETF CL
SETF Placeform GETHASH CL
SETF Placeform SEND* (set instance variable)
SHADOW CL
SHADOWING-IMPORT CL
SIGNUM CL*
SINH CL*
SOME CL
SPECIALP CL
STABLE-SORT CL
STRING-CAPITALIZE CL
SUBSETP CL
SUBSTITUTE CL
SUBSTITUTE-IF CL
SUBSTITUTE-IF-NOT CL
SYMBOL-PACKAGE CL
TANH CL*
TIME CL
TOP-LEVEL-LOOP
TRUENAME CL
TYPEP CL
UNEXPORT CL
UNINTERN CL*
UNION CL
UNUSE-PACKAGE CL
USE-PACKAGE CL
VALUES CL
VALUES-LIST CL
WITH-INPUT-FROM-STRING CL*
WITH-OPEN-FILE CL*
WITH-OUTPUT-TO-STRING CL*
Y-OR-N-P CL*
YES-OR-NO-P CL*
Changed functions
&ALLOW-OTHER-KEYS CL (now functions, is no longer ignored)
:ALLOW-OTHER-KEYS CL
* CL CR CX (with no arguments, returns 1)
+ CL CR CX (with no arguments, returns 0)
- CL CR CX
XLISP-PLUS 3.0 BUG FIXES AND EXTENSIONS Page 118
/ CL CR CX
1+ CL CR CX
1- CL CR CX
ABS CL CR CX
ACOS CL CR CX
ALLOC (new optional second argument)
APPLY CL (allows multiple arguments)
AREF CL (now works on strings)
ASIN CL CR CX
ASSOC CL (added :key)
ATAN CL CR CX (second argument now allowed)
BREAK CL
CERROR CL
CHAR-CODE CL (parity bit is stripped)
CLOSE CL (will close unnamed stream strings)
COS CL CR CX
DEFCONSTANT CL# (true constants)
DEFPARAMETER CL# (true special variables)
DEFSTRUCT (added option :print-function, comment field)
DEFVAR CL# (true special variables)
DELETE (added keywords :key :start :end :count :from-end. Works on arrays
and strings)
DELETE-IF (added keywords :key :start :end :count :from-end. Works on
arrays and strings)
DELETE-IF-NOT (added keywords :key :start :end :count :from-end. Works on
arrays and strings)
DIGIT-CHAR CL (added optional radix argument)
DIGIT-CHAR-P CL (added optional radix argument)
ERROR CL
EXP CL CR CX
EXPT CL CR CX
FMAKUNBOUND #
FORMAT (added directives # ~B ~D ~E ~F ~G ~O ~R ~X ~& ~* ~? ~| ~( ~[ ~{ ~T
~\N and lowercase directives)
GET CL
HASH (hashes everything, not just symbols or strings)
LOAD CL (uses path to find file, allows file stream for name argument)
LOGAND CL (with no arguments, returns -1)
LOGIOR CL (with no arguments, returns 0)
LOGXOR CL (with no arguments returns 0)
MAKE-ARRAY (added keywords :initial-contents and :initial-element)
MAKE-STRING-INPUT-STREAM CL (:end NIL means end of string)
MAKUNBOUND #
MAPCAN #
MAPCON #
MEMBER CL (added :key)
NSTRING-DOWNCASE CL (string argument can be symbol, :end NIL means end of
string)
NSTRING-UPCASE CL (string argument can be symbol, :end NIL means end of
string)
NSUBLIS CL
NSUBST CL
NSUBST-IF CL
NSUBST-IF-NOT CL
OPEN CL (many additional options, as in Common Lisp)
XLISP-PLUS 3.0 BUG FIXES AND EXTENSIONS Page 119
PEEK (fixnum sized location is fetched)
PEEK-CHAR CL (input stream NIL is *standard-input*, T is *terminal-io*, eof
arguments)
POKE (fixnum sized location is stored)
PPRINT (output stream NIL is *standard-output*, T is *terminal-io*)
PRIN1 CL (output stream NIL is *standard-output*, T is *terminal-io*)
PRINC CL (output stream NIL is *standard-output*, T is *terminal-io*)
PRINT (output stream NIL is *standard-output*, T is *terminal-io*)
RANDOM CL (works with random-states)
READ (input stream NIL is *standard-input*, T is *terminal-io*, eof
arguments)
READ-BYTE CL
READ-CHAR CL (input stream NIL is *standard-input*, T is *terminal-io*, eof
arguments)
READ-LINE CL (input stream NIL is *standard-input*, T is *terminal-io*, eof
arguments)
REM CR CL (only two arguments now allowed, may be floating point)
REMOVE (added keywords :key :start :end :count :from-end. Works on arrays
and strings)
REMOVE-IF (added keywords :key :start :end :count :from-end. Works on
arrays and strings)
REMOVE-IF-NOT (added keywords :key :start :end :count :from-end. Works on
arrays and strings)
RESTORE (uses path to find file, restores file streams, fine name argument
may be file stream)
REVERSE CL (works on arrays and strings)
ROUND CL (rounds to nearest even)
SAVE (file name argument may be file stream)
SIN CL CR CX
SORT (added :key) CL (with most compilers)
SQRT CL CR CX
STRCAT * (now a macro, use of CONCATENATE is recommended)
STRING-comparisonFunctions CL (string arguments can be symbols)
STRING-DOWNCASE CL (string argument can be symbol, :end NIL means end of
string)
STRING-LEFT-TRIM CL (string argument can be symbol)
STRING-RIGHT-TRIM CL (string argument can be symbol)
STRING-TRIM CL (string argument can be symbol)
STRING-UPCASE CL (string argument can be symbol, :end NIL means end of
string)
SUBLIS CL (modified to do minimum copying)
SUBSEQ CL (works on arrays and lists)
SUBST CL (modified to do minimum copying)
TAN CL CR CX
TERPRI CL (output stream NIL is *standard-output*, T is *terminal-io*)
TRUNCATE CR CL (allows denominator argument)
TYPE-OF (returns HASH-TABLE for hashtables, COMPLEX for complex, and LIST
for NIL)
UNTRACE CL (with no arguments, untraces all functions)
VALUES CL
VALUES-LIST CL
WRITE-BYTE CL
WRITE-CHAR CL (output stream NIL is *standard-output*, T is *terminal-io*)
XLISP-PLUS 3.0 BUG FIXES AND EXTENSIONS Page 120
New messages for class Object
:prin1 <stream>
:superclass *
:ismemberof <cls> *
:iskindof <cls> *
:respondsto <selector> *
:storeon (returns form that will create a copy of the object) *
New messages for class Class
:superclass *
:messages *
:storeon (returns form that will recreate class and methods) *
XLISP-PLUS 3.0 EXAMPLES Page 121
EXAMPLES: FILE I/O FUNCTIONS
Input from a File
To open a file for input, use the OPEN function with the keyword argument
:DIRECTION set to :INPUT. To open a file for output, use the OPEN function
with the keyword argument :DIRECTION set to :OUTPUT. The OPEN function
takes a single required argument which is the name of the file to be
opened. This name can be in the form of a string or a symbol. The OPEN
function returns an object of type FILE-STREAM if it succeeds in opening
the specified file. It returns the value NIL if it fails. In order to
manipulate the file, it is necessary to save the value returned by the OPEN
function. This is usually done by assigning it to a variable with the SETQ
special form or by binding it using LET or LET*. Here is an example:
(setq fp (open "init.lsp" :direction :input))
Evaluating this expression will result in the file "init.lsp" being opened.
The file object that will be returned by the OPEN function will be assigned
to the variable "fp".
It is now possible to use the file for input. To read an expression from
the file, just supply the value of the "fp" variable as the optional
"stream" argument to READ.
(read fp)
Evaluating this expression will result in reading the first expression from
the file "init.lsp". The expression will be returned as the result of the
READ function. More expressions can be read from the file using further
calls to the READ function. When there are no more expressions to read, the
READ function will give an error (or if a second nil argument is specified,
will return nil or whatever value was supplied as the third argument to
READ).
Once you are done reading from the file, you should close it. To close the
file, use the following expression:
(close fp)
Evaluating this expression will cause the file to be closed.
XLISP-PLUS 3.0 EXAMPLES Page 122
Output to a File
Writing to a file is pretty much the same as reading from one. You need to
open the file first. This time you should use the OPEN function to indicate
that you will do output to the file. For example:
(setq fp (open "test.dat" :direction :output :if-exists :supersede))
Evaluating this expression will open the file "test.dat" for output. If the
file already exists, its current contents will be discarded. If it doesn't
already exist, it will be created. In any case, a FILE-STREAM object will
be returned by the OPEN function. This file object will be assigned to the
"fp" variable.
It is now possible to write to this file by supplying the value of the "fp"
variable as the optional "stream" parameter in the PRINT function.
(print "Hello there" fp)
Evaluating this expression will result in the string "Hello there" being
written to the file "test.dat". More data can be written to the file using
the same technique.
Once you are done writing to the file, you should close it. Closing an
output file is just like closing an input file.
(close fp)
Evaluating this expression will close the output file and make it
permanent.
A Slightly More Complicated File Example
This example shows how to open a file, read each Lisp expression from the
file and print it. It demonstrates the use of files and the use of the
optional "stream" argument to the READ
function.
(do* ((fp (open "test.dat" :direction :input))
(ex (read fp nil) (read fp nil)))
((null ex) (close fp) nil)
(print ex))
The file will be closed with the next garbage collection.
XLISP-PLUS 3.0 INDEX Page 123
INDEX
:allow-other-keys 18 :set-pname 70
:answer 23 :show 22
:append 91 :size 40
:capitalize 15 :start 43-47, 63, 64, 85, 93
:class 22 :start1 43, 47, 48, 64, 65
:conc-name 68 :start2 43, 47, 48, 64, 65
:constituent 13 :storeon 22, 23
:count 43, 45, 46 :superclass 22, 23
:create 91 :supersede 91
:direction 91 :test 33, 40, 43-46, 48, 50,
:downcase 15 51, 52, 53, 75
:element-type 91 :test-not 33, 43-46, 48, 50,
:end 43-47, 63, 64, 85, 93 51, 52, 53, 75
:end1 43, 47, 48, 64, 65 :tmacro 13
:end2 43, 47, 48, 64, 65 :upcase 15
:error 91 :use 36
:external 30, 36 :verbose 98
:from-end 43-46 :white-space 13
:if-does-not-exist 91 + 26, 55
:if-exists 91 ++ 26
:include 68 +++ 26
:inherited 30, 36 - 26, 56
:initial-contents 41 * 26, 56
:initial-element 41, 47, 52, ** 26
64 *** 26
:initial-value 46 *applyhook* 9, 25
:input 91 *breakenable* 4, 25
:internal 30, 36 *command-line* 26
:invert 15 *debug-io* 25
:io 91 *displace-macros* 8, 26
:iskindof 22 *dos-input* 3, 26
:ismemberof 22 *error-output* 25
:isnew 22, 23 *evalhook* 9, 25
:key 33, 43-47, 50-53, 75 *features* 14, 26
:mescape 13 *float-format* 26, 83
:messages 23 *gc-flag* 25
:new 23 *gc-hook* 9, 25
:new-version 91 *integer-format* 26, 83
:nicknames 36 *load-file-arguments* 2, 26
:nmacro 13 *obarray* 25
:output 91 *package* 25
:overwrite 91 *print-base* 26, 83
:preserve 15 *print-case* 15, 26, 83
:prin1 22 *print-length* 26, 83
:print 98 *print-level* 26, 83
:print-function 68 *random-state* 26
:probe 91 *ratio-format* 83
:rename 91 *read-base* 10
:rename-and-delete 91 *read-suppress* 26
:respondsto 22 *readtable-case* 15, 26, 83
:sescape 13 *readtable* 13, 25
:set-ivar 70 *standard-input* 25
XLISP-PLUS 3.0 INDEX Page 124
*standard-output* 25 backquote 27
*startup-functions* 2, 26 baktrace 96
*struct-slots* 68 block 81
*terminal-io* 25 both-case-p 66
*top-level-loop* 26 boundp 74
*trace-output* 25 break 95
*tracelimit* 4, 25 butlast 50
*tracelist* 25 byte 61
*tracenable* 4, 25 byte-position 61
/ 56 byte-size 61
/= 59 car 49
< 59 case 78
<= 59 catch 78
= 59 ccase 96
> 59 cdr 49
>= 59 ceiling 55
%DOC-FUNCTION 106 cerror 95
%DOC-STRUCTURE 106 char 66
%DOC-TYPE 106 char-code 66
%DOC-VARIABLE 106 char-downcase 66
&allow-other-keys 18 char-equal 67
&aux 18 char-greaterp 67
&key 18 char-int 67
&optional 18 char-lessp 67
&rest 18 char-name 67
1+ 56 char-not-equal 67
1- 56 char-not-greaterp 67
abs 56 char-not-lessp 67
acons 49 char-upcase 66
acos 57 char/= 67
acosh 58 char< 67
address-of 100 char<= 67
adjoin 53 char= 67
alloc 99 char> 67
alpha-char-p 66 char>= 67
and 76, 77 character 67, 100
append 49 characterp 73
apply 27 check-type 97
applyhook 9, 96 cis 58
apropos 35 class 25
apropos-list 35 classp 74
aref 41 clean-up 3, 95
ARRAY 100 clean-up, 4
array-in-bounds-p 73 close 92
arrayp 73 CLOSURE 100
ash 61 clrhash 40
asin 57 cls 102
asinh 58 code-char 66
assert 97 coerce 100
assoc 51 color 102
assoc-if 51 comma 27
assoc-if-not 51 comma-at 28
atan 57 complement 27
atanh 58 complex 59, 100
atom 72, 76 complexp 73
XLISP-PLUS 3.0 INDEX Page 125
concatenate 42 draw 103
cond 77 drawrel 103
conjugate 59 dribble 98
cons 49, 100 ecase 96
consp 72 eighth 49
constantp 72 elt 42
continue 3, 4, 95 endp 72
copy-alist 52 eq 75
copy-list 52 eql 75
copy-seq 47 equal 75
copy-symbol 32 equalp 75
copy-tree 52 error 95
cos 57 errset 4, 95
cosh 58 etypecase 96
count 44 eval 27
count-if 44 eval-when 102
count-if-not 44 evalhook 9, 96
ctypecase 96 evenp 74
cxxr 49 every 42
cxxxr 49 exit 101
cxxxxr 49 exp 58
debug 96 expand 99
decf 34 export 36
declare 32 expt 58
defclass 70 fboundp 74
defconstant 31 fifth 49
definst 71 file-length 93
defmacro 30 file-position 93
defmethod 70 FILE-STREAM 100
defpackage 35 fill 47
defparameter 31 find 44
defsetf 33 find-all-symbols 36
defstruct 68 find-if 44
defun 30 find-if-not 44
defvar 31 find-package 36
delete 45 find-symbol 36
delete-duplicates 46 first 49
delete-file 92 FIXNUM 100
delete-if 45 flatc 84
delete-if-not 45 flatsize 84
delete-package 35 flet 78
denominator 58 float 55
deposit-field 62 float-sign 57
describe 107 floatp 72
digit-char 67 FLONUM 100
digit-char-p 66 floor 55
do 80 fmakunbound 31
do-all-symbols 36 format 86
do-external-symbols 36 fourth 49
do-symbols 36 fresh-line 84
do* 80 FSUBR 100
documentation 106 funcall 27
dolist 80 function 27, 76
dotimes 80 functionp 74
dpb 62 gc 99
XLISP-PLUS 3.0 INDEX Page 126
gcd 57 log 58
generic 101 logand 60
gensym 30 logandc1 60
get 39 logandc2 60
get-internal-real-time 100 logbitp 61
get-internal-run-time 100 logcount 61
get-key 101 logeqv 60
get-lambda-expression 28 logior 60
get-macro-character 83 lognand 60
get-output-stream-list 94 lognor 60
get-output-stream-string 94 lognot 60
getf 39 logorc1 60
gethash 40 logorc2 60
glos 106 logtest 60
go 81 logxor 60
goto-xy 102 loop 80
hash 31 lower-case-p 66
HASH-TABLE 100 macroexpand 28
hash-table-count 40 macroexpand-1 28
hash-table-p 74 macrolet 78
identity 27 make-array 41
if 77 make-hash-table 40
imagpart 59 make-package 36
import 36 make-random-state 57
in-package 36 make-sequence 47
incf 34 make-string 64
input-stream-p 73 make-string-input-stream 94
ins 107 make-string-output-stream 94
insf 107 make-symbol 30
inspect 107 makunbound 31
int-char 67 map 42
integer-length 61 map-into 42
integerp 72 mapc 51
intern 30 mapcan 51
internal-time-units-per-second mapcar 51
25 mapcon 51
intersection 53 maphash 40
isqrt 58 mapl 51
keywordp 74 maplist 51
labels 78 mark-as-special 32
lambda 28 mask-field 62
last 50 max 56
lcm 57 member 50, 76
ldb 61 member-if 50
ldb-test 61 member-if-not 50
ldiff 53 merge 47
length 42 min 56
let 78 minusp 74
let* 78 mismatch 48
list 49, 76, 100 mod 56
list-all-packages 36 mode 102
list-length 50 move 103
list* 49 moverel 103
listp 72 multiple-value-bind 29
load 98 multiple-value-call 29
XLISP-PLUS 3.0 INDEX Page 127
multiple-value-list 29 pop 34
multiple-value-prog1 29 position 44
multiple-value-setq 29 position-if 44
nbutlast 50 position-if-not 44
nconc 54 pp 105
NIL 25 pprint 84
nintersection 53 prin1 83
ninth 49 prin1-to-string 84
nodebug 96 princ 84
not 72, 76 princ-to-string 84
notany 42 print 83
notevery 42 probe-file 92
nreconc 54 proclaim 32
nreverse 42 prog 81
nset-difference 53 prog* 81
nset-exclusive-or 53 prog1 81
nstring-capitalize 64 prog2 82
nstring-downcase 64 progn 82
nstring-upcase 63 progv 81
nsubst 51 psetf 33
nsubst-if 51 psetq 30
nsubst-if-not 51 push 33
nsubstitute 46 pushnew 33
nsubstitute-if 46 putprop 39
nsubstitute-if-not 46 quote 27
nth 50 random 57
nth-value 29 rassoc 51
nthcdr 50 rassoc-if 51
null 72, 76 rassoc-if-not 51
NUMBER 76 RATIO 100
numberp 72 rational 55, 76
numerator 58 rationalp 73
nunion 53 read 83
object 25, 76, 100 read-byte 92
objectp 73 read-char 89
oddp 74 read-from-string 85
open 91 read-line 90
open-stream-p 73 realp 73
or 76, 77 realpart 59
output-stream-p 73 reduce 46
package-name 37 rem 56
package-nicknames 37 remf 39
package-obarray 37 remhash 40
package-shadowingsymbols 37 remove 43
package-use-list 37 remove-duplicates 46
package-used-by-list 37 remove-if 43
package-valid-p 37 remove-if-not 43
packagep 74 remprop 39
pairlis 52 rename-package 37
peek 100 replace 47
peek-char 89 reset-system 101
phase 59 rest 49
pi 25 restore 98
plusp 74 return 81
poke 100 return-from 81
XLISP-PLUS 3.0 INDEX Page 128
revappend 50 string>= 64
reverse 42 stringp 73
room 99 STRUCT 76
round 55 sublis 52
rplaca 54 SUBR 100
rplacd 54 subseq 43
satisfies 76 subsetp 75
save 98 subst 51
search 43 substitute 45
second 49 substitute-if 45
self 21, 25 substitute-if-not 45
send 21, 70 SYMBOL 100
send-super 21, 70 symbol-function 31
set 30 symbol-name 30
set-difference 53 symbol-package 37
set-exclusive-or 53 symbol-plist 31
set-macro-character 83 symbol-value 30
set-stack-mark 101 symbolp 72
setf 33 system 101
setq 30 t 25
seventh 49 tagbody 81
shadow 37 tailp 50
shadowing-import 37 tan 57
signum 57 tanh 58
sin 57 tenth 49
sinh 58 terpri 84
sixth 49 third 49
sleep 99 throw 79
some 42 time 99
sort 43 top-level 3, 95
specialp 72 top-level-loop 2, 101
sqrt 58 trace 95
stable-sort 43 tracemethod 71
step 104 truename 92
strcat 64 truncate 55
STREAM 76 type-of 100
streamp 73 typecase 78, 96
string 63, 100 typep 76
string-capitalize 63 unexport 38
string-downcase 63 union 53
string-equal 65 unless 77
string-greaterp 65 UNNAMED-STREAM 100
string-left-trim 63 untrace 95
string-lessp 65 untracemethod 71
string-not-equal 65 unuse-package 38
string-not-greaterp 65 unwind-protect 79
string-not-lessp 65 upper-case-p 66
string-right-trim 63 use-package 38
string-trim 63 values 29
string-upcase 63 values-list 29
string/= 64 vector 41
string< 64 when 77
string<= 64 with-input-from-string 94
string= 64 with-open-file 92
string> 64 with-open-stream 92
XLISP-PLUS 3.0 INDEX Page 129
with-output-to-string 94
write-byte 92
write-char 89
XLPATH 98
y-or-n-p 84
yes-or-no-p 84
zerop 74
|