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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (c) 2021 Stijn van Dongen -->
<head>
<meta name="keywords" content="macro processing, programming, template expansion, mark-up, character filtering">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
.slartibartfast { background-color: pink; text-decoration: blink; }
/* open base2 */
/* start aephea.base.css */
body
{ text-align: justify;
margin-left: 0%;
margin-right: 0%;
}
a:link { text-decoration: none; }
a:active { text-decoration: none; }
a:visited { text-decoration: none; }
a:link { color: #1111aa; }
a:active { color: #1111aa; }
a:visited { color: #111166; }
a.local:link { color: #11aa11; }
a.local:active { color: #11aa11; }
a.local:visited { color: #116611; }
a.intern:link { color: #1111aa; }
a.intern:active { color: #1111aa; }
a.intern:visited { color: #111166; }
a.extern:link { color: #aa1111; }
a.extern:active { color: #aa1111; }
a.extern:visited { color: #661111; }
a.quiet:link { color: black; }
a.quiet:active { color: black; }
a.quiet:visited { color: black; }
p.asd_par { margin-bottom:0em }
p.asd_cpar { margin-bottom:0em }
span.asd_cpar_caption { font-weight: bold; display: block }
p.asd_car { margin-top:0em; margin-bottom:0em }
p.asd_ccar { margin-top:0em; margin-bottom:0em }
span.asd_ccar_caption { font-weight: bold; display: block }
div.verbatim
{ font-family: monospace;
margin-top: 1em;
margin-bottom: 1em;
font-size: 10pt;
margin-left: 2em;
white-space: pre;
}
div.indent
{ margin-left: 8%;
margin-right: 0%;
}
.right { text-align: right; }
.left { text-align: left; }
.nowrap { white-space: nowrap; }
.item_leader
{ position: relative;
margin-left: 8%;
}
.item_compact { position: absolute; vertical-align: baseline; }
.item_cascade { position: relative; }
.item_leftalign { text-align: left; }
.item_rightalign
{ width: 2em;
text-align: right;
}
.item_compact .item_rightalign
{ position: absolute;
width: 52em;
right: -2em;
text-align: right;
}
.item_text
{ position: relative;
margin-left: 3em;
}
.smallcaps { font-size: smaller; text-transform: uppercase }
.underline { text-decoration: underline }
acronym.ucase { font-size: smaller; text-transform: uppercase }
abbr.ucase { font-size: smaller; text-transform: uppercase }
/* end aephea.base.css */
/* close base2 */
/* open simpledocument2 */
/* start aephea.asd.css */
body {
margin:0px;
padding:0px;
border: 0px;
}
.sec_leader
{ margin-top: 1em;
margin-bottom: 0em;
position: relative;
right: 0px;
left: 0px;
top: 0px;
}
.sec_title
{ color: black;
position: relative;
margin-bottom: 0px;
margin-top: 0px;
margin-right: 5em;
margin-left: 5em;
text-align: center
}
.sec_num
{ color: black;
position: absolute;
right: 0px;
text-align: right;
width: 5em;
top: 0px;
}
.sec_lev1 { font-size: 20px; }
.sec_lev2 { font-size: 18px; }
.sec_lev3 { font-size: 16px; }
.sec_lev4 { font-size: 14px; }
.sec_lev5 { font-size: 12px; }
.sec_lev6 { font-size: 12px; }
.toc_toplevel
{ margin-top: 1em;
}
.toc_leader
{ margin-top: 0em;
margin-bottom: 0em;
position: relative;
right: 0px;
left: 0px;
}
.toc_title { position: relative; }
.toc_num
{ position: absolute;
text-align: left;
top: 0px;
left: 0px;
}
.toc_title1 { margin-left: 3em; }
.toc_title2 { margin-left: 6em; }
.toc_title3 { margin-left: 9em; }
.toc_title4 { margin-left: 12em; }
.toc_num1 { left: 1em; }
.toc_num2 { left: 3em; }
.toc_num3 { left: 6em; }
.toc_num4 { left: 9em; }
div.box { border:solid; border-width:thin; width:100%; padding:1em}
div.flushright { text-align: right }
/* end aephea.asd.css */
/* close simpledocument2 */
/* open css_append */
body { font-family: "Garamond", "Gill Sans", "Verdana", sans-serif; }
body
{ text-align: justify;
margin-left: 8%;
margin-right: 8%;
font-size: 14pt;
}
.toc_and_date_DATE { text-decoration: none; }
.zpr { text-decoration: none; }
acronym.ucase { font-size: smaller; text-transform: uppercase }
abbr.ucase { font-size: smaller; text-transform: uppercase }
#asd_document_outer { position: relative; }
#asd_document { position: relative; }
#asd_title { text-align: center; font-size: 30pt; margin-top: 40pt; }
#asd_subtitle { text-align: center; font-size: 18pt; margin-top: 10pt; margin-bottom: 40pt; }
#asd_date { position: absolute; left: 0pt; top: 10pt; }
#asd_version { position: absolute; right: 0pt; top: 10pt; }
/* close css_append */
</style>
<title>Zoem User's Manual</title>
</head>
<body>
<div id=asd_document_outer>
<a name="asd_body_start"></a>
<div id=asd_document>
<div id="asd_date">December 10, 2021</div>
<div id="asd_version">zoem-21-341
</div>
<div id="asd_title">Zoem User's Manual</div>
<div id="asd_subtitle"></div>
<a name="intro"></a><div class="sec_leader sec_lev1"><div class="sec_title"><a class="intern" href="#intro">Introduction</a></div><div class="sec_num"><a class="intern" href="#toc1"><span class="sec_num">1</span></a></div></div>
<p class="asd_par">
<b>Zoem:</b> <Dutch> The sound made by electrical devices and flying bugs.
Pronounced: <i>zoom</i> or <i>zum</i>; the vowel is short.
</p>
<p class="asd_par">
Zoem is a general macro/programming language with filtering capabilities.
It transforms text in two stages.</p>
<p class="asd_par">
In the first stage the text is scanned for macro escape sequences.
The core zoem language consists of so-called primitive macros.
They provide a wide spectre of functional behaviour, including
data storage,
arithmetic evaluation,
<span class="smallcaps">I/O</span> facilities,
iteration and flow control,
dictionary stacks,
system interaction,
and
regular expressions.
As with any macro/programming language, the real power comes from
the ability to create new user-defined macros in terms of primitives
and other user-defined macros.
Macro expansion can be arbitrarily delayed, and inside-out evaluation is
supported.</p>
<p class="asd_par">
A useful feature is the combination of anonymous macros, lists, and the
<a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a> primitive, constituting a callback mechanism in zoem.
Another feature is the automatic popping and pushing of dictionaries with
the begin/end environment, providing shadowing and localization.</p>
<p class="asd_par">
In the optional second stage, the text is filtered. Two filter scopes are
distinguished. The first is called <i>device scope</i> and is always enclosed
in a filter escape sequence. The second, <i>plain scope</i>, is everything
else. Filtering mechanisms are provided for both. The filtering language
is useful when the output is meant to be in an external format with
device-specific escape sequences, such as <abbr class="ucase" title="Hyper Text Markup Language">HTML</abbr> or troff. Conversions are
specified in device specific filtering rules that are applied in plain scope,
so that the zoem input is device agnostic. By setting up different
filtering rules the same input can be used to generate different outputs.</p>
<p class="asd_par">
This manual covers the whole zoem language. A large part of it is only
interesting for someone writing a reusable macro package. A smaller part is
still interesting for someone who is just using such a package, but might
want to add some utilities and shortcuts of his own. The part where file
inclusion, macro definitions, and macro expansions are explained is required
reading for anyone considering or planning to use zoem.</p>
<a name="section_1_1"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#section_1_1">Other documentation</a></div><div class="sec_num"><a class="intern" href="#toc1"><span class="sec_num">1.1</span></a></div></div>
<p class="asd_par">
<a class="local sibling" href="zoem.html">The manual page of the zoem interpreter</a>.
</p>
<p class="asd_par">
Zoem is used by
<a target="_parent" class="extern" href="http://micans.org/pud">Portable Unix Documentation</a> (<acronym class="ucase" title="Portable Unix Documentation">PUD</acronym>)
and
<a target="_parent" class="extern" href="http://micans.org/aephea">Aephea</a>.
The latter is a general authoring tool for writing <abbr class="ucase" title="Hyper Text Markup Language">HTML</abbr> documents and provides both useful
abstractions and a framework for creating new abstractions. It uses and
promotes the use of <abbr class="ucase" title="Cascading Style Sheets">CSS</abbr>.
A small core of Aephea has been ported to the typesetting language <em>troff</em>.
This core is used in <acronym class="ucase" title="Portable Unix Documentation">PUD</acronym>, which provides
mini-languages for <abbr class="ucase" title="Frequently Asked Questions">FAQ</abbr> documents and <span class="smallcaps">UNIX</span> manual pages.
Documents written in <acronym class="ucase" title="Portable Unix Documentation">PUD</acronym> can be output to troff and html,
and further to plain text, PostScript, and <abbr class="ucase" title="Portable Document Format">PDF</abbr>.
</p>
<a name="click"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#click">About this document</a></div><div class="sec_num"><a class="intern" href="#toc1"><span class="sec_num">1.2</span></a></div></div>
<p class="asd_par">
Clicking on the number next to a section title (e.g.
the 1.2 to the right of the title <b>About this document</b> of
this section) will get you to the corresponding section of the table of
contents.
</p>
<p class="asd_par">
Zoem input and zoem output are <i>both</i> generally shown in a typeface
font, <tt>like this</tt>.
</p>
<p class="asd_par">
<a name="colours"></a>
Links that point to locations within this document are shown in
<a class="intern" href="#colours">blueish colors</a>. Links that point to documents originating
from the same package (project) or perhaps the same site are shown in in
<a class="local" href="zum.html">greenish colors</a>. Links that point to other stations on the
internet or perhaps other packages on the same site are shown in in
<a target="_parent" class="extern" href="http://www.google.com">reddish colors</a>.
</p>
<a name="toc"></a><div class="sec_leader sec_lev1"><div class="sec_title"><a class="intern" href="#toc">Table of Contents</a></div><div class="sec_num"><a class="intern" href="#toc2"><span class="sec_num">2</span></a></div></div>
<div id=asd_toc>
<div class="toc_toplevel">
<a name="thetoc"></a>
<div class="toc_leader">
<div class="toc_num toc_num1"><a class="intern" href="#asd_body_start">Start</a>.</div>
<div class="toc_title toc_title1"><a name="toc_asd_body_start"></a><a class="intern" href="#asd_body_start"> </a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num1"><a name="toc1">1</a>.</div>
<div class="toc_title toc_title1"><a name="toc_intro"></a><a class="intern" href="#intro">Introduction</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">1.1.</div>
<div class="toc_title toc_title2"><a name="toc_section_1_1"></a><a class="intern" href="#section_1_1">Other documentation</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">1.2.</div>
<div class="toc_title toc_title2"><a name="toc_click"></a><a class="intern" href="#click">About this document</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num1"><a name="toc2">2</a>.</div>
<div class="toc_title toc_title1"><a name="toc_toc"></a><a class="intern" href="#toc">Table of Contents</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num1"><a name="toc3">3</a>.</div>
<div class="toc_title toc_title1"><a name="toc_nutshell"></a><a class="intern" href="#nutshell">Zoem in a nutshell</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">3.1.</div>
<div class="toc_title toc_title2"><a name="toc_features"></a><a class="intern" href="#features">Features</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num1"><a name="toc4">4</a>.</div>
<div class="toc_title toc_title1"><a name="toc_cline"></a><a class="intern" href="#cline">Invoking zoem from the command line</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num1"><a name="toc5">5</a>.</div>
<div class="toc_title toc_title1"><a name="toc_syntax"></a><a class="intern" href="#syntax">Zoem syntax and parsing</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">5.1.</div>
<div class="toc_title toc_title2"><a name="toc_nomenclature"></a><a class="intern" href="#nomenclature">Syntax and nomenclature</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">5.2.</div>
<div class="toc_title toc_title2"><a name="toc_namespaces"></a><a class="intern" href="#namespaces">Primitives, built-ins and user macros</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">5.3.</div>
<div class="toc_title toc_title2"><a name="toc_escape"></a><a class="intern" href="#escape">List of escape sequence classes</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">5.4.</div>
<div class="toc_title toc_title2"><a name="toc_stages"></a><a class="intern" href="#stages">Parsing stages</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">5.5.</div>
<div class="toc_title toc_title2"><a name="toc_fileread"></a><a class="intern" href="#fileread">File read</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">5.6.</div>
<div class="toc_title toc_title2"><a name="toc_searchpath"></a><a class="intern" href="#searchpath">File search path</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">5.7.</div>
<div class="toc_title toc_title2"><a name="toc_macro"></a><a class="intern" href="#macro">Macro expansion</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">5.8.</div>
<div class="toc_title toc_title2"><a name="toc_section_5_8"></a><a class="intern" href="#section_5_8">File inclusion</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">5.9.</div>
<div class="toc_title toc_title2"><a name="toc_protection"></a><a class="intern" href="#protection">Protection</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">5.10.</div>
<div class="toc_title toc_title2"><a name="toc_dichotomy"></a><a class="intern" href="#dichotomy">Scope dichotomy</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">5.11.</div>
<div class="toc_title toc_title2"><a name="toc_dscope"></a><a class="intern" href="#dscope">Device scope</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num3">5.11.1.</div>
<div class="toc_title toc_title3"><a name="toc_special"></a><a class="intern" href="#special">Device scope resulting from mapping special characters</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num3">5.11.2.</div>
<div class="toc_title toc_title3"><a name="toc_glyph"></a><a class="intern" href="#glyph">Device scope resulting from glyph definitions</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">5.12.</div>
<div class="toc_title toc_title2"><a name="toc_xmlsugar"></a><a class="intern" href="#xmlsugar"><abbr class="ucase" title="Standard Generalized Markup Language">SGML</abbr>/<abbr class="ucase" title="Hyper Text Markup Language">HTML</abbr>/<abbr class="ucase" title="Extensible Markup Language">XML</abbr> syntactic sugar cubes</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num1"><a name="toc6">6</a>.</div>
<div class="toc_title toc_title1"><a name="toc_section_6"></a><a class="intern" href="#section_6">Zoem miscellanea</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">6.1.</div>
<div class="toc_title toc_title2"><a name="toc_signature"></a><a class="intern" href="#signature">Key signatures</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">6.2.</div>
<div class="toc_title toc_title2"><a name="toc_anonymous"></a><a class="intern" href="#anonymous">Anonymous keys</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">6.3.</div>
<div class="toc_title toc_title2"><a name="toc_grape"></a><a class="intern" href="#grape">Tree data</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">6.4.</div>
<div class="toc_title toc_title2"><a name="toc_vararg"></a><a class="intern" href="#vararg">Of blocks and varargs</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">6.5.</div>
<div class="toc_title toc_title2"><a name="toc_session"></a><a class="intern" href="#session">Session keys</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">6.6.</div>
<div class="toc_title toc_title2"><a name="toc_builtin"></a><a class="intern" href="#builtin">Built-in macros</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">6.7.</div>
<div class="toc_title toc_title2"><a name="toc_dictionary"></a><a class="intern" href="#dictionary">Dictionary stacks</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num1"><a name="toc7">7</a>.</div>
<div class="toc_title toc_title1"><a name="toc_tour"></a><a class="intern" href="#tour">A zoem tour</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num1"><a name="toc8">8</a>.</div>
<div class="toc_title toc_title1"><a name="toc_language"></a><a class="intern" href="#language">The zoem language</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">8.1.</div>
<div class="toc_title toc_title2"><a name="toc_section_8_1"></a><a class="intern" href="#section_8_1">Alphabetic index</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">8.2.</div>
<div class="toc_title toc_title2"><a name="toc_topicindex"></a><a class="intern" href="#topicindex">Topic index</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num2">8.3.</div>
<div class="toc_title toc_title2"><a name="toc_section_8_3"></a><a class="intern" href="#section_8_3">Primitives</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num1"><a name="toc9">9</a>.</div>
<div class="toc_title toc_title1"><a name="toc_pitfalls"></a><a class="intern" href="#pitfalls">Pitfalls</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num1"><a name="toc10">10</a>.</div>
<div class="toc_title toc_title1"><a name="toc_glossary"></a><a class="intern" href="#glossary">Glossary</a></div>
</div>
<div class="toc_leader">
<div class="toc_num toc_num1"><a class="intern" href="#asd_body_end">End</a>.</div>
<div class="toc_title toc_title1"><a name="toc_asd_body_end"></a><a class="intern" href="#asd_body_end"> </a></div>
</div>
</div>
</div>
<a name="nutshell"></a><div class="sec_leader sec_lev1"><div class="sec_title"><a class="intern" href="#nutshell">Zoem in a nutshell</a></div><div class="sec_num"><a class="intern" href="#toc3"><span class="sec_num">3</span></a></div></div>
<p class="asd_par">
Zoem supports several programming constructs, immediate and postponed
expansions, stream character filtering, easy <span class="smallcaps">I/O</span> facilities, integer
arithmetic, and a whole lot more.
Its main aims are:</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Providing the building blocks for a structural and programmable approach.
<a class="intern" href="#features">Section 3.1</a>
contains an overview of the zoem primitives and their use.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Accepting a pleasant syntax that does not require much thinking,
favouring simplicity and rigor over looseness and context dependent
rules.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Creation from the keyboard while minimizing on key-strokes.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Few meta characters. Zoem achieves this by having a single
special character and a reasonably restricted syntax.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Adding filtering capabilities so that multiple devices can be
addressed.</p>
</div>
</div>
<a name="features"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#features">Features</a></div><div class="sec_num"><a class="intern" href="#toc3"><span class="sec_num">3.1</span></a></div></div>
<p class="asd_par">
Listed below are some features of the zoem primitives. In practice there are
two kinds of zoem files. The first is a zoem macro file, which should
contain macros defined in terms of lower-level macros, with zoem primitives
at the lowest level. The second is a zoem document file, which should import
such a macro file and only use the high-level macros defined in that macro
file. Additionally, a document file can define some high-level macros of
its own, in terms of low-level macros, zoem primitives, or a mixture of
both.
</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Macros with arguments, overloading of key names allowed (i.e. different
keys with the same name are distinguished by the number of arguments they
take). (<a class="intern" href="#def_2"><span class="zpr">\def#2</span></a>, <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a>, and <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>).
Zoem primitives look like regular macros, but
usually they expand their arguments before use. User macros
can be equipped with this behaviour by wrapping them in <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Support for variable number of arguments - see the
<a class="intern" href="#vararg">vararg</a> section.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Easy file, <span class="smallcaps">STDIN</span>, <span class="smallcaps">STDOUT</span>, and <span class="smallcaps">STDERR</span> input/output,
nested file inclusion (<a class="intern" href="#dofile_2"><span class="zpr">\dofile#2</span></a>, <a class="intern" href="#write_3"><span class="zpr">\write#3</span></a>, <a class="intern" href="#finsert_1"><span class="zpr">\finsert#1</span></a>,
and <a class="intern" href="#zinsert_1"><span class="zpr">\zinsert#1</span></a>).</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Extensive support for arithmetic with the primitives <a class="intern" href="#let_1"><span class="zpr">\let#1</span></a>, <a class="intern" href="#f_2"><span class="zpr">\f#2</span></a>,
<a class="intern" href="#f_3"><span class="zpr">\f#3</span></a>, <a class="intern" href="#fv_2"><span class="zpr">\fv#2</span></a>, and <a class="intern" href="#eqt_3"><span class="zpr">\eqt#3</span></a>.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Operators returning booleans (<a class="intern" href="#defined_2"><span class="zpr">\defined#2</span></a>, <a class="intern" href="#cmp_3"><span class="zpr">\cmp#3</span></a>, <a class="intern" href="#eqt_3"><span class="zpr">\eqt#3</span></a>),
control operators acting on those (<a class="intern" href="#while_2"><span class="zpr">\while#2</span></a>, <a class="intern" href="#if_3"><span class="zpr">\if#3</span></a>).</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The <i>for</i>-like primitives <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a> and <a class="intern" href="#table_5"><span class="zpr">\table#5</span></a>.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Match and substitution capabilities using <acronym class="ucase" title="Portable Operating System Interface [for Unix]">POSIX</acronym> regexes (<a class="intern" href="#inspect_4"><span class="zpr">\inspect#4</span></a>).</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Register macros with <a class="intern" href="#register_2"><span class="zpr">\register#2</span></a> to be processed after regular
processing (e.g. to output counters or warnings).</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The switch primitive <a class="intern" href="#switch_2"><span class="zpr">\switch#2</span></a>, employing the <a class="intern" href="#vararg">vararg
construct</a>.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Localized expansions (<a class="intern" href="#eval_1"><span class="zpr">\eval#1</span></a>)
and meta-zoem (<a class="intern" href="#excl"><span class="zpr">\!</span></a> and <a class="intern" href="#excl_1"><span class="zpr">\!#1</span></a>).</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
A user dictionary stack that can be manipulated using <a class="intern" href="#push_1"><span class="zpr">\push#1</span></a> and
<a class="intern" href="#pop_1"><span class="zpr">\pop#1</span></a>. An environment environment for doing <tt>\begin{stuff}</tt> <tt>..</tt>
<tt>\end{stuff}</tt> stuff (see <a class="intern" href="#env_4"><span class="zpr">\env#4</span></a>). This environment creates name
scopes by pushing and popping to/from the <a class="intern" href="#dictionary">dollar
dictionary stack</a>. Environments may take arguments,
one particular useful application is that local variables (e.g. local
to an <i>itemize</i> environment) can thus be specified by the user.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Storage of data by multiple string indexing — arbitrary data can be stored
in a tree by indexing nodes with (arbitrary) strings.
Refer to the <a class="intern" href="#grape">Tree data</a> section.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The ability to nicely format macros (see <a class="intern" href="#formatted_1"><span class="zpr">\formatted#1</span></a>).</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
<a class="intern" href="#xmlsugar">Syntactic sugar</a>
for writing <abbr class="ucase" title="Standard Generalized Markup Language">SGML</abbr>-style mark-up and having it checked.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Executing system commands, possibly sending data to <span class="smallcaps">STDIN</span> and
receiving data from <span class="smallcaps">STDOUT</span> — <a class="intern" href="#system_3"><span class="zpr">\system#3</span></a>.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
And more.</p>
</div>
</div>
<a name="cline"></a><div class="sec_leader sec_lev1"><div class="sec_title"><a class="intern" href="#cline">Invoking zoem from the command line</a></div><div class="sec_num"><a class="intern" href="#toc4"><span class="sec_num">4</span></a></div></div>
<p class="asd_par">
You use zoem by invoking it from the command line. The normal mode of
operation is that you specify a file for zoem to chew up and spit out. This
is called the <i>entry file</i>, and its name usually has the extension
<tt>.azm</tt>. A common invocation looks as follows:</p>
<div class="verbatim">zoem -i mcl.azm</div>
<p class="asd_car">
The <tt>-i</tt> flag specifies the entry file. It is not necessary to write the
<tt>.azm</tt> extension, zoem will append it for you. The preceding could also
have been entered as</p>
<div class="verbatim">zoem -i mcl</div>
<p class="asd_car">
In either case, zoem will set the session key <a class="intern" href="#session"><tt>\__fnbase__</tt></a> to the base
name of the entry file, i.e. the name stripped of its <tt>.azm</tt> suffix and
any leading path components. In this example, the key <a class="intern" href="#session"><tt>\__fnbase__</tt></a> will
get the value <tt>mcl</tt>. If you have an input file without the <tt>.azm</tt>
extension, you need to use the <tt>-I</tt> option.</p>
<p class="asd_par">
Zoem writes its output to a default output file which is named according to
three rules. The rules are:</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
If the <tt>-o</tt> flag was given the value say <tt>somestr</tt>,
zoem will write to the file named <tt>somestr</tt>.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
If <tt>-o</tt> was not supplied but the <tt>-d</tt> flag was used with argument say
<tt>zyx</tt>, zoem will write to the file named <a class="intern" href="#session"><tt>\__fnbase__.zyx</tt></a>.
The -d flag also results in the macro <a class="intern" href="#session"><tt>\__device__</tt></a> being set
to <tt>xyz</tt>.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
If neither <tt>-d</tt> nor <tt>-o</tt> was given, zoem will write to the
file named <a class="intern" href="#session"><tt>\__fnbase__.ozm</tt></a>.</p>
</div>
</div>
<p class="asd_par">
It is possible to change the default output file from within the document;
this is achieved with the <a class="intern" href="#writeto_1"><span class="zpr">\writeto#1</span></a> primitive. Zoem can mingle default
output with output to other files, use the <a class="intern" href="#write_3"><span class="zpr">\write#3</span></a> primitive for that.</p>
<p class="asd_par">
Both the <tt>-i</tt> and <tt>-o</tt> flag accept a hyphen as argument,
meaning respectively that zoem will read from <span class="smallcaps">STDIN</span> and write
to <span class="smallcaps">STDOUT</span>.</p>
<p class="asd_par">
Specifying just zoem and entering a return will cause zoem
to enter interactive mode, in which it reads from <span class="smallcaps">STDIN</span> and writes to <span class="smallcaps">STDOUT</span>.
Interactive mode currently should catch any errors occurring,
so it is a good way of experimenting and testing.
By default, interactive mode reads chunks that are ended by a single
dot on a line by itself. This behaviour can be changed by setting
the session variable <a class="intern" href="#session"><tt>\__parmode__</tt></a> using the <tt>-s</tt> option.
Using <tt>zoem -l parmode</tt> shows the bits that can be set in this variable.
It is for example possible to make zoem read paragraphs (ended by two
or more consecutive newlines).</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Note</span>
There is a difference between specifying <i>no</i> output stream
(i.e. not using the <tt>-o</tt> option) and explicitly specifying <tt>-o -</tt>.
In the latter case, zoem will never enter interactive mode. Should
you need to insert zoem into some pipe sequence, then you need to
use <tt>-o -</tt>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Tracing errors</span>
If your document contains erroneous input (e.g. using a macro that was never
defined), zoem will by default print the approximate corresponding line
number of the current input file and the last key it saw, and then exit. If
that does not suffice in tracking down the error, you have a choice of
options. One possibility is to use one of the various tracing modes
described below and in the zoem interpreter manual. Another possibility is
to specify the <tt>-x</tt> option which says to enter interactive mode should an
error occur. This enables you to inspect the values of keys defined or used
in the problematic area.
A selection of other options is given below. For the full story,
consult <a class="local sibling" href="zoem.html">the manual page of the zoem interpreter</a>.</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>-h</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
lists all flags accepted by zoem with a short description for each.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>-s foo=bar</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Sets key <tt>\foo</tt> to <tt>bar</tt>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>-e <any></tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Zoem will evaluate <tt><any></tt>, writing any result text to <span class="smallcaps">STDOUT</span>,
and then exit.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>-E <any></tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Zoem will evaluate <tt><any></tt>, writing any result text to <span class="smallcaps">STDOUT</span>,
and then proceed.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>-x</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
If an error occurs, zoem stops processing and enters interactive mode.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>-l <str></tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
lists all entities specified by <tt><str></tt>. It can be any of
<tt>all</tt>,
<tt>filter</tt>,
<tt>legend</tt>,
<tt>alias</tt>,
<tt>session</tt>,
<tt>trace</tt>, or
<tt>zoem</tt>.
Repeated use is allowed. In fact, zoem will only check whether
the target is present as a substring, so</p>
<div class="verbatim">zoem -l legendzoem</div>
<p class="asd_car">
will print the legend and the list of zoem primitives. </p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>--trace</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
This traces (prints) all keys encountered, and prints
possibly truncated arguments.
Zoem has several other tracing flags, use the <tt>-h</tt> flag
or refer to the zoem manual page for more information.</p>
<p class="asd_par">
Tracing can be set from within the document using the
<a class="intern" href="#trace_1"><span class="zpr">\trace#1</span></a> primitive. Part or whole of the data tree
can be output from within the document using the <tt>\%dump</tt> primitive
(refer to the <a class="intern" href="#grape">Tree data</a> section).</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>--stats</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
When zoem is done, it prints statistics about the primitive name
table and about the user name table.</p>
</div>
</div>
<a name="syntax"></a><div class="sec_leader sec_lev1"><div class="sec_title"><a class="intern" href="#syntax">Zoem syntax and parsing</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5</span></a></div></div>
<a name="nomenclature"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#nomenclature">Syntax and nomenclature</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.1</span></a></div></div>
<p class="asd_par">
Zoem parses text which may contain zoem <b>escape sequences</b>, these are
sequences that have special meaning and cause zoem to do special
processing. Each and every escape sequences starts with a backslash, no
exceptions. There are three kinds of sequences that are <i>macros</i>, which
may or may not take arguments. These are zoem primitives, user keys, and
dollar keys.</p>
<p class="asd_par">
There are currently about sixty zoem primitives, these are listed in the
<a class="intern" href="#language">The zoem language</a> section. Sixty is quite a lot; it includes
convenience sibling sets such as <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a>, <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>, <a class="intern" href="#def_2"><span class="zpr">\def#2</span></a>, and
<a class="intern" href="#def_2"><span class="zpr">\def#2</span></a>, and entries covering a variety of areas such as <span class="smallcaps">I/O</span>, arithmetic,
testing, control, string conversions, formatting, shadowing (scopes),
and all the other stuff listed in the <a class="intern" href="#topicindex">Topic index</a> section.</p>
<p class="asd_par">
Additionally there are a number of zoem built-ins that are defined
in terms of primitives. Built-ins live in the same dictionary as
primitives and behave the same in all aspects.
The next section has some further remarks on the differences
and resemblances between primitives/built-ins on the one hand
and user macros on the other hand.</p>
<p class="asd_par">
User keys and dollar keys are discussed in the
<a class="intern" href="#macro">Macro expansion</a> section. Arguments are shipped by delimiting them with curly
braces, as in</p>
<div class="verbatim"><tt>\thiskey{takes}{\bf{two}\it{arguments}}</tt>.</div>
<p class="asd_car">
No characters are allowed inbetween (the delimiting curlies of) two
arguments (but take note of the handy <a class="intern" href="#formatted_1"><span class="zpr">\formatted#1</span></a> primitive). See the
<a class="intern" href="#macro">Macro expansion</a> section for more information.
Zoem is very strict in the syntax it accepts, but it <i>garantuees</i> to
accept a text in which each backslash <tt>\</tt> is escaped as <tt>\\</tt> (i.e. a
text in which all consecutive runs of backslashes have even length).</p>
<p class="asd_par">
An <b>active backslash</b> is any backslash that is not made inactive by an
active backslash immediately preceding it. The first backslash seen by zoem
(proceeding sequentially through the text) is active. This is one
incomprehensible way of stating the obvious, and I bet you know what I mean
anyway. An active backslash must always have a meaning known to zoem. If
zoem does not get it, it will complain and exit. The meaning (i.e. class)
of the escape sequence introduced by an active backslash is determined by
the character immediately following it. A list is given below.</p>
<p class="asd_par">
Within arguments, curlies not functioning as argument delimiters must also
be escaped if they are not balanced. It is best practice to escape all
non-argument-delimiting curlies, but I never do so myself unless they are
not balanced.
An <b>escaped curly</b> is a curly preceded by an active
backslash.
An <b>active curly</b> is a curly that is not escaped.
A pair of
<b>balanced curlies</b> consists of an active left curly that matches an active
right curly, where inbetween all escaped curlies are disregarded.
A <b>block</b> is anything delimited by balanced curlies.
The word <b>scope</b> is most often used to distinguish between <b>device
scope</b> and <b>plain scope</b>, these are the two kinds of <b>parse scopes</b>.
An <b>environment scope</b> refers to the stuff enclosed by instances of the
<a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> and <a class="intern" href="#end_1"><span class="zpr">\end#1</span></a> primitives.
So called <b>name scopes</b> are entered and exited by <a class="intern" href="#push_1"><span class="zpr">\push#1</span></a> and <a class="intern" href="#pop_1"><span class="zpr">\pop#1</span></a>.</p>
<a name="namespaces"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#namespaces">Primitives, built-ins and user macros</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.2</span></a></div></div>
<p class="asd_par">
Zoem distinguishes between primitives and built-ins and user macros
on the other hand. Consider
the following slightly contrived example.</p>
<div class="verbatim">\def{fib#1}{
\push{fibonacci}
\set{a}{1}
\set{b}{1}
\set{c}{0}
\while{\let{\a <= \1}}{
\setx{c}{\a}
\setx{a}{\let{\a + \b}}
\write{-}{txt}{\c\|}
\setx{b}{\c}
}
\pop{fibonacci}
}</div>
<p class="asd_car">
The example is contrived in that zoem is not the most appropriate
language to compute Fibonacci numbers. The reason for using
it is that extracts from existing macro packages require more context
and are simply more boring.</p>
<p class="asd_par">
In the example, the following macros are primitives:
<b><a class="intern" href="#push_1"><span class="zpr">\push#1</span></a></b>, <b><a class="intern" href="#pop_1"><span class="zpr">\pop#1</span></a></b>,
<b><a class="intern" href="#def_2"><span class="zpr">\def#2</span></a></b>, <b><a class="intern" href="#set_2"><span class="zpr">\set#2</span></a></b>, <b><a class="intern" href="#while_2"><span class="zpr">\while#2</span></a></b>, <b><a class="intern" href="#let_1"><span class="zpr">\let#1</span></a></b>,
<b><a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a></b>, and <b><a class="intern" href="#write_3"><span class="zpr">\write#3</span></a></b>.
The example defines a user macro <b><tt>\fib#1</tt></b>, which can be
invoked e.g. as <tt>\fib{100}</tt>. Doing this either from a file
or from interactive mode should give the output below.</p>
<div class="verbatim">1
2
3
5
8
13
21
34
55
89</div>
<p class="asd_par">
From the above it can be seen that a macro (primitive or user-defined)
is in this text often referenced by its signature. The signature
contains both the name of the macro and the number of arguments it takes,
separated by the <tt>#</tt> (octothorpe) character. The octothorpe
and ensuing integer are omitted if a macro does not take
arguments. A new macro is defined
by specifying the required signature (without the leading backslash)
as the first argument of one of the definition macros.
In this text a signature is usually prefixed
with the backslash.</p>
<p class="asd_par">
The example above also defines user macros <tt>a</tt>, <tt>b</tt>, and <tt>c</tt>.
The <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a> primitive will not warn when a previous definition
exists. The <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a> acts similarly but will also first evaluate
the value assigned to the macro. Finally, <a class="intern" href="#push_1"><span class="zpr">\push#1</span></a> and <a class="intern" href="#pop_1"><span class="zpr">\pop#1</span></a>
temporarily create a new dictionary in which the definitions are stored.
This is one easy way to ensure that no other definitions are
overwritten. This level of care is generally not required though.</p>
<p class="asd_par">
The following are useful to know about primitives, built-ins
and user macros.</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em">•</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Primitives and built-ins live in one namespace (or dictionary),
user macros live in another.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em">•</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
A built-in is a special macro provided by zoem.
It is defined in terms of one or more primitives, but its definition
lives in the same dictionary as primitives do. It is called
a built-in because its definition is built into the zoem interpreter.
Example: <tt>begin#1</tt> is defined as <tt>\begin{\1}{}</tt> (cf <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a>).
The full list can be obtained by issuing <tt>zoem -l alias</tt>.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em">•</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Primitives and built-ins can be shadowed by user-macros, but a warning will
be issued. You can test this by issuing e.g.
<tt>\def{def#2}{\set{\1}{\2}}</tt>. This particular piece of code redefines
<a class="intern" href="#def_2"><span class="zpr">\def#2</span></a> as <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a> by shadowing the primitive <tt>\def#2</tt> as a user
macro, losing the property of <a class="intern" href="#def_2"><span class="zpr">\def#2</span></a> that it warns if a key already
exists.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em">•</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Primitives and built-ins can <i>always</i> be accessed by prefixing
the name with a right quote, as in <tt>\'def{foo}{bar}</tt>.
The prefixed primitive syntax also has the advantage that
it is slightly faster, although zoem speed is likely not something
one should worry about.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em">•</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
It is impossible to access a user macro with the quote prefix syntax.</p>
</div>
</div>
<p class="asd_par">
It is probably a good idea in macro packages that
export functionality to use the primitive quote prefix syntax.
This protects the package from user redefinitions. At the same
time, the ability to shadow zoem primitives implies that user
macros (also those exported by macro packages themselves)
are protected against potential clashes with zoem primitives
that may be introduced in later versions of the language.
The Fibonacci example looks as follows using the quote prefix syntax.</p>
<div class="verbatim">\'def{fib#1}{
\'push{fibonacci}
\'set{a}{1}
\'set{b}{1}
\'set{c}{0}
\'while{\'let{\a <= \1}}{
\'setx{c}{\a}
\'setx{a}{\'let{\a + \b}}
\'write{-}{txt}{\c\|}
\'setx{b}{\c}
}
\'pop{fibonacci}
}</div>
<p class="asd_par">
The quote mechanism only works for zoem primitives and built-ins that follow
the syntax of user macros. This includes names starting with a dollar <tt>$</tt>
or with a double quote <tt>"</tt>. The primitive <a class="intern" href="#dollar_2"><span class="zpr">\$#2</span></a> and the built-ins
<tt>\""</tt> and <tt>\""#1</tt> are the only examples in this category.
The quote mechanism does not work for special zoem primitives
such as data keys (<a class="intern" href="#grape">Tree data</a>), delay keys (<a class="intern" href="#excl_1"><span class="zpr">\!#1</span></a>),
or <abbr class="ucase" title="Extensible Markup Language">XML</abbr> syntactic sugar (<a class="intern" href="#xmlsugar"><abbr class="ucase" title="Standard Generalized Markup Language">SGML</abbr>/<abbr class="ucase" title="Hyper Text Markup Language">HTML</abbr>/<abbr class="ucase" title="Extensible Markup Language">XML</abbr> syntactic sugar cubes</a>).</p>
<a name="escape"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#escape">List of escape sequence classes</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.3</span></a></div></div>
<p class="asd_par">
This is a list of escape sequence classes recognized by zoem, indexed
by the (set of) character(s) triggering the class(es) — this assumes
that the character in question is preceded by an active backslash.</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>$[_a-zA-Z]*</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[dollar key]
A sequence starting with a dollar sign possibly continued with
underscores and alphanumeric characters. Introduces a dollar key. No
dollar signs are allowed in the remainder, and the first non-alphanumeric
non-underscore character terminates the sequence. The primary use of dollar
keys is that they are set by <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> and <a class="intern" href="#end_1"><span class="zpr">\end#1</span></a>. Dollar keys live
in the dollar dictionary stack, which is pushed and popped by <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a>
and <a class="intern" href="#end_1"><span class="zpr">\end#1</span></a>. Nested <tt>begin/end</tt> scopes can thus safely associate
different values with the same key name. Refer also to the <a class="intern" href="#macro">Macro expansion</a>
section, the <a class="intern" href="#language">The zoem language</a> section, and the <a class="intern" href="#dictionary">Dictionary stacks</a> section.</p>
<p class="asd_par">
Note: <a class="intern" href="#dollar_2"><span class="zpr">\$#2</span></a> is the only zoem primitive starting with a dollar.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>[_a-zA-Z][_a-zA-Z0-9]*</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[user key/zoem primitive]
A sequence starting with an underscore or an alphabetic character, with
only underscores and alphanumeric characters in the remainder. Introduces a
user key or a zoem primitive. The first non-alphanumeric non-underscore
character terminates the sequence. These keys live in the <i>user
dictionary stack</i>, which the user can control with the <a class="intern" href="#push_1"><span class="zpr">\push#1</span></a> and
<a class="intern" href="#pop_1"><span class="zpr">\pop#1</span></a> primitives. Refer also to the <a class="intern" href="#macro">Macro expansion</a>, <a class="intern" href="#language">The zoem language</a>,
and <a class="intern" href="#dictionary">Dictionary stacks</a> sections.</p>
<p class="asd_par">
A sequence consisting of a single underscore (i.e. not followed
by an alphanumeric character) introduces an
<a class="intern" href="#anonymous">anonymous key</a>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>"</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[user key or zoem built-in]
Starts a user key, which is only different from the user keys mentioned
above in that it looks different. The sequence is terminated by
a closing <tt>"</tt>. Inbetween, anything is allowed except
a backslash or curly. This is used for creating mnemonic names such as </p>
<div class="verbatim"> \"man::author"
\"man::section"
\"man::version"
\"html::title"
\"html::charset"</div>
<p class="asd_car">
These keys live in the <i>user dictionary stack</i>.
See the <a class="intern" href="#macro">Macro expansion</a> section and the <a class="intern" href="#dictionary">Dictionary stacks</a> section.</p>
<p class="asd_par">
There are two zoem built-ins that take this particular form. These are
<tt>\""</tt> and <tt>\""#1</tt>. Both expand to nothing. The first can be used to
temporarily separate two pieces of text, as they will be joined after
expansion. The second can be used to quickly outcomment sections of text.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>'</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[primitive quote prefix]
As seen above, primitives and user keys largely live in the
same syntactic namespace. It is possible to unambiguously
invoke a primitive by inserting a right quote to the left
of the primitive key or built-in.
Refer to section <a class="intern" href="#namespaces">Primitives, built-ins and user macros</a>.</p>
<p class="asd_par">
The user keys live in a stack of dictionaries. Dictionaries
can be pushed and popped using <a class="intern" href="#push_1"><span class="zpr">\push#1</span></a> and <a class="intern" href="#pop_1"><span class="zpr">\pop#1</span></a>.
The default user dictionary is always present and acts
as a global namespace. It is possible to retrieve a key <tt>\foo</tt>
directly from the global namespace using the syntax <tt>\''foo</tt>,
even if it is shadowed in stacked dictionaries. It is possible
to set a key in the global namespace using <a class="intern" href="#set_3"><span class="zpr">\set#3</span></a>.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>%</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[data key]
A sequence starting with a percent sign. The percent sign is
followed by a number of scopes. This is used to access multi-dimensional
data storage. Such data is stored using the <a class="intern" href="#def_2"><span class="zpr">\def#2</span></a> primitive or one
of its siblings. Refer also to section <a class="intern" href="#grape">Tree data</a>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>[1-9]</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[positional parameter]
A single (character encoding a) positive digit. The sequence
backslash followed by digit is called a <i>positional parameter</i>.
It is only interpreted in the second argument of <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a>, <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>,
<a class="intern" href="#def_2"><span class="zpr">\def#2</span></a>, and <a class="intern" href="#defx_2"><span class="zpr">\defx#2</span></a>, and in the definition part of an
<a class="intern" href="#anonymous">anonymous key</a> (which can be an argument to <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>
and <a class="intern" href="#inspect_4"><span class="zpr">\inspect#4</span></a>). In all these instances, the sequence denotes a
positional parameter into which the corresponding argument will be
interpolated when a key with arguments is used. It is allowed in other
places though, as it is possible in zoem to create key definitions
dynamically (see e.g. the <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a> primitive).
<b>Note</b> during interpolation, positional parameters that are enclosed by
the <i>delay scope</i> <tt>\!{..}</tt> will not be interpolated (see <a class="intern" href="#excl_1"><span class="zpr">\!#1</span></a>).
The status of this feature is not entirely clear.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt><newline></tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[strip newline] The newline will be stripped during the
interpretation stage. If you want the newline to be stripped during
the file-read preprocessing stage use the sequence <tt>\:{/}</tt>,
which is a special case of the comment sequence (see below).</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>:</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[preprocessing sequence]
There are a few preprocessing sequences, which are evaluated during file
read (cf the <a class="intern" href="#fileread">File read</a> section).
The most important preprocessing sequence is simply the sequence <tt>\:</tt>
followed by whitespace, an alphanumeric character, or a backslash. It
introduces a comment up till and excluding the next newline, which is
stripped.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>|</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[zoem glyph]
Comprises a special two-character sequence that can be given a
device-specific meaning. It is customarily used to encode a line break. To
zoem, this sequence is more or less the same as a 'normal' character. See
the <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> primitive.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>~</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[zoem glyph]
It is customarily used to encode a non-breaking space. See the entry above.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>-</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[zoem glyph]
It is customarily used to encode a long dash. See two entries back.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>\</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[backslash] Denotes a literal backslash.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>{</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[left curly] Denotes a literal left curly.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[right curly] Denotes a literal right curly.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>*</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[glyph sequence] Starts a glyph sequence or constant sequence.
Refer to the <a class="intern" href="#dscope">Device scope</a> section and to the <a class="intern" href="#constant_1"><span class="zpr">\constant#1</span></a> primitive.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt><</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[syntactic sugar]
This introduces syntactic sugar for directly writing <abbr class="ucase" title="Standard Generalized Markup Language">SGML</abbr>-style mark-up,
such as <abbr class="ucase" title="Hyper Text Markup Language">HTML</abbr> and <abbr class="ucase" title="Extensible Markup Language">XML</abbr> (e.g. DocBook).
Refer to the <a class="intern" href="#xmlsugar">anchor section</a> for that topic.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>@</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[at scope] <i>Typically seen in macro package files only</i>.
Starts a special instance of device scope called <i>at scope</i>. The
sequence <tt>\@</tt> <i>must</i> immediately be followed by a pair of balanced
curlies, so at scope always appears as <tt>\@{..}</tt>. Refer to the
<a class="intern" href="#dichotomy">Scope dichotomy</a> and <a class="intern" href="#dscope">Device scope</a> sections for more information.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>@e</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[at <abbr class="ucase" title="Hyper Text Markup Language">HTML</abbr> entity]
<tt>\@e{ent}</tt> will expand to the <abbr class="ucase" title="Hyper Text Markup Language">HTML</abbr> character entity &ent; —
it is equivalent to, somewhat easier to type and minimally shorter than
<tt>\@{&ent;}</tt>.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>&</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[and scope] <i>Typically seen in macro package files only</i>.
May only be used within device scope, and implements a limited
form of macro expansion within that scope.
The sequence <tt>\&</tt> <i>must</i> immediately be followed by a pair of balanced
curlies. so and scope always appears as <tt>\&{..}</tt>. Refer to the
<a class="intern" href="#dichotomy">Scope dichotomy</a> and <a class="intern" href="#dscope">Device scope</a> sections for more information.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>`</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[back quote - formatting escape]
<i>Typically seen in macro package files only</i>.
Must be followed by a pair of balanced curlies enclosing a formatting
sequence. This is only recognized within the <a class="intern" href="#formatted_1"><span class="zpr">\formatted#1</span></a> primitive.
This primitive removes all literal whitespace it encounters in its argument;
the formatting sequences are transformed to the whitespace characters encoded
by them.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>,</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[comma - atomic separator] <i>Typically seen in macro package files only</i>.
This is interpreted during filter time, and is
always mapped to nothing. Use it for glueing things as in <tt>\foo\,1</tt>,
which will result in <tt>theresultoffoo1</tt>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>!</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[delay sequence] <i>Typically seen in macro package files only</i>.
Introduces a zoem meta sequence. Such a sequence consists of a maximal run
of consecutive backslashes, possibly followed by a single block. It can be
used to delay interpretation during any number of interpretation stages, and
is useful to delay interpretation, perhaps even in a nested fashion, for
arguments in keys such as <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a> that expand one or more of their
arguments before use. The run of exclamation marks (or 'bangs' as they are
internally called) actually comprises an argument to the underlying
primitive, so the two primitives (one taking a single block argument)
internally have respective signatures <tt>!#1</tt> and <tt>!#2</tt>. Externally
though, they are just refered to as <a class="intern" href="#excl"><span class="zpr">\!</span></a> and <a class="intern" href="#excl_1"><span class="zpr">\!#1</span></a>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>=</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[inline files] <i>Rarely used feature</i>.
Starts either a sequence of the form <tt>\={fname}</tt>, which begins a so called
inline file named <tt>fname</tt>, or a sequence of the form <tt>\==</tt>, which
ends such an inline file. Refer to the <a class="intern" href="#fileread">File read</a> section.</p>
</div>
</div>
<p class="asd_par">
This leaves <tt>0>()[]?^#/.;</tt> for future use, hopefully
very few of these will ever acquire meaning.
If the sequence <tt>\#</tt> acquires meaning, it will probably be for encoding
Unicode scalar values.</p>
<a name="stages"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#stages">Parsing stages</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.4</span></a></div></div>
<p class="asd_par">
Parsing is separated into three stages, conceptually.
Zoem knows two different parse scopes, plain scope and device scope.
These are mentioned below, and explained in the <a class="intern" href="#dichotomy">Scope dichotomy</a>
section. The three stages are:</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
File read
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
Macro expansion / file inclusion - only plain scope is seen.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
Filtering - both plain scope and device scope are filtered.
Device directives that lay hidden in device scope
are interpreted during output.
</div>
</div>
<p class="asd_par">
A file is read in chunks, if possible. The requirement is that chunks must
end on lines and be in the outermost scope. The default minimum chunk size
is approximately one megabyte. Chunks are processed by recursively
chunking them into smaller chunks as dictated by macro expansion. As soon
as a chunk is no longer subject to macro expansion it is immediately
filtered and output.</p>
<p class="asd_par">
Macro expansion is done recursively. Whenever a macro is encountered, it is
replaced by its expansion, and the result is again fed to the parser.
Evaluatation is not necessarily lazy, that is, during macro expansion the
expander may expand arguments before they are interpolated and substituted in
the macro definition. This inside-out evaluation can recurse if necessary.
Many zoem primitives evaluate one or more of their arguments before use. The
default behaviour for user macros is lazy evaluation. This can be changed
however by wrapping both the macro and its arguments in <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>.
Expansion can be delayed using <a class="intern" href="#excl"><span class="zpr">\!</span></a> and <a class="intern" href="#excl_1"><span class="zpr">\!#1</span></a>, so different arguments
can be treated differently.</p>
<p class="asd_par">
Important is that the result from the second stage is still
valid zoem input.
If you re-feed it to zoem, file read and macro expansion are usually no-ops
(unless some interpretation delay-magic was used), and the syntax is
garantueed to be acceptable to zoem. This is because device scope is not
touched during the first two stages, and device specific text (which is most
likely not conforming to zoem syntax) lies always hidden in that scope. There
are three kinds of escape sequences introducing device scope; these are
described in the <a class="intern" href="#dscope">Device scope</a> section.</p>
<p class="asd_par">
This is used for example when creating a table of contents; you can write
expanded but unfiltered content to a file and read it in during the
following run. It is important that such content is fully expanded,
because you want things like index numbers and references as
they are at the time of macro invocation. It is equally important that what
you read back in is still valid zoem input; this is simply achieved by
witholding filtering. When the table of contents is read in, it can be
subjected to filtering, and this is the right way to do toc stuff in Zoem.</p>
<a name="fileread"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#fileread">File read</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.5</span></a></div></div>
<p class="asd_par">
File read - stripping comments, reading inline files.</p>
<p class="asd_par">
Zoem searches for files included via
<a class="intern" href="#dofile_2"><span class="zpr">\dofile#2</span></a> or one of its built-in aliases in a number of places if
it cannot find the file in the current directory.
The precise way of searching is documented in section <a class="intern" href="#searchpath">File search path</a>.</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style=""><tt>\:</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
In most cases, this sequence introduces a comment, namely
where it is followed by whitespace, an alphanumeric character, or a
backslash. It introduces a comment up until and excluding the next newline,
which is stripped.</p>
<p class="asd_par">
The sequence <tt>\:{/}</tt> introduces a comment up till and including
the newline. This feature can be
useful within the <a class="intern" href="#protect_1"><span class="zpr">\protect#1</span></a> primitive, as it is the only way to delete
actual newlines within the argument of that primitive.</p>
<p class="asd_par">
The sequence <tt>\:{!}</tt> is replaced by a backslash. The single
use currently known is to make it easy to quote zoem input containing
comment sequences. This</p>
<div class="verbatim">\protect{\foo
\bar
\zut \:{!}: this will end up as a comment.
}</div>
<p class="asd_car">
will result in the following</p>
<div class="verbatim">\foo
\bar
\zut \: this will end up as a comment.</div>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>\={fname}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
starts inline file named fname at the next line, removes remainder of line
after the <tt>\={fname}</tt> sequence. When using the <a class="intern" href="#dofile_2"><span class="zpr">\dofile#2</span></a> primitive or
one of its four built-in aliases, an inline file takes precedence over
regular files in the file system, whether it is present (as a regular file)
or not. See below. This feature can be used to ship zoem input in one piece
while putting the macro parts at the end. <a class="intern" href="#zinsert_1"><span class="zpr">\zinsert#1</span></a> can address inline
files as well, but <a class="intern" href="#finsert_1"><span class="zpr">\finsert#1</span></a> cannot. The reason for this is that inline
files have to satisfy zoem syntax, whereas <a class="intern" href="#finsert_1"><span class="zpr">\finsert#1</span></a> can be used to
read arbitrary data.</p>
<p class="asd_par">
The future will probably bring a zoem option that creates
such a self-contained file automatically from the zoem
entry file.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style=""><tt>\==</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
ends inline file, removes remainder of line.</p>
</div>
</div>
<p class="asd_par">
The above applies to any file read at any stage. Inline files may occur in
any file included at any time, but they do not nest.</p>
<p class="asd_par">
The <i>zoem entry file</i> is the single file that is specified
on the command line. This is the main file, from which other
files can be included if desired.</p>
<p class="asd_par">
Zoem entry files usually have the extension <tt>.azm</tt>, which is memnonic
for <b>A ZoeM</b> file. This is required if the <tt>-i</tt> option is used.
Arbitrary entry file names can be specified using the <tt>-I</tt> option.
It is not uncommon to generate sibling files with
<tt>.roff</tt>, <tt>.html</tt>, <tt>.zmt</tt> (zoem table of contents), and
<tt>.zmr</tt> (zoem references) extensions — however, this is all configurable
in user space and not part of zoem itself. There are no restrictions on
names of files that are included from the entry file. Inclusion is done
recursively.</p>
<p class="asd_par">
The future will probably bring a second extension that is allowed,
namely <tt>.ezm</tt> for <b>Expanded ZoeM</b> file, which is a self-contained
file in which every included file is present as an inline file.</p>
<a name="searchpath"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#searchpath">File search path</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.6</span></a></div></div>
<p class="asd_par">
If zoem cannot find a file in the current directory, it attempts
to find the file in one of three different ways. These are,
in the order in which they are attempted:</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The environment variable <tt>$ZOEMSEARCHPATH</tt> is checked. It may
contain a listing of paths separated by whitespace or colons.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The zoem variable <a class="intern" href="#session"><tt>\__searchpath__</tt></a> is checked. It must contain a listing
of paths stored as a vararg, i.e. a sequence of paths where each path is
delimited by curly brackets. <b>DO NOT</b> overwrite this variable, but
rather append or prepend to it. Most likely zoem was configured and compiled
locally on your system, in which case <a class="intern" href="#session"><tt>\__searchpath__</tt></a> contains the path
necessary to find the macro packages <tt>man.zmm</tt>, <tt>faq.zmm</tt>, and
<tt>ref.zmm</tt>.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The path of the file currently being parsed is used.
Assume that file <tt>foo</tt> contains <tt>\import{/a/b/c/bar}</tt>.
If file <tt>bar</tt> wants to include file <tt>zut</tt>, which is in
the same <tt>/a/b/c/</tt> directory, it need not prepend a path
but can just issue <tt>\import{zut}</tt>. Should the
previous search mechanisms fail to find zut, then zoem will
as a last resort deduce the path from <tt>/a/b/c/bar</tt>.
This feature is probably rarely needed, if ever at all.</p>
</div>
</div>
<a name="macro"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#macro">Macro expansion</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.7</span></a></div></div>
<p class="asd_par">
Macro expansion consists of recursive file inclusion and macro expansion.
All zoem primitives and user keys are recursively expanded
until none remains. Zoem primitives and user keys take one
of the following forms:</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>\abc_0123_</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
A key with alphanumerics and underscores only. Ends with
any other character. All zoem primitives but one have this form.</p>
<p class="asd_par">
Note: <tt>\_</tt> denotes an anonymous key, see the <a class="intern" href="#anonymous">Anonymous keys</a> section.</p>
<p class="asd_par">
These keys live in the <i>user</i> dictionary stack. Initially, there is
only one dictionary. The stack can be manipulated using the <a class="intern" href="#push_1"><span class="zpr">\push#1</span></a>
and <a class="intern" href="#pop_1"><span class="zpr">\pop#1</span></a> primitives.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>\"abc::def-ghi.jkl,mno+qrs"</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
A quoted key. Almost anything inbetween quotes is allowed. Always
ends with a quote. No zoem primitive has this form.
These keys live in the same <i>user</i> dictionary stack
as the keys above.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>\$abc_0123_</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
A key introduced with a dollar sign. The name may further consist
of alphanumerics and underscores and it ends with any other character.
These keys live in the <i>dollar</i> dictionary stack.
A dictionary is pushed with every occurrence of
<a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a>, and that dictionary is popped with the corresponding
occurrence of <a class="intern" href="#end_1"><span class="zpr">\end#1</span></a>.</p>
<p class="asd_par">
Further note: <a class="intern" href="#dollar_2"><span class="zpr">\$#2</span></a> is a zoem primitive.</p>
</div>
</div>
<p class="asd_par">
All three types of keys may take arguments, and overloading is allowed:</p>
<div class="verbatim"> \foo \: signature foo
\foo{bar} \: signature foo#1
\foo{bar}{bop} \: signature foo#2
\$foo{bar}{baz} \: signature $foo#2
\"foo::oof"{zut}{zit}{zot} \: signature "foo::oof"#3</div>
<p class="asd_car">
is an ensemble of valid and unique keys, which can be defined for
example by</p>
<div class="verbatim">\def{foo}{FOO}
\def{foo#1}{The FOO of \1}
\def{foo#2}{The FOO of \1 and \2}
\def{$foo#2}{The $FOO of \1 and \2}
\def{"foo::oof"#3}{\foo{\1}{\2}\foo{\2}{\3}}</div>
<p class="asd_car">
Additionally, zoem allows the definition of <i>constant keys</i> that map
directly into device space and are ignored during macro expansion. Usage of
such keys looks like <tt>\*{'e}</tt> or <tt>\*{(c)}</tt> and is detailed later on.</p>
<p class="asd_par">
A sequence <tt>\k</tt> where k is in 1-9 is allowed within anonymous keys (as
used for example in <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a> and <a class="intern" href="#inspect_4"><span class="zpr">\inspect#4</span></a>) and in the definition
argument of the <a class="intern" href="#def_2"><span class="zpr">\def#2</span></a> primitive and its siblings <a class="intern" href="#defx_2"><span class="zpr">\defx#2</span></a>,
<a class="intern" href="#set_2"><span class="zpr">\set#2</span></a>, and <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>. It indicates the position(s) where arguments
should be interpolated.
<b>Note</b> during interpolation, positional parameters that are enclosed by
the <i>delay scope</i> <tt>\!{..}</tt> will not be interpolated (see <a class="intern" href="#excl_1"><span class="zpr">\!#1</span></a>).
The status of this feature is not entirely clear.</p>
<p class="asd_par">
A feature that should only rarely be needed is that zoem allows
name scopes. Refer to the <a class="intern" href="#dictionary">Dictionary stacks</a> section.</p>
<a name="section_5_8"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#section_5_8">File inclusion</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.8</span></a></div></div>
<p class="asd_par">
There is one zoem primitive which has four different uses. For each
of those uses, a built-in alias exists.</p>
<div class="verbatim">\dofile#2 use alias meaning
\dofile{expr}{!+} \input{expr} require file, interpret and output
\dofile{expr}{!-} \import{expr} require file, interpret only
\dofile{expr}{?+} \read{expr} permit absence, interpret and output
\dofile{expr}{?-} \load{expr} permit absence, interpret only</div>
<p class="asd_car">
The <a class="intern" href="#dofile_2"><span class="zpr">\dofile#2</span></a> primitive and its four aliases are perhaps a little funny
interface-wise — better ideas are welcome. The <tt>expr</tt> argument is
<i>digested</i>, that is, expanded until no macro's remain. It is thus possible
to specify <a class="intern" href="#session"><tt>\__fnbase__.zmt</tt></a> and include a table of contents file that has
been written to in a previous run. <a class="intern" href="#dofile_2"><span class="zpr">\dofile#2</span></a> and its aliases have the
property that zoem really descends into the files, and on error will emit a
message containing the approximate line number where it occurred.</p>
<p class="asd_par">
Additionally, the contents of a file can be placed inline using
<a class="intern" href="#finsert_1"><span class="zpr">\finsert#1</span></a> and <a class="intern" href="#zinsert_1"><span class="zpr">\zinsert#1</span></a>.</p>
<p class="asd_par">
Note: wherever <tt>key</tt> is written, it means that something
of the form <tt>\foo</tt>, <tt>\$foo</tt>, or <tt>\"foo"</tt> has to
be provided, so you would use <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a> e.g. as
<tt>\setx{foo}{\finsert{\__fnbase__.zyx}}</tt>.</p>
<a name="protection"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#protection">Protection</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.9</span></a></div></div>
<p class="asd_par">
The <a class="intern" href="#dofile_2"><span class="zpr">\dofile#2</span></a> primitive requires that the files to be included
satisfy zoem syntax. It will descend into the files and proceed parsing
them.</p>
<p class="asd_par">
The <a class="intern" href="#finsert_1"><span class="zpr">\finsert#1</span></a> and <a class="intern" href="#zinsert_1"><span class="zpr">\zinsert#1</span></a> primitives do not descend,
but rather act as if the contents of the file specified were pasted
into the place of macro invocation.</p>
<p class="asd_par">
<a class="intern" href="#finsert_1"><span class="zpr">\finsert#1</span></a> will <i>protect</i> the contents of the inserted file,
that is, all backslashes and curlies are escaped by preprending
them with a backslash.
<a class="intern" href="#zinsert_1"><span class="zpr">\zinsert#1</span></a> will include the file unchanged, assuming that its
contents satisfy zoem syntax.</p>
<p class="asd_par">
The <a class="intern" href="#system_3"><span class="zpr">\system#3</span></a> primitive is able to pipe data to a system command's
<span class="smallcaps">STDIN</span> stream and retrieve data from the command's <span class="smallcaps">STDOUT</span> stream.
This primitive will <i>unprotect</i> the data it sends, and it will
protect the data it receives.
<b>Note</b> the security implications of this feature
as discussed at the <a class="intern" href="#system_3"><span class="zpr">\system#3</span></a> entry.</p>
<p class="asd_par">
Data can be explicitly protected using the <a class="intern" href="#protect_1"><span class="zpr">\protect#1</span></a> primitive.</p>
<p class="asd_par">
Protected data can (currently) never result in it being expanded
again. This is because escaped backslashes are only interpreted
at filter time, and never during expansion.
If you only need <i>temporary</i> delay of expansion, use
the <a class="intern" href="#excl"><span class="zpr">\!</span></a> primitive or the <a class="intern" href="#excl_1"><span class="zpr">\!#1</span></a> primitive.</p>
<a name="dichotomy"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#dichotomy">Scope dichotomy</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.10</span></a></div></div>
<p class="asd_par">
Zoem knows two parse scopes: <b>plain scope</b> and <b>device scope</b>. The
latter is also called 'at scope' because <tt>\@{..}</tt> is one (but not the only)
way of entering device scope. In plain scope, every character
represents itself as a glyph, i.e. as something that should show that way in
print/on screen (after the zoem output/device input is fed to the device
interpreter).</p>
<p class="asd_par">
For example, if you write the less than sign <tt><</tt> in plain scope,
it should show up as a readable less than glyph, like in
this very sentence. In order to make this happen, zoem provides
the <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> primitive, so that the less than sign can be
automatically mapped to the html entity sequence <tt>&lt;</tt>.</p>
<p class="asd_par">
In device scope, nothing is mapped except for a double backslash should it
occur. If you enter this particular sequence of mixed scope:
<tt>\@{<b>}<hello world>\@{</b>}</tt> as zoem input,
the zoem output/device input is (provided the <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a>
primitive was correctly used for the html device):
<tt><b>&lt;hello world&gt;</b></tt>
and what you finally see on screen is:
<b><hello world></b>.
In device scope, every character (except for the escape sequences available
in that scope) represents itself as the character that should be
present in the zoem output/device input. Device scope should normally only
be seen in macros and not in running zoem input.</p>
<p class="asd_par">
In plain space you type characters just as you want to see them eventually
— when you read the document after the zoem output was run through a device
interpreter (such as a browser or printer, or postscript previewer).
The only exceptions are the backslash and the two curlies, these should
be entered as <tt>\}</tt>, <tt>\{</tt>, and <tt>\}</tt>, respectively.
Those escape sequences are interpreted as the characters or glyphs
<tt>\</tt>, <tt>{</tt>, and <tt>}</tt>. For all characters, including these
three, it is checked whether they should be further mapped according to the
<a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> primitive. If a mapping is found, it is retrieved
and interpreted by the device scope filter. Read on.</p>
<a name="dscope"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#dscope">Device scope</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.11</span></a></div></div>
<p class="asd_par">
There are three kind of strings which are interpreted by the
generic device filter, and which are said to live in device scope:</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The strings embedded in <tt>\@{..}</tt> sequences.<br></p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The strings mapped to by the <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> primitive, including
mappings of the zoem glyphs <tt>\~</tt>, <tt>\|</tt>, and <tt>\-</tt>.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The strings mapped to by the <a class="intern" href="#constant_1"><span class="zpr">\constant#1</span></a> primitive.</p>
</div>
</div>
<p class="asd_par">
In a macro package that is meant to work for multiple devices, every use of
any of these constructs will typically be embedded in something that tests
the value of the active device. This can be done using either <a class="intern" href="#cmp_3"><span class="zpr">\cmp#3</span></a>
with <a class="intern" href="#if_3"><span class="zpr">\if#3</span></a>, <a class="intern" href="#switch_1"><span class="zpr">\switch#1</span></a>, or <a class="intern" href="#dollar_2"><span class="zpr">\$#2</span></a>, in conjuction with the
pre-defined zoem key <a class="intern" href="#session"><tt>\__device__</tt></a>, containing the name of the active
device (which can be specified on the command-line). The following are
equivalent:</p>
<div class="verbatim"> \if{\cmp{eq}{\__device__}{html}}{ \@{<!-- (c) foo bar -->} }{}
\: is equivalent with
\${html}{ \@{<!-- (c) foo bar -->} }</div>
<p class="asd_car">
The <a class="intern" href="#dollar_2"><span class="zpr">\$#2</span></a> primitive is used if something needs to be done for one
device only, and it may occasionally appear in documents. For example, the
<a target="_parent" class="extern" href="http://micans.org/pud/"><acronym class="ucase" title="Portable Unix Documentation">PUD</acronym></a>
man macros enable the creation of a table of contents (for both html
and troff). My own convention is to have a table of contents only in html,
and I specify this using the sequence</p>
<div class="verbatim"><tt>\${html}{\"man::maketoc"}</tt></div>
<p class="asd_car">
When zoem enters device scope, it
outputs all characters literally, except that the backslash still has
special meaning. It is used for encoding the backlash itself (as
<tt>\\</tt>), and for encoding the two curlies <tt>{</tt> and <tt>}</tt> (as
<tt>\{</tt> and <tt>\}</tt>). This is the same as in plain scope (except that
in plain scope the resulting character may again be mapped onto something
else, for example, in troff the backslash also needs encoding as
<tt>\\</tt>).</p>
<p class="asd_par">
In device scope the sequence <tt>\"</tt> maps to a double quote.
This is an additional feature to allow zoem input to be more susceptible to
some editors moving features. It is not <i>necessary</i> though; simply using
the double quote without escaping it is sufficient.</p>
<p class="asd_par">
Additionally, the backslash can be followed by a single letter from a
prescribed set listed below. Such a backslash+letter combination is called a
<i>device directive</i>. By default, zoem will never print consecutive
newlines, and it will never print consecutive spaces or spaces at the
beginning of a line. The device directives allow this to be altered.</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">N</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">garantuee a newline</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">P</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">garantuee a paragraph skip (two consecutive newlines)</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">S</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">garantuee a space (except if next char is newline)</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">I</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">increase indent by one (indent is printed after each newline)</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">J</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">decrease indent by one</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">C</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">set indent to zero</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">n</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">print newline</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">s</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">print space</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">t</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">print tab</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">w</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">stop managing white space (squashing spaces and newlines)</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">W</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">start managing white space (use after <tt>w</tt>)</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">&</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">start <i>and</i> scope (see further below)</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">+</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">set the special level (see further below)</p>
</div>
</div>
<p class="asd_par">
Note that the directives mainly affect the lay-out of the device text (which
is zoem output), not the look of the interpreted device text. The '<tt>N</tt>'
directive is rather important when constructing troff macros, as many
special troff commands are encoded by a dot as the first character on a
line, i.e. a newline followed by a dot. Since troff attaches special meaning
to two consecutive newlines as well (interpreting it as a paragraph break),
zoem needs to be able to specify <i>print a newline only if the previous
character was not a newline</i>. This is exactly what the <tt>N</tt> directive
means. The '<tt>W</tt>' and '<tt>w</tt>' directives are required for enabling
the construction of a verbatim environment.</p>
<p class="asd_par">
The sequence <tt>\&{<almost any>}</tt> can be used to avoid
overly cumbersome constructions. It is for example illegal
to write</p>
<div class="verbatim">\@{<table width="\width">}</div>
<p class="asd_car">
In the early days of zoem, you had to write</p>
<div class="verbatim">\@{<table width="}\width\@{">}</div>
<p class="asd_car">
— ugly by most standards. Today you write</p>
<div class="verbatim">\@{<table width="\&{\width}">}</div>
<p class="asd_car">
Which is not any shorter, but more pleasant to read.
What happens is that the contents of <i>and</i> scope <tt>\&{..}</tt> is first
fully expanded in plain scope, after which the result is passed back to
device scope. You have to be careful though. The content of <tt>\&{..}</tt>
should never expand to something containing the <i>at</i> sequence <tt>\@{..}</tt>,
because device scope is not allowed to nest. It should also not expand to
something containing the <i>and</i> sequence <tt>\&{..}</tt> either, as this
sequence is illegal in plain scope.</p>
<a name="special"></a><div class="sec_leader sec_lev3"><div class="sec_title"><a class="intern" href="#special">Device scope resulting from mapping special characters</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.11.1</span></a></div></div>
<p class="asd_par">
The first kind of zoem escape introducing device scope is <tt>\@{..}</tt>.
The second kind comprises the <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> mappings, including the
three zoem glyphs <tt>\~</tt>, <tt>\|</tt>, and <tt>\-</tt>. Conventionally, these
are used to encode a non-breaking space (<tt>&nbsp;</tt> in html), a line break
(<tt><br></tt> in html), and a long dash (emdash, not present in html).
You would for example put</p>
<div class="verbatim">\if{\cmp{eq}{\__device__}{html}}{
\special{
{38} {&amp;} \: 38 is ascii character '&'
{60} {&lt;} \: 60 -> '<'
{62} {&gt;} \: 62 -> '>'
{-1} {&nbsp;} \: the zoem escape \~
{-2} {<br>\!N} \: the zoem escape \|
{-3} {-} \: the zoem escape \-
}
}{
}</div>
<p class="asd_car">
All <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> definitions are interpreted in device scope. For every
character encountered in plain scope, it is checked whether a
<a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> definition exists, if so, the corresponding string is
retrieved and this is filtered through the device scope filter.
Note that the three zoem glyphs described here
may not be used in device scope, they can only be used in plain scope. In
device scope you will have to write the explicit, device-specific sequence
such as <tt><br></tt> (in html).</p>
<p class="asd_par">
The <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> primitive allows different levels of mappings
to be defined simultaneously. Several definitions of the same
character are allowed; these are placed on a stack particular
to that character (cf. the
<a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> entry).
When zoem encounters a character for which
one or more mappings exist, it retrieves a mapping
using the <i>special level</i>. This is an integer that has by
default the value <tt>1</tt>. Each open output stream has a unique
special level associated with it. [Output streams exist
for the <i>default output file</i> (see e.g. <a class="intern" href="#writeto_1"><span class="zpr">\writeto#1</span></a>) and
for each file openend by <a class="intern" href="#write_3"><span class="zpr">\write#3</span></a>].
A mapping is retrieved using this rule: <i>The deepest element
is fetched for which the depth does not exceed the level</i>.
The most visible element (which is the element first occurring
in the <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> invocation) has depth <tt>1</tt>.</p>
<p class="asd_par">
The presence of different levels comes in handy e.g. when the troff
device is used. In some contexts, the double quote
is a special character in troff (and a printable quote is then
mysteriously represented by <i>two consecutive double quotes</i>),
in most contexts it is not.
This is combatted by including these two specifications in the
<tt>\special#1</tt> call preparing for troff output (note that 34 is
the <abbr class="ucase" title="American Standard Code for Information Interchange">ASCII</abbr> value representing the double quote):</p>
<div class="verbatim">\special{
...
{34}{"}
{34}{""}
{92}{\\e}
...
}</div>
<p class="asd_car">
The first pair shown simply maps the double quote onto itself, and the second
pair maps it onto a double double quote. As long as the special level
is <tt>1</tt>, the second definition is not used. The backslash (with <abbr class="ucase" title="American Standard Code for Information Interchange">ASCII</abbr> value
<tt>92</tt>) needs only one definition as it is escaped in the same way in all
troff contexts.</p>
<p class="asd_par">
The special level can
be set using the <tt>\+</tt> directive, which must be followed
immediately by a digit in the range <tt>0-9</tt> enclosed by curly brackets,
e.g. <tt>\@{\+{2}}</tt> will set the special level to <tt>2</tt>.
The special level <i>can</i> be set to <tt>0</tt> (zero) and this means
that no character will be mapped.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Example</span>
Double quotes need to be escaped in certain troff contexts.
This is achieved by the following.</p>
<div class="verbatim">\@{\+{2}"} ... funny quote context ... \@{"\+{1}}</div>
<p class="asd_car">
Such a context is typically encapsulated by a macro defined in a package; its
definition should never be visibile to the user of the package.
Note that the double quotes embedded in <i>at</i> scope in the example
above are not susceptible to special mapping — mapping is only
applied in plain scope.</p>
<a name="glyph"></a><div class="sec_leader sec_lev3"><div class="sec_title"><a class="intern" href="#glyph">Device scope resulting from glyph definitions</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.11.2</span></a></div></div>
<p class="asd_par">
The third kind of device scope strings are those mapped to by the
<a class="intern" href="#constant_1"><span class="zpr">\constant#1</span></a> primitive. An example of (toy) usage is this:</p>
<div class="verbatim">\constant{
{'e} {&eacute;} \: Use e.g. as \*{'e}l\*{`e}ve (élève)
{(c)} {&copy;} \: Use e.g. as \*{(c)} DEEDEE (© DEEDEE)
{+-} {&plusmn;} \: Use e.g. as \*{+-} a few (± a few)
}</div>
<p class="asd_car">
This is largely convenient syntactic sugar. These constants
could also have been defined as</p>
<div class="verbatim"> \def{"'e"}{\@{&eacute;}}
\def{"(c)"}{\@{&copy;}}
\def{"+-"}{\@{&plusmn;}}</div>
<p class="asd_car">
The idea is that the <tt>\*{..}</tt> namespace is used for glyph-like
device-specific bindings, whereas the <tt>\".."</tt> namespace is used for
semantic purposes that are device-independent, but nothing prohibits you
from fiddling with this.</p>
<a name="xmlsugar"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#xmlsugar"><abbr class="ucase" title="Standard Generalized Markup Language">SGML</abbr>/<abbr class="ucase" title="Hyper Text Markup Language">HTML</abbr>/<abbr class="ucase" title="Extensible Markup Language">XML</abbr> syntactic sugar cubes</a></div><div class="sec_num"><a class="intern" href="#toc5"><span class="sec_num">5.12</span></a></div></div>
<p class="asd_par">
Zoem provides a shorthand for entering <abbr class="ucase" title="Standard Generalized Markup Language">SGML</abbr>-style tags.
It is checked by zoem for well-formedness of the resulting <abbr class="ucase" title="Standard Generalized Markup Language">SGML</abbr> code,
and it can be freely mixed with other modes of entering tags.
Normally you would
have to enter <abbr class="ucase" title="Standard Generalized Markup Language">SGML</abbr>-style tags in device scope,
or write a macro for doing that.
For example,
a macro <tt>x#2</tt> that expands <tt>\x{b}{be bold}</tt> to
<tt>\@{<b>}be bold\@{</b>}</tt> is a likely candidate.
However, this would be inelegant for constructions that span
a long distance, and it does not provide for letting zoem expressions
expand within an xml tag.</p>
<p class="asd_par">
Zoem provides the <tt>\<</tt> token. It can be used in several ways:</p>
<div class="verbatim">
\<foo> \: foo can be an expression.
Some <content> \: of course, expressions may occur here as well.
over here.
\<bar>{zut} \: bar can be an expression too;
\: this syntax will close itself.
Some <content> \: again, expressions may occur here as well.
over there.
\<> \: this is a closing tag for the first foo. \</foo> works too.
\<tim x=y/> \: zoem knows this closes itself.
\<*br> \: zoem converts this to <br>
</div>
<p class="asd_car">
Suppose that foo, bar, and zut are zoem expressions expanding
to strings FOO, BAR, and ZUT respectively (FOO and BAR might be of the form
<tt>tag a="b" c="d"</tt>). Provided that the characters <tt><</tt>, <tt>></tt>,
and <tt>&</tt> are automatically mapped in plain scope (as a result of correct
<a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> usage), the above will result in</p>
<div class="verbatim"> <FOO>
Some &lt;content&gt;
over here.
<BAR>
ZUT
</BAR>
Some &lt;content&gt;
over there.
</FOO>
<tim x=y/>
<br></div>
<p class="asd_car">
The <tt>foo</tt> part inside the <tt>\<foo></tt> syntax should never expand to
something containing a <tt>></tt>. This is entirely the responsibility of the
user or macro package author.</p>
<p class="asd_par">
Both kinds of syntax, <tt>\<foo></tt> and <tt>\<bar>{zut}</tt>, are kept as they are
during the expansion stage, and they can be subjected to multiple levels of
expansion (which may be the case if such syntax is used inside e.g.
<a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a> or <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>). It is only at the output stage that the
syntax is transformed to actual <abbr class="ucase" title="Standard Generalized Markup Language">SGML</abbr> code and that well-formedness is
checked. So, the two examples just seen will first transform to <tt>\<FOO></tt>
and <tt>\<BAR>{ZUT}</tt> (please note that foo, bar, and zut all denote
expressions here). If they are at that point no longer subject to expansion
they enter the output stage where they are converted to <tt><FOO></tt> and
<tt><BAR>ZUT</BAR></tt> (plus some additional formatting/indenting)
respectively.</p>
<p class="asd_par">
Zoem pushes on a stack of opening tags whenever it encounters <tt>\<foo></tt>
syntax during the output stage. It naturally knows that a tag can be
followed by attributes. It also knows that a tag such as <tt>\<tag a=b/></tt>
closes itself (<abbr class="ucase" title="Extensible Markup Language">XML</abbr> syntax), and the applies for <abbr class="ucase" title="Document Type Definition">DTD</abbr> tags such as
<tt>\<!ENTITY ...></tt>. As a special case, <tt>\<*tag foo bar zut></tt> is converted
to <tt><tag foo bar zut></tt> to allow encoding of <abbr class="ucase" title="Hyper Text Markup Language">HTML</abbr> tags such as <tt><meta></tt>,
<tt><link></tt>, and <tt><hr></tt>. This syntax is mandatory for tags that will not be
closed. Note that you should only use <tt>\<p></tt> if you are going to use
<tt>\</p></tt> or <tt>\<></tt> as well (because zoem requires closing tags for opening
tags). That said, the syntax <tt>\<p>{ paragraph content }</tt> is preferable in
most cases.
</p>
<p class="asd_par">
Zoem does not know about other ways of entering tags, so
<tt>\@{<body>}</tt> would not affect the stack just mentioned.
<tt>\<></tt> automatically closes
the top level opening tag from the stack. Again, syntax such as
<tt>\@{</body>}</tt> does not interact with the stack.
</p>
<p class="asd_par">
It is possible to explicitly close a tag by simply using <tt>\</foo></tt>
syntax. Zoem will check whether the closing tag matches the top level
opening tag. As seen before, <tt>\<></tt> does the same thing, but rather than
doing a check, zoem will use the top level opening tag to construct the
corresponding closing tag.</p>
<a name="section_6"></a><div class="sec_leader sec_lev1"><div class="sec_title"><a class="intern" href="#section_6">Zoem miscellanea</a></div><div class="sec_num"><a class="intern" href="#toc6"><span class="sec_num">6</span></a></div></div>
<a name="signature"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#signature">Key signatures</a></div><div class="sec_num"><a class="intern" href="#toc6"><span class="sec_num">6.1</span></a></div></div>
<p class="asd_par">
Several keys take another key as argument, e.g. they store a value in a
second key or check whether the second key exists. The full list of these
meta keys is <a class="intern" href="#def_2"><span class="zpr">\def#2</span></a>, <a class="intern" href="#defx_2"><span class="zpr">\defx#2</span></a>, <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a>, <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>,
<a class="intern" href="#undef_1"><span class="zpr">\undef#1</span></a>, <a class="intern" href="#defined_2"><span class="zpr">\defined#2</span></a>, <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>, and <a class="intern" href="#inspect_4"><span class="zpr">\inspect#4</span></a>. In all
cases, the argument key is passed as the first argument, by means of the
<b>key signature</b>.</p>
<p class="asd_par">
For a key <tt>\key</tt> taking <tt>k</tt> (<tt>k</tt>>0) arguments its signature is
<tt>key#k</tt>. The signature of a key <tt>\key</tt> taking no arguments is simply
<tt>key</tt>. The rule is: Key usage always includes a single
leading backslash (this activates the key). When a key is subject
of inspection, it is always referred to by its signature.</p>
<p class="asd_par">
Throughout this text, a key with signature <tt>key#k</tt> is mentioned
by means of its <b>key mention</b> <tt>\key#k</tt>, that is, for extra clarity
the backslash is prepended to the signature.</p>
<p class="asd_par">
As explained in <a class="intern" href="#namespaces">Primitives, built-ins and user macros</a>, almost all primitives
can be specified using quote syntax. The quote syntax is
integrated with signatures. This means that primitives that
expect a signature (such as <a class="intern" href="#def_2"><span class="zpr">\def#2</span></a>, <a class="intern" href="#undef_1"><span class="zpr">\undef#1</span></a>, and <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>)
accept quoted signatures too when the signature refers to
a primitive.</p>
<a name="anonymous"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#anonymous">Anonymous keys</a></div><div class="sec_num"><a class="intern" href="#toc6"><span class="sec_num">6.2</span></a></div></div>
<p class="asd_par">
A single underscore introduces an <b>anonymous key</b>. It is optionally
followed by a <tt>#k</tt> tag (for <tt>k</tt> in <tt>1..9</tt>), denoting the number of
arguments the anonymous key takes. An occurrence of the latter is called a
<b>tagged anonymous key</b>. The first argument to the key should be a key
definition, the other arguments are the arguments for that key definition.
If a tag is present, it is used for verifying that the anonymous key is used
properly.</p>
<div class="verbatim"> \_{\1 the \2}{row}{boat}
\_#2{\1 the \2}{row}{boat}</div>
<p class="asd_car">
results in</p>
<div class="verbatim"> row the boat
row the boat</div>
<p class="asd_car">
Anonymous keys may occur in the first argument of <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>, within the
first argument of <a class="intern" href="#inspect_4"><span class="zpr">\inspect#4</span></a>, and they may occur freely in running text.
The presence of a tag is required when an anonymous key is used
within either of <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a> and <a class="intern" href="#inspect_4"><span class="zpr">\inspect#4</span></a>.
An example of usage in <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>:</p>
<div class="verbatim">\apply{_#2{\1 kisses \2\|}}{{bill}{max}{max}{bill}}
bill kisses max
max kisses bill</div>
<p class="asd_car">
or even</p>
<div class="verbatim">\set{%foo}{{{\1 hugs \2\|}}}
\apply{_#2\%{foo}}{{bill}{max}{max}{bill}}
bill hugs max
max hugs bill</div>
<p class="asd_car">
Note that in order to store a block with <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a>, an extra pair of
curlies has to be used, as blocks can only be passed as a sub-argument of a
single-element <a class="intern" href="#vararg">vararg</a>. Also note that in a vararg it is
allowed to put white space inbetween the constituting elements.</p>
<a name="grape"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#grape">Tree data</a></div><div class="sec_num"><a class="intern" href="#toc6"><span class="sec_num">6.3</span></a></div></div>
<p class="asd_par">
Data can be organized in a global tree with a specialized use of
<a class="intern" href="#set_2"><span class="zpr">\set#2</span></a> and its siblings, as shown further below.
The data is retrieved from the tree using so called data keys.
Such a key is started using a percent sign, immediately followed
by zero, one, or more blocks, e.g. <tt>\%</tt>, <tt>\%{..}</tt>, and
<tt>\%{...}{...}{...}</tt> would all be allowable invocations.
If more than one block follows the percent sign,
there must be no interleaving white space.</p>
<p class="asd_par">
The underlying primitive has signature <tt>%#1</tt>, as the trailing scopes are
congregated into a single argument before they are further processed. The
two sibling primitives <tt>%free#1</tt> and <tt>%dump#1</tt> serve for freeing and
dumping parts or whole of the tree, as described further below.</p>
<p class="asd_par">
When applied to data keys, <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a> and its siblings set one or more
values in a global multi-dimensional associative array that we shall refer
to here as <tt>ROOT</tt>. Please note that <tt>ROOT</tt> is for explanatory purposes
only. This associative array is best viewed as a tree, in which every node
can have branches to higher nodes. A node may or may not contain a value.
Let us denote the value contained by a node <tt>some-node</tt> as
<tt>*(some-node)</tt>.
The fact that <tt>beta</tt> is a node one branch higher than <tt>alpha</tt>, which is
in turn one branch higher than <tt>ROOT</tt>, is denoted as
<tt>ROOT->"alpha"->"beta"</tt>.
In this <i>path</i> notation, strings indexing nodes in the trees are written
inbetween quotes. This has the advantage that the empty string, which is a
valid index string, has the representation <tt>""</tt>. Combining these
conventions, we write the value associated with <tt>beta</tt> as
<tt>*(ROOT->"alpha"->"beta")</tt>.
Consider these examples.</p>
<div class="verbatim">\set{%{foo}{bar}{zut}}{lez}
\: now *(ROOT->"foo"->"bar"->"zut") is "lez"
\set{%{foo}{bar}{zut}}{{a}{b}{x}{y}}
\: now *(ROOT->"foo"->"bar"->"zut"->"a") is "b"
\: and *(ROOT->"foo"->"bar"->"zut"->"x") is "y"
\: and *(ROOT->"foo"->"bar"->"zut") still is "lez"
\: some special cases
\set{%{foo}{bar}{zut}}{{{c}}}
\: now *(ROOT->"foo"->"bar"->"zut") is "{c}"
\set{%{foo}{bar}{zut}}{{c}}
\: now *(ROOT->"foo"->"bar"->"zut") is "c"
\set{%{foo}{bar}{zut}}{c}
\: now *(ROOT->"foo"->"bar"->"zut") is "c"
\set{{foo}{bar}{zut}}{{c}{d}{e}}
\: This does nothing, because the second argument
\: must either be an *even* vararg, a 1-element vararg,
\: or a simple argument.
\set{%{{tiger}}}{in the woods}
\: now *(ROOT->"{tiger}") is "in the woods"
\set{%{tiger}}{in the woods}
\: now *(ROOT->"tiger") is "in the woods"
\set{%tiger}{on the loose}
\: now *(ROOT->"tiger") is "on the loose"
\: stripping curlies from a vararg with one argument
\: does not make a difference with the exception of
\: the case shown below.
\set{%{}}{empty}
\: now *(ROOT->"") is "empty".
\set{%}{root}
\: now *(ROOT) is "root".</div>
<p class="asd_car">
Take note of the rule governing the second argument. If the first
non-white space character is a left curly, <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a> expects a
vararg. The vararg must either be even or it must contain exactly
<i>one</i> argument.</p>
<p class="asd_par">
An even vararg is interpreted as a sequence of key-value pairs.
Each key induces a new branch from the node specified in the first
argument, and each value is associated with the node at the end of
that branch.
If the vararg contains exactly one argument, that argument is simply used as
a value. This is the only way to specify a block as the value.
If the first non-white space character is not a curly, <tt>\set#2</tt> will
simply interpret the second argument as a value to append to the node
specified in the first argument.
It is possible to sidestep these issues by using <a class="intern" href="#set_3"><span class="zpr">\set#3</span></a> and
the directive <tt>u</tt> as argument to the <tt>modes</tt> key. This will cause
the value to be copied without further interpretation as a vararg
or block.
</p>
<p class="asd_par">
If you want the data to be stored to be expanded before it is bound,
use <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a> or <a class="intern" href="#defx_2"><span class="zpr">\defx#2</span></a>.</p>
<p class="asd_par">
Data is retrieved simply by prefixing the path with the <tt>\%</tt> token.
Example:</p>
<div class="verbatim">\set{%{foo}{bar}{zut}}{{a}{b}{x}{y}}
\%{foo}{bar}{zut}{a}
\%{foo}{bar}{zut}{x}</div>
<p class="asd_car">
will print <tt>b</tt> and <tt>y</tt>.
If the path is not an existing path in the current tree it will simply
be ignored, although an error message will be emitted.</p>
<p class="asd_par">
Whole or part of the data tree can be freed using the <tt>\%free</tt> primitive.
Again, simply append the access sequence in which you are interested. For
freeing the entire tree, use <tt>\%free</tt> without trailing scopes. The
<tt>\%free</tt> primitive largely exists for testing purposes to ensure that zoem
gets its internal data manipulation right.</p>
<p class="asd_par">
Whole or part of the data tree can be output for debugging purposes using
the <tt>\%dump</tt> primitive. Simply append the access sequence in which you are
interested. For printing the entire tree, use <tt>\%dump</tt> without trailing
scopes. This can be used for debugging if your data manipulation does not
work out as expected. There is no result text as far as usual processing is
concerned. The underlying primitive dumps its findings to <span class="smallcaps">STDOUT</span> in a
line-based textual representation of the data-tree.</p>
<a name="vararg"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#vararg">Of blocks and varargs</a></div><div class="sec_num"><a class="intern" href="#toc6"><span class="sec_num">6.4</span></a></div></div>
<p class="asd_par">
A <b>block</b> is a string beginning with a left curly and ending with a right
curly, the curlies being balanced. This is a convenient naming
convention. Blocks can be used in constructing anonymous keys; refer to the
<a class="intern" href="#anonymous">Anonymous keys</a> section.</p>
<p class="asd_par">
Some keys take a <i>vararg</i> argument, which is a single argument (enclosed
by curlies as are all arguments), which can contain any number of
sub-arguments, that is, a list consisting of blocks. Inbetween the blocks
white space may occur. The <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> and <a class="intern" href="#constant_1"><span class="zpr">\constant#1</span></a> keys both
take a single vararg argument, and the <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a> and <a class="intern" href="#switch_2"><span class="zpr">\switch#2</span></a> keys
each take a vararg as their second argument. For <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a> the first
argument is a key that is applied to subsequent batches of arguments from
that vararg. The <a class="intern" href="#table_5"><span class="zpr">\table#5</span></a> primitive takes a vararg as its last
argument. For examples, see the <a class="intern" href="#tour">A zoem tour</a> section and the <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>
entry.</p>
<p class="asd_par">
An <b>even vararg</b> is a vararg with an even number of elements,
An <b>odd vararg</b> is a vararg with an odd number of elements.</p>
<p class="asd_par">
User keys may check whether an argument is a vararg
by employing the <a class="intern" href="#nargs_1"><span class="zpr">\nargs#1</span></a> primitve. This can be used to
take different actions depending on the structure of the argument.</p>
<a name="session"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#session">Session keys</a></div><div class="sec_num"><a class="intern" href="#toc6"><span class="sec_num">6.5</span></a></div></div>
<p class="asd_car">
This is a compact listing of session keys, created
by issuing <tt>zoem -l session</tt>.</p>
<div class="verbatim">
Predefined session variables
\$__args__ (local to env) key/value pairs given to \begin#2
\$__xargs__ (local to env) key/value pairs given to \begin#2, expanded
\__device__ name of device (given by -d)
\__fnbase__ base name of entry file (given by -i/-I)
\__fnentry__ name of entry file (given by -i/-I)
\__fnin__ name of current input file
\__fnout__ name of current output file
\__fnpath__ path component of entry file (given by -i/-I)
\__fnwrite__ arg1 to \write#3, accessible in arg3 scope
\__lc__ expands to a left curly (only for magic)
\__line__ index of current input line
\__parmode__ paragraph slurping mode for interactive sessions
\__rc__ expands to a right curly (only for magic)
\__searchpath__ search path for macro packages (e.g. man.zmm)
\__split__ user space toggle for chapter mode indicator
\__sysval__ exit status of last system command
\__version__ version of zoem, formatted as e.g. 2003, 2004-010
\__zoemput__ result text of last \try#1 key
\__zoemstat__ status of last \try#1 key</div>
<p class="asd_car">
This manual is littered with examples of the usage of <a class="intern" href="#session"><tt>\__device__</tt></a>. The
<a class="intern" href="#session"><tt>\__fnbase__</tt></a> key is useful for creating sibling files of the entry file,
i.e. a table of contents file or a file containing reference information. I
have the habit of naming those <a class="intern" href="#session"><tt>\__fnbase__.zmt</tt></a> and <a class="intern" href="#session"><tt>\__fnbase__.zmr</tt></a>,
respectively. The <a class="intern" href="#session"><tt>\__fnin__</tt></a> key is useful for emitting log, warning, or
error messages particular to the file currently being parsed. The
<a class="intern" href="#session"><tt>\__parmode__</tt></a> macro affects the way in which zoem reads chunks in
interactive mode (refer to Section <a class="intern" href="#cline">Invoking zoem from the command line</a>). The <a class="intern" href="#session"><tt>\__searchpath__</tt></a>
macro is one of the ways in which zoem can be instructed to search for files
in a set of locations, when confronted with <a class="intern" href="#dofile_2"><span class="zpr">\dofile#2</span></a> or one of its
built-in aliases. Section <a class="intern" href="#searchpath">File search path</a> has more information about
the mechanism of file location. See also <a class="local sibling" href="zoem.html#session">the zoem
manual</a>.</p>
<a name="builtin"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#builtin">Built-in macros</a></div><div class="sec_num"><a class="intern" href="#toc6"><span class="sec_num">6.6</span></a></div></div>
<p class="asd_par">
This is the result from doing <tt>zoem -l builtin</tt>:</p>
<div class="verbatim">
Built-in aliases
done maps to \'throw{done}
ifdef#3 maps to \'if{\defined{\1}{\2}}{\3}{}
ifdef#4 maps to \'if{\defined{\1}{\2}}{\3}{\4}
input#1 maps to \'dofile{\1}{!+}
import#1 maps to \'dofile{\1}{!-}
read#1 maps to \'dofile{\1}{?+}
load#1 maps to \'dofile{\1}{?-}
begin#1 maps to \'begin{\1}{}
env#3 maps to \'env{\1}{}{\2}{\3}
system#2 maps to \'system{\1}{\2}{}
system#1 maps to \'system{\1}{}{}
throw#1 maps to \'throw{\1}{}
inform#1 maps to \'write{stderr}{device}{\1\@{\N}}
append#2 maps to \'set{{modes}{a}}{\1}{\2}
appendx#2 maps to \'set{{modes}{ax}}{\1}{\2}
seq#4 maps to \'set{\1}{\2}\'while{\'let{\'get{''}{\1}<\3}}{\4\'setx{\1}{\'let{\'get{''}{\1}+1}}}
update#2 maps to \'set{{modes}{e}}{\1}{\2}
updatex#2 maps to \'set{{modes}{ex}}{\1}{\2}
"" maps to (nothing)
""#1 maps to (nothing)
group#1 maps to \1
PI maps to 3.1415926536
E maps to 2.71828182846
$#1 maps to \'switch{\__device__}{\1}
$#3 maps to \'switch{\__device__}{{\1}{\2}{\3}}</div>
<a name="dictionary"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#dictionary">Dictionary stacks</a></div><div class="sec_num"><a class="intern" href="#toc6"><span class="sec_num">6.7</span></a></div></div>
<p class="asd_par">
By default, when using <a class="intern" href="#def_2"><span class="zpr">\def#2</span></a> and <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a>, keys and their values are
put in a global user dictionary. It could be useful to shadow keys by
entering a new name scope. Zoem facilitates this by providing the
<a class="intern" href="#push_1"><span class="zpr">\push#1</span></a> and <a class="intern" href="#pop_1"><span class="zpr">\pop#1</span></a> keys. These push and pop a new dictionary onto/from
the user dictionary stack.</p>
<p class="asd_par">
A second dictionary stack is the <i>dollar dictionary stack</i>, which
contains all keys that start with a dollar sign.
The <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> primitive pushes a dollar dictionary each
time it is invoked, and that dictionary is popped by the corresponding
<a class="intern" href="#end_1"><span class="zpr">\end#1</span></a> invocation. This is typically useful for creating nested
environments that need access to the same type of information - by storing
such information in dollar keys, it can be shadowed and recovered. Refer to
the <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> entry.</p>
<p class="asd_par">
When a key is used its definition is searched in all dictionaries, starting
from the top-level dictionary. The key <a class="intern" href="#undef_1"><span class="zpr">\undef#1</span></a> has only access to the
top-level dictionary, and will never delete a key in any other dictionary.</p>
<a name="tour"></a><div class="sec_leader sec_lev1"><div class="sec_title"><a class="intern" href="#tour">A zoem tour</a></div><div class="sec_num"><a class="intern" href="#toc7"><span class="sec_num">7</span></a></div></div>
<p class="asd_par">
What follows is an informal tour through zoem's offerings. The next
section contains a comprehensive overview of the zoem primitives.</p>
<p class="asd_par">
Let us start with how filtering in plain space is configured.
The following was obtained from the
<a target="_parent" class="extern" href="http://micans.org/pud/"><acronym class="ucase" title="Portable Unix Documentation">PUD</acronym></a> man macros.</p>
<div class="verbatim">\switch{\__device__}{
{html}{
\special{
{38} {&amp;}
{60} {&lt;}
{62} {&gt;}
{-1} {&nbsp;} \: the zoem escape \~
{-2} {<br>\!N} \: the zoem escape \|
{-3} {-} \: the zoem escape \-
}
}
{roff}{
\special{
{46} {\\.}
{96} {\\`}
{92} {\\\\} \: a single backslash
{-1} {\\ } \: the zoem escape \~
{-2} {\!N.br\!N} \: the zoem escape \|
{-3} {\\-} \: the zoem escape \-
}
}
{\write{stderr}{txt}{No such device: \__device__\|}
\write{\__fnbase__.err}{txt}{No such device: \__device__\|}
\exit
}
}</div>
<p class="asd_car">
Take note of the number of backslashes. In order to print a backslash
in troff, the troff input must contain two consecutive backslashes.
In order to specify a backslash in zoem, we must also provide two,
thus we need four backslashes in all (in order to create this example
I needed eight backslashes in the zoem input).</p>
<p class="asd_par">
Also note the use of the <a class="intern" href="#switch_2"><span class="zpr">\switch#2</span></a> primitive, which takes
an expression in the first argument and an arbitrary number of pairs plus an
optional clause in the second argument. The optional clause was in this case
used as a failure test.</p>
<p class="asd_par">
<a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> is an example of a zoem key taking an argument that may
contain arbitrarily many sub-arguments
(i.e. a <a class="intern" href="#vararg">vararg</a>).
In this particular case the
sub-arguments must be paired, each pair defining how certain
characters that are special to the device must be represented.</p>
<p class="asd_par">
The <a class="intern" href="#write_3"><span class="zpr">\write#3</span></a> and <a class="intern" href="#exit"><span class="zpr">\exit</span></a> need little comment, they work as
expected. Zoem opens output files as needed, and closes them when it is
done. The file name <tt>-</tt> is equivalent to
either <span class="smallcaps">STDOUT</span> or <span class="smallcaps">STDIN</span> (depending on context),
the file name <tt>stderr</tt> denotes <span class="smallcaps">STDERR</span>.</p>
<p class="asd_par">
<a class="intern" href="#exit"><span class="zpr">\exit</span></a> is considered a failure (and will cause zoem to stop and
complain), but <tt>\throw{done}</tt> is not. <a class="intern" href="#throw_2"><span class="zpr">\throw#2</span></a> with argument <tt>done</tt> will
merely quit parsing the current stack, so if you specify it at top level in
a file — not nested in a key that does its own parsing such as <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>,
zoem will stop parsing the current file and transfer control back to the
file from which it was included.</p>
<p class="asd_par">
The previous example introduces the keys <a class="intern" href="#session"><tt>\__device__</tt></a> and
<a class="intern" href="#session"><tt>\__fnbase__</tt></a>. They are so called session variables
described in section <a class="intern" href="#session">Session keys</a>.</p>
<p class="asd_par">
A sibling primitive to <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> is <a class="intern" href="#constant_1"><span class="zpr">\constant#1</span></a>. The
following is an example of use.</p>
<div class="verbatim">\constant{
{'e} {&eacute;} \: Use e.g. as \*{'e}l\*{`e}ve (élève)
{(c)} {&copy;} \: Use e.g. as \*{(c)} DEEDEE (© DEEDEE)
{+-} {&plusmn;} \: Use e.g. as \*{+-} a few (± a few)
}</div>
<p class="asd_car">
The main thing to note here is that the target string (e.g. <tt>&eacute;</tt>)
is <i>always interpreted in device space</i>. In the reference string (e.g.
<tt>'e</tt>, <tt>(c)</tt> and <tt>+-</tt> in the example above) almost anything is allowed,
including backslash-escaped characters and balanced curlies.
The latter are not recommended though.
</p>
<p class="asd_par">
There are three zoem tokens representing the characters that have meaning to
zoem syntax, the backslash and the two curlies. Those zoem tokens are just
like any other plain characters: they can be mapped in plain space, and they
are printed literally in device space.</p>
<div class="verbatim"> \\ \: A backslash; possibly mapped in plain space.
\{ \: A curly; possibly mapped in plain space.
\} \: A curly; possibly mapped in plain space.
\, \: The atomic separator (vanishes).</div>
<p class="asd_car">
These tokens are mapped only during the (final) filter stage.
The atomic separator can be useful when you want to glue together
items some of which will be the result of macro expansion.</p>
<div class="verbatim"> \def{foo}{bar}
\foo\,1 \: \foo1 would be the key \foo1</div>
<p class="asd_car">
This will result in bar1. The tokens <tt>\\</tt>, <tt>\{</tt>, and <tt>\}</tt>
are really the corresponding ordinary characters.
They can be mapped in plain space via <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> using their
<abbr class="ucase" title="American Standard Code for Information Interchange">ASCII</abbr> values 92, 123, and 125 as was seen above for the backslash.
In device space, they will result in <tt>\</tt>, <tt>{</tt>, and <tt>}</tt>.</p>
<p class="asd_par">
Let us now continue with device scope by implementing a <tt>\bf#1</tt> key.
Below you find two possible definitions:</p>
<div class="verbatim"> \def{bf}{1}{\@{<b>} \1 \@{</b>}} \: OK
\def{bf}{1}{\@{<b> \1 </b>}} \: Wrong! Wrong!</div>
<p class="asd_car">
The second is wrong because the contents of <tt>\1</tt> end up in device
space. If the expansion of <tt>\1</tt> still contains keys they will not be
expanded (and cause a fatal syntax error when device space is filtered),
and additionally any special characters in <tt>\1</tt> will not be
mapped.</p>
<a name="language"></a><div class="sec_leader sec_lev1"><div class="sec_title"><a class="intern" href="#language">The zoem language</a></div><div class="sec_num"><a class="intern" href="#toc8"><span class="sec_num">8</span></a></div></div>
<a name="section_8_1"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#section_8_1">Alphabetic index</a></div><div class="sec_num"><a class="intern" href="#toc8"><span class="sec_num">8.1</span></a></div></div>
<a href="#excl">
<tt>\!</tt>
</a>
<a href="#excl_1">
<tt>\!#1</tt>
</a>
<a href="#dollar_2">
<tt>\$#2</tt>
</a>
<a href="#apply_2">
<tt>\apply#2</tt>
</a>
<a href="#begin_2">
<tt>\begin#2</tt>
</a>
<a href="#catch_2">
<tt>\catch#2</tt>
</a>
<a href="#cmp_3">
<tt>\cmp#3</tt>
</a>
<a href="#constant_1">
<tt>\constant#1</tt>
</a>
<a href="#def_2">
<tt>\def#2</tt>
</a>
<a href="#defx_2">
<tt>\defx#2</tt>
</a>
<a href="#defined_2">
<tt>\defined#2</tt>
</a>
<a href="#dofile_2">
<tt>\dofile#2</tt>
</a>
<a href="#dowhile_2">
<tt>\dowhile#2</tt>
</a>
<a href="#__env___1">
<tt>\__env__#1</tt>
</a>
<a href="#end_1">
<tt>\end#1</tt>
</a>
<a href="#env_4">
<tt>\env#4</tt>
</a>
<a href="#eqt_3">
<tt>\eqt#3</tt>
</a>
<a href="#branch_1">
<tt>\branch#1</tt>
</a>
<a href="#eval_1">
<tt>\eval#1</tt>
</a>
<a href="#exit">
<tt>\exit</tt>
</a>
<a href="#f_2">
<tt>\f#2</tt>
</a>
<a href="#f_3">
<tt>\f#3</tt>
</a>
<a href="#fv_2">
<tt>\fv#2</tt>
</a>
<a href="#finsert_1">
<tt>\finsert#1</tt>
</a>
<a href="#format_2">
<tt>\format#2</tt>
</a>
<a href="#formatted_1">
<tt>\formatted#1</tt>
</a>
<a href="#get_2">
<tt>\get#2</tt>
</a>
<a href="#if_3">
<tt>\if#3</tt>
</a>
<a href="#inspect_4">
<tt>\inspect#4</tt>
</a>
<a href="#length_1">
<tt>\length#1</tt>
</a>
<a href="#let_1">
<tt>\let#1</tt>
</a>
<a href="#nargs_1">
<tt>\nargs#1</tt>
</a>
<a href="#pop_1">
<tt>\pop#1</tt>
</a>
<a href="#protect_1">
<tt>\protect#1</tt>
</a>
<a href="#push_1">
<tt>\push#1</tt>
</a>
<a href="#register_2">
<tt>\register#2</tt>
</a>
<a href="#set_2">
<tt>\set#2</tt>
</a>
<a href="#setx_2">
<tt>\setx#2</tt>
</a>
<a href="#set_3">
<tt>\set#3</tt>
</a>
<a href="#special_1">
<tt>\special#1</tt>
</a>
<a href="#switch_2">
<tt>\switch#2</tt>
</a>
<a href="#system_3">
<tt>\system#3</tt>
</a>
<a href="#table_5">
<tt>\table#5</tt>
</a>
<a href="#textmap_2">
<tt>\textmap#2</tt>
</a>
<a href="#throw_2">
<tt>\throw#2</tt>
</a>
<a href="#tr_2">
<tt>\tr#2</tt>
</a>
<a href="#trace_1">
<tt>\trace#1</tt>
</a>
<a href="#try_1">
<tt>\try#1</tt>
</a>
<a href="#undef_1">
<tt>\undef#1</tt>
</a>
<a href="#vanish_1">
<tt>\vanish#1</tt>
</a>
<a href="#while_2">
<tt>\while#2</tt>
</a>
<a href="#whilst_2">
<tt>\whilst#2</tt>
</a>
<a href="#write_3">
<tt>\write#3</tt>
</a>
<a href="#writeto_1">
<tt>\writeto#1</tt>
</a>
<a href="#zinsert_1">
<tt>\zinsert#1</tt>
</a>
<a name="topicindex"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#topicindex">Topic index</a></div><div class="sec_num"><a class="intern" href="#toc8"><span class="sec_num">8.2</span></a></div></div>
<p class="asd_par">
This is an overlapping categorization in topics.
</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Using and inspecting keys</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>
<a class="intern" href="#constant_1"><span class="zpr">\constant#1</span></a>
<a class="intern" href="#def_2"><span class="zpr">\def#2</span></a>
<a class="intern" href="#defined_2"><span class="zpr">\defined#2</span></a>
<a class="intern" href="#defx_2"><span class="zpr">\defx#2</span></a>
<a class="intern" href="#inspect_4"><span class="zpr">\inspect#4</span></a>
<a class="intern" href="#pop_1"><span class="zpr">\pop#1</span></a>
<a class="intern" href="#push_1"><span class="zpr">\push#1</span></a>
<a class="intern" href="#set_2"><span class="zpr">\set#2</span></a>
<a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>
<a class="intern" href="#table_5"><span class="zpr">\table#5</span></a>
<a class="intern" href="#undef_1"><span class="zpr">\undef#1</span></a>
<p class="asd_par">
These primitives affect or use either <i>user keys</i> that are
stored in the user dictionary,
<i>dollar keys</i> that are stored in the dollar dictionary,
or <i>anonymous keys</i>. Dictionaries are discussed in
<a class="intern" href="#dictionary">Section 6.7</a>.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Control, booleans, testing and comparison</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#dollar_2"><span class="zpr">\$#2</span></a>
<a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>
<a class="intern" href="#branch_1"><span class="zpr">\branch#1</span></a>
<a class="intern" href="#cmp_3"><span class="zpr">\cmp#3</span></a>
<a class="intern" href="#defined_2"><span class="zpr">\defined#2</span></a>
<a class="intern" href="#dowhile_2"><span class="zpr">\dowhile#2</span></a>
<a class="intern" href="#eqt_3"><span class="zpr">\eqt#3</span></a>
<a class="intern" href="#if_3"><span class="zpr">\if#3</span></a>
<a class="intern" href="#length_1"><span class="zpr">\length#1</span></a>
<a class="intern" href="#register_2"><span class="zpr">\register#2</span></a>
<a class="intern" href="#switch_2"><span class="zpr">\switch#2</span></a>
<a class="intern" href="#undef_1"><span class="zpr">\undef#1</span></a>
<a class="intern" href="#while_2"><span class="zpr">\while#2</span></a>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Expansion, delay</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#excl"><span class="zpr">\!</span></a>
<a class="intern" href="#excl_1"><span class="zpr">\!#1</span></a>
<a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>
<a class="intern" href="#defx_2"><span class="zpr">\defx#2</span></a>
<a class="intern" href="#eval_1"><span class="zpr">\eval#1</span></a>
<a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Meta-zoem, introspection, exceptions, errors</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#catch_2"><span class="zpr">\catch#2</span></a>
<a class="intern" href="#exit"><span class="zpr">\exit</span></a>
<a class="intern" href="#throw_2"><span class="zpr">\throw#2</span></a>
<a class="intern" href="#try_1"><span class="zpr">\try#1</span></a>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Execution, tracing</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#trace_1"><span class="zpr">\trace#1</span></a>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Input/output</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#dofile_2"><span class="zpr">\dofile#2</span></a>
<a class="intern" href="#finsert_1"><span class="zpr">\finsert#1</span></a>
<a class="intern" href="#format_1"><span class="zpr">\format#1</span></a>
<a class="intern" href="#register_2"><span class="zpr">\register#2</span></a>
<a class="intern" href="#vanish_1"><span class="zpr">\vanish#1</span></a>
<a class="intern" href="#write_3"><span class="zpr">\write#3</span></a>
<a class="intern" href="#writeto_1"><span class="zpr">\writeto#1</span></a>
<a class="intern" href="#zinsert_1"><span class="zpr">\zinsert#1</span></a>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Filtering</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#special_1"><span class="zpr">\special#1</span></a>
<a class="intern" href="#vanish_1"><span class="zpr">\vanish#1</span></a>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Environment scopes</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a>
<a class="intern" href="#end_1"><span class="zpr">\end#1</span></a>
<a class="intern" href="#env_4"><span class="zpr">\env#4</span></a>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Name scopes</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#pop_1"><span class="zpr">\pop#1</span></a>
<a class="intern" href="#push_1"><span class="zpr">\push#1</span></a>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Data storage</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<tt>\%</tt>, <tt>\%free</tt>, and <tt>\%dump</tt> are primitives described elsewhere
— refer to the <a class="intern" href="#grape">Tree data</a> section.
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>String conversions</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#format_2"><span class="zpr">\format#2</span></a>
<a class="intern" href="#inspect_4"><span class="zpr">\inspect#4</span></a>
<a class="intern" href="#length_1"><span class="zpr">\length#1</span></a>
<a class="intern" href="#textmap_2"><span class="zpr">\textmap#2</span></a>
<a class="intern" href="#tr_4"><span class="zpr">\tr#4</span></a>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Arithmetic</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#f_2"><span class="zpr">\f#2</span></a>
<a class="intern" href="#f_3"><span class="zpr">\f#3</span></a>
<a class="intern" href="#fv_2"><span class="zpr">\fv#2</span></a>
<a class="intern" href="#let_3"><span class="zpr">\let#3</span></a>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Glyphs</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#constant_1"><span class="zpr">\constant#1</span></a>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><b>Syntactic sugar</b></div></div></div>
<div class=" item_text " style="margin-left:2em">
<a class="intern" href="#formatted_1"><span class="zpr">\formatted#1</span></a>
<a class="intern" href="#vanish_1"><span class="zpr">\vanish#1</span></a>
<a class="intern" href="#xmlpr1"><tt>\<>#1</tt></a>
<a class="intern" href="#xmlpr2"><tt>\<>#2</tt></a>
</div>
</div>
<a name="section_8_3"></a><div class="sec_leader sec_lev2"><div class="sec_title"><a class="intern" href="#section_8_3">Primitives</a></div><div class="sec_num"><a class="intern" href="#toc8"><span class="sec_num">8.3</span></a></div></div>
<p class="asd_par">
Zoem primitives may expand (which is the same as evaluate) one, several, or all
of their arguments before using them. Such arguments are enclosed by double
angle brackets in the listing below. The inside-out type evaluation is done
recursively and works for arbitrary levels of nesting. An argument which is
first expanded and is then interpreted as a label is thus written
<tt><label></tt> in the primary entry. In the definition text accompanying the
entry, the expanded argument is simply refered to as <tt><label></tt>, so the extra
pair of brackets is dropped.
</p>
<p class="asd_par">
Each primitive below has a little paragraph with the caption
<b>Result text</b>. It gives a summary of 'what comes out'.
Note that the result of macro expansion is always passed to the parser
again, so the result text is again subject to expansion.
</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div class="" style="margin-top:0em"><div class=" item_cascade item_leftalign nowrap" style=""><a name="xmlpr1"><tt>\<>#1</tt></a></div><div class=" item_cascade item_leftalign nowrap" style=""><a name="xmlpr2"><tt>\<>#2</tt></a></div></div>
<div class=" item_text " style="margin-left:2em">
These are special. Refer to section <a class="intern" href="#xmlsugar"><abbr class="ucase" title="Standard Generalized Markup Language">SGML</abbr>/<abbr class="ucase" title="Hyper Text Markup Language">HTML</abbr>/<abbr class="ucase" title="Extensible Markup Language">XML</abbr> syntactic sugar cubes</a>.
The angle brackets are part of the syntax, do not confuse them
with the angle brackets used below to enclose arguments.
These primitives are respectively used as <tt>\<*any*></tt> and
<tt>\<*any*>{*any*}</tt>,
so the positioning of arguments is different from all other
zoem primitives.
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="excl">
</a>
<tt>\!</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
This primitive is triggered by an active backslash followed by a consecutive
run of exclamation marks, which is <i>not</i> followed by an opening curly.
The sequence is called a <i>delay sequence</i>, and its <i>arity</i> is the
count of backslashes. A single exclamation mark is stripped (i.e. the arity
is decremented) and the sequence is no longer subject to the current
expansion stage. It is used to construct valid zoem input, which is usually
redirected to file with the copy filter, stored using <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>, or used
in nested occurrences of <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>, <a class="intern" href="#inspect_4"><span class="zpr">\inspect#4</span></a>, and other primitives.
Other uses are possible, the main thing is that one should keep a clear view
of the meta-programming implied by <tt>\!</tt>.
Refer also to the <a class="intern" href="#eval_1"><span class="zpr">\eval#1</span></a> primitive.
<p class="asd_cpar"><span class="asd_cpar_caption">Example</span>
The primitive <a class="intern" href="#eval_1"><span class="zpr">\eval#1</span></a> evaluates its argument a single time,
and passes it on for further evaluation.
The following are fully equivalent:
</p>
<div class="verbatim">\set{foo}{zut}
\eval{\!foo}
\foo</div>
<p class="asd_car">
whereas <tt>\!foo</tt> would pass the sequence <tt>\foo</tt> to the filtering stage,
where it will yield a (non-fatal) error message.
Similarly, <tt>\eval{\eval{\!!foo}}</tt> is equivalent to the above.
</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
A delay sequence of decremented arity.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="excl_1">
</a>
<tt>\!#1</tt>: <tt>\!{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
This primitive is triggered by an active backslash followed by a consecutive
run of exclamation marks, which is in turn followed by a block. The block
is called a <i>delay</i> scope. The arity of the delay scope is the count of
backslashes found in the run. A single exclamation mark is stripped (i.e.
the arity is decremented); if no further exclamation marks remain (i.e. the
arity becomes zero) then the introducing backslash and the delimiting
curlies are stripped as well. The result (including the contents of the
block) is passed on and is no longer subject to the current expansion stage.
The same observations hold as those made for the previous entry.
Refer also to the <a class="intern" href="#eval_1"><span class="zpr">\eval#1</span></a> primitive.
</p>
<p class="asd_par">
Additionally, blocks that are protected by the delay primitive will be
skipped during parameter interpolation.
</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
<tt><any></tt>, if the arity of the delay scope just found was equal to one,
otherwise, <tt><any></tt> put in a decremented delay scope. <tt><any></tt> will in
both case no longer be subject to the current expansion stage.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="dollar_2">
</a>
<tt>\$#2</tt>: <tt>\${<str>}{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
This is a shortcut for activating output for a particular device.
If <a class="intern" href="#session"><tt>\__device__</tt></a> expands to <tt><str></tt>, <tt><any></tt>
is passed on for expansion, otherwise it is ignored.
The following two are equivalent:
<div class="verbatim">\${html}{Seen only in the html device}
\if{\cmp{eq}{\__device__}{html}}{Seen only in the html device}{}</div>
<p class="asd_ccar"><span class="asd_ccar_caption">Result text</span>
Either none or <tt><any></tt>.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="apply_2">
</a>
<tt>\apply#2</tt>: <tt>\apply{<<key-sig|anon-key>>}{<<vararg>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The first argument is expanded before use.
It should expand either to the signature of a user key, primitive or builtin
taking arguments, or to a <a class="intern" href="#anonymous">tagged anonymous key</a>. Examples
of the first are <tt>foo#k</tt> and <tt>"bar::baz"#k</tt>, the latter takes the form
<tt>_#k{..}</tt>. If you use an anonymous key containing macro sequences, be
sure to escape whole or part of the anonymous key, depending on your needs.
The expansion of <tt>_#2\!{{<any>}}</tt> for example, will result in
<tt>_#2{<any>}</tt>. Primitives can used in both quoted and regular syntax.</p>
<p class="asd_par">
The second argument should result in a vararg. <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a> extracts
<tt>k</tt> elements at a time from <tt><vararg></tt>,
and applies the key resulting from
the first argument to each vector of <tt>k</tt> elements successively.
Any elements remaining in <tt><vararg></tt> are ignored.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
Entirely depending on the key specified in the first argument.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="begin_2">
</a>
<tt>\begin#2</tt>: <tt>\begin{<label>}{<<vararg>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
<a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> pushes a new dictionary onto the dollar dictionary stack which
is popped by the matching <a class="intern" href="#end_1"><span class="zpr">\end#1</span></a>.</p>
<p class="asd_par">
<tt>\begin#1</tt> is an alias which invokes <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> with an empty
<tt><vararg></tt> argument.</p>
<p class="asd_par">
<a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> pushes the begin expression associated with <tt><label></tt> via
<a class="intern" href="#env_4"><span class="zpr">\env#4</span></a>. The <tt><label></tt> part is <i>not</i> expanded. The second argument
<tt><vararg></tt> consists of consecutive scopes denoting key-value pairs. It is
expanded before use and is allowed to be empty. The keys (which are the
odd-numbered scopes, starting with one) in <tt><vararg></tt> must be such that
prepending a dollar sign (<tt>$</tt>) to them yields a valid key signature. That
signature will be used to set a dollar key in the newly pushed dollar
dictionary that expands to the <tt>value</tt> part associated with the key
(specified as the consecutive even-numbered scope in <tt><vararg></tt>).
Alternatively, since the 07-333 release,
it is also possible to explicitly include the dollar sign in the keys rather
than having them prepended.
</p>
<p class="asd_par">
The <a class="intern" href="#env_4"><span class="zpr">\env#4</span></a> invocation that defines the environment likely
sets defaults for the dollar keys (via the second argument
of <a class="intern" href="#env_4"><span class="zpr">\env#4</span></a>) that can be set as described above.</p>
<p class="asd_par">
The pushing of a dictionary provides a means for shadowing and localization
with nested <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> statements. By associating dollar keys with an
environment, these keys can be given different meanings in nested
environments - the previous meaning will be restored once an environment is
closed. The advantages are that the environment does not have to exercise
<a class="intern" href="#push_1"><span class="zpr">\push#1</span></a> and <a class="intern" href="#pop_1"><span class="zpr">\pop#1</span></a> itself, that the user dictionary stack is not
unnecessarily extended (saving look-up time), and that the 'dollar' look of
a key such as <tt>\$align</tt> signals that it will automagically work in nested
enviroments. Of course, the latter is still the responsibility of the
author of the environment.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The string associated with <tt><label></tt> via <a class="intern" href="#env_4"><span class="zpr">\env#4</span></a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Example I</span>
The zoem faq macros define a <tt>faqsec</tt> environment, for which
two additional arguments are required. It is used for example as</p>
<div class="verbatim">\begin{faqsec}{{ref}{misc}{cap}{Miscellaneous questions}}
...
\end{faqsec}</div>
<p class="asd_car">
The <tt>ref</tt> key introduces the label, the <tt>cap</tt> key introduces the
caption.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Example II</span>
The itemize environment in the zoem <i>generic</i> package allows one
additional and optional argument. This argument, if present, must contain a
vararg, and is used to set options related to the itemize environment. It
is used for example as</p>
<div class="verbatim">\begin{itemize}{
{interitem}{0}
{flow}{compact}
{mark}{\*{itembullet}}
{align}{right}
}
...
\end{itemize}</div>
<p class="asd_car">
Internally, the itemize environment maps these options to dollar keys.
Because a unique dollar dictionary is associated with each environment, this
makes it possible for nested itemize instances to have separate namespaces.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The (unexpanded) string stored in the third argument of the corresponding
<a class="intern" href="#env_4"><span class="zpr">\env#4</span></a> invocation.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="catch_2">
</a>
<tt>\catch#2</tt>: <tt>\catch{<type>}{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
This will process <tt><any></tt>. Depending on <tt><type></tt> the
result is accepted as succesful.
If <tt><type></tt> is <tt>towel</tt>,
any occurrence of <tt>\throw{towel}</tt> in <tt><any></tt> is caught, and
the truncated result is further processed. For <tt>towel</tt>,
zoem <i>errors</i> are not caught but cascade/escalate further down/up.
If <tt><type></tt> is <tt>error</tt>,
any error in <tt><any></tt> is caught, and
the truncated result is further processed.
If <tt><type></tt> is <tt>done</tt>, no exception is accepted.
It is possible though to use <tt>throw{done{..}}</tt> which will stop processing
without generating an exception. See also <a class="intern" href="#throw_2"><span class="zpr">\throw#2</span></a>.</p>
<p class="asd_par">
Output will be truncated in case an error or exception was caught.
The status, currently one of <tt>done</tt>, <tt>towel</tt>, or <tt>error</tt>,
is written in the session macro <a class="intern" href="#session"><tt>\__zoemstat__</tt></a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The possibly truncated result of expanding <tt><any></tt> in case
of a caught exception or error, else the full result.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="cmp_3">
</a>
<tt>\cmp#3</tt>: <tt>\cmp{<str>}{<<any>>}{<<any>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The last two arguments are expanded. Their results are compared as
strings. The first argument must be one of the labels
<tt>lt|lq|eq|gq|gt|ne|cp</tt>. In case it equals one of the six labels
<tt>lt|lq|eq|gq|gt|ne</tt>, this primitive puts in place
the associated boolean as
a string (i.e. either <tt>0</tt> or <tt>1</tt>). In case the label equals <tt>cp</tt>,
it puts in place the result of the string compare (as a string),
namely one of <tt>-1</tt>, <tt>0</tt>, or <tt>1</tt>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
Either the string enconding of a boolean (<tt>0</tt> or <tt>1</tt>)
or the string encoding of the ternary value resulting from a string compare
(<tt>-1</tt> or <tt>0</tt> or <tt>1</tt>).</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="constant_1">
</a>
<tt>\constant#1</tt>: <tt>\constant{<vararg>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
<tt><vararg></tt> must have an even number of arguments. These are interpreted
as pairs. The first of each pair must enclose a string that does not contain
any of the characters <tt>*</tt>, <tt>\</tt>, <tt>{</tt>, or <tt>}</tt>, say string
<tt><keystr></tt>. The second encloses a string that will be interpreted in
device space, say string <tt><valstr></tt>. When a sequence
<tt>\*</tt>{<tt><keystr></tt>} is encountered, it is interpreted as
<tt>\@{</tt><tt><valstr></tt><tt>}</tt>. This is done at filter time only, the sequence
is skipped during macro expansion. It is not allowed to use a sequence
<tt>\*</tt>{<tt><keystr></tt>} in device scope, e.g.
<tt>\@{\*</tt>{<tt><keystr></tt>} is illegal. For further information see
section <a class="intern" href="#dscope">Device scope</a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>None.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="def_2">
</a>
<tt>\def#2</tt>: <tt>\def{<key-sig|data-seq>}{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Bind second argument to the key or access sequence in the first argument.
This primitive will complain if a binding exists already, but it will
overwrite the previous binding and continue anyway. Use <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a> if you
do no want to be warned for overwriting. Examples of usage:</p>
<div class="verbatim"> \def{foo}{FOO}
\def{foo#1}{The FOO of \1}
\def{foo#2}{The FOO of \1 and \2}
\def{$foo#2}{The $FOO of \1 and \2}
\def{"foo::oof"#3}{\foo{\1}{\2}\foo{\2}{\3}}</div>
<p class="asd_car">
These examples are all of type <tt>key-sig</tt>.
See the <a class="intern" href="#grape">Tree data</a> section for examples of type <tt>data-seq</tt>
(this pertains to multi-dimensional data storage).
See the <a class="intern" href="#macro">Macro expansion</a> section for the forms that keys may take. A key
signature is the name of a key with appended to
it the number of argument that the key takes, if any. If the key takes no
arguments, than the key signature is identical to the key name.</p>
<p class="asd_par">
If you want the value to be bound to be expanded before binding it,
use either <a class="intern" href="#defx_2"><span class="zpr">\defx#2</span></a> or <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>. This works the same for
data keys.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>None.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">See also</span><a class="intern" href="#set_3"><span class="zpr">\set#3</span></a>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="defx_2">
</a>
<tt>\defx#2</tt>: <tt>\defx{<key-sig>}{<<any>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The second argument is expanded and stored in the key <tt><key-name></tt>. This
primitive will complain if a binding for that key exists already, but it
will overwrite the previous value anyway.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>None.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">See also</span><a class="intern" href="#set_3"><span class="zpr">\set#3</span></a>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="defined_2">
</a>
<tt>\defined#2</tt>: <tt>\defined{<type>}{<<access>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
<tt><type></tt> is one string of <tt>key</tt>, <tt>lkey</tt>, <tt>data</tt>,
<tt>primitive</tt>, <tt>builtin</tt>, <tt>zoem</tt> or <tt>ENV</tt>. The
second argument is expanded before use.
For the type <tt>key</tt>, the <tt><access></tt> argument is looked up as a key
signature in either the user dictionary stack or the dollar dictionary
stack.
For the type <tt>lkey</tt>, it is looked up only in the top level dictionary.
For the type <tt>data</tt>, the <tt><access></tt> argument is interpreted as a data
access sequence.
For the type <tt>primitive</tt>, the <tt><access></tt> argument is looked up in
the zoem primitive table.
For the type <tt>builtin</tt>, the <tt><access></tt> argument is looked up in
the zoem builtin macro table.
The type <tt>zoem</tt> corresponds with the union of the types <tt>primitive</tt> and
<tt>alias</tt>.
For the type <tt>ENV</tt>, it is checked whether it exists as an environment
variable (which can be retrieved using the <a class="intern" href="#__env___1"><span class="zpr">\__env__#1</span></a> primitive).
This primitive pushes the string <tt>1</tt> if the result is
indeed a valid reference, it pushes the string <tt>0</tt> otherwise.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>The string encoding of a boolean (<tt>0</tt> or <tt>1</tt>).</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="dofile_2">
</a>
<tt>\dofile#2</tt>: <tt>\dofile{<<file name>>}{<char[!?]><char[+-]>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Open a file and process its contents while keeping track of line numbers.
Depending on the second argument, absence of the file is either allowed or
not, and its interpreted contents are output or not. The fact
that <tt><file name></tt> is first expanded allows you to specify
file names such as <a class="intern" href="#session"><tt>\__fnbase__.zyx</tt></a>.</p>
<p class="asd_par">
Zoem may search for a file in several locations until it is found.
The process of locating a file is described in section <a class="intern" href="#searchpath">File search path</a>.</p>
<p class="asd_par">
When found, the file is opened according to the specification in the second
argument. This argument must contain exactly two characters, the first one
of [<tt>!?</tt>], the second one of [<tt>+-</tt>]. The first character indicates
whether the file is allowed to be absent. A '<tt>!</tt>' implies that absence is
fatal, a '<tt>?</tt>' permits absence. The latter is useful e.g. when creating a
Table Of Contents file. The second character indicates whether the
interpreted file should be filtered and output or not ('<tt>+</tt>' for yes and
'<tt>-</tt>' for no). Macro packages typically need interpretation only, whereas
concatenation of document parts (c.q. chapters) stored in different files
requires that the interpreted content is also filtered and output. The
following aliases are available:</p>
<div class="verbatim">
\input{fname} \dofile{fname}{!+}
\import{fname} \dofile{fname}{!-}
\read{fname} \dofile{fname}{?+}
\load{fname} \dofile{fname}{?-}</div>
<p class="asd_car">
The contents of <tt><file name></tt> cannot be captured. If you need to
capture the contents of a file, use <a class="intern" href="#finsert_1"><span class="zpr">\finsert#1</span></a> or <a class="intern" href="#zinsert_1"><span class="zpr">\zinsert#1</span></a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
Technically none. Of course the processing of <tt><file name></tt>
may result in output, depending on the mode of opening.
However, this result text cannot be captured.
For example,</p>
<div class="verbatim">\setx{foo}{\dofile{bar}{!+}}</div>
<p class="asd_car">
will result in the file <tt><bar></tt> being processed and output via
the standard output mechanisms, while the key <tt>\foo</tt> will have
the empty string as value.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="dowhile_2">
</a>
<tt>\dowhile#2</tt>: <tt>\dowhile{<any>}{<condition>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
<tt><any></tt> is expanded and concatenated to the result text
until <tt><condition></tt> exands to something that is nonzero when interpreted
as an integer. <tt><any></tt> is expanded at least one time.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="__env___1">
</a>
<tt>\__env__#1</tt>: <tt>\__env__{<name>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Looks up <tt><name></tt> in the environment.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The corresponding value if <tt><name></tt> exists in the environment, the
empty string otherwise.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Note</span>
This primitive yields identical results for names not in the environment
and names in the environment for which the value is empty.
Use <a class="intern" href="#defined_2"><span class="zpr">\defined#2</span></a> to check whether <tt><name></tt> exist.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="end_1">
</a>
<tt>\end#1</tt>: <tt>\end{<label>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Expands the end definition associated with <tt><label></tt> via <a class="intern" href="#env_4"><span class="zpr">\env#4</span></a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The string associated with <tt><label></tt> via <a class="intern" href="#env_4"><span class="zpr">\env#4</span></a>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="env_4">
</a>
<tt>\env#4</tt>: <tt>\env{<label>}{<<any1>>}{<any2>}{<any3>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Stores <i>expanded</i> <tt><any1></tt> and <i>unexpanded</i> <tt><any2></tt>
for later use with <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> (when
given argument <tt><label></tt>) and
unexpanded <tt><any3></tt> for later use with <a class="intern" href="#end_1"><span class="zpr">\end#1</span></a> (when
given argument <tt><label></tt>).</p>
<p class="asd_par">
<tt><any1></tt> may contain a vararg denoting key-value pairs.
These will be set for each <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> invocation
in the corresponding dollar dictionary. It provides a convenient
mechanism to set default values for keys that can be passed
in the second argument of <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a>.
Note that keys are passed as regular macro signatures, but
they are then transformed to dollar keys by prepending a dollar sign.
Environments are tighly linked to the dollar dictionary stack.
Read more about this in the description of <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a>.</p>
<p class="asd_par">
With each <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> invocation, after <tt><any1></tt> is
processed as indicated above,
<tt><any2></tt> will be pushed onto the input stream.
Before this, <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> defines the keys <tt>\$__args__</tt>
and <tt>\$__xargs__</tt>. These contain respectively the vararg
that was passed as the second argument of <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> and the
same vararg after it was expanded.
These keys can be used in <tt><any2></tt>. One possible usage is
to pass the key-values on to other environment invocations.
This is a likely scenario in case one environment is a thin customization
wrapper around a full-fledged base
environment.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>None.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="eqt_3">
</a>
<tt>\eqt#3</tt>: <tt>\eqt{<str>}{<<num1>>}{<<num2>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The last two arguments are expanded. Their results are compared as
numbers. The first argument must be one of the labels
<tt>lt|lq|eq|gq|gt|ne|cp</tt>. In case it equals one of the six labels
<tt>lt|lq|eq|gq|gt|ne</tt>, this primitive pushes the associated boolean as a
string (i.e. either <tt>0</tt> or <tt>1</tt>). In case the label equals <tt>cp</tt>,
this primitive pushes the result of the integer compare,
namely one of <tt>-1</tt> (if the result of <tt><any1></tt> is
smaller than the result of <tt><any2></tt>),
<tt>0</tt> (equal to), or <tt>1</tt> (greater than).</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
Either the string enconding of a boolean (<tt>0</tt> or <tt>1</tt>)
or the string encoding of the ternary value resulting from
a numeric compare, (<tt>-1</tt> or <tt>0</tt> or <tt>1</tt>).</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="branch_1">
</a>
<tt>\branch#1</tt>: <tt>\branch{<<vararg>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Two arguments are successively taken from <tt><vararg></tt>. The first is
expanded and then evaluated as an integer. If the integer is nonzero, the
second argument is expanded and everything else is ignored. Otherwise the
procedure is repeated. If no (odd) argument matches, and the <tt><vararg></tt>
has an odd number of arguments, the last argument is put in place. It can
be considered a default, else, or failure clause.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="eval_1">
</a>
<tt>\eval#1</tt>: <tt>\eval{<<any>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Expands <tt><any></tt> and passes it on for further evaluation.
This can come in handy when complicated requirements demand
zoem acrobatics. This primitive used to be implemented as a macro;
it is fully equivalent to</p>
<div class="verbatim">\set{eval#1}{\apply{_#1{\!1}}{\1}}</div>
<p class="asd_car">
The above macro works as follows. First, <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a> expands both of its
arguments. The second argument is the data it received from <tt>\eval</tt>, i.e.
the latter's single argument. At this stage, the data is thus expanded for
the first time. <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a> also expands its first argument. The sequence
<tt>\!1</tt> is contracted to the sequence <tt>\1</tt>. The <tt>\1</tt> needed by
<a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a> needs to be protected by the interpolation that occurs when
<tt>eval#1</tt>'s argument is interpolated. Expansion of <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>'s first
argument thus yields the anonymous key <tt>_#1{\1}</tt> — a key that simply
copies it argument and passes it on for further expansion.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Example</span>
<tt>\foo</tt> and <tt>\eval{\!foo}</tt> are fully equivalent.
<tt>\!foo</tt> on the other hand, expands to <tt>\foo</tt> and is then
passed to the filter stage.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">See also</span>
<a class="intern" href="#excl"><span class="zpr">\!</span></a>, <a class="intern" href="#excl_1"><span class="zpr">\!#1</span></a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
<tt><any></tt> gone through <i>two</i> stages of interpretation.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="exit">
</a>
<tt>\exit</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
goodbye world. This is a disgraceful exit for use when some error test
presumably yields true. See also <a class="intern" href="#throw_2"><span class="zpr">\throw#2</span></a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>None.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="f_2">
</a>
<tt>\f#2</tt>: <tt>\f{<fun>}{<<num1>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Expand the last argument, interprets the result as a number,
applies the operand specified by <tt><fun></tt>, and puts the
result in place.
<tt><fun></tt> can be one of</p>
<p class="asd_par">
<tt>floor</tt>, <tt>ceil</tt>, <tt>round</tt>, <tt>abs</tt>, <tt>sign</tt>, <tt>inc</tt>, <tt>dec</tt>, <tt>not</tt>, <tt>drand</tt>, <tt>irand</tt>,
and that's about it. Mode <tt>\f{drand}{<num>}</tt> yields a floating point
number in the range <tt>[0-<num>]</tt>, and mode <tt>\f{irand}{<int>}</tt>
yields an integer in the range <tt>[0-<int>)</tt>, that is, the argument
<tt><int></tt> itself is excluded from the range.
</p>
<p class="asd_par">
For a wider range of mathematical functions, refer to
the <a class="intern" href="#let_1"><span class="zpr">\let#1</span></a> primitive.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The string encoding of a number.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="f_3">
</a>
<tt>\f#3</tt>: <tt>\f{<fun>}{<<num1>>}{<<num2>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Expands the last two arguments, interprets the results as
numbers, applies the operand specified by <tt><fun></tt>, and puts the
result in place.</p>
<p class="asd_par">
Most arithmetic is done using floating point arithmetic (with the C double
type). Integers are preserved if possible. Since nearly everything is
treated as a string in zoem, this simply means that no decimal fraction is
printed when the number is output. A number is considered integer if the
difference with the integer nearest by is less than the precision (1e-8)
<i>and</i> if it can be represented as an integer using the C long type.
Otherwise it is output in decimal representation of the underlying floating
point representation.</p>
<p class="asd_par">
<tt><fun></tt> can be one of</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">*</div></div></div>
<div class=" item_text " style="margin-left:2em">
Multiplication.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">+</div></div></div>
<div class=" item_text " style="margin-left:2em">
Addition.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">-</div></div></div>
<div class=" item_text " style="margin-left:2em">
Subtraction.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">/</div></div></div>
<div class=" item_text " style="margin-left:2em">
Does true division, returns real.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">%</div></div></div>
<div class=" item_text " style="margin-left:2em">
Modulus.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">and</div></div></div>
<div class=" item_text " style="margin-left:2em">
Boolean <i>and</i>, results in <tt>0</tt> or <tt>1</tt>.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">or</div></div></div>
<div class=" item_text " style="margin-left:2em">
Boolean <i>or</i>, results in <tt>0</tt> or <tt>1</tt>.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">div</div></div></div>
<div class=" item_text " style="margin-left:2em">
Does integer division.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">mod</div></div></div>
<div class=" item_text " style="margin-left:2em">
Same as <tt>%</tt>.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">pow</div></div></div>
<div class=" item_text " style="margin-left:2em">
Power.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">max</div></div></div>
<div class=" item_text " style="margin-left:2em">
Maximum.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">min</div></div></div>
<div class=" item_text " style="margin-left:2em">
Minimum.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">ceil</div></div></div>
<div class=" item_text " style="margin-left:2em">
Nearest by higher multiple, e.g. <tt>\f{ceil}{12}{5}=15</tt>.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">floor</div></div></div>
<div class=" item_text " style="margin-left:2em">
Nearest by lower multiple, e.g. <tt>\f{floor}{12}{5}=10</tt>.
</div>
</div>
<p class="asd_par">
For a wider range of mathematical functions, refer to
the <a class="intern" href="#let_1"><span class="zpr">\let#1</span></a> primitive.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Note</span>
<tt>and</tt> and <tt>or</tt> short-circuit.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The string encoding of a number.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="fv_2">
</a>
<tt>\fv#2</tt>: <tt>\fv{<fun>}{<<vararg>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Expands the second argument and interprets it as vararg,
and applies the operator specified by <tt><fun></tt> to the elements of vararg.</p>
<p class="asd_par">
<tt><fun></tt> can be one of</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">*</div></div></div>
<div class=" item_text " style="margin-left:2em">
Multiplication.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">+</div></div></div>
<div class=" item_text " style="margin-left:2em">
Addition.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">and</div></div></div>
<div class=" item_text " style="margin-left:2em">
Boolean and.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">or</div></div></div>
<div class=" item_text " style="margin-left:2em">
Boolean or.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">max</div></div></div>
<div class=" item_text " style="margin-left:2em">
Maximum.
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">min</div></div></div>
<div class=" item_text " style="margin-left:2em">
Minimum.
</div>
</div>
<p class="asd_cpar"><span class="asd_cpar_caption">Note</span>
<tt>and</tt> and <tt>or</tt> short-circuit.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The string encoding of a number.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="finsert_1">
</a>
<tt>\finsert#1</tt>: <tt>\finsert{<file name>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The argument is expanded and interpreted as file name. The file is read,
and every <tt>\</tt>, <tt>{</tt>, and <tt>}</tt> is escaped (resulting in one of
<tt>\\</tt>, <tt>\{</tt>, and <tt>\}</tt>) The altered contents are then put in
place. See also <a class="intern" href="#zinsert_1"><span class="zpr">\zinsert#1</span></a>.
If file can not be opened, the empty string results.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Note</span>
This primitive cannot be used to read
<a class="intern" href="#fileread">inline files</a> whereas <a class="intern" href="#zinsert_1"><span class="zpr">\zinsert#1</span></a> can.
The reason is that inline files have to satisfy zoem syntax.
<tt>\finsert#1</tt> can be used to read arbitrary data.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The escaped contents of <tt><file name></tt> or the empty string if
file can not be opened.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="format_2">
</a>
<tt>\format#2</tt>: <tt>\format{<<fmt>>}{<<vararg>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_ccar"><span class="asd_ccar_caption">NOTE</span>
This primitive was changed in an incompatible way in the 07-333 release.
The special case specification syntax was discarded and replaced by the more
robust and extensible key-value based syntax described below.
</p>
<p class="asd_par">
The primitive formats elements from <tt><vararg></tt> according to the format
specification in <tt><fmt></tt>. A format string may contain normal characters
that will be output, and meta sequences. A meta sequence is started with the
percent character <tt>%</tt> and either followed by a block or by another percent
sign. A meta sequence consisting of two consecutive percent signs (<tt>%%</tt>)
will be skipped and result in the output of a single percent sign.
Otherwise, the meta sequence will format the next argument from <tt><arg></tt>
according to the specification in the block. A specification consists of a
series of key-value pairs that may occur in any order. The key is called the
<i>directive</i> and the supported directives are:</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>{padding}{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The literal string <tt>padding</tt> is the directive and indicates that the value
specifies the padding. The <tt><any></tt> content of the
value block is used as the padding string. By default spaces are used
for padding (and incidentally runs of spaces will be squashed unless
<tt>\@{\w}</tt> is issued).
Padding is applied if the width of the field exceeds the width of
<tt><arg></tt> plus the width of the optional delimiter(s) described below.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>{delimit}{<delimiter>}[{<delimiter>}]</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The content of the first block is inserted inbetween the padding and
<tt><arg></tt>. If centered alignment is used, this will be done on both sides.
By default no such delimiter is used.
It is possible to specify two <tt><delimiter></tt> arguments. In that
case the first specifies the left delimiter and the second specifies
the right delimiter.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>{align}{left|center|right}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The directive is <tt>align</tt>, the value is one of <tt>left</tt>, <tt>center</tt>, or <tt>right</tt>
and specifies how the argument taken from <tt><vararg></tt> is to be aligned.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>{width}{<num>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The directive is <tt>width</tt>, the value should be a positive integer number denoting
the desired width of the field on which <tt><arg></tt> is to be printed.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>{length}{{key}[{args}*]}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The directive is <tt>length</tt>, the value consists of one or more blocks.
The first value block should contain the name of a macro.
This is for when you want to customize the way in
which the length of strings is computed.
The macro will be used to compute the lenght of strings under
consideration, using entries in the <i>double</i> directive as appropriate (see below).
This allows you for example to do alignment in <tt><pre></tt> formatted blocks in html,
while keeping the
possibility to insert elements that do not take up any width (e.g. links).
The first value block should contain the name of a macro.
A likely candidate is
<a class="intern" href="#length_1"><span class="zpr">\length#1</span></a>, which should be specified simply as <tt>length</tt>.
The first argument that is given to this macro will be the string
under consideration. The rest of the value blocks, if any, will be given
as additional arguments.
</p>
<p class="asd_par">
Currently, this custom length computation is only applied to the
argument that is being formatted and the two delimiters if present.
All three of these can be replaced, for the purpose of length
computation, by placeholders using the <i>double</i> directive.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>{double}{{[{key}{value}]*}}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The directive is <tt>double</tt>, the value consists of a single block containing
a vararg. This is used to specify placeholders when computing the length of
elements. The vararg contains placeholder types as keys and the
corresponding placeholder values. It is currently possible to specify three
different types of placeholders. These are the argument to be typeset,
specified with the placeholder key <i>arg</i>, the left delimiter, specified
with <i>delimit-left</i>, and the right delimiter, specified with
<i>delimit-right</i>.
</p>
<p class="asd_cpar"><span class="asd_cpar_caption">NOTE</span>
The value is enclosed in a block, as part of the key-value specification
employed by the <i>double</i> specification. The value itself is
a block containing key-value pairs (again specified as curly-delimited
blocks). So be sure to supply the correct number and nesting of blocks.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>{alignat}{{<pivot>}{<width>}}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The directive is <tt>alignat</tt>, the value consists of two blocks. This is used to
specify alignment. The content of the first value block is used as the
string on which to align. The content of the second block is used as the
width on which the first part of <tt><arg></tt> (up to and including the
alignment substring) will be right-aligned. If the <tt>length</tt> specification
is used as well, the length macro specified therein will be used to compute
the width of the string specified in the first block.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>{reuse}{<num>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
This instructs zoem to reuse the current specification for another <tt><num></tt>
arguments taken from <tt><vararg></tt>.
Instead of <tt><num></tt> it is possible to specify <tt>{reuse}{*}</tt>. This
will reuse the current specification until all arguments have been exhausted.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style=""><tt>{border}{{<left>}{<right>}}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
This borders the result of the current specification with <tt><left></tt>
and <tt><right></tt>.
This is useful in conjunction with the <tt>reuse</tt> specifier, for example
for adding device line-breaks to each formatted item.
</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Example</span></p>
<div class="verbatim">\format{%{{align}{right}{width}{10}{reuse}{*}{padding}{{'}{}}}}{
{beauty}{lies}{in}{the}{eye}{of}{the}{beholder}
}</div>
<p class="asd_car">results in</p>
<div class="verbatim">''''beauty''''''lies''''''''in'''''''the'''''''eye''''''''of'''''''the''beholder</div>
</div>
</div>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The formatted string.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="formatted_1">
</a>
<tt>\formatted#1</tt>: <tt>\formatted{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
This removes and adds white space from its arguments
via the following rules:</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
It skips any <tt>\@{..}</tt> enclosed sequence.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
It skips any <tt>\<..></tt> enclosed sequence - note that the contents
eventually will end up in <tt>\@{..}</tt> (at) scope.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
It removes all spaces, tabs, and newlines it encounters otherwise.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
It inspects and (after inspection) removes all <tt>\`{..}</tt> enclosed
sequences it encounters. During inspection, <a class="intern" href="#formatted_1"><span class="zpr">\formatted#1</span></a> maps
'<tt>s</tt>' to a space, '<tt>t</tt>' to a tab, and '<tt>n</tt>' to a newline.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
If the sequence <tt>\`{<}</tt> is encountered (not in at scope),
<tt>\formatted#1</tt> starts copying literally without munging
whitespace; it resumes its normal mode of operation
after encountering the sequence <tt>\`{>}</tt>.</p>
</div>
</div>
<p class="asd_par">
This is useful for writing legible macro files while exercising full control
over whitespace (modulo Zoem's white space munging rules).</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The argument in its unformatted form.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="get_2">
</a>
<tt>\get#2</tt>: <tt>\get{<dict-label>}{<key-sig>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The user stack is searched from top to bottom for dictionaries
with label <tt><dict-label></tt>, and those dictionaries
are searched in order for a key with signature <tt><key-sig></tt>.
The first succesful match is retrieved and its definition
is pushed onto the interpretation stack.
It is an error if no such definition is found.
</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Note</span>
The label of the default user dictionary is <tt>''</tt>. This ties
in with the syntax <tt>\''keysig</tt>, used to specify the user
dictionary stack. So the following:</p>
<div class="verbatim"> \set{user}{Jill}
\push{foo}
\set{user}{Phil}
\push{bar}
\set{user}{Bill}
\get{''}{user} \get{foo}{user} \get{bar}{user}</div>
<p class="asd_car">
yields output <tt>Jill Phill Bill</tt>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Note</span>
It is currently not possible to access keys that take arguments.
</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The result of processing the retrieved definition.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="if_3">
</a>
<tt>\if#3</tt>: <tt>\if{<<int-expr>>}{<any1>}{<any2>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The first argument is expanded and interpreted as an integer.
If it is nonzero, <tt><any1></tt> is pushed on the interpretation stack
and <tt><any2></tt> is ignored, vice versa if it is zero.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
Either <tt><any1></tt> or <tt><any2></tt>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="inspect_4">
</a>
<tt>\inspect#4</tt>: <tt>\inspect{<<vararg>>}{<<reg>>}{<<any|anon key>>}{<<any>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_ccar"><span class="asd_ccar_caption">status</span>Experimental</p>
<p class="asd_par">
All arguments are expanded before use. <tt><vararg></tt> currently
recognizes a single key <i>mods</i>. The value of <i>mods</i> may contain a
comma-separated list of the following directives. Repeated use
of <i>mods</i> is allowed.</p>
<div class="verbatim">
posix
icase
dotall
iter-lines
iter-args
match-once
discard-nmp
discard-nil-out
discard-miss
count-matches</div>
<p class="asd_par">
The <tt>posix</tt> directive is currently required, specifying that <acronym class="ucase" title="Portable Operating System Interface [for Unix]">POSIX</acronym>
regular expressions are used. The future might bring other regex syntaxes.</p>
<p class="asd_par">
Argument <tt><reg></tt> specifies a (<acronym class="ucase" title="Portable Operating System Interface [for Unix]">POSIX</acronym>) regular expression. Before being
passed to the match engine, it undergoes <span class="smallcaps">UNIX</span> and <span class="smallcaps">TILDE</span> tilde replacement
as described in <a class="local sibling" href="zoem.html#tildexp">the zoem manual</a>.</p>
<p class="asd_par">
Consult the <acronym class="ucase" title="Portable Operating System Interface [for Unix]">POSIX</acronym> documentation or the regex(7) manual page for a description
of posix regexp syntax.</p>
<p class="asd_par">
The expansion of <tt><any|anon key></tt> can either result in plain data or in an
anonymous key. The expansion of the last argument results in data to which
the regex <tt><reg></tt> is successively applied.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Interpolation</span>
If the second expansion starts with the pattern <tt>_#k{</tt> it is assumed
to be an anonymous key. The subpatterns from the matched pattern are
interpolated by the key, and the entire matched pattern is substituted by the
interpolation. Else, the matched pattern is simply replaced by the expansion.</p>
<p class="asd_par">
<tt>icase</tt> induces case insensitive matching.
<tt>dotall</tt> makes the dot <tt>.</tt> match any character, including the newline.
<tt>iter-lines</tt> causes matching to be applied to lines shifted from the data (i.e.
data is split on newlines).
<tt>iter-args</tt> causes matching to be applied to blocks shifted from the data (which
should obviously be a vararg).
<tt>match-once</tt> inspects each element under consideration only once.
<tt>count-matches</tt> replaces the data by the count of matches. In conjunction
with <tt>iter-lines</tt> or <tt>iter-args</tt> it yields the counts on separate lines
and in separate blocks, respectively.
<tt>discard-nmp</tt> discards non-matching parts.
<tt>discard-miss</tt> removes any lines or blocks which are empty after inspect
is done with it.
<tt>discard-nil-out</tt> discards any strings or lines or blocks that are empty
after matching and optionally interpolation has been applied.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Bugs</span>
The <acronym class="ucase" title="GNU's Not Unix">GNU</acronym> implementation of <acronym class="ucase" title="Portable Operating System Interface [for Unix]">POSIX</acronym> regexes was at some point known to be buggy
for long strings and/or long matches.</p>
<p class="asd_par">
A search pattern consisting of a single word boundary or the start-of-string
token (<tt>^</tt>) will match at each position, because after a succesful match
<a class="intern" href="#inspect_4"><span class="zpr">\inspect#4</span></a> simply resumes searching for a new match by skipping to the
end of the previous match (and adding a single position if the match had
width zero and offset zero). Similar but not yet noticed bugs may exist.</p>
<p class="asd_par">
Nevertheless, this can be a very useful primitive for the occasional
odd job, and it should always work except for the cases just mentioned.
If you have a complicated instance of <a class="intern" href="#inspect_4"><span class="zpr">\inspect#4</span></a>, test it first
in isolation. Consider sending a bug report in case you find one (a bug,
or a bug report).</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
Depending on the presence of a match and the modifiers given.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="length_1">
</a>
<tt>\length#1</tt>: <tt>\length{<<any>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Computes the length of <tt><any></tt> and puts this in place.
It takes into account the zoem escape sequences <tt>\\</tt>, <tt>\{</tt>,
and <tt>\}</tt>. The future may bring a generalized <tt>\length#2</tt> primitive
that provides different ways of measuring string length.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>The length of any <tt><any></tt>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="let_1">
</a>
<tt>\let#1</tt>: <tt>\let{<<let expression>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The <a class="intern" href="#let_1"><span class="zpr">\let#1</span></a> primitive puts zoem in arithmetic mode and the contents are
parsed accordingly. All of C's operators are supported including the
logical, bitwise, and comparison operators as well as the ternary operator.
The operators <tt>**</tt> and <tt>//</tt> are added, which respectively denote
exponentiation and integer division.
Operations or functions resulting in integers are tracked, and
the result will be stored in the integer type used (typically
long) if possible. Thus one may find that</p>
<div class="verbatim">\let{2**42}
\let{2**22}
</div>
<p class="asd_car">
respectively result in <tt>4398046511104.0</tt> and <tt>2097152</tt>.</p>
<p class="asd_par">
The precedence rules used by Zoem are simpler than C's. The respective groups
of logical, bitwise, and comparison operators all have identical precedence
internally, and associate from left to right.</p>
<p class="asd_par">
Most of the <abbr class="ucase" title="American National Standards Institute">ANSI</abbr> C math functions are supported, with in addition
<tt>max</tt> and <tt>min</tt>. The functions <tt>round</tt>, <tt>sign</tt>, and <tt>abs</tt> behave
slightly different from their C counterparts, as they result in integer
results if no overflow occurs.</p>
<p class="asd_par">
At any place where an atomic type is expected one is allowed to insert
a zoem macro invocation. It will be evaluated and the result will be
interpreted as a number. Evaluation will take place in the order
as dictated by the precedence rules governing the expression.</p>
<p class="asd_par">
The logical operators shortcircuit and the ternary operator evaluates
only one of its branches. This can be used to create side effects, such
as in</p>
<div class="verbatim">
\let{\bar && \group{\set{foo}{zut}1}}
</div>
<p class="asd_car">
This sets <tt>foo</tt> only if <tt>bar</tt> evaluates to a non-zero number.
The trailing <tt>1</tt> in the <tt>group</tt> macro is good practice because
<a class="intern" href="#let_1"><span class="zpr">\let#1</span></a> expects a number to be the result of any macro it encounters.
It could have been any other number, or a macro or sequence of macros
evaluating to a number.
The <tt>group</tt> macro is a predefined macro that does nothing except
passing its arguments. It is necessary in this concocted example
because any occurrence of
a macro within <a class="intern" href="#let_1"><span class="zpr">\let#1</span></a> is interpreted as a number by itself.
The sequence <tt>\bar \bar</tt> would for example be syntactically
identical to <tt>1 1</tt>, which is incorrect.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>A number.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="nargs_1">
</a>
<tt>\nargs#1</tt>: <tt>\nargs{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The argument is not expanded. It puts in place a number that indicates
whether this argument could be parsed as a number of scopes or whether it is
a regular argument. The following list of examples illustrates
the rules according to which the number is created.</p>
<div class="verbatim">
\nargs{{abc}def} : -2 \: neither fish nor fowl
\nargs{abc} : -1 \: regular argument
\nargs{abc{def}} : -1 \: regular argument too
\nargs{} : 0 \: empty vararg (not empty regular arg)
\nargs{ } : 0 \: empty vararg again
\nargs{{abc}} : 1 \: vararg with 1 argument
\nargs{{abc}{def}} : 2 \: vararg with 2 arguments
\nargs{ {abc}
{def}
} : 2 \: vararg with 2 arguments
\: etc.
</div>
<p class="asd_par">
From this it is seen that if the first non-whitespace character
is an opening curly the primitive expects to find a number of scopes
with nothing inbetween or trailing.
If it does not succeed the result text is set to the special value -2.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>integer</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="pop_1">
</a>
<tt>\pop#1</tt>: <tt>\pop{<label>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Pops a dictionary from the user dictionary stack pushed earlier
by <a class="intern" href="#push_1"><span class="zpr">\push#1</span></a>. The tag <tt><label></tt> must be same as the one
supplied by that specific <a class="intern" href="#push_1"><span class="zpr">\push#1</span></a> invocation.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>None.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="protect_1">
</a>
<tt>\protect#1</tt>: <tt>\protect{<<any>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The argument is expanded. Subsequently, all backslashes and curlies
are escaped. The resulting text is put in place.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
<tt><any></tt> with backslashes and curlies escaped.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="push_1">
</a>
<tt>\push#1</tt>: <tt>\push{<label>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Pushes a new dictionary onto the user dictionary stack with tag
<tt><label></tt>. The corresponding <a class="intern" href="#pop_1"><span class="zpr">\pop#1</span></a> should use the same tag. Note
that <a class="intern" href="#defined_2"><span class="zpr">\defined#2</span></a> with the <tt>lkey</tt> directive checks only the top-level
dictionary, whereas <a class="intern" href="#defined_2"><span class="zpr">\defined#2</span></a> with the <tt>key</tt> directive checks the
whole stack of dictionaries. Also, <a class="intern" href="#undef_1"><span class="zpr">\undef#1</span></a> only removes a key from the
top-level dictionary. There is currently not a way to access keys based on
dictionary label.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>None.</p>
<p class="asd_par">
Example of usage:</p>
<div class="verbatim">\def{num}{1}
\push{foo}
\def{num}{2}
\push{bar}
\def{num}{3}
\push{tim}
\def{num}{4}
\pop{tim}
num is \num
\pop{bar}
num is \num
\pop{foo}
num is \num</div>
<p class="asd_car">
results in
</p>
<div class="verbatim">num is 3
num is 2
num is 1</div>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="register_2">
</a>
<tt>\register#2</tt>: <tt>\register{<tag>}{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Register <tt><any></tt> to be processed at the occassion specified by
<tt><tag></tt>. The only <tt><tag></tt> currently supported is <tt>END</tt>.
<tt>END</tt> registrees are processed only after all regular input has been
processed. Multiple <a class="intern" href="#register_2"><span class="zpr">\register#2</span></a> invocations are allowed. Registrees are
processed in the order of registration.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
None at time of registering, the result of <tt><any></tt> at time of
processing.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="set_2">
</a>
<tt>\set#2</tt>: <tt>\set{<key-sig>}{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
As <a class="intern" href="#def_2"><span class="zpr">\def#2</span></a> above, except that <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a> will not complain
if the key labeled by <tt><key-sig></tt> already exists.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>None.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">See also</span><a class="intern" href="#set_3"><span class="zpr">\set#3</span></a>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="setx_2">
</a>
<tt>\setx#2</tt>: <tt>\setx{<key-sig>}{<<any>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The second argument is expanded and stored in the key <tt><key-name></tt>.
Besides simply storing the expansion of an expression, it can
also be used to do trickier things as</p>
<div class="verbatim"> \def{bar}{klaas}
\setx{foo#2}{\bar says \1 and \2}
\foo{x}{y}
klaas says x and y</div>
<p class="asd_car">
If you need lambda-like capabilities, take note that you can use <tt>\!k</tt> or
<tt>\!{\k}</tt> to construct a positional parameter <tt>\k</tt>, if you want to
interpolate arguments into a key that will later take other arguments. Like
this:</p>
<div class="verbatim"> \: is there any use for this wacky stuff?
\def{lambda#2}{\setx{\1#1}{\2 says \!1}}
\lambda{foo}{bar}
\foo{moo}
bar says moo</div>
<p class="asd_car">
Take care: the <a class="intern" href="#dofile_2"><span class="zpr">\dofile#2</span></a> key outputs
to the default output file. If you need to include the contents of
a file within a <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a> call, you need to use <a class="intern" href="#finsert_1"><span class="zpr">\finsert#1</span></a> or <a class="intern" href="#zinsert_1"><span class="zpr">\zinsert#1</span></a>
in conjunction with <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>None.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">See also</span><a class="intern" href="#set_3"><span class="zpr">\set#3</span></a>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="set_3">
</a>
<tt>\set#3</tt>: <tt>\set{<{modes}{..}{if}{..}{unless}{..}{dict}{..}{start}{..}{width}{..}>}{<key-sig>}{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
This primitive encompasses all of the previous four as well as providing
additional modes of operation.
The first argument
is a vararg storing key-value pairs. The possible keys are <tt>modes</tt>,
<tt>if</tt>, <tt>unless</tt>, <tt>dict</tt>, <tt>start</tt> and <tt>width</tt>. All of these
are optional.
</p>
<p class="asd_par">
The <tt><modes></tt>
value, if present must be a string over the following characters.</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">a</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">append to the key, do not overwrite, create if not existing.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">c</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">conditionally; only set if not already defined.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">e</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">existing; update existing key, possibly in lower dictionary.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">g</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">global; set in the global (bottom) user dictionary.</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">u</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">unary; do not interpret vararg in <tt><any></tt> as key-value list (data keys only)</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">v</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">vararg; interpret vararg in <tt><any></tt> as key-value list (regular keys only).</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">w</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">warn if key exists (like <tt>\def#2</tt> and <tt>\defx#2</tt>).</p>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_leftalign nowrap "
style="">x</div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">expand argument (like <tt>\setx#2</tt> and <tt>\defx#2</tt>).</p>
</div>
</div>
<p class="asd_par">
The <tt>u</tt> directive applies when setting <a class="intern" href="#grape">data</a>.
The <tt>v</tt> directive applies when setting regular keys.
In this case, <tt><key-sig></tt> must be empty, and <tt><any></tt>
is treated as a vararg of repeated key-value pairs.
Directives can be combined as needed.
</p>
<p class="asd_par">
Note that keys in the global user dictionary can be accessed
even if other dictionaries are pushed using the syntax <tt>\''foo</tt>.</p>
<p class="asd_par">
The <i>if</i> and <i>unless</i> directives can be used to trigger action (i.e.
definition of keys) only if the corresponding clause evaluates to non-zero
or zero, respectively.
</p>
<p class="asd_par">
The <i>dict</i> directive must be followed by a dictionary name in the subsequent
block. The dictionary stack will be searched for a dictionary with
this name. The type of dictionary is derived from the key signature.
This is either the dollar dictonary used for the dictionary stack
associated with <a class="intern" href="#begin_2"><span class="zpr">\begin#2</span></a> (if the key starts with a dollar sign <tt>$</tt>),
or the default user dictionary.
</p>
<p class="asd_par">
The <i>start</i> and <i>width</i> directives only work if a single key is set.
Their values should evaluate to integers <tt><start></tt> and <tt><width></tt>.
The key will be set to its old value with a segment of length
<tt><width></tt> starting at offest <tt><start></tt> replaced by <tt><any></tt>.
Offsets are zero-based and units are in bytes.
</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>None.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">See also</span><a class="intern" href="#def_2"><span class="zpr">\def#2</span></a>, <a class="intern" href="#defx_2"><span class="zpr">\defx#2</span></a>, <a class="intern" href="#set_2"><span class="zpr">\set#2</span></a>, <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="special_1">
</a>
<tt>\special#1</tt>: <tt>\special{<<vararg>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
<tt><vararg></tt> is expanded before use.
It must have an even number of arguments. These are
interpreted as pairs. The first of each pair must enclose an integer in
the range 0-255 or one of the special token identifiers <tt>-1</tt>,
<tt>-2</tt> or <tt>-3</tt>. The integers in the range 0-255 are interpreted as
character indices The characters indexed <tt>-1</tt>, <tt>-2</tt>
and <tt>-3</tt> correspond with the zoem glyphs <tt>\~</tt>, <tt>\|</tt>, and <tt>\-</tt>
respectively. The second element in each pair defines the string to
which the character specified by the first element must be mapped. This
string is interpreted in device scope. See the
<a class="intern" href="#dscope">Device scope</a> section for simple uses.</p>
<p class="asd_par">
A key may occur multiple times. The corresponding definitions
are stacked away and will be accessed according to the current
<i>special level</i>
(cf. the section on <a class="intern" href="#special">mapped characters in device scope</a>).</p>
<p class="asd_par">
Repeated use of <tt>\special#1</tt> does not cause the removal of previous
definitions, with one exception: If <tt>\special#1</tt> is invoked
with no arguments at all then all definitions are removed.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Note</span>
Be sure to use delay sequences as appropriate, noting that vararg is expanded.
Below is how <a target="_parent" class="extern" href="http://micans.org/pud/">Portable Unix Documentation</a>
encodes a line break in troff:</p>
<div class="verbatim">{-2} {\!N.br\!N}</div>
<p class="asd_car">
Zoem interprets the value and accordingly associates
the device scope sequence <tt>\N.br\N</tt> with the token <tt>\|</tt>.
The escape sequence <tt>\N</tt> will thus be processed during
the filter stage as is appropriate.
Without the delay sequence zoem would try to expand <tt>\N</tt> during
processing of the <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a> primitive.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>None.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="switch_2">
</a>
<tt>\switch#2</tt>: <tt>\switch{<<pivot>>}{<vararg>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The first argument is expanded. Subsequently, two arguments are successively
taken from <tt><vararg></tt>. The first is expanded and string compared with
<tt><pivot></tt>. If they match, the second argument is expanded and everything
else is ignored. If they do not match, the procedure is repeated. If no
(odd) argument matches, and the <tt><vararg></tt> has an odd number of
arguments, the last argument is put in place. It can be considered a
failure clause. This primitive does not have fall-through behaviour; at
most one branch will be handed to the parser.</p>
<p class="asd_car">
Different cases can be grouped in a vararg. If <a class="intern" href="#switch_2"><span class="zpr">\switch#2</span></a> recognizes
that the test argument can be parsed as a vararg it will exctract all
the corresponding sub-arguments. If the pivot matches any of these
the branch corresponding to the test argument will be taken.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
Either the first block associated with a matching case of <tt><pivot></tt>,
the failure clause, or nothing at all.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="system_3">
</a>
<tt>\system#3</tt>: <tt>\system{<cmd>}{<<args>>}{<<data>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
<i>By default this primitive is disallowed.</i>
The first argument is the name of a system command. The environment variable
PATH is used in tracing the location of the command. If <tt><data></tt> is
non-empty, it is first <i>unprotected</i>, that is, escaped backslashes and
curlies are unescaped. The resulting text is then fed to command <tt><cmd></tt>
with arguments <tt><args></tt>. The latter, if non-empty, must be
specified as a vararg, even if only a single argument is present.
Should execution of the command (be it with or
without data) result in output on <span class="smallcaps">STDOUT</span> then the latter is captured,
backslashes and curlies are escaped (i.e. the output is protected), and the
result is put in place. <span class="smallcaps">STDERR</span> is the same as it is for the parent (zoem).</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Note</span>
The security implications of this feature. By default
zoem will <i>ignore</i> <tt>\system</tt>. The
command line option <tt>--unsafe</tt> will cause zoem to prompt for user
confirmation (if prompting is not possible it will ignore again) for
each encountered <tt>\system</tt> invocation. The option <tt>--unsafe-silent</tt>
will silently allow all <tt>\system</tt> invocations. The option
<tt>--allow=cmd[:cmd]*</tt> explicitly specifies which commands to allow silently.
It is also possible to use this option repeatedly rather than separate
different commands by colons.</p>
<p class="asd_par">
If the zoem command line option <tt>--system-honor</tt> is used, zoem will
exit if a system command fails or is ignored.</p>
<p class="asd_par">
A simple exit status is written in the variable <a class="intern" href="#session"><tt>\__sysval__</tt></a>:
it is zero (<tt>0</tt>) on success, and one (<tt>1</tt>) on failure.</p>
<p class="asd_par">
Refer to <a class="local sibling" href="zoem.html">the manual page of the zoem interpreter</a> for
more information on <tt>--unsafe</tt>, <tt>--unsafe-silent</tt>,
<tt>--allow=</tt>, and <tt>--system-honor</tt>.</p>
<p class="asd_par">
Built-in macros <tt>\system#2</tt> and <tt>system#1</tt> exist. The former
drops the <tt><data></tt> argument, the latter also drops the <tt><args></tt>
argument.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Example</span></p>
<div class="verbatim">\system{sort}{{-n}}{\finsert{foo}}
\system{ls}{{-l}{-a}}
\system{date}</div>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The output captured (and then protected) from <tt><cmd></tt>'s <span class="smallcaps">STDOUT</span>, if any.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="table_5">
</a>
<tt>\table#5</tt>: <tt>\table{<<row length>>}{<any1>}{<any2>}{<any3>}{<<vararg>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The first argument is expanded and interpreted as an integer, say <tt>k</tt>.
Successively, vectors of <tt>k</tt> elements are shifted from
<tt><vararg></tt>. Each vector is bordered on the left with
<tt><any1></tt>, bordered on the right with <tt><any3></tt>, and
all elements in the vector are separated with <tt><any2></tt>.</p>
<p class="asd_par">
This primitive is perhaps not really needed as its functionality
is largely covered by <a class="intern" href="#apply_2"><span class="zpr">\apply#2</span></a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The blocks from <tt><vararg></tt> interspersed in a table-like
manner with <tt><any1></tt>, <tt><any2></tt>, and <tt><any3></tt>.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="textmap_2">
</a>
<tt>\textmap#2</tt>: <tt>\textmap{<vararg>}{<<any>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Apply one or more transformations to <tt><any></tt> and
put the result in place.
<tt><vararg></tt> takes a succession of key-value pairs.
The associated transformation are applied in order. The
supported transformations are:</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign nowrap "
style="right:-5em">{word}{ucase}</div></div></div>
<div class=" item_text " style="margin-left:6em">
Uppercase <tt><any></tt>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign nowrap "
style="right:-5em">{word}{lcase}</div></div></div>
<div class=" item_text " style="margin-left:6em">
Lowercase <tt><any></tt>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign nowrap "
style="right:-5em">{number}{roman}</div></div></div>
<div class=" item_text " style="margin-left:6em">
Convert number to Roman
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign nowrap "
style="right:-5em">{number}{alpha}</div></div></div>
<div class=" item_text " style="margin-left:6em">
Convert number to letters
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign nowrap "
style="right:-5em">{repeat}{<num>}</div></div></div>
<div class=" item_text " style="margin-left:6em">
Concatenate <num> copies of <tt><any></tt>
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign nowrap "
style="right:-5em">{caesar}{<num>}</div></div></div>
<div class=" item_text " style="margin-left:6em">
Apply caesar encryption
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign nowrap "
style="right:-5em">{vigenere}{<key>}</div></div></div>
<div class=" item_text " style="margin-left:6em">
Apply vigenere encryption
</div>
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign nowrap "
style="right:-5em">{vigenerex}{<key>}</div></div></div>
<div class=" item_text " style="margin-left:6em">
Apply vigenere encryption and include space
</div>
</div>
<p class="asd_par">
The roman transformation can e.g. used to equip the Aephea itemize
environment with roman numbering. To get uppercase roman,
do this:</p>
<div class="verbatim"> \textmap{{number}{roman}{word}{ucase}}{\your_nice_counter}</div>
<p class="asd_car">
The alpha transformation maps its argument to a string over the alphabet <tt>_a-z</tt>, i.e.
all the set of all lowercase letters with the underscore added.
This set is simply used for counting in base 27, with the underscore
playing the role of zero.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The transformed text.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="throw_2">
</a>
<tt>\throw#2</tt>: <tt>\throw{<towel|error|done>}{<<any>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Quit parsing, unwind stack until some occurrence of
<a class="intern" href="#catch_2"><span class="zpr">\catch#2</span></a>, <a class="intern" href="#try_1"><span class="zpr">\try#1</span></a> captures this throw.
</p>
<p class="asd_par">
The throw <tt>\throw{done}</tt> is also unconditionally caught by
<a class="intern" href="#while_2"><span class="zpr">\while#2</span></a> and <a class="intern" href="#eval_1"><span class="zpr">\eval#1</span></a>.
If <tt>\throw{done}</tt> is encapsulated by neither of these four
primitives it means that processing of the current file
is stopped, and processing at the including file, if applicable,
is resumed.
</p>
<p class="asd_par">
<tt><any></tt> is digested; if it has positive length the result
is issued as a diagnostic.
</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Note</span>
Many primitives evaluate one or more of their arguments before use,
as indicated in this manual.
An occurrence of <tt>\throw{done}</tt> in such an argument, if not caught, will be
treated like an error. It is possible to use <tt>\throw{done}</tt> in such
an instance by encapsulating the argument in <a class="intern" href="#eval_1"><span class="zpr">\eval#1</span></a>.
</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
None, affects the result text of the embedding scopes.
</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="tr_2">
</a>
<tt>\tr#2</tt>: <tt>\tr{<vararg>}{<<any>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
<tt><vararg></tt> contains key-value pairs. The accepted keys
are <i>from</i> and <i>to</i> which must always occur together,
and <i>delete</i> and <i>squash</i>. The values of these keys
must be valid <i>translation</i> specifications.
This primitive transforms <tt><any></tt> by successively applying
translation, deletion and squashing in that order. Only the
transformations that are needed need be specified.</p>
<p class="asd_par">
The syntax accepted as translation specification is almost
fully compliant with the syntax accepted by <b>tr</b>(1), with
three exceptions. First, repeats are introduced as
<tt>[*a*20]</tt> rather than <tt>[a*20]</tt>. Second, ranges can (for
now) only be entered as <tt>X-Y</tt>, not as <tt>[X-Y]</tt>.
<tt>X</tt> and <tt>Y</tt> <i>can</i> be entered in either octal or
hexadecimal notation (see further below).
As an additional feature, the magic repeat operator <tt>[*a#]</tt> stops on both
class and range boundaries. Finally, character specifications can be
complemented by preceding them with the caret <tt>^</tt>. See further below for
examples where these features are used.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Preprocessing</span>
The values (not the data <tt><any></tt>) are subjected to <span class="smallcaps">UNIX</span> tilde expansion
as described in the <a class="local sibling" href="zoem.html#tildexp">the zoem manual</a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Syntax</span>
Specifications may contain ranges of
characters such as <tt>a-z</tt> and <tt>0-9</tt>. Posix character classes
are allowed. The available classes are</p>
<div class="verbatim"> [:alnum:]
[:alpha:]
[:cntrl:]
[:digit:]
[:graph:]
[:lower:]
[:print:]
[:punct:]
[:space:]
[:upper:]
[:xdigit:]</div>
<p class="asd_par">
Characters can be specified using octal notation, e.g.
<tt>\012</tt> encodes the newline. Use <tt>\173</tt> for the opening curly,
<tt>\175</tt> for the closing curly, <tt>\134</tt> for the backslash, and <tt>\036</tt> for
the caret if it is the first character in a specification. <i>DON'T</i> use
<tt>\\</tt>, <tt>\{</tt>, or <tt>\}</tt> in this case! Hexadecimal notation is written
as <tt>\x7b</tt> (the left curly in this instance).</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The expanded <tt><any></tt> subjected to the <tt>tr</tt> operator as specified.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Example</span>
The following was entered in interactive mode.</p>
<div class="verbatim">\tr{
{from}{[:lower:][:upper:][:digit:][:space:][:punct:]}
{to}{[*L#][*U#][*D#][*S#][*P#]}}{
!"#$%&'()*+,-./0123456789:;<=>?@
ABCDEFGHIJKLMNOPQRSTUVWXYZ
[\\]^_`
abcdefghijklmnopqrstuvwxyz
\{|\}~]}
.
----------------------------------------
SSPPPPPPPPPPPPPPPDDDDDDDDDDPPPPPPPSUUUUUUUUUUUUUUUUUUUUUUUUUUSPPPPPPSLLLLLLLLLLLLLLLLLLLLLLLLLLSPPPPP
----------------------------------------
\tr{
{squash}{^}
{from}{[:lower:][:upper:][:digit:][:space:][:punct:]}
{to}{[*L#][*U#][*D#][*S#][*P#]}}{
!"#$%&'()*+,-./0123456789:;<=>?@
ABCDEFGHIJKLMNOPQRSTUVWXYZ
[\\]^_`
abcdefghijklmnopqrstuvwxyz
\{|\}~]}
.
----------------------------------------
SPDPSUSPSLSP</div>
<p class="asd_car">Note how the magic repeat operator <tt>[*#]</tt> stops on class boundaries.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="trace_1">
</a>
<tt>\trace#1</tt>: <tt>\trace{<<int>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The argument is expanded and interpreted as an integer. This integer
encodes an ensemble of flags controlling the trace output. The different
modes are exactly the same as those that can be set from the command line.
Refer to the <a class="intern" href="#cline">corresponding section</a> for more information.
Special values are <tt>0</tt> (switch off all tracing),
<tt>-1</tt> (switch on all tracing modes in short mode),
<tt>-2</tt> (switch on all tracing modes in long mode),
<tt>-3</tt> (switch to the previous tracing value),
and <tt>-4</tt> emit a listing of tracing bits.
The third can be useful to switch tracing on for a short while and then off
again if you need to debug your document.
Additionally and redundantly, <tt>\trace#1</tt> puts the previous tracing
value in place.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The previous tracing value.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="try_1">
</a>
<tt>\try#1</tt>: <tt>\try{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
This will process the content and
output is written in the macro <a class="intern" href="#session"><tt>\__zoemput__</tt></a>. Output will
be truncated in case <a class="intern" href="#throw_2"><span class="zpr">\throw#2</span></a> was used or an error occurred.
The status, currently one of <tt>done</tt>, <tt>towel</tt>, or <tt>error</tt>,
is written in the session macro <a class="intern" href="#session"><tt>\__zoemstat__</tt></a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
None.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="undef_1">
</a>
<tt>\undef#1</tt>: <tt>\undef{<key-sig>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Deletes the key with signature <tt><key-sig></tt> from the
top level dictionary. Complains (but does not fail) if the key
does not exist in that dictionary.
It is possible to specify that a regular key (i.e. not a dollar key)
must be looked up in the global dictionary by prefixing its
signature with two single quotes.
</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
None.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="vanish_1">
</a>
<tt>\vanish#1</tt>: <tt>\vanish{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
This will only process the content for its side effects. Any result text is
disregarded. This allows easy free-style commenting of sequences of
definitions. By comparison, <a class="intern" href="#formatted_1"><span class="zpr">\formatted#1</span></a> provides the means to give a
formatted presentation of the definitions themselves.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
None.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="while_2">
</a>
<tt>\while#2</tt>: <tt>\while{<condition>}{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
While <tt><condition></tt> exands to something that is nonzero when interpreted
as an integer, <tt><any></tt> is expanded and concatenated to the result text.
The following piece of zoem asks the user for an integer and writes all
Fibonacci numbers smaller than that integer plus one extra to <span class="smallcaps">STDOUT</span>.</p>
<div class="verbatim">\import{ctr.zmm} \: import ctr macros.
\def{fib#1}{
\ctrset{a}{1}
\ctrset{b}{1}
\ctrset{c}{0}
\while{\eqt{lq}{\ctrput{c}}{\1}}{
\ctrset{c}{\ctrput{a}}
\ctrset{a}{\let{\ctrput{a}+\ctrput{b}}}
\write{-}{txt}{\ctrput{c}\|}
\ctrset{b}{\ctrset{c}}
}
}
\write{-}{txt}{Enter a number please, }
\write{-}{txt}{then press <cr> and <ctl-d>\|}
\setx{num}{\finsert{-}} \: this reads from <span class="smallcaps">STDIN</span>.
\fib{\num}</div>
<p class="asd_ccar"><span class="asd_ccar_caption">Note</span>
The strings built up by <a class="intern" href="#while_2"><span class="zpr">\while#2</span></a> are internally concatenated
until it is done, so the result from <a class="intern" href="#while_2"><span class="zpr">\while#2</span></a> <i>can</i> be captured.
This will make <a class="intern" href="#while_2"><span class="zpr">\while#2</span></a> work for <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a>. If you want to output
100M worth of lines or paragraphs in a while loop, either embed the stuff to
be output in a <a class="intern" href="#write_3"><span class="zpr">\write#3</span></a> call and make sure that no whitespace results
from the loop (for example by using <a class="intern" href="#formatted_1"><span class="zpr">\formatted#1</span></a>), or simply use
<a class="intern" href="#whilst_2"><span class="zpr">\whilst#2</span></a>. With <a class="intern" href="#write_3"><span class="zpr">\write#3</span></a> you can specify a file name to which
results should be output (use <a class="intern" href="#session"><tt>\__fnout__</tt></a> for the current default output
file) whereas <a class="intern" href="#whilst_2"><span class="zpr">\whilst#2</span></a> simply outputs to the current default stream.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="whilst_2">
</a>
<tt>\whilst#2</tt>: <tt>\whilst{<condition>}{<any>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
While <tt><condition></tt> exands to something that is nonzero when interpreted
as an integer, <tt><any></tt> is expanded and <i>immediately output</i> to
the current default output stream.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
None — everything is sent to the default output stream right away.
Output from <a class="intern" href="#while_2"><span class="zpr">\while#2</span></a> <i>can</i> be captured, i.e. it can be that what
is assigned by a <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a> invocation.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="write_3">
</a>
<tt>\write#3</tt>: <tt>\write{<<file name>>}{<str>}{<<any>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The first argument is expanded and used as a file name. It is a fatal error
if the file has either not been opened by a previous <tt>\write#3</tt> call or
cannot be opened for writing. Two special file names or 'streams' are
recognized, namely <tt>-</tt> and <tt>stderr</tt>. They map to <span class="smallcaps">STDOUT</span>
and <span class="smallcaps">STDERR</span>.
The third argument is expanded, filtered, and written to file. The second
argument indicates the filter to be used. It must be one of the (literal)
strings <tt>copy</tt>, <tt>device</tt>, or <tt>txt</tt>.</p>
<p class="asd_par">
The <tt>copy</tt> filter does not filter anything at all (neither plain scope
nor device scope) and does not touch any of the zoem escape sequences
remaining after expansion.</p>
<p class="asd_par">
The <tt>device</tt> filter does a full-fledged filtering of both parse scopes.
It respects the settings according to the <a class="intern" href="#special_1"><span class="zpr">\special#1</span></a>
primitive. The write primitive associates unique metadata with each
file it opens, so <i>at directives</i> such as <tt>\N</tt>, <tt>\W</tt>, and <tt>\+</tt>
for different output files do not interfere with one another.
Refer to the <a class="intern" href="#dscope">Device scope</a> section for more information on
at directives.</p>
<p class="asd_par">
The <tt>txt</tt> filter maps <tt>\\</tt> to <tt>\</tt> (i.e. a single
backslash), <tt>\~</tt> to a single space, <tt>\-</tt> to a single hyphen,
<tt>\,</tt> (the atomic separator) to nil, <tt>\|</tt> to a newline,
<tt>\{</tt> to <tt>{</tt>, and <tt>\}</tt> to <tt>}</tt>. It copies everything
else verbatim.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
Technically none, as the output of <a class="intern" href="#write_3"><span class="zpr">\write#3</span></a> cannot be captured.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="writeto_1">
</a>
<tt>\writeto#1</tt>: <tt>\writeto{<<file-name>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
Closes the current default output stream, and changes it to point to file
<tt><file name></tt>. Useful when splitting a document into chapters, or god
forbid, nodes.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Notes</span>
If the file name contains a path separator, zoem will refuse to carry
on, because this may pose a risk that sensitive files are overwritten -
in case someone has written a malicious zoem input file to do just that.
If the option <tt>--unsafe</tt> is used, zoem will query the user
what to do. If the option <tt>--unsafe-silent</tt> is used, zoem will
merrily buzz on without querying.
The path separator is entirely <span class="smallcaps">UNIX</span>-centric, i.e. a forward slash.</p>
<p class="asd_par">
Zoem will recognize if <tt>\writeto#1</tt> is issued more than once for the same
file <tt><file-name></tt>. On the first occassion, it will simply open the file
and truncate any previous contents. On the second occasion and onwards, it
will append to the file. There is currently no option to vary this
behaviour. Zoem will not recognize the fact that different strings might
refer to the same file (e.g. <tt>foo</tt> and <tt>./foo</tt>). Whenever it encounters
a file name not seen before, it will try to open the file in write mode.</p>
<p class="asd_par">
In interactive mode, <tt>\writeto#1</tt> has no effect for text entered
in plain mode. It <i>does</i> have effect in case <a class="intern" href="#write_3"><span class="zpr">\write#3</span></a> is issued
with <a class="intern" href="#session"><tt>\__fnout__</tt></a> as the file name argument, since <tt>\writeto#3</tt>
resets the <a class="intern" href="#session"><tt>\__fnout__</tt></a> macro.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
None.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_cascade"><div class=" item_leftalign nowrap "
style="">
<a name="zinsert_1">
</a>
<tt>\zinsert#1</tt>: <tt>\zinsert{<<file name>>}</tt></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
The contents of file <tt><file name></tt> are put in place unaltered
enclosed by the <a class="intern" href="#excl_1"><span class="zpr">\!#1</span></a> delay primitive. The contents must necessarily
satisfy zoem syntax. If the file can not be opened, the empty
string results.
See also <a class="intern" href="#finsert_1"><span class="zpr">\finsert#1</span></a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Example</span></p>
<div class="verbatim">\setx{foo}{\zinsert{mydata}}
\setx{foo}{\eval{\zinsert{mydata}}}</div>
<p class="asd_par">
In the first case, <tt>\foo</tt> will contain the exact contents
of file <tt>mydata</tt>. Those contents are first
enclosed within the <a class="intern" href="#excl_1"><span class="zpr">\!#1</span></a> primitive by <a class="intern" href="#zinsert_1"><span class="zpr">\zinsert#1</span></a>.
The resulting text is evaluated by <a class="intern" href="#setx_2"><span class="zpr">\setx#2</span></a> - the only
thing this does is strip the enclosing <tt>\!{}</tt> scope.</p>
<p class="asd_par">
In the second case, <tt>\foo</tt> will contain the <i>evaluated</i>
contents of file <tt>mydata</tt>, as <a class="intern" href="#eval_1"><span class="zpr">\eval#1</span></a> adds an additional
layer of evaluation.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Note</span>
This primitive is able to read
<a class="intern" href="#fileread">inline files</a>, unlike <a class="intern" href="#finsert_1"><span class="zpr">\finsert#1</span></a>.</p>
<p class="asd_cpar"><span class="asd_cpar_caption">Result text</span>
The contents of file <tt>file name</tt> or the empty string if
file can not be opened.</p>
</div>
</div>
<a name="pitfalls"></a><div class="sec_leader sec_lev1"><div class="sec_title"><a class="intern" href="#pitfalls">Pitfalls</a></div><div class="sec_num"><a class="intern" href="#toc9"><span class="sec_num">9</span></a></div></div>
<p class="asd_par">
This is a young section, with only few entries yet.</p>
<div class=" itemize " style="margin-top:1em; margin-left:0em; font-size:100%">
<div style="position:relative; margin-top:0em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[<a class="intern" href="#system_3"><span class="zpr">\system#3</span></a>] Beware that the argument/option list (the second
argument of <tt>\system#3</tt>) is encoded
as a vararg. If you have a single argument, it is easy to
forget the enclosing curlies. In that case, zoem ignores the
argument altogether.</p>
<p class="asd_par">
Zoem protects the data returned by <tt>\system#3</tt>. So you may
e.g. think (as I once did) that</p>
<div class="verbatim">\system{date}{{%e}{%B}{%Y}}</div>
<p class="asd_car">
Is a neat way to create a vararg, but you will end up with
something like</p>
<div class="verbatim">\{24\}\{April\}\{2004\}</div>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
[Package authors] Beware of using <i>and</i> scope within <i>at</i> scope
within a <tt>\write#3</tt> invocation that uses the copy filter.</p>
<div class="verbatim">\write{file}{copy}{ foo \@{ zut \&{ bar }}}</div>
<p class="asd_car">
The <tt>bar</tt> part will not be evaluated as the copy filter does not apply the
filtering stage. If the stuff written is read back in from some other part
of the document, or from another document altogether, the <tt>bar</tt> part will
be evaluated in a different context than the one in which it was created.</p>
</div>
<div style="position:relative; margin-top:1em"><div class=" item_compact"><div class=" item_rightalign "
style="right:-1em"><span class="itembullet">•</span></div></div></div>
<div class=" item_text " style="margin-left:2em">
<p class="asd_car">
<a class="intern" href="#throw_2"><span class="zpr">\throw#2</span></a> with argument <tt>done</tt> can be used to halt processing of the
current file. Refer to the <a class="intern" href="#throw_2"><span class="zpr">\throw#2</span></a> description for the associated
requirements.</p>
</div>
</div>
<a name="glossary"></a><div class="sec_leader sec_lev1"><div class="sec_title"><a class="intern" href="#glossary">Glossary</a></div><div class="sec_num"><a class="intern" href="#toc10"><span class="sec_num">10</span></a></div></div>
<p class="asd_par">
For <b>user keys</b>, <b>dollar keys</b>, and <b>dictionary stacks</b>,
refer to the <a class="intern" href="#dictionary">Dictionary stacks</a> section and the <a class="intern" href="#macro">Macro expansion</a> section.
For <b>data keys</b>, refer to the <a class="intern" href="#grape">Tree data</a> section.</p>
<p class="asd_par">
For <b>key signatures</b> and <b>key mention</b>, refer to the <a class="intern" href="#signature">Key signatures</a>
section. For <b>anonymous keys</b>: the <a class="intern" href="#anonymous">Anonymous keys</a> section.</p>
<p class="asd_par">
<b>Session variables</b> are described in the <a class="intern" href="#session">Session keys</a> section.</p>
<p class="asd_par">
For <b>varargs</b>, arguments in which a variable number of sub-arguments
can be stored, and for <b>blocks</b>: the <a class="intern" href="#vararg">Of blocks and varargs</a> section.</p>
<p class="asd_par">
For <b>plain scope</b>, <b>device scope</b>, <b>at scope</b>, and <b>glyph
sequences</b>: The <a class="intern" href="#dichotomy">Scope dichotomy</a> and <a class="intern" href="#dscope">Device scope</a> sections.</p>
<p class="asd_par">
For file read and <b>inline files</b>: the <a class="intern" href="#fileread">File read</a> section.</p>
<p class="asd_par">
Sometimes zoem <i>protects</i> or <i>unprotects</i> data. Refer to the
<a class="intern" href="#protection">Protection</a> section.</p>
<a name="asd_body_end"></a>
</div></div>
</body>
</html>
|