File: chicken.texi

package info (click to toggle)
chicken 1.63-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 27,072 kB
  • ctags: 39,156
  • sloc: ansic: 399,116; lisp: 50,264; sh: 8,206; makefile: 628
file content (12667 lines) | stat: -rw-r--r-- 372,262 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
\input texinfo @c -*-texinfo-*-
@setfilename chicken.info
@settitle CHICKEN - A practical and portable Scheme system. Version 1, Build 63

@ifnottex
@macro pointrightarrow
->
@end macro
@end ifnottex

@iftex
@macro pointrightarrow
@math{@rightarrow{}}
@end macro
@end iftex

@copying
@noindent
Copyright @copyright{} 2000-2004, Felix L. Winkelmann
All rights reserved.

@noindent
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

@itemize
@item Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
@item Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
@item Neither the name of the author nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.  
@end itemize

@
@

@noindent

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE,
DATA, OR PROFITS OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

@end copying

@dircategory The Algorithmic Language Scheme
@direntry
* CHICKEN: (chicken).          A pratical and portable Scheme system (Version 1, Build 63).
@end direntry

@titlepage
@title CHICKEN
@subtitle A practical and portable Scheme system
@subtitle User's Manual
@subtitle Version 1 Build 43
@author Felix L. Winkelmann
@end titlepage

@insertcopying
@contents

@syncodeindex vr fn


@ifnottex
@node Top
@top CHICKEN

CHICKEN - A practical and portable Scheme system
User's manual (Version 1, Build 63)

(c) 2000-2004, Felix L. Winkelmann
All rights reserved. Translated to LaTeX by Peter Keller. Translated to texinfo by Linh Dang.

@menu
* Introduction::                
* Basic mode of operation::     
* Using the compiler::          
* Using the interpreter::       
* Supported language::          
* Interface to external functions and variables::  
* chicken-setup::
* Additional files::            
* Data Representation::         
* Bugs and limitations::        
* Acknowledgements::            
* Bibliography::                
* Index::                       

@detailmenu
 --- The Detailed Node Listing ---

Using the compiler

* Compiler command line format::  
* Runtime options::             
* An example::                  
* Extending the compiler::      
* Distributing compiled C files::  

Using the interpreter

* Interpreter  command line format::  
* Writing Scheme scripts::      
* Toplevel commands::           
* Macros and procedures implemented in the interpreter::  

Supported language

* Deviations from the standard::  
* Extensions to the standard::  
* Non standard read syntax::    
* Non-standard macros and special forms::  
* Declarations::                
* Parameters::                  
* Unit library::                
* Unit eval::                   
* Unit extras::                 
* Unit srfi-1::                 
* Unit srfi-4::                 
* Unit srfi-13::                
* Unit srfi-14::                
* Unit srfi-25::                
* Unit match::                  
* Unit regex::                  
* Unit syntax-case::            
* Unit srfi-18::                
* Unit format::                 
* Unit posix::                  
* Unit utils::           
* Unit tcp::                    
* Unit srfi-37::                
* Unit lolevel::                
* Unit tinyclos::               

Non-standard macros and special forms 

* Binding forms for optional arguments::  
* Other binding forms::         
* Substitution forms and macros::  
* Conditional forms::           
* Record structures::           
* Other forms::                 

Unit library

* Arithmetic::                  
* File Input/Output::           
* Files::                       
* String ports::                
* Feature identifiers::         
* Keywords::                    
* Exceptions::                  
* Environment information and system interface::  
* Execution time::              
* Interrupts and error-handling::  
* Garbage collection::          
* Other control structures::    
* String utilities::
* Generating uninterned symbols::  
* Standard Input/Output::       
* User-defined named characters::  
* Vectors::                     
* The unspecified value::       
* call/cc::                     

Unit eval

* Loading code::                
* Read-eval-print loop::        
* Macros::                      
* Loading extension libraries::         
* Reader extensions::           
* Eval::                        

Unit extras

* Lists::                       
* String-port extensions::      
* Formatted output::            
* Hash tables::                 
* Queues::                      
* Sorting::                     
* Random numbers::              
* Input/Output extensions::     
* Strings::                     
* Combinators::                 
* Binary searching::            

Unit posix

* Directories::                 
* Pipes::                       
* Fifos::                       
* File descriptors and low-level I/O::  
* Retrieving file attributes::  
* Changing file attributes::    
* Processes::                   
* Symbolic links::              
* Permissions::                 
* Record locking::              
* Signal handling::             
* Environment access::          
* Memory mapped I/O::           
* Time routines::               
* Raw exit::                    
* ERRNO values::                
* Finding files::               
* Getting the hostname and system information::  
* Setting a files buffering mode::  
* Terminal ports::              
* How Scheme procedures relate to UNIX C functions::  

Unit utils

* Pathname operations::         
* Temporary files::             
* Deleting a file without signalling an error::  
* Iterating over input lines and files::  
* Executing shell commands with formatstring and error checking::  

Unit lolevel

* Foreign pointers::            
* Tagged pointers::             
* Extending procedures with data::  
* Bytevectors::                 
* Data in unmanaged memory::    
* Locatives::                   
* Accessing toplevel variables::  
* Low-level data access::       
* Procedure-call- and variable reference hooks::  
* Magic::                       

Unit tinyclos

* Defining forms::              
* Base language::               
* Introspection::               
* Intercessory protocol::       
* Additional protocol::         
* Utility procedures::          
* Builtin classes::             

Interface to external functions and variables

* Accessing external objects::  
* Foreign type specifiers::     
* Entry points::                
* Callbacks::                   
* Locations::                   
* Other support procedures::    
* The Easy Foreign Function Interface::  
* C interface::                 

The @emph{Easy} Foreign Function Interface

* #> ... <# Syntax::            
* General operation::           
* Pseudo declarations::         
* Grammar::                     
* C notes::                     
* C++ notes::                   

chicken-setup

* Extension libraries::
* Installing extensions::
* Creating extensions::
* Procedures and macros available in setup scripts::

Additional files

* srfi-13-syntax.scm::          
* chicken-highlevel-macros.scm::  
* chicken-more-macros.scm::     
* chicken-ffi-macros.scm::      
* chicken-entry-points.scm::    
* chicken-default-entry-points.scm::  
* test-infrastructure.scm::     

@code{test-infrastructure.scm}

* The Test Package Macro API::  
* The Test Case Macro API::     
* The Expectation Macro API::   
* Result Object API::           
* Test Package Result Object API::  
* Test Case Result Object API::  
* Single Clause Style Expectation::  
* Equivalence Style Expectation::  
* Tolerance Style Expectation::  
* Various Helper API::          
* Termination API::             
* Destructor Object API::       
* Todo API::                    
* Gloss API::                   
* Skip API::                    
* Side Effect API::             
* Miscellaneous API::           
* Analysis of the Result Tree::  
* Output Generation API::       
* Example Usages of the Test Suite Infrastructure::  

@end detailmenu
@end menu

@end ifnottex

@node Introduction
@chapter Introduction
CHICKEN is a compiler that translates Scheme source files into C, which in
turn can be fed to a C-compiler to generate a standalone executable. This
principle, which is used by several existing compilers, achieves high
portability because C is implemented on nearly all available platforms.

This package is distributed under the BSD license and as such is free
to use and modify. An interpreter is also available and can be used as
a scripting environment or for testing programs before compilation.

The method of compilation and the design of the runtime-system follow
closely Henry Baker's @cite{CONS Should Not CONS Its Arguments, Part II:
Cheney on the M.T.A.} paper and expose a number of interesting
properties: consing (creation of data on the heap) is relatively
inexpensive, because a generational garbage collection scheme is used,
in which short-lived data structures are reclaimed extremely quickly.
Moreover, @code{call-with-current-continuation} is practically for free
and CHICKEN does not suffer under any performance penalties if
first-class continuations are used in complex ways.  The generated C
code is fully tail-recursive.

Some of the features supported by CHICKEN:
@itemize
@item SRFIs 0, 1, 2, 4, 6, 7, 8, 9, 10, 13, 14, 16, 18, 22, 23, 25, 28, 30, 37
 and 39.
@item @code{syntax-case} highlevel macros
@item Lightweight threads based on first-class continuations
@item Pattern matching with Andrew Wright's @code{match} package
@item Record structures
@item An object system with multiple inheritance, multimethods and a
                meta-object protocol
@item Extended comment- and string-literal syntaxes
@item Libraries for regular expressions, string handling, Common LISP
                style @code{format},
UNIX system calls and extended data structures
@item Create interpreted or compiled shell scripts written in Scheme
                for UNIX or Windows
@item Compiled C files can be easily distributed
@item Allows the creation of fully self-contained statically linked executables
@item On systems that support it, compiled code can be loaded dynamically
@end itemize

@node Basic mode of operation
@chapter Basic mode of operation

The compiler translates Scheme source code into fairly portable C that
can be compiled and linked with most available C compilers. CHICKEN supports
the generation of executables and libraries, linked either statically or
dynamically. Compiled Scheme code can be loaded dynamically, or can be
embedded in applications written in other languages. Separate compilation
of modules is fully supported.

The most portable way of creating separately linkable entities is
supported by so-called @emph{unit}s.  A unit is a single
compiled object module that contains a number of toplevel expressions that
are executed either when the unit is the @emph{main} unit or if the
unit is @emph{used}.  To use a unit, the unit has to be @emph{declare}ed
as used, like this:

@verbatim
(declare (uses UNITNAME))
@end verbatim

The toplevel expressions of used units are executed in the order in
which the units appear in the @code{@b{uses}} declaration. Units
may be used multiple times and @code{@b{uses}} declarations may
be circular (the unit is initialized at most once).  To compile a file
as a unit, add a @code{@b{unit}} declaration:

@verbatim
(declare (unit UNITNAME))
@end verbatim

When compiling different object modules, make sure to have one main
unit. This unit is called initially and initializes all used units
before executing its toplevel expressions. The main-unit has no
@code{@b{unit}} declaration.

Another method of using definitions in separate source files is to
@emph{include} them. This simply inserts the code in a given file into
the current file:

@verbatim
(include "FILENAME")
@end verbatim

One important thing: macro definitions are only available when processed
by @code{include} or @code{visit}.
Macro definitions in separate units are not available, since
they are defined at compile time, i.e the time when that other unit
was compiled (macros defined using the low-level macro system can optionally be
available at runtime, see @code{@b{define-macro}} in @ref{Substitution forms and macros}).

On platforms that support dynamic loading of compiled code (like Windows and most ELF based
systems like Linux or BSD), it is not necessary to use unit declarations. Here
code can be compiled into a shared object (@code{.so}) and loaded dynamically into
a running application.


@node Using the compiler
@chapter Using the compiler

The interface to @code{chicken} is intentionally simple.  System
dependent makefiles, shell-scripts or batch-files should perform
any necessary steps before and after invocation of @code{chicken}.
On UNIX-compatible systems, a shell script named @code{chicken-config}
is supplied that emits the correct options for the host system's C
compiler. Enter

@verbatim
chicken-config -help
@end verbatim

on the command line for a list of available options.  On most UNIX
systems, a Scheme script named @code{csc} provides a much simpler
interface to the Scheme- and C-compilers and linker. Enter

@verbatim
csc -help
@end verbatim

on the command line for more information.  A batch-file (@code{csc.bat})
with the same functionality is also available for Windows platforms. The Windows
version of csc (@code{csc.bat}) does not accept more than 8 arguments.

@menu
* Compiler command line format::  
* Runtime options::             
* An example::                  
* Extending the compiler::      
* Distributing compiled C files::  
@end menu

@node Compiler command line format
@section Command line format 

@code{chicken FILENAME @{OPTION@}}

@code{FILENAME} is the complete pathname of the source file that is to
be translated into C. A filename argument of ``@code{-}'' specifies that
the source text should be read from standard input. Note that the filename
has to be the first argument to @code{chicken}.
Possible options are:

@table @code

@item -analyze-only

Stop compilation after first analysis pass.

@item -benchmark-mode

Equivalent to @code{-debug-level 0 -optimize-level 3}
@code{-fixnum-arithmetic -disable-interrupts -block -lambda-lift}.

@item -block

Enable block-compilation. When this option is specified, the
compiler assumes that global variables are not modified outside this
compilation-unit.  Specifically, toplevel bindings are not seen by
@code{eval} and unused toplevel bindings are removed.

@item -case-insensitive

Enables the reader to read symbols case insensitive. The default is to read
case sensitive (in violation of R5RS).  This option registers the @code{case-insensitive}
feature identifier.

@item -check-syntax

Aborts compilation process after macro-expansion and syntax checks.

@item -compress-literals THRESHOLD

Compiles quoted literals that exceed the size @code{THRESHOLD} as strings
and parse the strings at run-time. This reduces the size of the code and
speeds up compile-times of the host C compiler, but has a small run-time
performance penalty. The size of a literal is computed by counting recursively the objects
in the literal, so a vector counts as 1 plus the count of the elements,
a pair counts as the counts of the car and the cdr, respectively.
All other objects count 1.

@item -debug MODES

Enables one or more compiler debugging modes. @code{MODES} is a string
of characters that select debugging information about the compiler that
will be printed to standard output.

@table @kbd
@item t
show time needed for compilation
@item b
show breakdown of time needed for each compiler pass
@item o
show performed optimizations
@item r
show invocation parameters
@item s
show program-size information and other statistics
@item a
show node-matching during simplification
@item p
show execution of compiler sub-passes
@item l
show lambda-lifting information
@item m
show GC statistics during compilation
@item n
print the line-number database 
@item c
print every expression before macro-expansion
@item e
lists all exported toplevel bindings
@item x
display information about experimental features
@item D
when printing nodes, use node-tree output
@item N
show the real-name mapping table
@item U
show expressions after the secondary user pass
@item 0
show database before lambda-lifting pass
@item L
show expressions after lambda-lifting
@item F
show output of ``easy'' FFI parser
@item P
show execution of outer partitioning
@item Q
show execution of middle partitioning
@item R
show execution of inner partitioning
@item 1
show source expressions
@item 2
show canonicalized expressions
@item 3
show expressions converted into CPS
@item 4
show database after each analysis pass
@item 5
show expressions after each optimization pass
@item 6
show expressions after each inlining pass
@item 7
show expressions after complete optimization
@item 8
show database after final analysis
@item 9
show expressions after closure conversion
@end table


@item -debug-level LEVEL

Selects amount of debug-information. @code{LEVEL} should be an integer.


@itemize
@item @code{-debug-level 0} is equivalent to @code{-no-trace}.
@item @code{-debug-level 1} does nothing.
@end itemize

@item -disable-c-syntax-checks

Disable basic syntax checking of embedded C code fragments.

@item -disable-interrupts

Equivalent to the @code{(disable-interrupts)} declaration. No
interrupt-checks are generated for compiled programs.

@item -disable-stack-overflow-checks

Disables detection of stack overflows. This is equivalent to running the compiled
executable with the @code{-:o} runtime option.

@item -dynamic

This option should be used when compiling files intended to be loaded dynamically into
a running Scheme program.

@item -epilogue FILENAME
 Includes the file named
@code{FILENAME} at the end of the compiled source file. The include-path
is not searched. This option may be given multiple times.

@item -explicit-use

Disables automatic use of the units @code{library, eval} and @code{extras}.
Use this option if compiling a library unit instead of an application
unit.

@item -extend FILENAME

Loads a Scheme source file or compiled Scheme program (on systems that
support it) before compilation commences. This feature can be used to
extend the compiler.  This option may be given multiple times.
The file is also searched in the current include path and in the
extension-repository.

@item -feature SYMBOL

Registers @code{SYMBOL} to be a valid feature identifier for
@code{cond-expand}.

@item -ffi

Compile C/C++ code and generate Scheme bindings. This is effectively
equivalent to wrapping the code in @code{#>! ... <#}.

@item -ffi-define SYMBOL

Defines a macro that will be accessible in @code{foreign-parse}
declarations.

@item -ffi-include-path PATH

Set include path for ``easy'' FFI parser.

@item -fixnum-arithmetic

Equivalent to @code{(fixnum-arithmetic)} declaration. Assume all
mathematical operations use small integer arguments.

@item -heap-size NUMBER

Sets a fixed heap size of the generated executable to @code{NUMBER}
bytes. The parameter may be followed by a 
@code{M} (@code{m}) or @code{K} (@code{k})
suffix which stand for mega- and kilobytes, respectively.  The default
heap size is 5 kilobytes. Note that only half of it is in use at every
given time.

@item -heap-initial-size NUMBER

Sets the size that the heap of the compiled application should have at
startup time.

@item -heap-growth PERCENTAGE

Sets the heap-growth rate for the compiled program at compile time
(see: @code{-:hg}).

@item -heap-shrinkage PERCENTAGE

Sets the heap-shrinkage rate for the compiled program at compile time
(see: @code{-:hs}).

@item -help

Print a summary of available options and the format of the command line
parameters and exit the compiler.

@item -syntax

@item -hygienic

Load ``syntax-case'' macro package and enable high-level macros in
compiled code.  This option registers the @code{hygienic-macros}
feature identifier.

@item -hygienic-at-run-time

Makes hygienic (``syntax-case'') macro system available at run-time. Note
that this has a slight overhead, because the hygienic macro definitions
have to be loaded. This will only install the standard R5RS macros,
plus SRFI-0 (@code{cond-expand}). To load all further macros, execute:

@verbatim
(require-extension chicken-more-macros)
@end verbatim

@item -include-path PATHNAME

Specifies an additional search path for files included via the
@code{include} special form. This option may be given multiple times. If
the environment variable @code{CHICKEN_INCLUDE_PATH} is set, it
should contain a list of alternative include pathnames separated by
``@code{;}''. The environment variable @code{CHICKEN_HOME} is also
considered as a search path.

@item -keyword-style STYLE

Enables alternative keyword syntax, where @code{STYLE} may be either
@code{prefix} (as in Common Lisp), @code{suffix} (as in DSSSL) or @code{none}.
Any other value is ignored. The default is @code{suffix}.
If @code{-strict} or @code{-strict-reader} is specified, then the keyword
style is set to @code{none}.

@item -lambda-lift

Enable the optimization known as lambda-lifting.

@item -no-trace

Disable generation of tracing information. If a compiled executable should
halt due to a runtime error, then a list of the name and the line-number (if
available) of the last procedure calls is printed, unless @code{-no-trace}
is specified. With this option the generated
code is slightly faster.

@item -no-feature SYMBOL

Unregisters feature identifier @code{SYMBOL}.

@item -no-warnings

Disable generation of compiler warnings.

@item -nursery NUMBER -stack-size NUMBER

Sets the size of the first heap-generation of the generated executable
to @code{NUMBER} bytes. The parameter may be followed by a @code{M}
(@code{m}) or @code{K} (@code{k}) suffix.  The default stack-size
depends on the target platform.

@item -optimize-leaf-routines

Enable leaf routine optimization.

@item -optimize-level LEVEL

Enables certain sets of optimization options. @code{LEVEL} should be
an integer.


@itemize
@item @code{-optimize-level 0} does nothing.
@item @code{-optimize-level 1} is equivalent to
      @code{-optimize-leaf-routines}
@item @code{-optimize-level 2} is equivalent to
      @code{-optimize-leaf-routines -usual-integrations}
@item @code{-optimize-level 3} is equivalent to
      @code{-optimize-leaf-routines -usual-integrations -unsafe}
@end itemize

@item -output-file FILENAME

Specifies the pathname of the generated C file. Default is @code{FILENAME.c}.

@item -postlude EXPRESSIONS

Add @code{EXPRESSIONS} after all other toplevel expressions in the
compiled file.  This option may be given multiple times. Processing of
this option takes place after processing of @code{-epilogue}.

@item -prelude EXPRESSIONS

Add @code{EXPRESSIONS} before all other toplevel expressions in the
compiled file.  This option may be given multiple times. Processing of
this option takes place before processing of @code{-prologue}.

@item -profile

Instruments the source code to count procedure calls and execution
times. After the program terminates (either via an explicit @code{exit}
or implicitly), profiling statistics are written to a file named
@code{PROFILE}. Each line of the generated file contains a list with
the procedure name, the number of calls and the time spent executing
it. Use the @code{chicken-format-profile} program to display the profiling
information in a more user-friendly form. Enter @code{chicken-format-profile}
with no arguments at the command line to get a list of available options.

@item -prologue FILENAME

Includes the file named @code{FILENAME} at the start of the compiled
source file.  The include-path is not searched. This option may be given
multiple times.

@item -quiet

Disables output of compile information.

@item -require-for-syntax NAME

Loads the extension @code{NAME} before the compilation process
commences.

@item -r5rs

Equivalent to @code{-hygienic -strict}.

@item -run-time-macros

Makes low-level macros (compiled without the @code{-hygienic} option) also available
at run-time. By default low-level macros are not available at
run-time. Note that highlevel-macros (@code{syntax-case}) defined in
compiled code are never available at run-time.

@item -split NUMBER
Splits output into multiple C files that can be compiled seperately. The generated
C files will be named @code{filename0}, ..., @code{filename<NUMBER-1>} with as many
files as given in @code{NUMBER}.

@item -split-level NUMBER
Specifies how hard the partitioning algorithm should work:

@itemize
@item 0 Exit after first iteration (quickest)
@item 1 Exit when cost does not decrease by at least one-half (the default)
@item 2 Exit when cost does not change 
@end itemize

@item -strict

Disable non-standard macros. This option registers the @code{strict}
feature identifier. Implies @code{-strict-letrec} and @code{-strict-reader}.

@item -strict-srfi-0

Disable non-standard macros except @code{cond-expand}.  This option
registers the @code{strict} feature identifier. Implies @code{-strict-letrec}
and @code{-strict-reader}.

@item -strict-reader

Disables non-standard read syntax. Implies @code{-case-insensitive}.

@item -strict-letrec

Enable fully R5RS compliant @code{letrec}. This generates slightly less
efficient code but preserves standard semantics.

@item -to-stdout

Write compiled code to standard output instead of creating a @code{.c} file.

@item -unit NAME

Compile this file as a library unit. Equivalent to 

@verbatim
-prelude "(declare (unit NAME))"
@end verbatim

@item -unsafe

Disable runtime safety checks.

@item -unsafe-libraries

Marks the generated file for being linked with the unsafe runtime system. This
should be used when generating shared object files that are to be loaded
dynamically. If the marker is present, any attempt to load code compiled with
this option will signal an error.

@item -uses NAME

Use definitions from the library unit @code{NAME}. This is equivalent to

@verbatim
-prelude "(declare (uses NAME))"
@end verbatim

@item -usual-integrations

Specifies that standard procedures and certain internal procedures are
never redefined, and can be inlined. This is equivalent to declaring
@code{(usual-integrations)}.

@item -version

Prints the version and some copyright information and exit the compiler.

@item -verbose

Prints progress information to standard output during compilation.

@end table

The environment variable @code{CHICKEN_OPTIONS} can be set to a string
with default command-line options for the compiler.

@node Runtime options
@section Runtime options

After successful compilation a C source file is generated and can be
compiled with a C compiler. Executables generated with CHICKEN (and the
compiler itself) accept a small set of runtime options:

@table @code
@item -:?

Shows a list of the available runtime options and exits the program.

@item -:c

Forces console mode. Currently this is only used in the interpreter
(@code{csi}) to force output of the @b{#;>} prompt even if stdin
is not a terminal (for example if running in an @code{emacs} buffer
under Windows).

@item -:d

Prints some debug-information during startup.

@item -:hNUMBER

Specifies fixed heap size

@item -:hiNUMBER

Specifies the initial heap size

@item -:hgPERCENTAGE

Sets the growth rate of the heap in percent. If the heap is exhausted,
then it will grow by @code{PERCENTAGE}.
The default is 200.

@item -:hmNUMBER

Specifies a maximal heap size. The default is (2GB - 15).

@item -:hsPERCENTAGE

Sets the shrink rate of the heap in percent. If no more than a quarter
of @code{PERCENTAGE} of the heap is used, then it will shrink to
@code{PERCENTAGE}. The default is 50.  Note: If you want to make sure
that the heap never shrinks, specify a value of @code{0}.  (this can
be useful in situations where an optimal heap-size is known in advance).

@item -:o

Disables detection of stack overflows at run-time

@item -:sNUMBER

Specifies stack size

@item -:tNUMBER

Specifies symbol table size

@item -:w

Enables garbage collection of unused symbols. By default unused and
unbound symbols are not garbage collected.

@item -:r

Writes trace output to stdout. This option has no effect with
in files compiled with the @code{-no-trace} or @code{-debug-level 0}
options.

@end table

The argument values may be given in bytes, in kilobytes (suffixed with
@code{K} or @code{k}), in megabytes (suffixed with @code{M}
or @code{m}), or in gigabytes (suffixed with @code{G}
or @code{g}). Runtime options may be combined, like @code{-:dc},
but everything following a @code{NUMBER} argument is ignored. So
@code{-:wh64m} is OK, but @code{-:h64mw} will not enable GC of
unused symbols.


@node An example
@section An example

To compile a Scheme program (assuming a UNIX-like environment) we perform
the following steps:

@itemize

@item Consider this Scheme source file, named @code{foo.scm}
@verbatim
  ;;; foo.scm

  (define (fac n)
    (if (zero? n)
        1
        (* n (fac (- n 1))) ) )

  (write (fac 10))
  (newline)
@end verbatim

@item Compile the file @code{foo.scm}
@verbatim
% chicken foo.scm
@end verbatim

@item Compile the generated C file @code{foo.c}
@verbatim
% gcc foo.c -o foo `chicken-config -cflags -libs`
@end verbatim

@item Start the compiled program
@verbatim
% foo
@end verbatim
@verbatim
3628800
@end verbatim

@end itemize


If multiple bodies of Scheme code are to be combined into a single
executable, then we have to compile each file and link the resulting
object files together with the runtime system: 

@itemize

@item Consider these two Scheme source files, named @code{foo.scm}
and @code{bar.scm}

@verbatim
  ;;; foo.scm

  (declare (uses bar))

  (write (fac 10)) (newline)


  ;;; bar.scm

  (declare (unit bar))

  (define (fac n)
    (if (zero? n)
        1
        (* n (fac (- n 1))) ) )
@end verbatim

@item Compile the files @code{foo.scm} and @code{bar.scm}
@verbatim
% chicken foo.scm
% chicken bar.scm
@end verbatim

@item Compile the generated C files @code{foo.c} and @code{bar.c}
@verbatim
% gcc -c foo.c `chicken-config -cflags`
% gcc -c bar.c `chicken-config -cflags`
@end verbatim

@item Link the object files @code{foo.o} and @code{bar.o}
@verbatim
% gcc foo.o bar.o -o foo `chicken-config -libs`
@end verbatim

@item Start the compiled program
@verbatim
% foo
3628800

@end verbatim

@end itemize


The declarations specify which of the compiled files is the main
module, and which is the library module. An executable can only have
one main module, since a program has only a single entry-point. In this
case @code{foo.scm} is the main module, because it doesn't have a
@code{unit} declaration.


Extensions to the basic CHICKEN runtime libraries are available in a
separate utility library (@code{libsrfi-chicken.[a|so]}
and @code{libstuffed-chicken.[a|so]} on UNIX-like platforms,
@code{libsrfi-chicken.lib} and @code{libstuffed-chicken.lib} on Windows
systems). Whenever you use one or more of the units @code{format, srfi-1, srfi-4, srfi-13, srfi-14, srfi-18, srfi-25, srfi-37,
posix, utils, lolevel, tinyclos} or @code{regex}, then you
should add these library to the command line of the C compiler or
linker. The compiler driver @code{csc} and the helper script @code{chicken-config}
will do this automatically.


@node Extending the compiler
@section Extending the compiler


The compiler supplies a couple of hooks to add user-level passes to the
compilation process. Before compilation commences any Scheme source files
or compiled code specified using the @code{-extend} option are loaded
and evaluated.  The parameters @code{user-options-pass, user-read-pass,
user-preprocessor-pass, user-pass, user-pass-2} and @code{user-post-analysis-pass} can be set
to procedures that are called to perform certain compilation passes
instead of the usual processing (for more information about parameters
see: @ref{Parameters}.



@defvr {parameter} user-options-pass
Holds a procedure that will be called with a list of command-line
arguments and should return two values: the source filename and the actual
list of options, where compiler switches have their leading @code{-}
(hyphen) removed and are converted to symbols.  Note that this parameter
is invoked @b{before} processing of the @code{-extend} option,
and so can only be changed in compiled user passes.
@end defvr

@defvr {parameter} user-read-pass
Holds a procedure of three arguments. The first argument is a list
of strings with the code passed to the compiler via @code{-prelude}
options. The second argument is a list of source files including any files
specified by @code{-prologue} and @code{-epilogue}. The third argument
is a list of strings specified using @code{-postlude} options. The
procedure should return a list of toplevel Scheme expressions.
@end defvr

@defvr {parameter} user-preprocessor-pass
Holds a procedure of one argument. This procedure is applied
to each toplevel expression in the source file @b{before}
macro-expansion. The result is macro-expanded and compiled in place of
the original expression.
@end defvr

@defvr {parameter} user-pass
Holds a procedure of one argument. This procedure is applied to each
toplevel expression @b{after} macro-expansion.  The result of the
procedure is then compiled in place of the original expression.
@end defvr

@defvr {parameter} user-pass-2
Holds a procedure of three arguments, which is called with the canonicalized
node-graph and the analysis database accessors as arguments (see below for an
explanation of the accessor arguments). The result is ignored,
so this pass has to mutate the node-structure to cause any effect.
@end defvr

@defvr {parameter} user-post-analysis-pass
Holds a procedure that will be called after the
last performed program analysis. The procedure (when defined) will be
called with three arguments: the program database, a getter and a 
setter-procedure which
can be used to access and manipulate the program database, which
holds various information about the compiled program. The getter procedure
should be called with two arguments: a symbol representing the
binding for which information should be retrieved, and a symbol
that specifies the database-entry. The current value of the database
entry will be returned or @code{#f}, if no such entry is
available. The setter procedure is called with three arguments: the
symbol and key and the new value.

For information about the contents of the program database contact
the author.
@end defvr



Loaded code (via the @code{-extend} option) has access to the library
units @code{extras, srfi-1, srfi-4, utils, regex} and the pattern matching macros. 
The highlevel macro-system and multithreading is not available.


Note that the macroexpansion/canonicalization phase of the compiler adds
certain forms to the source program.  These extra expressions are not
seen by @code{user-preprocessor-pass} but by @code{user-pass}.


@node Distributing compiled C files
@section Distributing compiled C files

It is relatively easy to create distributions of Scheme projects that
have been compiled to C.  The runtime system of CHICKEN consists of only
two handcoded C files (@code{runtime.c} and @code{chicken.h}), plus
the file @code{chicken-config.h}, which is generated by the build process. All
other modules of the runtime system and the extension libraries are just
compiled Scheme code. For more information, study the CHICKEN source code
and/or get in contact with the author.


@node Using the interpreter
@chapter Using the interpreter


CHICKEN provides an interpreter named @code{csi} for evaluating Scheme programs
and expressions.

@menu
* Interpreter  command line format::  
* Writing Scheme scripts::      
* Toplevel commands::           
* Macros and procedures implemented in the interpreter::  
@end menu

@node Interpreter  command line format
@section Command line format

@verbatim
  csi {FILENAME|OPTION}
@end verbatim

where @code{FILENAME} specifies a file with Scheme source-code.  If the
extension of the source file is @code{.scm}, it may be omitted. The
runtime options described in @ref{Compiler command line format} are also available
for the interpreter.  If the environment variable @code{CSI_OPTIONS}
is set to a list of options, then these options are additionally passed
to every direct or indirect invocation of @code{csi}. Please note that
runtime options (like @code{-:...}) can not be passed using this method.
The options recognized by the interpreter are:

@table @code

@item --

Ignore everything on the command-line following this marker. Runtime
options (``@code{-:...}'') are still recognized.

@item -case-insensitive

Enables the reader to read symbols case insensitive. The default is to read
case sensitive (in violation of R5RS).  This option registers the @code{case-insensitive}
feature identifier.

@item -batch

Quit the interpreter after processing all command line options.

@item -eval EXPRESSIONS

Evaluate @code{EXPRESSIONS}.

@item -feature SYMBOL

Registers @code{SYMBOL} to be a valid feature identifier for
@code{cond-expand}.

@item -help

Write a summary of the available command line options to standard output
and exit.

@item -syntax

@item -hygienic

Load @b{syntax-case} macro package and enable high-level macros in
interpreted code.  This option registers the @code{hygienic-macros}
feature identifier.

@item -include-path PATHNAME

Specifies an alternative search-path for files included via the
@code{include} special form. This option may be given multiple times. If
the environment variable @code{CHICKEN_INCLUDE_PATH} is set, it
should contain a list of alternative include pathnames separated by
``@b{;}''. The environment variable @code{CHICKEN_HOME} is also
considered as a search path.

@item -keyword-style STYLE

Enables alternative keyword syntax, where @code{STYLE} may be either
@code{prefix} (as in Common Lisp) or @code{suffix} (as in DSSSL).
Any other value is ignored.

@item -no-feature SYMBOL

Unregisters feature identifier @code{SYMBOL}.

@item -no-init

Do not load initialization-file. If this option is not given and the file
@file{~/.csirc} exists, then it is loaded before the read-eval-print
loop commences.

@item -no-warnings

Disables any warnings that might be issued by the reader or evaluated code.

@item -quiet

Do not print a startup message.

@item -r5rs

Equivalent to @code{-hygienic -strict}.

@item -script PATHNAME

This is equivalent to @code{-batch -quiet -no-init
PATHNAME}. Arguments following @code{PATHNAME} are available by using
@code{command-line-arguments} and are not processed as interpreter
options.

@item -script-meta PATHNAME

This is similar to the @code{-script} option, but the file specified
by @code{PATHNAME} is opened, the first line is treated as containing
additional command line options and (after processing all the options)
the code from the given file is loaded.

@item -strict

Disable non-standard macros. Implies @code{-strict-letrec} and @code{-strict-reader}.

@item -strict-srfi-0

Disable non-standard macros except @code{cond-expand}. Implies @code{-strict-letrec}
and @code{-strict-reader}.

@item -strict-reader

Disables non-standard read syntax. Implies @code{-case-insensitive}.

@item -strict-letrec

Enable fully R5RS compliant @code{letrec}. This generates slightly less
efficient code but preserves standard semantics.

@item -version

Write the banner with version information to standard output and exit.

@end table

@node Writing Scheme scripts
@section Writing Scheme scripts

@itemize
@item Since UNIX shells use the @code{#!} notation for starting scripts,
the interpreter ignores the first line of a source file, if prefixed by @code{#!}.

The easiest way is to use the @code{-script} option like this:

@verbatim
% cat foo
#! /usr/local/bin/csi -script
(print (eval (with-input-from-string
                (car (command-line-arguments))
                 read)))

% chmod +x foo
% foo "(+ 3 4)"
7
@end verbatim

The parameter @code{command-line-arguments} is set to a list of the
parameters that were passed to the Scheme script.  Scripts can be compiled
to standalone executables (don't forget to declare used library units).
Note that the compiler does @b{not} parse the extra arguments passed
to a script via the @code{-script-meta} option!

To overcome a limitation of UNIX that allows only a single argument to
scripts, the @code{-script-meta} options is provided:


@verbatim
% cat foo
#! /usr/local/bin/csi -script-meta
-case-insensitive
(print (with-input-from-string (car (command-line-arguments)) read))

% chmod +x foo
% foo "FooBar"
"foobar"
@end verbatim

@item CHICKEN implements SRFI-22 but provides no driver programs
(@code{scheme-r4rs, scheme-ieee-1178-1990, scheme-r5rs} and
@code{scheme-srfi-0}).  Scheme scripts can be
compiled, the compiler determines language dialect from the invocation
line:

@verbatim
% cat bar
#! /usr/bin/env scheme-r5rs
(define (main args)
  (write (list->string (reverse (string->list (cadr args)))))
  (newline)
  0)

% csi -script bar "one two three"
"eerht owt eno"
% chicken bar -quiet
% gcc bar.c `chicken-config -cflags -libs` -o cbar
% cbar "one two three"}
"eerht owt eno"
@end verbatim 

For more information, see the @uref{http://srfi.schemers.org/srfi-22/srfi-22.html, SRFI-22 document }

@item Windows and DOS:

CHICKEN supports writing shell scripts in Scheme for these platforms as well,
using a slightly different approach. The first example would look like
this on Windows:

@verbatim
C:>type foo.bat
@;csibatch %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
(print (eval (with-input-from-string
                (car (command-line-arguments))
                read)))

C:>foo "(+ 3 4)"
7
@end verbatim

Like UNIX scripts, batch files can be compiled. Windows batch scripts do not
accept more than 8 arguments.

@end itemize

@node Toplevel commands
@section Toplevel commands

The toplevel loop understands a number of special commands:

@table @code
@item ,?

Show summary of available toplevel commands.

@item ,NUM

Evaluate @code{NUM}th command in history-list

@item ,h

List history of last commands

@item ,l FILENAME

Load file with given @code{FILENAME} (may be a symbol or string).

@item ,ln FILENAME

Load file and print result(s) of each top-level expression.

@item ,p EXP

Pretty-print evaluated expression @code{EXP}.

@item ,d EXP

Describe result of evaluated expression @code{EXP}.

@item ,du EXP

Dump contents of the result of evaluated expression @code{EXP}.

@item ,dur EXP N

Dump @code{N} bytes of the result of evaluated expression @code{EXP}.

@item ,q

Quit the interpreter.

@item ,r

Show system information.

@item ,s STRING-OR-SYMBOL

Execute shell-command.

@item ,t EXP

Evaluate form and print elapsed time.

@item ,x EXP

Pretty-print macroexpanded expression @code{EXP} (the expression is
not evaluated).

@end table

@node Macros and procedures implemented in the interpreter
@section Macros and procedures implemented in the interpreter

Additional macros and procedures available in the interpreter are:



@deffn {syntax} advise
@lisp
(advise NAME MODE PROC)
@end lisp
Modifies the behavior of the procedures named @code{NAME}, according
to @code{MODE}:

@table @code
@item before

Call the procedure @code{PROC} before every invocation of @code{NAME},
with the same arguments.

@item after

Call the procedure @code{PROC} with the result value(s) of @code{NAME}.

@item around

Call the procedure @code{PROC} with the arguments passed to
@code{NAME}.  Additionally the (original) value of @code{NAME}
is passed as the first argument to @code{PROC}.

@end table

Only the @code{PROC} argument is evaluated. Note that multiple pieces
of advice on the same procedure are allowed.

@verbatim
#;> (define (fac n)
      (if (zero? n) 1 (* n (fac (sub1 n)))))
#;> (define count 0)
#;> (advise fac before (lambda _ (set! count (add1 count))))
#;> (fac 10)                           ==> 3628800
#;> count                              ==> 11
#;> (advise fac around
      (let ((i 0))
        (define (indent)
          (do ((i i (sub1 i)))
              ((zero? i))
            (write-char #\space)))
      (lambda (f n)
        (indent)
        (print "fac: " n)
        (set! i (add1 i))
        (let ((x (f n)))
          (set! i (sub1 i))
          (indent)
          (print "-> " x)
          x))))
#;> (fac 3)
fac: 3
 fac: 2
  fac: 1
   fac: 0
   -> 1
  -> 1
 -> 2
-> 6                                   ==> 6
#;> count                              ==> 15
#;> (set! count 0)
#;> (unadvise fac)
#;> (fac 10)                           ==> 3628800
#;> count                              ==> 0
@end verbatim

@end deffn
@deffn {syntax} unadvise
@lisp
(unadvise NAME ...)
@end lisp
Removes all pieces of advice from the procedures @code{NAME ...}
and restores their original behavior.

@end deffn
@deffn {syntax} trace
@lisp
(trace NAME ...)
@end lisp
Switches tracing on for the procedures with the given names.

@verbatim
#;> (fac 10)                       ==> 3628800
#;> (trace fac)
#;> (fac 3)
|(fac 3)
| (fac 2)
|  (fac 1)
|   (fac 0)
|   fac -> 1 
|  fac -> 1 
| fac -> 2 
|fac -> 6                          ==> 6
#;> (untrace fac)
#;> (fac 3)                        ==> 6
@end verbatim

@end deffn
@deffn {syntax} untrace
@lisp
(untrace NAME ...)
@end lisp
Switches tracing of the given procedures off.
@end deffn

@deffn {procedure} $
@lisp
($ [INDEX])
@end lisp
Returns entry number @code{INDEX} in the history list.
@end deffn

@deffn {procedure} &
@lisp
(& [INDEX])
@end lisp
Returns result(s) of entry number @code{INDEX} in the history list.
@end deffn


@node Supported language
@chapter Supported language

@menu
* Deviations from the standard::  
* Extensions to the standard::  
* Non standard read syntax::    
* Non-standard macros and special forms::  
* Declarations::                
* Parameters::                  
* Unit library::                
* Unit eval::                   
* Unit extras::                 
* Unit srfi-1::                 
* Unit srfi-4::                 
* Unit srfi-13::                
* Unit srfi-14::                
* Unit srfi-25::                
* Unit match::                  
* Unit regex::                  
* Unit syntax-case::            
* Unit srfi-18::                
* Unit format::                 
* Unit posix::                  
* Unit utils::           
* Unit tcp::                    
* Unit srfi-37::                
* Unit lolevel::                
* Unit tinyclos::               
@end menu

@node Deviations from the standard
@section Deviations from the standard

[2] Identifiers are by default case-sensitive.

[4.1.4] Extended DSSSL style lambda lists are supported. DSSSL formal argument lists are defined by the following grammar:

@verbatim
<formal-argument-list> ==> <required-formal-argument>*
                           [(#!optional <optional-formal-argument>*)]
                           [(#!rest <rest-formal-argument>)]
                           [(#!key <key-formal-argument>*)]
<required-formal-argument> ==> <ident>
<optional-formal-argument> ==> <ident>
                             | (<ident> <initializer>)
<rest-formal-argument> ==> <ident>
<key-formal-argument> ==> <ident>
                          | (<ident> <initializer>)
<initializer> ==> <expr>
@end verbatim

When a procedure is applied to a list of actual arguments, the formal and actual arguments are processed from left to right as follows:

@enumerate
@item Variables in required-formal-arguments are bound to successive actual arguments starting with the first actual argument. It shall be an error if there are fewer actual arguments than required-formal-arguments.

@item Next, variables in optional-formal-arguments are bound to any remaining actual arguments. If there are fewer remaining actual arguments than optional-formal-arguments, then variables are bound to the result of the evaluation of initializer, if one was specified, and otherwise to @code{#f}. The initializer is evaluated in an environment in which all previous formal arguments have been bound.
@item If there is a rest-formal-argument, then it is bound to a list of all remaining actual arguments. The remaining actual arguments are also eligible to be bound to keyword-formal-arguments. If there is no rest-formal-argument and there are no keyword-formal-arguments, the it shall be an error if there are any remaining actual arguments.
@item If @code{#!key} was specified in the formal-argument-list, there shall be an even number of remaining actual arguments. These are interpreted as a series of pairs, where the first member of each pair is a keyword specifying the argument name, and the second is the corresponding value. It shall be an error if the first member of a pair is not a keyword. It shall be an error if the argument name is not the same as a variable in a keyword-formal-argument, unless there is a rest-formal-argument. If the same argument name occurs more than once in the list of actual arguments, then the first value is used. If there is no actual argument for a particular keyword-formal-argument, then the variable is bound to the result of evaluating initializer if one was specified, and otherwise @code{#f}. The initializer is evaluated in an environment in which all previous formal arguments have been bound. 
@end enumerate

It shall be an error for an @code{<ident>} to appear more than once in a formal-argument-list.

Example:

@verbatim
((lambda (x y) x) 3 4 5 6)   =>(3 4 5 6)
((lambda (x y #!rest z) z)
 3 4 5 6)                    => (5 6)
((lambda (x y #!optional z #!rest r #!key i (j 1)) 
    (list x y z i: i j: j))
 3 4 5 i: 6 i: 7)            => (3 4 5 i: 6 j: 1)
@end verbatim

[4.1.6] @code{set!} for unbound toplevel variables is allowed.

[5.2] @code{define} with a single argument is allowed and initializes the toplevel or local binding
to an unspecified value.

[6.2.4]  The runtime system uses the numerical string-conversion
routines of the underlying C library and so does only understand standard
(C-library) syntax for floating-point constants.

[6.2.5]  The routines @code{complex?}, @code{real?}
and @code{rational?} are identical to the standard procedure
@code{number?}. The procedures @code{numerator}, @code{denominator}
and @code{rationalize} are not implemented.  Also not implemented are
all procedures related to complex numbers.

[6.2.6] The procedure @code{string->number} does not obey read/write
invariance on inexact numbers.

[6.5] Code evaluated in @code{scheme-report-environment} or
@code{null-environment} still sees non-standard syntax unless running
under the interpreter (@code{csi}) invoked with the @code{-strict}
option.

[6.6.2] The procedure @code{char-ready?} is handling terminal input
ports only under DJGPP correctly. On other platforms it returns always
@code{#t}.  The procedure @code{read} does not obey read/write
invariance on inexact numbers.

[6.6.3] The procedures @code{write} and @code{display} do not obey
read/write invariance to inexact numbers.

@node Extensions to the standard
@section Extensions to the standard

[2.1] Identifiers may contain special characters if delimited with
@code{| ... |}.

[2.3] The brackets @code{[ ... ]} are provided as an alternative syntax
for @code{( ... )}.  A number of reader extensions is provided. See
@ref{Non standard read syntax}.

[4] Numerous non-standard macros are provided. See @ref{Non-standard
macros and special forms} for more information.

[4.2.2] It is allowed for initialization values of bindings in a @code{letrec}
construct to refer to previous variables in the same set of bindings, so

@verbatim
(letrec ([foo 123]
         [bar foo] )
  bar)
@end verbatim

is allowed and returns @code{123}. This extension is not available
when strict R5RS @code{letrec} semantics have been selected (by using the 
@code{-strict}, @code{-strict-srfi-0} or @code{-strict-letrec}
option).

[4.2.3] @code{(begin)} is allowed in non-toplevel contexts and evaluates
to an unspecified value.

[4.2.5] Delayed expressions may return multiple values.

[5.2.2] CHICKEN extends standard semantics by allowing internal definitions
everywhere, and not only at the beginning of a body. A set of internal definitions
is equivalent to a @code{letrec} form enclosing all following expressions
in the body:

@verbatim
(let ([foo 123])
  (bar)
  (define foo 456)
  (baz foo) )
@end verbatim

expands into

@verbatim
(let ([foo 123])
  (bar)
  (letrec ([foo 456])
    (baz foo) ) )
@end verbatim

This extension to the standard semantics is not available in combination with
the hygienic (@code{syntax-case}) macro system. Under the hygienic macro system
an error will be signalled when internal definitions occur at a position that
is not at the beginning of a body.

[6] CHICKEN provides numerous non-standard procedures. See the manual
sections on library units for more information.

[6.3.4] User defined character names are supported. See
@code{char-name} in @ref{User-defined named characters}.

[6.3.5]  CHICKEN supports special characters preceded with
a backslash ``\'' in quoted string
constants. ``\n'' denotes the newline-character,
``\r'' carriage return, ``\b''
backspace, ``\t'' TAB and
``\xXX'' a character with the code @code{XX} in hex.

The third argument to @code{substring} is optional and defaults to the length
of the string.

[6.4] @code{force} called with an argument that is not a promise returns
that object unchanged.  Captured continuations can be safely invoked
inside before- and after-thunks of a @code{dynamic-wind} form and
execute in the outer dynamic context of the @code{dynamic-wind} form.

[6.5] The second argument to @code{eval} is optional and
defaults to the value of @code{(interaction-environment)}.
@code{scheme-report-environment} and @code{null-environment} accept
an optional 2nd parameter: if not @code{#f} (which is the default),
toplevel bindings to standard procedures are mutable and new toplevel
bindings may be introduced.

[6.6.1] if the procedures @code{current-input-port} and
@code{current-output-port} are called with an argument (which should
be a port), then that argument is selected as the new current input- and
output-port, respectively.  The procedures @code{open-input-file},
@code{open-output-file}, @code{with-input-from-file},
@code{with-output-to-file}, @code{call-with-input-file} and
@code{call-with-output-file} accept an optional second (or third)
argument which should be one or more keywords, if supplied. These
arguments specify the mode in which the file is opened. Possible
values are the keywords @code{#:text}, @code{#:binary} or
@code{#:append}.

@node Non standard read syntax
@section Non standard read syntax 



@deffn {read syntax} {#| @dots{} |#}
A multiline ``block'' comment. May be nested. Implements @uref{http://srfi.schemers.org/srfi-30/srfi-30.html, SRFI-30
})
@end deffn

@deffn {read syntax} {#;EXPRESSION}
Treats @code{EXPRESSION} as a comment.
@end deffn

@deffn {read syntax} {#,(CONSTRUCTORNAME DATUM ...)}
Allows user-defined extension of external representations.
(For more information see the documentation for
@uref{http://srfi.schemers.org/srfi-10/srfi-10.html, SRFI-10 })
@end deffn

@deffn {read syntax} {#'EXPRESSION}
An abbreviation for @code{(syntax EXPRESSION)}.
@end deffn

@deffn {read syntax} {#$EXPRESSION}
An abbreviation for @code{(location EXPRESSION)}.
@end deffn

@deffn {read syntax} {#:SYMBOL}
Syntax for keywords. Keywords are symbols that evaluate to themselves,
and as such don't have to be quoted.
@end deffn

@deffn {read syntax} {#<<TAG}
Specifies a multiline string constant. Anything up to a line equal to
@code{TAG} will be returned as a single string:

@ifhtml
@html
<pre>
(define msg #&lt;&lt;END
"Hello, world!", she said.
END
)
</pre>
@end html
@end ifhtml
@ifnothtml
@verbatim
(define msg #<<END
"Hello, world!", she said.
END
)
@end verbatim
@end ifnothtml

is equivalent to

@verbatim
(define msg "\"Hello, world!\", she said.")
@end verbatim
@end deffn

@deffn {read syntax} #<#TAG
Similar to @code{#<<}, but allows substitution of embedded Scheme
expressions prefixed with @code{#} and optionally enclosed in
@code{@{ @dots{} @}}.  Two consecutive @code{#}s are translated to a
single @code{#}:

@verbatim
(define three 3)
(display #<#EOF
This is a simple string with an embedded `##' character
and substituted expressions: (+ three 99) ==> #(+ three 99)
(three is "#{three}")
EOF
)
@end verbatim

prints

@verbatim
This is a simple string with an embedded `#' character
and substituted expressions: (+ three 99) ==> 102
(three is "3")
@end verbatim
@end deffn

@deffn {read syntax} #> ... <#
Abbreviation for @code{(declare (foreign-declare " ... "))}.
@end deffn

@deffn {read syntax} #>? ... <#
Abbreviation for @code{(declare (foreign-parse " ... "))}.
@end deffn

@deffn {read syntax} #>! ... <#
Abbreviation for

@verbatim
(declare
  (foreign-declare " ... ")
  (foreign-parse " ... ") )
@end verbatim
@end deffn

@deffn {read syntax} #%...
Reads like a normal symbol.
@end deffn

@deffn {read syntax} #!...
If occurring in the first line of an interpreted or compiled source file, then the @code{#!}
and everything following it are ignored. If occurring anywhere else, reads as a normal symbol.
The special (self-evaluating) symbol @code{#!eof} is read as the end-of-file object.
@end deffn




@node Non-standard macros and special forms
@section Non-standard macros and special forms 

@menu
* Making extra libraries and extensionsd available::
* Binding forms for optional arguments::  
* Other binding forms::         
* Substitution forms and macros::  
* Conditional forms::           
* Record structures::           
* Other forms::                 
@end menu


@node Making extra libraries and extensionsd available
@subsection Making extra libraries and extensionsd available


@deffn {syntax} require-extension
@deffnx {syntax} use
@lisp
(require-extension ID ...)
(use ID ...)
@end lisp
This form does all necessary steps to make the libraries or extensions given
in @code{ID ...} available. It loads syntactic extension, if needed and generates
code for loading/linking with core library modules or separately installed
extensions. @code{use} is just a shorter alias for @code{require-extension}.

During interpretation/evaluation @code{require-extension} performs one of the
following:

@itemize
@item If @code{ID} names a built in features @code{chicken srfi-22 srfi-23 srfi-30 srfi-39 srfi-8 srfi-6 srfi-2 srfi-0 srfi-10 
srfi-9}, then nothing is done.
@item If @code{ID} names one of syntactic extensions @code{chicken-match-macros chicken-more-macros chicken-default-entry-points 
 chicken-highlevel-macros test-infrastructure chicken-entry-points chicken-ffi-macros}, then this extension will be loaded.
@item If @code{ID} names one of the core library units shipped with CHICKEN, then a @code{(load-library 'ID)} will be performed.
If one of those libraries define specific syntax (@code{match srfi-13}), then the required source file defining the syntax
will be loaded.
@item If @code{ID} names an installed extension with the @code{syntax} or @code{require-at-runtime} attribute, then
the equivalent of @code{(require-for-syntax 'ID)} is performed.
@item Otherwise @code{(require-extension ID)} is equivalent to @code{(require 'ID)}.
@end itemize

During compilation one of the following happens instead:

@itemize
@item If @code{ID} names a built in features @code{chicken srfi-22 srfi-23 srfi-30 srfi-39 srfi-8 srfi-6 srfi-2 srfi-0 srfi-10 
 srfi-9}, then nothing is done.
@item If @code{ID} names one of syntactic extensions @code{chicken-match-macros chicken-more-macros chicken-default-entry-points 
 chicken-highlevel-macros test-infrastructure chicken-entry-points chicken-ffi-macros}, then this extension will be loaded 
 at compile-time, making the syntactic extensions available in compiled code.
@item If @code{ID} names one of the core library units shipped with CHICKEN, then a @code{(declare (uses ID))} is generated.
 If one of those libraries define specific syntax (@code{match srfi-13}), then the required source file defining the syntax
 will be loaded at compile-time, making the syntactic extension available in compiled code.
@item If @code{ID} names an installed extension with the @code{syntax} or @code{require-at-runtime} attribute, then
 the equivalent of @code{(require-for-syntax 'ID)} is performed.
@item Otherwise @code{(require-extension ID)} is equivalent to @code{(require 'ID)}.
@end itemize

To make long matters short - just use @code{require-extension} and it will normally figure everything out for dynamically
loadable extensions and core library units.

@end deffn


@node Binding forms for optional arguments
@subsection Binding forms for optional arguments



@deffn {syntax} :optional
@lisp
(:optional ARGS DEFAULT)
@end lisp
Use this form for procedures that take a single optional argument. If
@code{ARGS} is the empty list @code{DEFAULT} is evaluated and
returned, otherwise the first element of the list @code{ARGS}. It is
an error if @code{ARGS} contains more than one value.

@verbatim
(define (incr x . i) (+ x (:optional i 1)))
(incr 10)                                   ==> 11
(incr 12 5)                                 ==> 17
@end verbatim

@end deffn
@deffn {syntax} case-lambda
@lisp
(case-lambda (LAMBDA-LIST1 EXP1 ...) ...)
@end lisp
SRFI-16. Expands into a lambda that invokes the body following the first
matching lambda-list.

@verbatim
(define plus
  (case-lambda 
    (() 0)
    ((x) x)
    ((x y) (+ x y))
    ((x y z) (+ (+ x y) z))
    (args (apply + args))))

(plus)                      ==> 9
(plus 1)                    ==> 1
(plus 1 2 3)                ==> 6
@end verbatim

For more information see the documentation for
@uref{http://srfi.schemers.org/srfi-16/srfi-16.html, SRFI-16 }

@end deffn
@deffn {syntax} let-optionals
@deffnx {syntax} let-optionals*
@lisp
(let-optionals ARGS ((VAR1 DEFAULT1) ...) BODY ...)
(let-optionals* ARGS ((VAR1 DEFAULT1) ... [RESTVAR]) BODY ...)
@end lisp
Binding constructs for optional procedure arguments. @code{ARGS} should
be a rest-parameter taken from a lambda-list. @code{let-optionals}
binds @code{VAR1 ...} to available arguments in parallel, or
to @code{DEFAULT1 ...} if not enough arguments were provided.
@code{let-optionals*} binds @code{VAR1 ...} sequentially, so every
variable sees the previous ones. If a single variable @code{RESTVAR}
is given, then it is bound to any remaining arguments, otherwise it is
an error if any excess arguments are provided.

@verbatim
(let-optionals '(one two) ((a 1) (b 2) (c 3))
  (list a b c) )                               ==> (one two 3)
(let-optionals* '(one two) ((a 1) (b 2) (c a))
  (list a b c) )                               ==> (one two one)
@end verbatim
@end deffn



@node Other binding forms
@subsection Other binding forms



@deffn {syntax} and-let*
@lisp
(and-let* (BINDING ...) EXP1 EXP2 ...)
@end lisp
SRFI-2. Bind sequentially and execute body. @code{BINDING} can
be a list of a variable and an expression, a list with a single
expression, or a single variable. If the value of an expression
bound to a variable is @code{#f}, the @code{and-let*} form
evaluates to @code{#f} (and the subsequent bindings and the body
are not executed).  Otherwise the next binding is performed. If
all bindings/expressions evaluate to a true result, the body is
executed normally and the result of the last expression is the
result of the @code{and-let*} form. See also the documentation for
@uref{http://srfi.schemers.org/srfi-2/srfi-2.html, SRFI-2 }.

@end deffn
@deffn {syntax} cut
@deffnx {syntax} cute
@lisp
(cut SLOT ...)
(cute SLOT ...)
@end lisp
@uref{http://srfi.schemers.org/srfi-26/srfi-26.html, Syntactic sugar for specializing parameters.}

@end deffn
@deffn {syntax} define-values
@lisp
(define-values (NAME ...) EXP)
@end lisp
Defines several variables at once, with the result values of expression
@code{EXP}.

@end deffn
@deffn {syntax} fluid-let
@lisp
(fluid-let ((VAR1 X1) ...) BODY ...)
@end lisp
Binds the variables @code{VAR1 ...} dynamically to the values @code{X1 ...} 
during execution of @code{BODY ...}.

@end deffn
@deffn {syntax} let-values
@lisp
(let-values (((NAME ...) EXP) ...) BODY ...)
@end lisp
Binds multiple variables to the result values of @code{EXP ...}.
All variables are bound simultaneously.

@end deffn
@deffn {syntax} let*-values
@lisp
(let*-values (((NAME ...) EXP) ...) BODY ...)
@end lisp
Binds multiple variables to the result values of @code{EXP ...}.
The variables are bound sequentially.
@verbatim
(let*-values (((a b) (values 2 3))
              ((p) (+ a b)) )
  p)                               ==> 5
@end verbatim

@end deffn
@deffn {syntax} letrec-values
@lisp
(letrec-values (((NAME ...) EXP) ...) BODY ...)
@end lisp
Binds the result values of @code{EXP ...} to multiple variables at once.
All variables are mutually recursive.
@verbatim
(letrec-values (((odd even)
                   (values 
                     (lambda (n) (if (zero? n) #f (even (sub1 n))))
                     (lambda (n) (if (zero? n) #t (odd (sub1 n)))) ) ) )
  (odd 17) )                           ==> #t
@end verbatim

@end deffn
@deffn {syntax} parameterize
@lisp
(parameterize ((PARAMETER1 X1) ...) BODY ...)
@end lisp
Binds the parameters @code{PARAMETER1 ...} dynamically to the values
@code{X1 ...} during execution of @code{BODY ...}.  (see also:
@code{make-parameter} in @ref{Parameters}). Note that @code{PARAMETER} may be any
expression that evaluates to a parameter procedure.

@end deffn
@deffn {syntax} receive
@lisp
(receive (NAME1 ... [. NAMEn]) VALUEEXP BODY ...)
(receive VALUEEXP)
@end lisp
SRFI-8. Syntactic sugar for @code{call-with-values}. Binds variables
to the result values of @code{VALUEEXP} and evaluates @code{BODY ...}.

The syntax 

@verbatim
(receive VALUEEXP)
@end verbatim

is equivalent to

@verbatim
(receive _ VALUEEXP _)
@end verbatim

@end deffn
@deffn {syntax} set!-values
@lisp
(set!-values (NAME ...) EXP)
@end lisp
Assigns the result values of expression @code{EXP} to multiple
variables.
@end deffn



@node Substitution forms and macros
@subsection Substitution forms and macros



@deffn {syntax} define-constant
@lisp
(define-constant NAME CONST)
@end lisp
Define a variable with a constant value, evaluated at compile-time. 
Any reference to such a
constant should appear textually @b{after} its definition. This
construct is equivalent to @code{define} when evaluated or interpreted.
Constant definitions should only appear at toplevel. Note that constants
are local to the current compilation unit and are not available outside
of the source file in which they are defined. Names of constants still
exist in the Scheme namespace and can be lexically shadowed.  If the
value is mutable, then the compiler is careful to preserve its identity.
@code{CONST} may be any constant expression, and may also refer to
constants defined via @code{define-constant} previously.
This for should only be used at top-level.

@end deffn
@deffn {syntax} define-inline
@lisp
(define-inline (NAME VAR ... [. VAR]) BODY ...)
(define-inline NAME EXP)
@end lisp
Defines an inline procedure. Any occurrence of @code{NAME} will be
replaced by @code{EXP} or @code{(lambda (VAR ... [. VAR]) BODY ...)}. 
This is similar to a macro, but variable-names and -scope will
be correctly handled.  Inline substitutions take place @b{after}
macro-expansion.  @code{EXP} should be a lambda-expression. Any
reference to @code{NAME} should appear textually @b{after}
its definition. Note that inline procedures are local to the current
compilation unit and are not available outside of the source file in
which they are defined. Names of inline procedures still exist in the
Scheme namespace and can be lexically shadowed.  This construct is
equivalent to @code{define} when evaluated or interpreted. Inline
definitions should only appear at toplevel.

@end deffn
@deffn {syntax} define-macro
@lisp
(define-macro (NAME VAR ... [. VAR]) EXP1 ...)
(define-macro NAME (lambda (VAR ... [. VAR]) EXP1 ...))
(define-macro NAME1 NAME2)
@end lisp
Define a globally visible macro special form. The macro is available
as soon as it is defined, i.e. it is registered at compile-time. If
the file containing this definition invokes @code{eval} and the
declaration @code{run-time-macros} (or the command line option
@code{-run-time-macros}) has been used, then the
macro is visible in evaluated expressions during runtime. The second
possible syntax for @code{define-macro} is allowed for portability
purposes only. In this case the second argument @b{must} be a
lambda-expression or a macro name.  Only global macros can be defined using this form.
@code{(define-macro NAME1 NAME2)} simply copies the macro definition
from @code{NAME2} to @code{NAME1}, creating an alias.

This form is also available with the @code{syntax-case} macro
system.
@end deffn


@node Conditional forms
@subsection Conditional forms



@deffn {syntax} switch
@lisp
(switch EXP (KEY EXP1 ...) ... [(else EXPn ...)])
@end lisp
This is similar to @code{case}, but a) only a single key is allowed,
and b) the key is evaluated.

@end deffn
@deffn {syntax} unless
@lisp
(unless TEST EXP1 EXP2 ...)
@end lisp
Equivalent to: 
@verbatim
(if (not TEST) (begin EXP1 EXP2 ...))
@end verbatim

@end deffn
@deffn {syntax} when
@lisp
(when TEST EXP1 EXP2 ...)
@end lisp
Equivalent to:
@verbatim
(if TEST (begin EXP1 EXP2 ...))
@end verbatim
@end deffn



@node Record structures
@subsection Record structures



@deffn {syntax} define-record
@lisp
(define-record NAME SLOTNAME ...)
@end lisp
Defines a record type. Call @code{make-NAME} to create an instance
of the structure (with one initialization-argument for each slot).
@code{(NAME? STRUCT)} tests any object for being an instance of this
structure.  Slots are accessed via @code{(NAME-SLOTNAME STRUCT)}
and updated using @code{(NAME-SLOTNAME-set!} @code{STRUCT}
@code{VALUE)}.

@verbatim
(define-record point x y)
(define p1 (make-point 123 456))
(point? p1)                      ==> #t
(point-x p1)                     ==> 123
(point-y-set! p1 99)
(point-y p1)                     ==> 99
@end verbatim

@end deffn
@deffn {syntax} define-record-printer
@lisp
(define-record-printer (NAME RECORDVAR PORTVAR) BODY ...)
(define-record-printer NAME PROCEDURE)
@end lisp
Defines a printing method for record of the type @code{NAME} by
associating a procedure with the record type. When a record of this
type is written using @code{display, write} or @code{print}, then
the procedure is called with two arguments: the record to be printed
and an output-port.

@verbatim
(define-record foo x y z)
(define f (make-foo 1 2 3))
(define-record-printer (foo x out)
  (fprintf out "#,(foo ~S ~S ~S)"
           (foo-x x) (foo-y x) (foo-z x)) )
(define-reader-ctor 'foo make-foo)
(define s (with-output-to-string
              (lambda () (write f))))
s                                   ==> "#,(foo 1 2 3)"
(equal? f (with-input-from-string
              s read)))             ==> #t
@end verbatim

@code{define-record-printer} works also with SRFI-9 record types.

@end deffn
@deffn {syntax} define-record-type
@lisp
(define-record-type NAME (CONSTRUCTOR TAG ...) PREDICATE
                    (FIELD ACCESSOR [MODIFIER]) ...)
@end lisp
SRFI-9 record types. For more information see the documentation for
@uref{http://srfi.schemers.org/srfi-9/srfi-9.html, SRFI-9 }
@end deffn



@node Other forms
@subsection Other forms



@deffn {syntax} assert
@lisp
(assert EXP [STRING ARG ...])
@end lisp
Signal error if @code{EXP} evaluates to false. An optional message
@code{STRING} and arguments @code{ARG ...} may be supplied to give a
more informative error-message.  If compiled in @emph{unsafe} mode (either
by specifying the @code{-unsafe} compiler option or by declaring
@code{(unsafe)}), then this expression expands to an unspecified value.

@end deffn
@deffn {syntax} cond-expand
@lisp
(cond-expand FEATURE-CLAUSE ...)
@end lisp
SRFI-0. Expands by selecting feature clauses. Predefined
feature-identifiers are @code{srfi-0}, @code{srfi-2}, @code{srfi-6},
@code{srfi-8}, @code{srfi-9}, @code{srfi-10},
 and @code{chicken}. In @code{strict-srfi-0} mode only @code{srfi-0}
and @code{chicken} are defined.  If the source file containing
this form is currently compiled, the feature @code{compiling}
is defined.  For further information, see the documentation for
@uref{http://srfi.schemers.org/srfi-0/srfi-0.html, SRFI-0 } This form
is allowed to appear in non-toplevel expressions.

@end deffn
@deffn {syntax} critical-section
@lisp
(critical-section BODY ...)
@end lisp
Evaluate @code{BODY ...} with timer-interrupts temporarily disabled.

@end deffn
@deffn {syntax} ensure
@lisp
(ensure PREDICATE EXP [ARGUMENTS ...])
@end lisp
Evaluates the expression @code{EXP} and applies the one-argument
procedure @code{PREDICATE} to the result. If the predicate returns
@code{#f} an error is signaled, otherwise the result of @code{EXP}
is returned.  If compiled in @emph{unsafe} mode (either by specifying
the @code{-unsafe} compiler option or by declaring @code{(unsafe)}),
then this expression expands to an unspecified value.  If specified,
the optional @code{ARGUMENTS} are used as arguments to the invocation
of the error-signalling code, as in @code{(error ARGUMENTS ...)}. If
no @code{ARGUMENTS} are given, a generic error message is displayed
with the offending value and @code{PREDICATE} expression.

@end deffn
@deffn {syntax} eval-when
@lisp
(eval-when (SITUATION ...) EXP ...)
@end lisp
Controls evaluation/compilation of subforms. @code{SITUATION} should
be one of the symbols @code{eval}, @code{compile} or @code{load}.
When encountered in the evaluator, and the situation specifier
@code{eval} is not given, then this form is not evaluated and an
unspecified value is returned.  When encountered while compiling code,
and the situation specifier @code{compile} is given, then this form is
evaluated at compile-time.  When encountered while compiling code, and the
situation specifier @code{load} is not given, then this form is ignored
and an expression resulting into an unspecified value is compiled instead.

The following table should make this clearer:

@multitable {compile} {evaluate at compile time} {In interpreted code}
@item                @tab in compiled code         @tab In interpreted code
@item @code{eval}    @tab ignore                   @tab evaluate 
@item @code{compile} @tab evaluate at compile time @tab ignore 
@item @code{load}    @tab compile as normal        @tab ignore 
@end multitable

Note: It is currently not possible to use @code{define-syntax} or
@code{define} inside @code{eval-when} forms when hygienic macros
are enabled.

@end deffn
@deffn {syntax} include
@lisp
(include STRING)
@end lisp
Include toplevel-expressions from the given source file in the currently
compiled/interpreted program.  If the included file has the extension
@code{.scm}, then it may be omitted.  The file is searched in the
current directory and, if not found, in all directories specified in the
@code{-include-path} option.

@end deffn
@deffn {syntax} nth-value
@lisp
(nth-value N EXP)
@end lisp
Returns the @code{N}th value (counting from zero) of the values returned
by expression @code{EXP}.

@end deffn
@deffn {syntax} time
@lisp
(time EXP1 ...)
@end lisp
Evaluates @code{EXP1 ...} and print elapsed time and memory
information. The result of the last expression is returned.
@end deffn


@node Declarations
@section Declarations



@deffn {syntax} declare
@lisp
(declare DECLSPEC ...)
@end lisp
Process declaration specifiers. Declarations always override
any command-line settings.  Declarations are valid for the whole
compilation-unit (source file), the position of the declaration in
the source file can be arbitrary. @code{DECLSPEC} may be any of the
following:



@deffn {declaration specifier} always-bound
@lisp
(always-bound SYMBOL ...)
@end lisp
Declares that the given variables are always bound and
accesses to those have not to be checked.
@end deffn

@deffn {declaration specifier} block
@lisp
(block)
@end lisp
Assume global variables are never redefined. This is the same as
specifying the @code{-block} option.
@end deffn

@deffn {declaration specifier} block-global
@deffnx {declaration specifier} hide
@lisp
(block-global SYMBOL ...)
(hide SYMBOL ...)
@end lisp
Declares that the toplevel bindings for @code{SYMBOL ...}
should not be accessible from code in other compilation units or by
@code{eval}. Access to toplevel bindings declared as block global is
also more efficient.
@end deffn

@deffn {declaration specifier} bound-to-procedure
@lisp
(bound-to-procedure SYMBOL ...)
@end lisp
Declares that the given identifiers are always bound to procedure values.
@end deffn

@deffn {declaration specifier} compress-literals
@lisp
(compress-literals [THRESHOLD [INITIALIZER]])
@end lisp
The same as the @code{-compress-literals} compiler option.
The threshold argument defaults to 50. If the optional argument @code{INITIALIZER}
is given, then the literals will not be created at module startup,
but when the procedure with this name will be called.
@end deffn

@deffn {declaration specifier} export
@lisp
(export SYMBOL ...)
@end lisp
The opposite of @code{hide}. All given identifiers will be exported and all toplevel variables
not listed will be hidden and not be accessible outside of this compilation unit.
When the hygienic (@code{syntax-case}) macro system is used, the exported identifier
may also have the form @code{(MODULE-NAME SYMBOL ...)}, which specifies identifiers to
be exported from a module as (undecorated) toplevel variables.
@end deffn

@deffn {declaration specifier} foreign-declare
@lisp
(foreign-declare STRING ...)
@end lisp
Include given strings verbatim into header of generated file.
@end deffn

@deffn {declaration specifier} foreign-parse
@lisp
(foreign-parse STRING ...)
@end lisp
Parse given strings and generate foreign-interface bindings. See @ref{The Easy Foreign Function Interface}
for more information.
@end deffn

@deffn {declaration specifier} interrupts-enabled
@lisp
(interrupts-enabled)
@end lisp
Enable timer-interrupts checks in the compiled program (the default).
@end deffn

@deffn {declaration specifier} disable-interrupts
@deffnx {declaration specifier} not
@lisp
(disable-interrupts)
(not interrupts-enabled)
@end lisp
Disable timer-interrupts checks in the compiled program. Threads can
not be preempted in main- or library-units that contain this declaration.
@end deffn

@deffn {declaration specifier} no-argc-checks
@lisp
(no-argc-checks)
@end lisp
Disables argument count checking.
@end deffn

@deffn {declaration specifier} no-bound-checks
@lisp
(no-bound-checks)
@end lisp
Disables the bound-checking of toplevel bindings.
@end deffn

@deffn {declaration specifier} no-procedure-checks
@lisp
(no-procedure-checks)
@end lisp
Disables checking of values in operator position for being of procedure type.
@end deffn

@deffn {declaration specifier} TYPE
@deffnx {declaration specifier} fixnum-arithmetic
@lisp
([number-type] TYPE)
(fixnum-arithmetic)
@end lisp
Declares that only numbers of the given type are used. @code{TYPE}
may be @code{fixnum} or @code{generic} (which is
the default).
@end deffn

@deffn {declaration specifier} run-time-macros
@lisp
(run-time-macros)
@end lisp
Equivalent to the compiler option of the same name - low-level
macros defined in the compiled code are also made available at
runtime.
@end deffn

@deffn {declaration specifier} standard-bindings
@lisp
([not] standard-bindings SYMBOL ...)
@end lisp
Declares that all given standard procedures (or all if no symbols are
specified) are never globally redefined.  If @code{not} is specified,
then all but the given standard bindings are assumed to be never
redefined.
@end deffn

@deffn {declaration specifier} extended-bindings
@lisp
([not] extended-bindings SYMBOL ...)
@end lisp
Declares that all given non-standard and CHICKEN-specific procedures
(or all if no symbols are specified) are never globally redefined.
If @code{not} is specified, then all but the given extended bindings
are assumed to be never redefined.
@end deffn

@deffn {declaration specifier} usual-integrations
@lisp
([not] usual-integrations SYMBOL ...)
@end lisp
Declares that all given standard and extended bindings (or all if no
symbols are specified) are never globally redefined.  If @code{not}
is specified, then all but the given standard and extended bindings are
assumed to be never redefined.
@end deffn

@deffn {declaration specifier} unit
@lisp
(unit SYMBOL)
@end lisp
Specify compilation unit-name (if this is a library)
@end deffn

@deffn {declaration specifier} unsafe
@deffnx {declaration specifier} not
@lisp
(unsafe)
(not safe)
@end lisp
Do not generate safety-checks. This is the same as specifying the
@code{-unsafe} option.  Also implies

@verbatim
(declare (no-bound-checks) (no-procedure-checks) (no-argc-checks))
@end verbatim
@end deffn

@deffn {declaration specifier} uses
@lisp
(uses SYMBOL ...)
@end lisp
Gives a list of used library-units. Before the toplevel-expressions
of the main-module are executed, all used units evaluate their
toplevel-expressions in the order in which they appear in this
declaration. If a library unit A uses another unit B, then B's toplevel
expressions are evaluated before A's.  Furthermore, the used symbols
are registered as features during compile-time, so @code{cond-expand}
knows about them.
@end deffn


@end deffn



@node Parameters
@section Parameters 


Certain behavior of the interpreter and compiled programs can be
customized via 'parameters', where a parameter is a procedure of
zero or one arguments. To retrieve the value of a parameter call the
parameter-procedure with zero arguments. To change the setting of the
parameter, call the parameter-procedure with the new value as argument:

@verbatim
(define foo (make-parameter 123))
(foo)                             ==> 123
(foo 99)
(foo)                             ==> 99
@end verbatim

Parameters are fully thread-local, each thread of execution
owns a local copy of a parameters' value.

CHICKEN implements @uref{http://srfi.schemers.org/srfi-39/srfi-39.html, SRFI-39}



@deffn {procedure} make-parameter
@lisp
(make-parameter VALUE [GUARD])
@end lisp
Returns a procedure that accepts zero or one argument. Invoking the
procedure with zero arguments returns @code{VALUE}. Invoking the
procedure with one argument changes its value to the value of that
argument (subsequent invocations with zero parameters return the new
value). @code{GUARD} should be a procedure of a single argument. Any
new values of the parameter (even the initial value) are passed to this
procedure. The guard procedure should check the value and/or convert it
to an appropriate form.

@end deffn
@defvr {parameter} case-sensitive
If true, then @code{read} reads symbols and identifiers in
case-sensitive mode and uppercase characters in symbols are printed
escaped. Defaults to @code{#t}.

@end defvr
@defvr {parameter} dynamic-load-libraries
A list of strings containing shared libraries that should be checked
for explicitly loaded library units (this facility is not available on
all platforms). See @code{load-library}.

@end defvr
@defvr {parameter} command-line-arguments
Contains the list of arguments passed to this program, with the name of
the program and any runtime options (all options starting with @code{-:})
removed.

@end defvr
@defvr {parameter} exit-handler
A procedure of a single optional argument. When @code{exit} is called,
then this procedure will be invoked with the exit-code as argument. The
default behavior is to terminate the program.

@end defvr
@defvr {parameter} eval-handler
A procedure of one or two arguments. When @code{eval} is invoked, it
calls the value of this parameter with the same arguments. The default
behavior is to evaluate the argument expression and to ignore the
second parameter.

@end defvr
@defvr {parameter} force-finalizers
If true, force and execute all pending finalizers before exiting the
program (either explicitly by @code{exit} or implicitly when the last
toplevel expression has been executed). Default is @code{#t}.

@end defvr
@defvr {parameter} implicit-exit-handler
A procedure of no arguments. When the last toplevel expression of the
program has executed, then the value of this parameter is called. The
default behaviour is to do nothing, or, if one or more entry-points
were defined (see: @ref{Entry points}) to enter a loop that waits for
callbacks from the host program.

@end defvr
@defvr {parameter} keyword-style
Enables alternative keyword syntax, where @code{STYLE} may be either
@code{#:prefix} (as in Common Lisp) or @code{#:suffix} (as in DSSSL).
Any other value disables the alternative syntaxes.

@end defvr
@defvr {parameter} load-verbose
A boolean indicating whether loading of source files, compiled code
(if available) and compiled libraries should display a message.

@end defvr
@defvr {parameter} repl-prompt
A string that will be printed before reading interactive input from
the user in a read-eval-print loop. Defaults to @code{"#;> "}.

@end defvr
@defvr {parameter} reset-handler
A procedure of zero arguments that is called via @code{reset}. The
default behavior in compiled code is to invoke the value of
@code{(exit-handler)}. The default behavior in the interpreter is to
abort the current computation and to restart the read-eval-print loop.

@end defvr
@defvr {parameter} strict-reader
If true, then most non-standard read syntax is disabled. Defaults to
@code{#f}.
@end defvr




@node Unit library
@section Unit library

This unit contains basic Scheme definitions. This unit is used by default, unless the program
is compiled with the @code{-explicit-use} option.

@menu
* Arithmetic::                  
* File Input/Output::           
* Files::                       
* String ports::                
* Feature identifiers::         
* Keywords::                    
* Exceptions::                  
* Environment information and system interface::  
* Execution time::              
* Interrupts and error-handling::  
* Garbage collection::          
* Other control structures::    
* String utilities::
* Generating uninterned symbols::  
* Standard Input/Output::       
* User-defined named characters::  
* Vectors::                     
* The unspecified value::       
* call/cc::                     
@end menu

@node Arithmetic
@subsection Arithmetic


@deffn {procedure} add1
@deffnx {procedure} sub1
@lisp
(add1 N)
(sub1 N)
@end lisp
Adds/subtracts 1 from @code{N}.

@end deffn
@deffn {procedure} bitwise-and
@deffnx {procedure} bitwise-ior
@deffnx {procedure} bitwise-xor
@deffnx {procedure} bitwise-not
@deffnx {procedure} arithmetic-shift
@lisp
(bitwise-and N1 ...)
(bitwise-ior N1 ...)
(bitwise-xor N1 ...)
(bitwise-not N)
(arithmetic-shift N1 N2)
@end lisp
Binary fixnum operations. @code{arithmetic-shift} shifts the argument
@code{N1} by @code{N2} bits to the left. If @code{N2} is negative,
than @code{N1} is shifted to the right.

@end deffn
@deffn {procedure} fixnum?
@lisp
(fixnum? X)
@end lisp
Returns @code{#t} if @code{X} is a fixnum, or @code{#f} otherwise.

@end deffn
@deffn {procedure} fx+
@deffnx {procedure} fx-
@deffnx {procedure} fx*
@deffnx {procedure} fx/
@deffnx {procedure} fxmod
@deffnx {procedure} fxneg
@deffnx {procedure} fxmin
@deffnx {procedure} fxmax
@deffnx {procedure} fx=
@deffnx {procedure} fx>
@deffnx {procedure} fx<
@deffnx {procedure} fx>=
@deffnx {procedure} fx<=
@lisp
(fx+ N1 N2)
(fx- N1 N2)
(fx* N1 N2)
(fx/ N1 N2)
(fxmod N1 N2)
(fxneg N)
(fxmin N1 N2)
(fxmax N1 N2)
(fx= N1 N2)
(fx> N1 N2)
(fx< N1 N2)
(fx>= N1 N2)
(fx<= N1 N2)
@end lisp
Arithmetic fixnum operations. These procedures do not check their
arguments, so non-fixnum parameters will result in incorrect
results. @code{fxneg} negates its argument.

On division by zero, @code{fx/} and @code{fxmod} signal a condition of
kind @code{(exn arithmetic)}.

@end deffn
@deffn {procedure} signum
@lisp
(signum N)
@end lisp
Returns @code{1} if @code{N} is positive, @code{-1} if @code{N} 
is negative or @code{0} if @code{N} is zero.
@end deffn




@node File Input/Output
@subsection File Input/Output


@deffn {procedure} current-error-port
@lisp
(current-error-port [PORT])
@end lisp
Returns default error output port. If @code{PORT} is given, then that
port is selected as the new current error output port.

@end deffn
@deffn {procedure} end-of-file
@lisp
(end-of-file)
@end lisp
Returns the end-of-file object.

@end deffn
@deffn {procedure} flush-output
@lisp
(flush-output [PORT])
@end lisp
Write buffered output to the given output-port. @code{PORT} defaults
to the value of @code{(current-output-port)}.

@end deffn
@deffn {procedure} port-name
@lisp
(port-name PORT)
@end lisp
Fetch filename from @code{PORT}. This returns the filename that was
used to open this file.  Returns a special tag string, enclosed into
parentheses for non-file ports.

@end deffn
@deffn {procedure} port-position
@lisp
(port-position PORT)
@end lisp
Returns the current position of @code{PORT} as two values: row and
column number.  If the port does not support such an operation an error
is signaled. This procedure is currently only available for input ports.

@end deffn
@deffn {procedure} set-port-name!
@lisp
(set-port-name! PORT STRING)
@end lisp
Sets the name of @code{PORT} to @code{STRING}.
@end deffn




@node Files
@subsection Files




@deffn {procedure} delete-file
@lisp
(delete-file STRING)
@end lisp
Deletes the file with the pathname @code{STRING}. If the file does
not exist, an error is signaled.

@end deffn
@deffn {procedure} file-exists?
@lisp
(file-exists? STRING)
@end lisp
Returns @code{#t} if a file with the given pathname exists, or
@code{#f} otherwise.

@end deffn
@defvr {variable} pathname-directory-separator
Contains the directory-separator character for pathnames on this platform.

@end defvr
@defvr {variable} pathname-extension-separator
Contains the extension-separator character for pathnames on this platform.

@end defvr
@deffn {procedure} rename-file
@lisp
(rename-file OLD NEW)
@end lisp
Renames the file or directory with the pathname @code{OLD} to
@code{NEW}. If the operation does not succeed, an error is signaled.
@end deffn



@node String ports
@subsection String ports




@deffn {procedure} get-output-string
@lisp
(get-output-string PORT)
@end lisp
Returns accumulated output of a port created with
@code{(open-output-string)}.

@end deffn
@deffn {procedure} open-input-string
@lisp
(open-input-string STRING)
@end lisp
Returns a port for reading from @code{STRING}.

@end deffn
@deffn {procedure} open-output-string
@lisp
(open-output-string)
@end lisp
Returns a port for accumulating output in a string.
@end deffn




@node Feature identifiers
@subsection Feature identifiers




@deffn {procedure} features
@lisp
(features)
@end lisp
Returns a list of all registered features that will be accepted as valid
feature-identifiers by @code{cond-expand}.

@end deffn
@deffn {procedure} register-feature!
@lisp
(register-feature! FEATURE ...)
@end lisp
Register one or more features that will be accepted as valid
feature-identifiers by @code{cond-expand}. @code{FEATURE ...} may
be a keyword, string or symbol.

@end deffn
@deffn {procedure} unregister-feature!
@lisp
(unregister-feature! FEATURE ...)
@end lisp
Unregisters the specified feature-identifiers. @code{FEATURE ...}
may be a keyword, string or symbol.
@end deffn




@node Keywords
@subsection Keywords

Keywords are special symbols prefixed with @code{#:} that evaluate
to themselves.  Procedures can use keywords to accept optional named
parameters in addition to normal required parameters.  Assignment to
and bindings of keyword symbols is not allowed.
The parameter @code{keyword-style} and the compiler/interpreter option
@code{-keyword-style} can be used to allow an additional keyword
syntax, either compatible to Common LISP, or to DSSSL.



@deffn {procedure} get-keyword
@lisp
(get-keyword KEYWORD ARGLIST [THUNK])
@end lisp
Returns the argument from @code{ARGLIST} specified under the keyword
@code{KEYWORD}.  If the keyword is not found, then the zero-argument
procedure @code{THUNK} is invoked and the result value is returned. If
@code{THUNK} is not given, @code{#f} is returned.

@verbatim
(define (increase x . args)
  (+ x (get-keyword #:amount args (lambda () 1))) )
(increase 123)                                      ==> 124
(increase 123 #:amount 10)                          ==> 133
@end verbatim

Note: the @code{KEYWORD} may actually be any kind of object.

@end deffn
@deffn {procedure} keyword?
@lisp
(keyword? X)
@end lisp
Returns @code{#t} if @code{X} is a keyword symbol, or @code{#f}
otherwise.

@end deffn
@deffn {procedure} keyword->string
@lisp
(keyword->string KEYWORD)
@end lisp
Transforms @code{KEYWORD} into a string.

@end deffn
@deffn {procedure} string->keyword
@lisp
(string->keyword STRING)
@end lisp
Returns a keyword with the name @code{STRING}.
@end deffn




@node Exceptions
@subsection Exceptions


CHICKEN implements the (currently withdrawn) SRFI-12
exception system. For more information, see the @uref{http://srfi.schemers.org/srfi-12/srfi-12.html, SRFI-12
document }



@deffn {syntax} condition-case
@lisp
(condition-case EXPRESSION CLAUSE ...)
@end lisp
Evaluates @code{EXPRESSION} and handles any exceptions that are covered by
@code{CLAUSE ...}, where @code{CLAUSE} should be of the following form:

@verbatim
CLAUSE = ([VARIABLE] (KIND ...) BODY ...)
@end verbatim

If provided, @code{VARIABLE} will be bound to the signalled exception
object. @code{BODY ...} is executed when the exception is a property-
or composite condition with the kinds given @code{KIND ...} (unevaluated).
If no clause applies, the exception is re-signalled in the same dynamic
context as the @code{condition-case} form.

@verbatim
(define (check thunk)
  (condition-case (thunk)
    [(exn file) (print "file error")]
    [(exn) (print "other error")]
    [var () (print "something else")] ) )

(check (lambda () (open-input-file "")))   ; -> "file error"
(check (lambda () some-unbound-variable))  ; -> "othererror"
(check (lambda () (signal 99)))            ; -> "something else"

(condition-case some-unbound-variable
  [(exn file) (print "ignored)] )      ; -> signals error

@end verbatim
@end deffn



All error-conditions signalled by the system are of kind @code{exn}.
The following composite conditions are additionally defined:

@table @code

@item (exn arity)

Signalled when a procedure is called with the wrong number of arguments.

@item (exn type)

Signalled on type-mismatch errors, for example when an argument of the wrong
type is passed to a builtin procedure.

@item (exn arithmetic)

Signalled on arithmetic errors, like division by zero.

@item (exn i/o)

Signalled on input/output errors.

@item (exn i/o file)

Signalled on file-related errors.

@item (exn i/o net)

Signalled on network errors.

@item (exn bounds)

Signalled on errors caused by accessing non-existent elements of a collection.

@item (exn runtime)

Signalled on low-level runtime-system error-situations.

@item (exn runtime limit)

Signalled when an internal limit is exceeded (like running out of memory).

@item (exn match)

Signalled on errors raised by failed matches (see the section on @code{match}).

@item (exn syntax)

Signalled on syntax errors.

@end table

Notes:
@itemize
@item All error-exceptions (of the kind @code{exn}) are non-continuable.

@item Error-exceptions of the @code{exn} kind have additional
@code{arguments} and @code{location} properties that contain the
arguments passed to the error-handler and the name of the procedure
where the error occurred (if available).

@item When the @code{posix} unit is available and used, then a
user-interrupt (@code{signal/int}) signals an exception of the kind
@code{user-interrupt}. 

@item the procedure @code{condition-property-accessor} accepts an optional
third argument. If the condition does not have a value for the desired property
and if the optional argument is given and false, no error is signalled and
the accessor returns @code{#g}.

@end itemize


@node Environment information and system interface
@subsection Environment information and system interface



@deffn {procedure} argv
@lisp
(argv)
@end lisp
Return a list of all supplied command-line arguments. The first item in
the list is a string containing the name of the executing program. The
other items are the arguments passed to the application. This list is
freshly created on every invocation of @code{(argv)}.  It depends on
the host-shell whether arguments are expanded ('globbed') or not.

@end deffn
@deffn {procedure} exit
@lisp
(exit [CODE])
@end lisp
Exit the running process and return exit-code, which defaults to 0
(Invokes @code{exit-handler}).

@end deffn
@deffn {procedure} build-platform
@lisp
(build-platform)
@end lisp
Returns a symbol specifying the toolset which has been used for
building the executing system, which is one of the following:

@verbatim
djgpp
cygwin
msvc
mingw32
gnu
metrowerks
unknown
@end verbatim

@end deffn
@deffn {procedure} chicken-version
@lisp
(chicken-version)
@end lisp
Returns a string containing the version number of the CHICKEN runtime
system.

@end deffn
@deffn {procedure} errno
@lisp
(errno)
@end lisp
Returns the error code of the last system call.

@end deffn
@deffn {procedure} getenv
@lisp
(getenv STRING)
@end lisp
Returns the value of the environment variable @code{STRING} or
@code{#f} if that variable is not defined.

@end deffn
@deffn {procedure} machine-type
@lisp
(machine-type)
@end lisp
Returns a symbol specifying the processor on which this process is
currently running, which is one of the following:

@verbatim
alpha
mips
hppa
ultrasparc
sparc
ppc
ia64
x86
x86-64
unknown
@end verbatim

@end deffn
@deffn {procedure} software-type
@lisp
(software-type)
@end lisp
Returns a symbol specifying the operating system on which this process
is currently running, which is one of the following:

@verbatim
msdos
windows
unix
macos
unknown
@end verbatim

@end deffn
@deffn {procedure} software-version
@lisp
(software-version)
@end lisp
Returns a symbol specifying the operating system version on which this
process is currently running, which is one of the following:

@verbatim
linux
freebsd
netbsd
openbsd
macosx
hpux
solaris
sunos
unknown
@end verbatim

@end deffn
@deffn {procedure} system
@lisp
(system STRING)
@end lisp
Execute shell command. The functionality offered by this procedure
depends on the capabilities of the host shell.
@end deffn




@node Execution time
@subsection Execution time



@deffn {procedure} cpu-time
@lisp
(cpu-time)
@end lisp
Returns the used CPU time of the current process in milliseconds as
two values: the time spent in user code, and the time spent in system
code. On platforms where user and system time can not be differentiated,
system time will be always be 0.

@end deffn
@deffn {procedure} current-milliseconds
@lisp
(current-milliseconds)
@end lisp
Returns the number of milliseconds since process- or machine startup.

@end deffn
@deffn {procedure} current-seconds
@lisp
(current-seconds)
@end lisp
Returns the number of seconds since midnight, Jan. 1, 1970.
@end deffn




@node Interrupts and error-handling
@subsection Interrupts and error-handling



@deffn {procedure} enable-interrupts
@deffnx {procedure} disable-interrupts
@lisp
(enable-interrupts)
(disable-interrupts)
@end lisp
Enables/disables processing of timer-interrupts and interrupts caused
by signals.

@verbatim
(disable-interrupts)
(disable-interrupts)
(enable-interrupts)
; <interrupts still disabled - call enable-interrupts once more>
@end verbatim

@end deffn
@deffn {procedure} enable-warnings
@lisp
(enable-warnings [BOOL])
@end lisp
Enables or disables warnings, depending on wether @code{BOOL} is true or false.
If called with no arguments, this procedure returns @code{#t} if warnings are
currently enabled, or @code{#f} otherwise. Note that this is not a parameter.
The current state (wether warnings are enabled or disabled) is global and not
thread-local.

@end deffn
@deffn {procedure} error
@lisp
(error [LOCATION] STRING EXP ...)
@end lisp
Prints error message, writes all extra arguments to the
value of @code{(current-error-port)} and invokes the
current value of @code{(error-handler)}.  This conforms to
@uref{http://srfi.schemers.org/srfi-23/srfi-23.html, SRFI-23 }.
If @code{LOCATION} is given and a symbol, it specifies the ``location'' (the name
of the procedure) where the error occurred.

@end deffn
@deffn {procedure} print-backtrace
@lisp
(print-backtrace [PORT])
@end lisp
Prints a backtrace of the procedure call history to @code{PORT},
which defaults to @code{(current-error-port)}. Backtrace information
is only generated in compiled code, with a @code{-debug-level} >= 1.

@end deffn
@deffn {procedure} print-error-message
@lisp
(print-error-message EXN [PORT [STRING]])
@end lisp
Prints an appropriate error message to @code{PORT} (which defaults to the
value of @code{(current-error-port)} for the object @code{EXN}.
@code{EXN} may be a condition, a string or any other object.
If the optional argument @code{STRING} is given, it is printed before the
error-message. @code{STRING} defaults to @code{"Error:"}.

@end deffn
@deffn {procedure} reset
@lisp
(reset)
@end lisp
Reset program (Invokes @code{reset-handler}).
@end deffn




@node Garbage collection
@subsection Garbage collection



@deffn {procedure} gc
@lisp
(gc [FLAG])
@end lisp
Invokes a garbage-collection and returns the number of free bytes
in the heap. The flag specifies whether a minor (@code{#f}) or
major (@code{#t}) GC is to be triggered. If no argument is given,
@code{#t} is assumed. When the argument is @code{#t}, all pending
finalizers are executed.

@deffn {procedure} memory-statistics
@lisp
(memory-statistics)
@end lisp
Performs a major garbage collection and returns a three element vector 
containing the total heap size in bytes, the number of bytes currently
used and the size of the nursery (the first heap generation). Note
that the actual heap is actually twice the size given in the heap size,
because CHICKEN uses a copying semi-space collector.
@end deffn

@end deffn
@deffn {procedure} set-finalizer!
@lisp
(set-finalizer! X PROC)
@end lisp
Registers a procedure of one argument @code{PROC}, that will be
called as soon as the non-immediate data object @code{X} is about to
be garbage-collected (with that object as its argument).  Note that
the finalizer will @b{not} be called when interrupts are disabled.

@end deffn
@deffn {procedure} set-gc-report!
@lisp
(set-gc-report! FLAG)
@end lisp
Print statistics after every GC, depending on @code{FLAG}. A value of
@code{#t} shows statistics after every major GC. A true value different
from @code{#t} shows statistics after every minor GC. @code{#f}
switches statistics off.
@end deffn




@node Other control structures
@subsection Other control structures



@deffn {procedure} andmap
@lisp
(andmap PROC LIST1 ...)
@end lisp
Repeatedly calls @code{PROC} with arguments taken from @code{LIST1 ...}.  
If any invocation should return @code{#f}, the result of
@code{andmap} is @code{#f}. If all invocations return a true result,
then the result of @code{andmap} is @code{#t}.

@end deffn
@deffn {procedure} ormap
@lisp
(ormap PROC LIST1 ...)
@end lisp
Repeatedly calls @code{PROC} with arguments taken from @code{LIST1 ...}.  
If any invocation should return a value different from
@code{#f}, then this value is returned as the  result of
@code{ormap}. If all invocations return @b{#f},
then the result of @code{ormap} is @code{#f}.
@end deffn



@node String utilities
@subsection String utilities


@deffn {procedure} reverse-list->string
@lisp
(reverse-list->string LIST)
@end lisp
Returns a string with the characters in @code{LIST} in reverse order. This is equivalent to
@code{(list->string (reverse LIST))}, but much more efficient.
@end deffn


@node Generating uninterned symbols
@subsection Generating uninterned symbols



@deffn {procedure} gensym
@lisp
(gensym [STRING-OR-SYMBOL])
@end lisp
Returns a newly created uninterned symbol. If an argument is provided,
the new symbol is prefixed with that argument.

@end deffn
@deffn {procedure} string->uninterned-symbol
@lisp
(string->uninterned-symbol STRING)
@end lisp
Returns a newly created, unique symbol with the name @code{STRING}.
@end deffn




@node Standard Input/Output
@subsection Standard Input/Output

@deffn {procedure} port?
@lisp
(port? X)
@end lisp
Returns @code{#t} if @code{X} is a port object or @code{#f}
otherwise.

@end deffn
@deffn {procedure} print
@lisp
(print EXP1 EXP2 ...)
@end lisp
Outputs the arguments @code{EXP1 EXP2 ...} using @code{display}
and writes a newline character to the port that is the value of
@code{(current-output-port)}. Returns its first argument.

@end deffn
@deffn {procedure} print*
@lisp
(print* EXP1 ...)
@end lisp
Similar to @code{print}, but does not output a terminating newline
character.
@end deffn



@node User-defined named characters
@subsection User-defined named characters



@deffn {procedure} char-name
@lisp
(char-name SYMBOL-OR-CHAR [CHAR])
@end lisp
This procedure can be used to inquire about character names or to
define new ones. With a single argument the behavior is as follows:
If @code{SYMBOL-OR-CHAR} is a symbol, then @code{char-name} returns
the character with this name, or @code{#f} if no character is defined
under this name.  If @code{SYMBOL-OR-CHAR} is a character, then the
name of the character is returned as a symbol, or @code{#f} if the
character has no associated name.

If the optional argument @code{CHAR} is provided, then
@code{SYMBOL-OR-CHAR} should be a symbol that will be the new name of
the given character.  If multiple names designate the same character,
then the @code{write} will use the character name that was defined last.

@verbatim
(char-name 'space)                  ==> #\space
(char-name #\space)                 ==> space
(char-name 'bell)                   ==> #f
(char-name (integer->char 7))       ==> #f
(char-name 'bell (integer->char 7))
(char-name 'bell)                   ==> #\bell
(char->integer (char-name 'bell))   ==> 7
@end verbatim
@end deffn




@node Vectors
@subsection Vectors



@deffn {procedure} vector-copy!
@lisp
(vector-copy! VECTOR1 VECTOR2 [COUNT])
@end lisp
Copies contents of @code{VECTOR1} into @code{VECTOR2}. If the
argument @code{COUNT} is given, it specifies the maximal number of
elements to be copied. If not given, the minimum of the lengths of the
argument vectors is copied.

Exceptions: @code{(exn bounds)}

@end deffn
@deffn {procedure} vector-resize
@lisp
(vector-resize VECTOR N [INIT])
@end lisp
Creates and returns a new vector with the contents of @code{VECTOR} and length @code{N}.
If @code{N} is greater than the original length of @code{VECTOR}, then all additional
items are initialized to @code{INIT}. If @code{INIT} is not specified, the
contents are initialized to some unspecified value.
@end deffn




@node The unspecified value
@subsection The @emph{unspecified} value



@deffn {procedure} void
@lisp
(void)
@end lisp
Returns an unspecified value.
@end deffn




@node call/cc
@subsection call/cc



@deffn {procedure} call/cc
@lisp
(call/cc PROCEDURE)
@end lisp
An alias for @code{call-with-current-continuation}.
@end deffn




@node Unit eval
@section Unit eval

This unit has support for evaluation and macro-handling. This unit is used
by default, unless the program is compiled with the @code{-explicit-use}
option.

@menu
* Loading code::                
* Read-eval-print loop::        
* Macros::                      
* Loading extension libraries::         
* Reader extensions::           
* Eval::                        
@end menu

@node Loading code
@subsection Loading code



@deffn {procedure} load
@lisp
(load FILE [EVALPROC])
@end lisp
Loads and evaluates expressions from the given source file, which may
be either a string or an input port.  Each expression read is passed to
@code{EVALPROC} (which defaults to @code{eval}).  On platforms that
support it (currently Linux ELF and Solaris), @code{load} can be used
to load compiled programs:

@verbatim
% cat x.scm
(define (hello) (print "Hello!"))
% chicken x.scm -quiet -dynamic
% gcc x.c -shared -fPIC `chicken-config -cflags -shared -libs` -o x.so
% csi -quiet
#;> (load "x.so")
; loading x.so ...
#;> (hello)
Hello!
#;>
@end verbatim

The second argument to @code{load} is ignored when loading compiled
code.  The same compiled object file can not be loaded more than once.
If source code is loaded from a port, then that port is closed after
all expressions have been read.

@end deffn
@deffn {procedure} load-library
@lisp
(load-library UNIT [LIBRARYFILE])
@end lisp
On platforms that support dynamic loading, @code{load-library} loads
the compiled library unit @code{UNIT} (which should be a symbol). If the
string @code{LIBRARYFILE} is given, then the given shared library will
be loaded and the toplevel code of the contained unit will be executed.
If no @code{LIBRARYFILE} argument is given, then the following libraries
are checked for the required unit:

@itemize
@item a file named ``@code{<UNIT>.so}''

@item the files given in the parameter @code{dynamic-load-libraries}

@end itemize

If the unit is not found, an error is signaled.  When the library unit
can be successfully loaded, a feature-identifier named @code{UNIT}
is registered. If the feature is already registered before loading,
the @code{load-library} does nothing.

@end deffn
@deffn {procedure} load-noisily
@lisp
(load-noisily FILE [EVALPROC])
@end lisp
As @code{load} but the result(s) of each evaluated toplevel-expression
is written to standard output.

@end deffn



@node Read-eval-print loop
@subsection Read-eval-print loop



@deffn {procedure} repl
@lisp
(repl)
@end lisp
Start a new read-eval-print loop. Sets the @code{reset-handler} so that
any invocation of @code{reset} restarts the read-eval-print loop. Also
changes the current @code{error-handler} to display a message, write
any arguments to the value of @code{(current-error-port)} and reset.
@end deffn




@node Macros
@subsection Macros




@deffn {procedure} get-line-number
@lisp
(get-line-number EXPR)
@end lisp
If @code{EXPR} is a pair with the car being a symbol, and line-number
information is available for this expression, then this procedure returns
the associated line number. If line-number information is not available,
then @code{#f} is returned.  Note that line-number information for
expressions is only available in the compiler.

@end deffn
@deffn {procedure} macro?
@lisp
(macro? SYMBOL)
@end lisp
Returns @code{#t} if there exists a macro-definition for @code{SYMBOL}.

@end deffn
@deffn {procedure} macroexpand
@lisp
(macroexpand X)
@end lisp
If @code{X} is a macro-form, expand the macro (and repeat expansion
until expression is a non-macro form).  Returns the resulting expression.

@end deffn
@deffn {procedure} macroexpand-1
@lisp
(macroexpand-1 X)
@end lisp
If @code{X} is a macro-form, expand the macro.  Returns the resulting
expression.

@end deffn
@deffn {procedure} undefine-macro!
@lisp
(undefine-macro! SYMBOL)
@end lisp
Remove the current macro-definition of the macro named @code{SYMBOL}.
@end deffn

@deffn {procedure} syntax-error
@lisp
(syntax-error [LOCATION] MESSAGE ARGUMENT ...)
@end lisp
Signals an exception of the kind @code{(exn syntax)}. Otherwise identical to 
@code{error}.
@end deffn


@node Loading extension libraries
@subsection Loading extension libraries


This functionality is only available on platforms that support dynamic
loading of compiled code. Currently Linux, BSD, Solaris, Windows (with Cygwin) and HP/UX are supported.


@deffn {parameter} repository-path
Contains a string naming the path to the extension repository, which defaults to
either the value of the environment variable @code{CHICKEN_REPOSITORY}, the value
of the environment variable @code{CHICKEN_HOME} or the default library path
(usually @code{/usr/local/lib/chicken} on UNIX systems.
@end deffn

@deffn {procedure} extension-info
@lisp
(extension-info ID)
@end lisp
If an extension with the name @code{ID} is installed and if it has a setup-information
list registered in the extension repository, then the info-list is returned. Otherwise
@code{extension-info} returns @code{#f}.
@end deffn

@deffn {procedure} provide
@lisp
(provide ID ...)
@end lisp
Registers the extension IDs @code{ID ...} as loaded. This is mainly
intended to provide aliases for certain extension identifiers.

@end deffn
@deffn {procedure} provided?
@lisp
(provided? ID ...)
@end lisp
Returns @code{#t} if the extension with the IDs @code{ID @dots{}}
are currently loaded, or @code{#f} otherwise.
Works also for feature-ids.

@end deffn
@deffn {procedure} require
@lisp
(require ID ...)
@end lisp
If the extension library @code{ID} is not already loaded into the
system, then @code{require} will lookup the location of the shared
extension library and load it. If @code{ID} names a library-unit of
the base system, then it is loaded via @code{load-library}.  If no
extension library is available for the given ID, then an attempt is
made to load the file @code{ID.so} or @code{ID.scm} (in that order)
from one of the following locations:

@enumerate

@item the current directory

@item the current include path, which defaults to the pathnames
given in @code{CHICKEN_INCLUDE_PATH} and @code{CHICKEN_HOME}.
In case @code{ID} is a list, it is interpreted as a (relative)
pathname.

@end enumerate

@code{ID} may be a symbol, or a list of symbols.  See also:
@code{require-for-syntax}.
@end deffn





@node Reader extensions
@subsection Reader extensions



@deffn {procedure} define-reader-ctor
@lisp
(define-reader-ctor SYMBOL PROC)
@end lisp
Define new read-time constructor for @code{#,} read syntax. For further information, see
the documentation for @uref{http://srfi.schemers.org/srfi-10/srfi-10.html, SRFI-10 }.
@end deffn

@deffn {procedure} set-read-syntax!
@lisp
(set-read-syntax! CHAR PROC)
@end lisp
When the reader is encounting the non-whitespace character @code{CHAR} while reading
an expression from a given port, then the procedure @code{PROC} will be called with
that port as its argument. The procedure should return a value that will be returned
to the reader:

@lisp
; A simple RGB color syntax:

(set-read-syntax! #\%
  (lambda (port)
    (apply vector
      (map (cut string->number <> 16)
           (string-chop (read-string 6 port) 2) ) ) ) )

(with-input-from-string "(1 2 %e0e0e0 3)" read)
; ==> (1 2 #(240 240 240) 3)
@end lisp
@end deffn



@node Eval
@subsection Eval



@deffn {procedure} eval
@lisp
(eval EXP [ENVIRONMENT])
@end lisp
Evaluates @code{EXP} and returns the result of the evaluation. The second argument is optional
and defaults to the value of @code{(interaction-environment)}.
@end deffn




@node Unit extras
@section Unit extras


This unit contains a collection of useful utility definitions. 
This unit is used by default, unless the program
is compiled with the @code{-explicit-use} option.


@menu
* Lists::                       
* String-port extensions::      
* Formatted output::            
* Hash tables::                 
* Queues::                      
* Sorting::                     
* Random numbers::              
* Input/Output extensions::     
* Strings::                     
* Combinators::                 
* Binary searching::            
@end menu

@node Lists
@subsection Lists


@deffn {procedure} alist-ref
@lisp
(alist-ref KEY ALIST [TEST [DEFAULT]])
@end lisp
Looks up @code{KEY} in @code{ALIST} using @code{TEST} as the comparison function (or @code{eqv?} if
no test was given) and returns the cdr of the found pair, or @code{DEFAULT} (which defaults to @code{#f}).
@end deffn

@deffn {procedure} alist-update!
@lisp
(alist-update! KEY VALUE ALIST [TEST])
@end lisp
If the list @code{ALIST} contains a pair of the form @code{(KEY . X)}, then this procedure
replaces @code{X} with @code{VALUE} and returns @code{ALIST}. If @code{ALIST} contains no such item, then
@code{alist-update!} returns @code{((KEY . VALUE) . ALIST)}. The optional argument
@code{TEST} specifies the comparison procedure to search a matching pair in @code{ALIST}
and defaults to @code{eqv?}.

@end deffn
@deffn {procedure} butlast
@lisp
(butlast LIST)
@end lisp
Returns a fresh list with all elements but the last of @code{LIST}.

@end deffn
@deffn {procedure} chop
@lisp
(chop LIST N)
@end lisp
Returns a new list of sublists, where each sublist contains @code{N}
elements of @code{LIST}. If @code{LIST} has a length that is not
a multiple of @code{N}, then the last sublist contains the remaining
elements.

@verbatim
(chop '(1 2 3 4 5 6) 2) ==> ((1 2) (3 4) (5 6))
(chop '(a b c d) 3)     ==> ((a b c) (d))
@end verbatim

@end deffn
@deffn {procedure} compress
@lisp
(compress BLIST LIST)
@end lisp
Returns a new list with elements taken from @code{LIST} with
corresponding true values in the list @code{BLIST}.

@verbatim
(define nums '(99 100 110 401 1234))
(compress (map odd? nums) nums)      ==> (99 401)
@end verbatim

@end deffn
@deffn {procedure} flatten
@lisp
(flatten LIST1 ...)
@end lisp
Returns @code{LIST1 @dots{}} concatenated together, with nested lists
removed (flattened).

@end deffn
@deffn {procedure} intersperse
@lisp
(intersperse LIST X)
@end lisp
Returns a new list with @code{X} placed between each element.

@end deffn
@deffn {procedure} join
@lisp
(join LISTOFLISTS [LIST])
@end lisp
Concatenates the lists in @code{LISTOFLISTS} with @code{LIST} placed
between each sublist. @code{LIST} defaults to the empty list.

@verbatim
(join '((a b) (c d) (e)) '(x y)) ==> (a b x y c d x y e)
(join '((p q) () (r (s) t)) '(-))  ==> (p q - - r (s) t)
@end verbatim

@end deffn
@deffn {procedure} shuffle
@lisp
(shuffle LIST)
@end lisp
Returns @code{LIST} with its elements sorted in a random order.


@code{join} could be implemented as follows:

@verbatim
(define (join lstoflsts . lst)
  (apply append (intersperse lstoflists (:optional lst '()))) )
@end verbatim

@end deffn
@deffn {procedure} tail?
@lisp
(tail? X LIST)
@end lisp
Returns true if @code{X} is one of the tails (cdr's) of @code{LIST}.
@end deffn




@node String-port extensions
@subsection String-port extensions




@deffn {procedure} call-with-input-string
@lisp
(call-with-input-string STRING PROC)
@end lisp
Calls the procedure @code{PROC} with a single argument that is a
string-input-port with the contents of @code{STRING}.

@end deffn
@deffn {procedure} call-with-output-string
@lisp
(call-with-output-string PROC)
@end lisp
Calls the procedure @code{PROC} with a single argument that is a
string-output-port.  Returns the accumulated output-string.

@end deffn
@deffn {procedure} with-input-from-string
@lisp
(with-input-from-string STRING THUNK)
@end lisp
Call procedure @code{THUNK} with the current input-port temporarily
bound to an input-string-port with the contents of @code{STRING}.

@end deffn
@deffn {procedure} with-output-to-string
@lisp
(with-output-to-string THUNK)
@end lisp
Call procedure @code{THUNK} with the current output-port temporarily
bound to a string-output-port and return the accumulated output string.
@end deffn




@node Formatted output
@subsection Formatted output




@deffn {procedure} fprintf
@deffnx {procedure} printf
@deffnx {procedure} sprintf
@lisp
(fprintf PORT FORMATSTRING ARG ...)
(printf FORMATSTRING ARG)
(sprintf FORMATSTRING ARG ...)
@end lisp
Simple formatted output to a given port (@code{fprintf}), the
value of @code{(current-output-port) } (@code{printf}) or a string
(@code{sprintf}).  The @code{FORMATSTRING} can contain any sequence
of characters. The character `~' prefixes special formatting directives:

@table @code
@item ~%
write newline character
@item ~S
write the next argument
@item ~A
display the next argument
@item ~\n
skip all whitespace in the format-string until the next non-whitespace character
@item ~B
write the next argument as a binary number
@item ~O
write the next argument as an octal number
@item ~X
write the next argument as a hexadecimal number
@item ~C
write the next argument as a character
@item ~~
display `~'
@item ~!
flush all pending output
@item ~?
invoke formatted output routine recursively with the next two arguments as format-string and list of parameters
@end table
 
For more powerful output formatting, see the section about the @code{format} unit.
@end deffn




@node Hash tables
@subsection Hash tables




@deffn {procedure} clear-hash-table!
@lisp
(clear-hash-table! HASH-TABLE)
@end lisp
Erases all entries in the hash-table @code{HASH-TABLE}.

@end deffn
@deffn {procedure} get
@lisp
(get HASH-TABLE KEY PROP)
@end lisp
Returns the value of property @code{PROP} of the item @code{KEY}
in @code{HASH-TABLE }. This facility can be used as a kind of
``disembodied'' property-list. If no entry named @code{KEY} is stored
in the hash-table or if no property @code{PROP} for that key exists,
@code{#f} is returned.

@end deffn
@deffn {procedure} hash-table?
@lisp
(hash-table? X)
@end lisp
Returns @code{#t} if the argument is a hash-table.

@end deffn
@deffn {procedure} hash-table->list
@lisp
(hash-table->list HASH-TABLE)
@end lisp
Converts @code{HASH-TABLE} into an association-list.

@end deffn
@deffn {procedure} hash-table-count
@lisp
(hash-table-count HASH-TABLE)
@end lisp
Returns the number of entries in the given hash-table.

@end deffn
@deffn {procedure} hash-table-size
@lisp
(hash-table-size HASH-TABLE)
@end lisp
Returns the size of the hash-table.

@end deffn
@deffn {procedure} hash-table-for-each
@lisp
(hash-table-for-each PROC HASH-TABLE)
@end lisp
Calls @code{PROC} which should expect two arguments. This procedure
is called for each entry in the hash-table with the key and the value
as parameters.

@end deffn
@deffn {procedure} hash-table-ref
@lisp
(hash-table-ref HASH-TABLE KEY [DEFAULT])
@end lisp
Returns the entry in the given hash-table under @code{KEY}. If no
entry is stored in the table, @code{#f} is returned.

@end deffn
@deffn {procedure} hash-table-remove!
@lisp
(hash-table-remove! HASH-TABLE KEY)
@end lisp
Removes an entry in the given hash-table.

@end deffn
@deffn {procedure} hash-table-set!
@lisp
(hash-table-set! HASH-TABLE KEY VALUE)
@end lisp
Adds or changes an entry in the given hash-table.

@end deffn
@deffn {procedure} make-hash-table
@lisp
(make-hash-table [PRED [SIZE]])
@end lisp
Creates and returns a hash-table with keys compared via @code{PRED},
which defaults to @code{eq?}. If @code{SIZE} is provided it specifies
the initial size of the hash-table.  If the hash-table fills above a
certain size it is automatically resized to accommodate more entries.

@end deffn
@deffn {procedure} put!
@lisp
(put! HASH-TABLE KEY PROP VALUE)
@end lisp
Stores @code{VALUE} as property @code{PROP} under the item
@code{KEY} in the given hash-table. Any previously existing value
is overwritten.
@end deffn




@node Queues
@subsection Queues




@deffn {procedure} list->queue
@lisp
(list->queue LIST)
@end lisp
Returns @code{LIST} converted into a queue, where the first element
of the list is the same as the first element of the queue. The resulting
queue may share memory with the list and the list should not be modified
after this operation.

@end deffn
@deffn {procedure} make-queue
@lisp
(make-queue)
@end lisp
Returns a newly created queue.

@end deffn
@deffn {procedure} queue?
@lisp
(queue? X)
@end lisp
Returns @code{#t} if @code{X} is a queue, or @code{#f} otherwise.

@end deffn
@deffn {procedure} queue->list
@lisp
(queue->list QUEUE)
@end lisp
Returns @code{QUEUE} converted into a list, where the first element
of the list is the same as the first element of the queue. The resulting
list may share memory with the queue object and should not be modified.

@end deffn
@deffn {procedure} queue-add!
@lisp
(queue-add! QUEUE X)
@end lisp
Adds @code{X} to the rear of @code{QUEUE}.

@end deffn
@deffn {procedure} queue-empty?
@lisp
(queue-empty? QUEUE)
@end lisp
Returns @code{#t} if @code{QUEUE} is empty, or @code{#f} otherwise.

@end deffn
@deffn {procedure} queue-first
@lisp
(queue-first QUEUE)
@end lisp
Returns the first element of @code{QUEUE}. If @code{QUEUE} is empty
an error is signaled

@end deffn
@deffn {procedure} queue-last
@lisp
(queue-last QUEUE)
@end lisp
Returns the last element of @code{QUEUE}. If @code{QUEUE} is empty
an error is signaled

@end deffn
@deffn {procedure} queue-remove!
@lisp
(queue-remove! QUEUE)
@end lisp
Removes and returns the first element of @code{QUEUE}. If @code{QUEUE}
is empty an error is signaled
@end deffn




@node Sorting
@subsection Sorting




@deffn {procedure} merge
@deffnx {procedure} merge!
@lisp
(merge LIST1 LIST2 LESS?)
(merge! LIST1 LIST2 LESS?)
@end lisp
Joins two lists in sorted order. @code{merge!} is the destructive
version of merge. @code{LESS?  } should be a procedure of two arguments,
that returns true if the first argument is to be ordered before the
second argument.

@end deffn
@deffn {procedure} sort
@deffnx {procedure} sort!
@lisp
(sort SEQUENCE LESS?)
(sort! SEQUENCE LESS?)
@end lisp
Sort @code{SEQUENCE}, which should be a list or a vector. @code{sort!}
is the destructive version of sort.

@end deffn
@deffn {procedure} sorted?
@lisp
(sorted? SEQUENCE LESS?)
@end lisp
Returns true if the list or vector @code{SEQUENCE} is already sorted.
@end deffn




@node Random numbers
@subsection Random numbers




@deffn {procedure} random
@lisp
(random N)
@end lisp
Returns an exact random integer from 0 to @code{N}-1.

@end deffn
@deffn {procedure} randomize
@lisp
(randomize [X])
@end lisp
Set random-number seed. If @code{X} is not supplied, the current time is used.
On startup (when the @code{extras} unit is initialized), the random number generator
is initialized with the current time.
@end deffn




@node Input/Output extensions
@subsection Input/Output extensions




@deffn {procedure} make-input-port
@lisp
(make-input-port READ READY? CLOSE [PEEK])
@end lisp
Returns a custom input port. Common operations on this
port are handled by the given parameters, which should be
procedures of no arguments. @code{READ} is called when the
next character is to be read and should return a character or
the value of @code{(end-of-file)}. @code{READY?} is called
when @code{char-ready?} is called on this port and should return
@code{#t} or @code{#f}.  @code{CLOSE} is called when the port is
closed. @code{PEEK} is called when @code{peek-char} is called on this
port and should return a character or the value of @code{(end-of-file)}.
if the argument @code{PEEK} is not given, then @code{READ} is used
instead and the created port object handles peeking automatically (by
calling @code{READ} and buffering the character).

@end deffn
@deffn {procedure} make-output-port
@lisp
(make-output-port WRITE CLOSE [FLUSH])
@end lisp
Returns a custom output port. Common operations on this port are handled
by the given parameters, which should be procedures.  @code{WRITE} is
called when output is sent to the port and receives a single argument,
a string.  @code{CLOSE} is called when the port is closed and should
be a procedure of no arguments. @code{FLUSH} (if provided) is called
for flushing the output port.

@end deffn
@deffn {procedure} pretty-print
@deffnx {procedure} pp
@lisp
(pretty-print EXP [PORT])
(pp EXP [PORT])
@end lisp
Print expression nicely formatted. @code{PORT} defaults to the value
of @code{(current-output-port)}.

@end deffn
@defvr {parameter} pretty-print-width
Specifies the maximal line-width for pretty printing, after which line
wrap will occur.

@end defvr
@deffn {procedure} read-file
@lisp
(read-file [FILE-OR-PORT])
@end lisp
Returns a list containing all toplevel expressions
read from the file or port @code{FILE-OR-PORT}. If no argument is given,
input is read from the port that is the current value of @code{(current-input-port)}.
After all expressions are read, and if the argument is a port, then the port will
not be closed.

@end deffn
@deffn {procedure} read-line
@deffnx {procedure} write-line
@lisp
(read-line [PORT [LIMIT]])
(write-line STRING [PORT])
@end lisp
Line-input and -output. @code{PORT} defaults to the value of
@code{(current-input-port)} and @code{(current-output-port)},
respectively. if the optional argument @code{LIMIT} is given and
not @code{#f}, then @code{read-line} reads at most @code{LIMIT}
characters per line.

@end deffn
@deffn {procedure} read-lines
@lisp
(read-lines [PORT [MAX]])
@end lisp
Read @code{MAX} or fewer lines from @code{PORT}. @code{PORT}
defaults to the value of @code{(current-input-port)}.

@end deffn
@deffn {procedure} read-string
@deffnx {procedure} write-string
@lisp
(read-string [NUM [PORT]])
(write-string STRING [NUM [PORT]]
@end lisp
Read or write @code{NUM} characters from/to @code{PORT}, which defaults to the
value of @code{(current-input-port)} or @code{(current-output-port)}, respectively. 
If @code{NUM} is @code{#f} or not given, then all data
up to the end-of-file is read, or, in the case of @code{write-string} the whole
string is written. If no more input is available, @code{read-string} returns the
empty string.
@end deffn

@deffn {procedure} read-token
@lisp
(read-token PREDICATE [PORT])
@end lisp
Reads characters from @code{PORT} (which defaults to the value of @code{(current-input-port)})
and calls the procedure @code{PREDICATE} with each character until @code{PREDICATE} returns
false.
@end deffn

@deffn {procedure} with-error-output-to-port
@lisp
(with-error-output-to-port PORT THUNK)
@end lisp
Call procedure @code{THUNK} with the current error output-port
temporarily bound to @code{PORT}.

@end deffn
@deffn {procedure} with-input-from-port
@lisp
(with-input-from-port PORT THUNK)
@end lisp
Call procedure @code{THUNK} with the current input-port temporarily
bound to @code{PORT}.

@end deffn
@deffn {procedure} with-output-to-port
@lisp
(with-output-to-port PORT THUNK)
@end lisp
Call procedure @code{THUNK} with the current output-port temporarily
bound to @code{PORT}.
@end deffn



@node Strings
@subsection Strings


@deffn {procedure} conc
@lisp
(conc X ...)
@end lisp
Returns a string with the string-represenation of all arguments concatenated
together. @code{conc} could be implemented as

@verbatim
(define (conc . args)
  (apply string-append (map ->string args)) )
@end verbatim
@end deffn


@deffn {procedure} ->string
@lisp
(->string X)
@end lisp
Returns a string-representation of @code{X}.

@end deffn
@deffn {procedure} string-chop
@lisp
(string-chop STRING LENGTH)
@end lisp
Returns a list of substrings taken by ``chopping'' @code{STRING} every @code{LENGTH}
characters:

@verbatim
(string-chop "one two three" 4)  ==>  ("one " "two " "thre" "e")
@end verbatim

@end deffn
@deffn {procedure} string-compare3
@lisp
(string-compare3 STRING1 STRING2)
@end lisp
@end deffn
@deffn {procedure} string-compare3-ci
@lisp
(string-compare3-ci STRING1 STRING2)
@end lisp
Perform a three-way comparison between the @code{STRING1} and @code{STRING2},
returning either @code{-1} if @code{STRING1} is lexicographically less
than @code{STRING2}, @code{0} if it is equal, or @code{1} if it s greater.
@code{string-compare3-ci} performs a case-insensitive comparison.
@end deffn

@deffn {procedure} string-intersperse
@lisp
(string-intersperse LIST STRING)
@end lisp
Returns a string that contains all strings in @code{LIST} concatenated
together.  @code{STRING} is placed between each concatenated string.

@verbatim
(string-intersperse '("one" "two") "three")
@end verbatim

is equivalent to

@verbatim
(apply string-append (intersperse '("one" "two") "three"))
@end verbatim

@end deffn
@deffn {procedure} string-split
@lisp
(string-split STRING [DELIMITER-STRING [KEEPEMPTY]])
@end lisp
Split string into substrings separated by the given delimiters. If
no delimiters are specified, a string comprising the tab, newline and space characters 
is assumed. If the
parameter @code{KEEPEMPTY} is given and not @code{#f}, then empty
substrings are retained:

@verbatim
(string-split "one  two  three") ==> ("one" "two" "three")
(string-split "foo:bar::baz:" ":" #t) ==> ("foo" "bar" "" "baz" "")
@end verbatim

@end deffn
@deffn {procedure} string-translate
@lisp
(string-translate STRING FROM [TO])
@end lisp
Returns a fresh copy of @code{STRING} with characters matching
@code{FROM} translated to @code{TO}.  If @code{TO} is omitted, then
matching characters are removed. @code{FROM} and @code{TO} may be
a character, a string or a list. If both @code{FROM} and @code{TO}
are strings, then the character at the same position in @code{TO}
as the matching character in @code{FROM} is substituted.

@end deffn
@deffn {procedure} string-translate*
@lisp
(string-translate* STRING SMAP)
@end lisp
Substitutes elements of @code{STRING} according to @code{SMAP}.
@code{SMAP} should be an association-list where each element of the list
is a pair of the form @code{(MATCH \. REPLACEMENT)}. Every occurrence of
the string @code{MATCH} in @code{STRING} will be replaced by the string
@code{REPLACEMENT}:

@verbatim
(string-translate*
  "<h1>this is a \"string\"</h1>"
  '(("<" . "&lt:") (">" . "&gt;") ("\"" . "&quot;")) )

==>  "&lt;h1&gt;this is a &quot;string&quot;&lt;/ht&gt;"
@end verbatim

@end deffn
@deffn {procedure} substring=?
@deffnx {procedure} substring-ci=?
@lisp
(substring=? STRING1 STRING2 [START1 [START2 [LENGTH]]])
(substring-ci=? STRING1 STRING2 [START1 [START2 [LENGTH]]])
@end lisp
Returns @code{#t} if the strings @code{STRING1} and @code{STRING2} are equal, or
@code{#f} otherwise.
The comparison starts at the positions @code{START1} and @code{START2} (which default
to 0), comparing @code{LENGTH} characters (which defaults to the minimum of the remaining
length of both strings).

@end deffn
@deffn {procedure} substring-index
@deffnx {procedure} substring-index-ci
@lisp
(substring-index WHICH WHERE [START])
(substring-index-ci WHICH WHERE [START])
@end lisp
Searches for first index in string @code{WHERE} where string
@code{WHICH} occurs.  If the optional argument @code{START} is given,
then the search starts at that index.  @code{substring-index-ci}
is a case-insensitive version of @code{substring-index}.
@end deffn




@node Combinators
@subsection Combinators


@deffn {procedure} constantly
@lisp
(constantly X ...)
@end lisp
Returns a procedure that always returns the values @code{X ...} regardless of the number and value of its arguments.

@verbatim
(constantly X) <=> (lambda args X)
@end verbatim

@end deffn
@deffn {procedure} complement
@lisp
(complement PROC)
@end lisp
Returns a procedure that returns the boolean inverse of @code{PROC}.
@verbatim
(complement PROC) <=> (lambda (x) (not (PROC x)))
@end verbatim

@end deffn
@deffn {procedure} compose
@lisp
(compose PROC1 PROC2 ...)
@end lisp
Returns a procedure that represents the composition of the
argument-procedures @code{PROC1 PROC2 ...}.

@verbatim
(compose F G) <=> (lambda args
                      (call-with-values
                         (lambda () (apply G args))
                         F))
@end verbatim

@end deffn
@deffn {procedure} conjoin
@lisp
(conjoin PRED ...)
@end lisp
Returns a procedure that returns @code{#t} if its argument satisfies the
predicates @code{PRED ...}.
@verbatim
((conjoin odd? positive?) 33)   ==>  #t
((conjoin odd? positive?) -33)  ==>  #f
@end verbatim

@end deffn
@deffn {procedure} disjoin
@lisp
(disjoin PRED ...)
@end lisp
Returns a procedure that returns @code{#t} if its argument satisfies any
predicate @code{PRED ...}.
@verbatim
((disjoin odd? positive?) 32)    ==>  #t
((disjoin odd? positive?) -32)   ==>  #f
@end verbatim

@end deffn
@deffn {procedure} flip
@lisp
(flip PROC)
@end lisp
Returns a two-argument procedure that calls @code{PROC} with its
arguments swapped:
@verbatim
(flip PROC) <=> (lambda (x y) (PROC y x))
@end verbatim

@end deffn
@deffn {procedure} identity
@lisp
(identity X)
@end lisp
Returns its sole argument @code{X}.

@end deffn
@deffn {procedure} project
@lisp
(project N)
@end lisp
Returns a procedure that returns its @code{N}th argument.

@end deffn
@deffn {procedure} list-of
@lisp
(list-of PRED)
@end lisp
Returns a procedure of one argument that returns @code{#t} when
applied to a list of elements that all satisfy the predicate procedure
@code{PRED}, or @code{#f} otherwise.

@verbatim
((list-of even?) '(1 2 3))   ==> #f
((list-of number?) '(1 2 3)) ==> #t
@end verbatim
@end deffn




@node Binary searching
@subsection Binary searching



@deffn {procedure} binary-search
@lisp
(binary-search SEQUENCE PROC)
@end lisp
Performs a binary search in @code{SEQUENCE}, which should be a sorted
list or vector.  @code{PROC} is called to compare items in the sequence,
should accept a single argument and return an exact integer: zero if the
searched value is equal to the current item, negative if the searched
value is ``less'' than the current item, and positive otherwise.
@end deffn




@node Unit srfi-1
@section Unit srfi-1

List library, see the documentation for
@uref{http://srfi.schemers.org/srfi-1/srfi-1.html, SRFI-1 }

@node Unit srfi-4
@section Unit srfi-4 

Homogeneous numeric vectors, see the documentation for @uref{http://srfi.schemers.org/srfi-4/srfi-4.html, SRFI-4
}
In addition to that, the following procedures are also provided:


@deffn {procedure} u8vector->byte-vector
@deffnx {procedure} s8vector->byte-vector
@deffnx {procedure} u16vector->byte-vector
@deffnx {procedure} s16vector->byte-vector
@deffnx {procedure} u32vector->byte-vector
@deffnx {procedure} s32vector->byte-vector
@deffnx {procedure} f32vector->byte-vector
@deffnx {procedure} f64vector->byte-vector
@lisp
(u8vector->byte-vector U8VECTOR)
(s8vector->byte-vector S8VECTOR)
(u16vector->byte-vector U16VECTOR)
(s16vector->byte-vector S16VECTOR)
(u32vector->byte-vector U32VECTOR)
(s32vector->byte-vector S32VECTOR)
(f32vector->byte-vector F32VECTOR)
(f64vector->byte-vector F64VECTOR)
@end lisp
Each of these procedures return the contents of the given vector as a
'packed' byte-vector. The byte order in that vector is platform-dependent
(for example little-endian on an @b{Intel} processor). The returned
byte-vector shares memory with the contents of the vector.
@end deffn

@deffn {procedure} byte-vector->u8vector
@deffnx {procedure} byte-vector->s8vector
@deffnx {procedure} byte-vector->u16vector
@deffnx {procedure} byte-vector->s16vector
@deffnx {procedure} byte-vector->u32vector
@deffnx {procedure} byte-vector->s32vector
@deffnx {procedure} byte-vector->f32vector
@deffnx {procedure} byte-vector->f64vector
@lisp
(byte-vector->u8vector BYTE-VECTOR)
(byte-vector->s8vector BYTE-VECTOR)
(byte-vector->u16vector BYTE-VECTOR)
(byte-vector->s16vector BYTE-VECTOR)
(byte-vector->u32vector BYTE-VECTOR)
(byte-vector->s32vector BYTE-VECTOR)
(byte-vector->f32vector BYTE-VECTOR)
(byte-vector->f64vector BYTE-VECTOR)
@end lisp
Each of these procedures return a vector where the argument
@code{BYTE-VECTOR} is taken as a 'packed' representation of the contents
of the vector. The argument-byte-vector shares memory with the contents
of the vector.

@end deffn
@deffn {procedure} subu8vector
@deffnx {procedure} subu16vector
@deffnx {procedure} subu32vector
@deffnx {procedure} subs8vector
@deffnx {procedure} subs16vector
@deffnx {procedure} subs32vector
@deffnx {procedure} subf32vector
@deffnx {procedure} subf64vector
@lisp
(subu8vector U8VECTOR FROM TO)
(subu16vector U16VECTOR FROM TO)
(subu32vector U32VECTOR FROM TO)
(subs8vector S8VECTOR FROM TO)
(subs16vector S16VECTOR FROM TO)
(subs32vector S32VECTOR FROM TO)
(subf32vector F32VECTOR FROM TO)
(subf64vector F64VECTOR FROM TO)
@end lisp
Creates a number vector of the same type as the argument vector with the elements at the positions @code{FROM} up to but
not including @code{TO}.
@end deffn




@node Unit srfi-13
@section Unit srfi-13 


String library, see the documentation for
@uref{http://srfi.schemers.org/srfi-13/srfi-13.html, SRFI-13 }

The file @code{srfi-13-syntax.scm} contains macro definitions for
@code{let-string-start+end}.


On systems that support dynamic loading, the @code{srfi-13} unit can
be made available in the interpreter (@code{csi}) by entering

@verbatim
(require-extension srfi-13)
@end verbatim

@node Unit srfi-14
@section Unit srfi-14

Character set library, see the documentation for
@uref{http://srfi.schemers.org/srfi-14/srfi-14.html, SRFI-14 }

On systems that support dynamic loading, the @code{srfi-14} unit can
be made available in the interpreter (@code{csi}) by entering

@verbatim
(require-extension srfi-14)
@end verbatim

@itemize
@item This library provides only the Latin-1 character set.
@end itemize

@node Unit srfi-25
@section Unit srfi-25

Multi-dimensional array, see the documentation for
@uref{http://srfi.schemers.org/srfi-25/srfi-25.html, SRFI-25 }

On systems that support dynamic loading, the @code{srfi-25} unit can
be made available in the interpreter (@code{csi}) by entering

@verbatim
(require-extension srfi-25)
@end verbatim

@node Unit match
@section Unit match

Andrew Wright's pattern matching package. Note that to use the macros in
normal compiled code it is not required to declare this unit as used. Only
if forms containing these macros are to be expanded at runtime, this
is needed.



@deffn {syntax} match
@deffnx {syntax} match-lambda
@deffnx {syntax} match-lambda*
@deffnx {syntax} match-let
@deffnx {syntax} match-let*
@deffnx {syntax} match-letrec
@deffnx {syntax} match-define
@lisp
(match EXP CLAUSE ...)
(match-lambda CLAUSE ...)
(match-lambda* CLAUSE ...)
(match-let ((PAT EXP) ...) BODY)
(match-let* ((PAT EXP) ...) BODY)
(match-letrec ((PAT EXP) ...) BODY)
(match-define PAT EXP)
@end lisp
Match expression or procedure arguments with pattern and
execute associated expressions.  A @uref{http://www.call-with-current-continuation.org/match.ps, Postscript manual} is
available .

@end deffn
@deffn {syntax} define-structure
@deffnx {syntax} define-const-structure
@lisp
(define-structure (ID_0 ID_1 ... ID_N))
(define-structure (ID_0 ID_1 ... ID_N)
                  ((@math{ID_{N+1}} @math{EXP_1}) ...
                   (@math{ID_{N+M} EXP_M})))
(define-const-structure (@math{ID_0 ARG_1} ... @math{ARG_N}))
(define-const-structure @math{(ID_0 ARG_1 ... ARG_N)}
                        @math{((ARG_{N+1} EXP_1) ...}
                               @math{(ARG_{N+M} EXP_M))})
@end lisp
Macros for defining record structures that can be decomposed by @code{match}.

@end deffn

@deffn {procedure} match-error-control
@lisp
(match-error-control [MODE])
@end lisp
Selects a mode that specifies how @code{match...} macro forms are to
be expanded.  With no argument this procedure returns the current mode. A
single argument specifies the new mode that decides what should happen
if no match-clause applies.  The following modes are supported:

@table @code

@item #:error

Signal an error. This is the default.

@item #:match

Signal an error and output the offending form.

@item #:fail

Omits @code{pair?} tests when the consequence is to fail in @code{car}
or @code{cdr} rather than to signal an error.

@item #:unspecified

Non-matching expressions will either fail in @code{car} or @code{cdr}
or return an unspecified value.  This mode applies to files compiled
with the @code{unsafe} option or declaration.

@end table


When an error is signalled, the raised exception will be of kind @code{(exn match)}.

@end deffn


Note: @code{match:structure-control} is not available. Structures
defined by the macros provided in this unit are always implemented
as vectors.  @code{match:runtime-structures} is also not available.

To use the pattern matching macros with the highlevel (@code{syntax-case})
macro system @code{(require-extension match)}.


@node Unit regex
@section Unit regex

This library unit provides support for regular expressions. The flavor depends on
the particular installation platform:

@itemize
@item On UNIX systems that have PCRE (the Perl Compatible Regular Expression package)
installed, PCRE is used.
@item If PCRE is not available, and the C library provides regular expressions, these
are used instead.
@item on Windows (or of PCRE and libc regexes are not available), Dorai Sitaram's
portable @code{pregexp} library is used.
@end itemize



@deffn {procedure} grep
@lisp
(grep REGEX LIST)
@end lisp
Returns all items of @code{LIST} that match the regular expression
@code{REGEX}.  This procedure could be defined as follows:

@verbatim
(define (grep regex lst)
  (filter (lambda (x) (string-match regex x)) lst) )
@end verbatim

@end deffn
@deffn {procedure} pattern->regexp
@lisp
(pattern->regexp PATTERN)
@end lisp
Converts the file-pattern @code{PATTERN} into a regular expression.

@verbatim
(pattern->regexp "foo.*") ==> "foo\..*"
@end verbatim

@end deffn
@deffn {procedure} regexp
@lisp
(regexp STRING)
@end lisp
Returns a precompiled regular expression object for @code{string}.

@end deffn
@deffn {procedure} regexp?
@lisp
(regexp? X)
@end lisp
Returns @code{#t} if @code{X} is a precompiled regular expression,
or @code{#f} otherwise.

@end deffn
@deffn {procedure} string-match
@deffnx {procedure} string-match-positions
@lisp
(string-match REGEXP STRING [START])
(string-match-positions REGEXP STRING [START])
@end lisp
Matches the regular expression in @code{REGEXP} (a string or a precompiled
regular expression) with
@code{STRING} and returns either @code{#f} if the match failed,
or a list of matching groups, where the first element is the complete
match. If the optional argument @code{START} is supplied, it specifies
the starting position in @code{STRING}.  For each matching group the
result-list contains either: @code{#f} for a non-matching but optional
group; a list of start- and end-position of the match in @code{STRING}
(in the case of @code{string-match-positions}); or the matching
substring (in the case of @code{string-match}). Note that the exact string
is matched. For searching a pattern inside a string, see below.

@end deffn
@deffn {procedure} string-search
@deffnx {procedure} string-search-positions
@lisp
(string-search REGEXP STRING [START [RANGE]])
(string-search-positions REGEXP STRING [START [RANGE]])
@end lisp
Searches for the first match of the regular expression in
@code{REGEXP} with @code{STRING}. The search can be limited to
@code{RANGE} characters.

@end deffn
@deffn {procedure} string-split-fields
@lisp
(string-split-fields REGEXP STRING [MODE [START]])
@end lisp
Splits @code{STRING} into a list of fields according to @code{MODE},
where @code{MODE} can be the keyword @code{#:infix} (@code{REGEXP}
matches field separator), the keyword @code{#:suffix} (@code{REGEXP}
matches field terminator) or @code{#t} (@code{REGEXP} matches field),
which is the default.

@end deffn
@deffn {procedure} string-substitute
@lisp
(string-substitute REGEXP SUBST STRING [INDEX])
@end lisp
Searches substrings in @code{STRING} that match @code{REGEXP}
and substitutes them with the string @code{SUBST}. The substitution
can contain references to subexpressions in 
@code{REGEXP} with the @code{\NUM} notation, where @code{NUM}
refers to the NUMth parenthesized expression. The optional argument
@code{INDEX} defaults to 1 and specifies the number of the match to
be substituted. Any non-numeric index specifies that all matches are to
be substituted.

@verbatim
(string-substitute "([0-9]+) (eggs|chicks)"
                   "2 (1)" "99 eggs or 99 chicks" 2)
 ==> "99 eggs or chicks (99)"
@end verbatim

@end deffn
@deffn {procedure} string-substitute*
@lisp
(string-substitute* STRING SMAP)
@end lisp
Substitutes elements of @code{STRING} according to @code{SMAP}.
@code{SMAP} should be an association-list where each element of the list
is a pair of the form @code{(MATCH . REPLACEMENT)}. Every occurrence of
the regular expression @code{MATCH} in @code{STRING} will be replaced by the string
@code{REPLACEMENT}

@verbatim
(string-substitute* "<h1>Hello, world!</h1>"
                    '(("<[/A-Za-z0-9]+>" . ""))))

==>  "Hello, world!"
@end verbatim
@end deffn




@node Unit syntax-case
@section Unit syntax-case

Hieb's and Dybvig's hygienic macro package. Provides @code{syntax-case}
and @code{syntax-rules}. A postscript manual can be found here:
@uref{http://www.call-with-current-continuation.org/tr356.ps, Indiana University Computer Science Department, Technical Report #356}

@b{Notes:}
@itemize

@item The alternative form
@verbatim
(define-syntax (keyword var) ...)
@end verbatim
is allowed for @code{define-syntax}.

@item The module system described in the Chez Scheme Uses Manual is
supported (including separate compilation). When @code{import} or @code{import-only}
is used with an argument that names a module that is currently not defined, then
the current @code{include-path} (and the @code{repository-path} as well) is searched for a source-file 
of the same name (possibly with the extension @code{.scm}), which (if found)
will be ``visited'' (it's module- and syntax-definitions are processed) using the
procedure @code{visit}. Note that exported identifiers must be defined
via @code{define} or @code{define-syntax}. Other defining forms (like @code{define-values})
are not recognized as exporting definitions.

There are currently no built-in modules.

@item To use the macro-system in compiled or interpreted code, just give
the @code{-hygienic} option to the compiler or interpreter. The @code{syntax-case} unit has
only to be declared as used if compiled code invokes @code{macroexpand}
or @code{eval} with high-level macro syntax forms.

@item @code{define-syntax} can not be used inside an @code{eval-when} form.

@end itemize

Here is a small example that demonstrates separate compilation:

Let's say we have one file @code{foo.scm} that defines a module:

@lisp
(module foo (pr (bar baz))
  (define pr print)
  (define baz 99)
  (define-syntax bar
    (syntax-rules ()
      [(_ x) (list baz 'x)] ) ) )
@end lisp

and another that uses it (@code{use-foo.scm}):

@lisp
(load "foo.so")   ; (require 'foo) would also work

(import foo)
(pr (bar hello))
@end lisp

Compiling the files like this will lead to one dynamically loadable library
and a plain executable:

@verbatim
$ csc -s -hygienic foo.scm
$ csc -hygienic use-foo.scm
$ use-foo
$ (99 hello)
@end verbatim

The @code{export} declaration can be used to export identifiers exported from modules
defined in a given source file. These exports will then be visible as normal toplevel
variables in external code that loads or links with this file. The rationale behind
this is to make it possible to create libraries and extensions that use modules
internally, but still can be used in client code that doesn't use modules.

@deffn {procedure} visit
@lisp
(visit FILENAME)
@end lisp
Reads all toplevel expressions from the given file and expands all syntax, extracting
module- and syntax-information to be subsequently used during the current compilation or
interpretation of modules.
@end deffn

@node Unit srfi-18
@section Unit srfi-18

A simple multithreading package. This threading package follows largely
the specification of SRFI-18. For more information see the documentation
for @uref{http://srfi.schemers.org/srfi-18/srfi-18.html, SRFI-18 }

@b{Notes:}

@itemize

@item When an uncaught exception (i.e. an error) is signalled in a thread other than
the primordial thread and warnings are enabled (see: @code{enable-warnings}, then a warning 
message is written to the port that is the value of @code{(current-error-port)}.

@item Blocking I/O will block all threads, except for some socket operations
(see the section about the @code{tcp} unit).

@item It is generally not a good idea for one thread to call a
continuation created by another thread, if @code{dynamic-wind}
is involved.

@item When more than one thread compete for the current time-slice,
the thread that was waiting first will become the next runnable thread.

@item The dynamic environment of a thread consists of the following state:

 @itemize

 @item The current input-, output- and error-port

 @item The current exception handler

 @item The values of all current parameters (created by @code{make-parameter})

 @item Any pending @code{dynamic-wind} thunks.

 @end itemize

@end itemize

The following procedures are provided, in addition to the procedures defined in SRFI-18:



@deffn {procedure} thread-deliver-signal!
@lisp
(thread-deliver-signal! THREAD X)
@end lisp
This will cause @code{THREAD} to signal the condition @code{X} once it is scheduled
for execution. After signalling the condition, the thread continues with its normal
execution.

@end deffn
@deffn {procedure} thread-quantum
@lisp
(thread-quantum THREAD)
@end lisp
Returns the quantum of @code{THREAD}, which is an exact integer
specifying the approximate time-slice of the thread.

@end deffn
@deffn {procedure} thread-quantum-set!
@lisp
(thread-quantum-set! THREAD QUANTUM)
@end lisp
Sets the quantum of @code{THREAD} to @code{QUANTUM}.
@end deffn




@node Unit format
@section Unit format



@deffn {procedure} format
@lisp
(format DESTINATION FORMAT-STRING . ARGUMENTS)
@end lisp
An almost complete implementation of Common LISP format description
according to the CL reference book @b{Common LISP} from Guy L.
Steele, Digital Press. This code was originally part of SLIB. The author
is Dirk Lutzebaeck.

Returns @code{#t}, @code{#f} or a string; has side effect of
printing according to @code{FORMAT-STRING}.  If @code{DESTINATION} is
@code{#t}, the output is to the current output port and @code{#t}
is returned.  If @code{DESTINATION} is @code{#f}, a formatted
string is returned as the result of the call.  If @code{DESTINATION}
is a string, @code{DESTINATION} is regarded as the format string;
@code{FORMAT-STRING} is then the first argument and the output
is returned as a string. If @code{DESTINATION} is a number, the
output is to the value of @code{(current-error-port)}.  Otherwise
@code{DESTINATION} must be an output port and @code{#t} is returned.

@code{FORMAT-STRING} must be a string.  In case of a formatting
error format returns @code{#f} and prints a message on the value
of @code{(current-error-port)}.  Characters are output as if the
string were output by the @code{display} function with the exception
of those prefixed by a tilde (~).  For a detailed description of
the @code{FORMAT-STRING} syntax please consult a Common LISP format
reference manual. A list of all supported, non-supported and extended
directives can be found in @code{format.txt}.

This unit uses definitions from the @code{extras} unit.

@code{format} implements
@uref{http//srfi.schemers.org/srfi-28/srfi-28.html, SRFI-28 }
@end deffn



@node Unit posix
@section Unit posix

This unit provides services as used on many UNIX-like systems.  Note that
the following definitions are not available on non-UNIX systems like
Windows or DOS.

This unit uses the @code{regex} and @code{extras} units.

All errors related to failing file-operations will signal a condition
of kind @code{(exn i/o file)}.

@menu
* Directories::                 
* Pipes::                       
* Fifos::                       
* File descriptors and low-level I/O::  
* Retrieving file attributes::  
* Changing file attributes::    
* Processes::                   
* Symbolic links::              
* Permissions::                 
* Record locking::              
* Signal handling::             
* Environment access::          
* Memory mapped I/O::           
* Time routines::               
* Raw exit::                    
* ERRNO values::                
* Finding files::               
* Getting the hostname and system information::  
* Setting a files buffering mode::  
* Terminal ports::              
* How Scheme procedures relate to UNIX C functions::  
@end menu

@node Directories
@subsection Directories



@deffn {procedure} change-directory
@lisp
(change-directory NAME)
@end lisp
Changes the current working directory to @code{NAME}.

@end deffn
@deffn {procedure} current-directory
@lisp
(current-directory)
@end lisp
Returns the name of the current working directory.

@end deffn
@deffn {procedure} create-directory
@lisp
(create-directory NAME)
@end lisp
Creates a directory with the pathname @code{NAME}.

@end deffn
@deffn {procedure} delete-directory
@lisp
(delete-directory NAME)
@end lisp
Deletes the directory with the pathname @code{NAME}. The directory has
to be empty.

@end deffn
@deffn {procedure} directory
@lisp
(directory PATHNAME)
@end lisp
Returns a list with all files that are contained in the directory with the name @code{PATHNAME}.

@end deffn
@deffn {procedure} directory?
@lisp
(directory? NAME)
@end lisp
Returns @code{#t} if there exists a file with the name @code{NAME}
and if that file is a directory, or @code{#f} otherwise.

@end deffn
@deffn {procedure} glob
@lisp
(glob PATTERN1 ...)
@end lisp
Returns a list of the pathnames of all existing files matching
@code{PATTERN1 ...}, which should be strings containing the usual
file-patterns (with @code{*} matching zero or more characters and
@code{?} matching zero or one character).
@end deffn



@node Pipes
@subsection Pipes



@deffn {procedure} call-with-input-pipe
@deffnx {procedure} call-with-output-pipe
@lisp
(call-with-input-pipe CMDLINE PROC [MODE])
(call-with-output-pipe CMDLINE PROC [MODE])
@end lisp
Call @code{PROC} with a single argument: a input- or output port
for a pipe connected to the subprocess named in @code{CMDLINE}. If
@code{PROC} returns normally, the pipe is closed and any result values
are returned.

@end deffn
@deffn {procedure} close-input-pipe
@deffnx {procedure} close-output-pipe
@lisp
(close-input-pipe PORT)
(close-output-pipe PORT)
@end lisp
Closes the pipe given in @code{PORT} and waits until the connected
subprocess finishes.

@end deffn
@deffn {procedure} create-pipe
@lisp
(create-pipe)
@end lisp
The fundamental pipe-creation operator. Calls the C function
@code{pipe()} and returns 2 values: the file-descriptors of the input-
and output-ends of the pipe.

@end deffn
@deffn {procedure} open-input-pipe
@lisp
(open-input-pipe CMDLINE [MODE])
@end lisp
Spawns a subprocess with the command-line string @code{CMDLINE} and
returns a port, from which the output of the process can be read. If
@code{MODE} is specified, it should be the keyword @code{#:text}
(the default) or @code{#:binary}.

@end deffn
@deffn {procedure} open-output-pipe
@lisp
(open-output-pipe CMDLINE [MODE])
@end lisp
Spawns a subprocess with the command-line string @code{CMDLINE} and
returns a port. Anything written to that port is treated as the input
for the process.  If @code{MODE} is specified, it should be the keyword
@code{#:text} (the default) or @code{#:binary}.

@end deffn
@defvr {limit} pipe/buf
This variable contains the maximal number of bytes that can be written
atomically into a pipe or FIFO.

@end defvr
@deffn {procedure} with-input-from-pipe
@deffnx {procedure} with-output-to-pipe
@lisp
(with-input-from-pipe CMDLINE THUNK [MODE])
(with-output-to-pipe CMDLINE THUNK [MODE])
@end lisp
Temporarily set the value of
@code{current-input-port/current-output-port} to a port for a
pipe connected to the subprocess named in @code{CMDLINE} and call
the procedure @code{THUNK} with no arguments. After @code{THUNK}
returns normally the pipe is closed and the standard input-/output port
is restored to its previous value and any result values are returned.

@verbatim
(with-output-to-pipe 
  "gs -dNOPAUSE -sDEVICE=jpeg -dBATCH -sOutputFile=signballs.jpg -g600x600 -q -"
  (lambda ()
    (print #<<EOF
%!IOPSC-1993 %%Creator: HAYAKAWA Takashi<xxxxxxxx@xx.xxxxxx.xx.xx>
/C/neg/d/mul/R/rlineto/E/exp/H{{cvx def}repeat}def/T/dup/g/gt/r/roll/J/ifelse 8
H/A/copy(z&v4QX&93r9AxYQOZomQalxS2w!!O&vMYa43d6r93rMYvx2dca!D&cjSnjSnjjS3o!v&6A
X&55SAxM1CD7AjYxTTd62rmxCnTdSST0g&12wECST!&!J0g&D1!&xM0!J0g!l&544dC2Ac96ra!m&3A
F&&vGoGSnCT0g&wDmlvGoS8wpn6wpS2wTCpS1Sd7ov7Uk7o4Qkdw!&Mvlx1S7oZES3w!J!J!Q&7185d
Z&lx1CS9d9nE4!k&X&MY7!&1!J!x&jdnjdS3odS!N&mmx1C2wEc!G&150Nx4!n&2o!j&43r!U&0777d
]&2AY2A776ddT4oS3oSnMVC00VV0RRR45E42063rNz&v7UX&UOzF!F!J![&44ETCnVn!a&1CDN!Y&0M
V1c&j2AYdjmMdjjd!o&1r!M){( )T 0 4 3 r put T(/)g{T(9)g{cvn}{cvi}J}{($)g[]J}J
cvx}forall/moveto/p/floor/w/div/S/add 29 H[{[{]setgray fill}for Y}for showpage
EOF
) ) )
@end verbatim
@end deffn




@node Fifos
@subsection Fifos




@deffn {procedure} create-fifo
@lisp
(create-fifo FILENAME [MODE])
@end lisp
Creates a FIFO with the name @code{FILENAME} and the permission bits
@code{MODE}, which defaults to

@verbatim
(+ perm/irwxu perm/irwxg perm/irwxo)
@end verbatim

@end deffn
@deffn {procedure} fifo?
@lisp
(fifo? FILENAME)
@end lisp
Returns @code{#t} if the file with the name @code{FILENAME} names
a FIFO.
@end deffn




@node File descriptors and low-level I/O
@subsection File descriptors and low-level I/O




@deffn {procedure} duplicate-fileno
@lisp
(duplicate-fileno OLD [NEW])
@end lisp
If @code{NEW} is given, then the file-descriptor @code{NEW} is opened
to access the file with the file-descriptor @code{OLD}. Otherwise a
fresh file-descriptor accessing the same file as @code{OLD} is returned.

@end deffn
@deffn {procedure} file-close
@lisp
(file-close FILENO)
@end lisp
Closes the input/output file with the file-descriptor @code{FILENO}.

@end deffn
@deffn {procedure} file-open
@lisp
(file-open FILENAME FLAGS [MODE])
@end lisp
Opens the file specified with the string @code{FILENAME} and open-flags
@code{FLAGS} using the C function @code{open()}. On success a
file-descriptor for the opened file is returned.  @code{FLAGS}
should be a bitmask containing one or more of the @code{open/...}
values @b{or}ed together using @code{bitwise-ior} (or simply added
together).  The optional @code{MODE} should be a bitmask composed of one
or more permission values like @code{perm/irusr} and is only relevant
when a new file is created. The default mode is 
@code{perm/irwxu | perm/irgrp | perm/iroth}.

@end deffn
@deffn {procedure} file-mkstemp
@lisp
(file-mkstemp TEMPLATE-FILENAME)
@end lisp
Create a file based on the given @code{TEMPLATE-FILENAME}, in which
the six last characters must be ``XXXXXX''.  These will be replaced
with a string that makes the filename unique.  The file descriptor of
the created file and the generated filename is returned.  See the
@code{mkstemp(3)} manual page for details on how this function
works.  The template string given is not modified.

Example usage:
@verbatim
(let-values (((fd temp-path) (file-mkstemp "/tmp/mytemporary.XXXXXX")))
  (let ((temp-port (open-output-file* fd)))
    (format temp-port "This file is ~A.~%" temp-path)
    (close-output-port temp-port)))
@end verbatim

@end deffn
@deffn {procedure} file-read
@lisp
(file-read FILENO SIZE [BUFFER])
@end lisp
Reads @code{SIZE} bytes from the file with the file-descriptor
@code{FILENO}.  If a string or bytevector is passed in the optional
argument @code{BUFFER}, then this string will be destructively modified
to contain the read data. This procedure returns a list with two values:
the buffer containing the data and the number of bytes read.

@end deffn
@deffn {procedure} file-select
@lisp
(file-select READFDLIST WRITEFDLIST [TIMEOUT])
@end lisp
Waits until any of the file-descriptors given in the lists
@code{READFDLIST} and @code{WRITEFDLIST} is ready for input or
output, respectively. If the optional argument @code{TIMEOUT} is
given and not false, then it should specify the number of seconds after
which the wait is to be aborted. This procedure returns two values:
the lists of file-descriptors ready for input and output, respectively.
@code{READFDLIST} and @b{WRITEFDLIST} may also by file-descriptors
instead of lists.  In this case the returned values are booleans
indicating whether input/output is ready by @code{#t} or @code{#f}
otherwise.  You can also pass @code{#f} as @code{READFDLIST} or
@code{WRITEFDLIST} argument, which is equivalent to @code{()}.

@end deffn
@deffn {procedure} file-write
@lisp
(file-write FILENO BUFFER [SIZE])
@end lisp
Writes the contents of the string or bytevector @code{BUFFER} into
the file with the file-descriptor @code{FILENO}. If the optional
argument @code{SIZE} is given, then only the specified number of bytes
are written.
@end deffn

@defvr {file descriptor} fileno/stdin
@defvrx {file descriptor} fileno/stdout
@defvrx {file descriptor} fileno/stderr
These variables contain file-descriptors for the standard I/O files.
@end defvr

@defvr {flag} open/rdonly
@defvrx {flag} open/wronly
@defvrx {flag} open/rdwr
@defvrx {flag} open/read 
@defvrx {flag} open/write 
@defvrx {flag} open/creat
@defvrx {flag} open/append 
@defvrx {flag} open/excl
@defvrx {flag} open/noctty 
@defvrx {flag} open/nonblock 
@defvrx {flag} open/trunc
@defvrx {flag} open/sync
@defvrx {flag} open/fsync
@defvrx {flag} open/binary
@defvrx {flag} open/text
Flags for use with @code{file-open}.
@end defvr

@deffn {procedure} open-input-file*
@deffnx {procedure} open-output-file*
@lisp
(open-input-file* FILENO [OPENMODE])
(open-output-file* FILENO [OPENMODE])
@end lisp
Opens file for the file-descriptor @code{FILENO} for input or output
and returns a port.  @code{FILENO} should be a positive exact integer.
@code{OPENMODE} specifies an additional mode for opening the file
(currently only the keyword @code{#:append} is supported, which opens
an output-file for appending).
@end deffn

@deffn {procedure} port->fileno
@lisp
(port->fileno PORT)
@end lisp
If @code{PORT} is a file-port, then a file-descriptor is returned for
this port. Otherwise an error is signaled.
@end deffn




@node Retrieving file attributes
@subsection Retrieving file attributes




@deffn {procedure} file-modification-time
@lisp
(file-modification-time FILE)
@end lisp
Returns time (in seconds) of the last modification of @code{FILE}. @code{FILE}
may be a filename or a file-descriptor. If the file does not exist,
an error is signaled.

@end deffn
@deffn {procedure} file-position
@lisp
(file-position FILE)
@end lisp
Returns the current file position of @code{FILE}, which should be a
port or a file-descriptor.

@end deffn
@deffn {procedure} file-size
@lisp
(file-size FILENAME)
@end lisp
Returns the size of the file designated by @code{FILE}.  @code{FILE}
may be a filename or a file-descriptor.  If the file does not exist,
an error is signaled.
@end deffn




@node Changing file attributes
@subsection Changing file attributes




@deffn {procedure} file-truncate
@lisp
(file-truncate FILE OFFSET)
@end lisp
Truncates the file @code{FILE} to the length @code{OFFSET},
which should be an integer. If the file-size is smaller or equal to
@code{OFFSET} then nothing is done.  @code{FILE} should be a filename
or a file-descriptor.

@end deffn
@deffn {procedure} set-file-position!
@lisp
(set-file-position! FILE POSITION [WHENCE])
@end lisp
Sets the current read/write position of @code{FILE} to
@code{POSITION}, which should be an exact integer. @code{FILE}
should be a port or a file-descriptor.  @code{WHENCE} specifies
how the position is to interpreted and should be one of the values
@code{seek/set, seek/cur} and @code{seek/end}. It defaults to
@code{seek/set}.

Exceptions: @code{(exn bounds)}, @code{(exn i/o file)}
@end deffn




@node Processes
@subsection Processes




@deffn {procedure} current-process-id
@lisp
(current-process-id)
@end lisp
Returns the process ID of the current process.

@end deffn
@deffn {procedure} parent-process-id
@lisp
(parent-process-id)
@end lisp
Returns the process ID of the parent of the current process.

@end deffn
@deffn {procedure} process-execute
@lisp
(process-execute PATHNAME [LIST])
@end lisp
Creates a new child process and replaces the running process with it
using the UNIX system call @code{execv()}. If the optional argument
@code{LIST} is given, then it should contain a list of strings which
are passed as arguments to the subprocess.

@end deffn
@deffn {procedure} process-fork
@lisp
(process-fork [THUNK])
@end lisp
Creates a new child process with the UNIX system call
@code{fork()}. Returns either the PID of the child process or 0. If
@code{THUNK} is given, then the child process calls it as a procedure
with no arguments and terminates.

@end deffn
@deffn {procedure} process-run
@lisp
(process-run PATHNAME [LIST])
@end lisp
Creates a new child process using the UNIX system call @code{fork()}
that executes the program given by the string @code{PATHNAME} using
the UNIX system call @code{execv()}.  The PID of the new process is
returned. If @code{LIST} is not specified, then @code{PATHNAME}
is passed to a program named by the environment variable @code{SHELL}
(or @code{/bin/sh}, if the variable is not defined), so usual argument
expansion can take place.

@end deffn
@deffn {procedure} process-signal
@lisp
(process-signal PID [SIGNAL])
@end lisp
Sends @code{SIGNAL} to the process with the id @code{PID} using the
UNIX system call @code{kill()}. @code{SIGNAL} defaults to the value
of the variable @code{signal/term}.

@end deffn
@deffn {procedure} process-wait
@lisp
(process-wait [PID [NOHANG]])
@end lisp
Suspends the current process until the child process with
the id @code{PID} has terminated using the UNIX system call
@code{waitpid()}. If @code{PID} is not given, then this procedure
waits for any child process. If @code{NOHANG} is given and not
@code{#f} then the current process is not suspended.  This procedure
returns three values:
@end deffn

@itemize
@item @code{PID} or 0, if @code{NOHANG} is true and the child process
has not terminated yet;

@item @code{#t} if the process exited normally or @code{#f}
otherwise;

@item either the exit status, if the process terminated normally or the
signal number that terminated/stopped the process.
@end itemize

@deffn {procedure} process
@lisp
(process COMMANDLINE)
@end lisp
Passes the string @code{COMMANDLINE} to the host-system's shell that
is invoked as a subprocess and returns three values: an input port from
which data written by the sub-process can be read, an output port from
which any data written to will be received as input in the sub-process
and the process-id of the started sub-process. All I/O from/to ports
returned by @code{process} is fully nonblocking.

@end deffn
@deffn {procedure} sleep
@lisp
(sleep SECONDS)
@end lisp
Puts the process to sleep for @code{SECONDS}. Returns either 0 if
the time has completely elapsed, or the number of remaining seconds,
if a signal occurred.
@end deffn



@node Symbolic links
@subsection Symbolic links



@deffn {procedure} create-symbolic-link
@lisp
(create-symbolic-link OLDNAME NEWNAME)
@end lisp
Creates a symbolic link with the filename @code{NEWNAME} that points
to the file named @code{OLDNAME}.

@end deffn
@deffn {procedure} read-symbolic-link
@lisp
(read-symbolic-link FILENAME)
@end lisp
Returns the filename to which the symbolic link @code{FILENAME} points.
@end deffn




@node Permissions
@subsection Permissions, owners, users and groups




@deffn {procedure} file-owner
@lisp
(file-owner FILE)
@end lisp
Returns the user-id of @code{FILE}.  @code{FILE} may be a filename
or a file-descriptor.

@end deffn
@deffn {procedure} file-permissions
@lisp
(file-permissions FILE)
@end lisp
Returns the permission bits for @code{FILE}. You can test this value
by performing bitwise operations on the result and the @code{perm/@dots{}}
values.  @code{FILE} may be a filename or a file-descriptor.

@end deffn
@deffn {procedure} file-read-access?
@deffnx {procedure} file-write-access?
@deffnx {procedure} file-execute-access?
@lisp
(file-read-access? FILENAME)
(file-write-access? FILENAME)
(file-execute-access? FILENAME)
@end lisp
These procedures return @code{#t} if the current user has read,
write or execute permissions on the file named @code{FILENAME}.

@end deffn
@deffn {procedure} change-file-mode
@lisp
(change-file-mode FILENAME MODE)
@end lisp
Changes the current file mode of the file named @code{FILENAME}
to @code{MODE} using the @code{chmod()} system call.  The
@code{perm/...} variables contain the various permission bits and can
be combinded with the @code{bitwise-ior} procedure.

@end deffn
@deffn {procedure} change-file-owner
@lisp
(change-file-owner FILENAME UID GID)
@end lisp
Changes the owner information of the file named @code{FILENAME} to
the user- and group-ids @code{UID} and @code{GID} (which should be
exact integers) using the @code{chown()} system call.

@end deffn
@deffn {procedure} current-user-id
@deffnx {procedure} current-group-id
@deffnx {procedure} current-effective-user-id
@deffnx {procedure} current-effective-group-id
@lisp
(current-user-id)
(current-group-id)
(current-effective-user-id)
(current-effective-group-id)
@end lisp
Return the user- and group-ids of the current process.

@end deffn
@deffn {procedure} group-information
@lisp
(group-information GROUP)
@end lisp
If @code{GROUP} specifies a valid group-name or group-id, then this
procedure returns four values: the group-name, the encrypted group password,
the group ID and a list of the names of all group members. If no group with the
given name or ID exists, then @code{#f} is returned.
@end deffn

@deffn {procedure} get-groups
@lisp
(get-groups)
@end lisp
Returns a list with the supplementary group IDs of the current user.
@end deffn

@deffn {procedure} set-groups!
@lisp
(set-groups! GIDLIST)
@end lisp
Sets the supplementrary group IDs of the current user to the IDs given in the list @code{GIDLIST}.

Only the superuser may invoke this procedure.
@end deffn

@deffn {procedure} initialize-groups
@lisp
(initialize-groups USERNAME BASEGID)
@end lisp
Sets the supplementrary group IDs of the current user to the IDs from the user with name @code{USERNAME} 
(a string), including @code{BASEGID}.

Only the superuser may invoke this procedure.
@end deffn

@defvr {permission bits} perm/irusr
@defvrx {permission bits} perm/iwusr
@defvrx {permission bits} perm/ixusr
@defvrx {permission bits} perm/irgrp
@defvrx {permission bits} perm/iwgrp
@defvrx {permission bits} perm/ixgrp
@defvrx {permission bits} perm/iroth
@defvrx {permission bits} perm/iwoth
@defvrx {permission bits} perm/ixoth
@defvrx {permission bits} perm/irwxu
@defvrx {permission bits} perm/irwxg
@defvrx {permission bits} perm/irwxo
@defvrx {permission bits} perm/isvtx
@defvrx {permission bits} perm/isuid
@defvrx {permission bits} perm/isgid
These variables contain permission bits as used in @code{change-file-mode}.
@end defvr

@deffn {procedure} set-user-id!
@lisp
(set-user-id! UID)
@end lisp
Sets the effective user id of the current process to @code{UID},
which should be a positive integer.
@end deffn

@deffn {procedure} user-information
@lisp
(user-information USER)
@end lisp
If @code{USER} specifes a valid username (as a string) or user ID, then
the user database is consulted and a list of 7 values are returned: the user-name,
the encrypted password, the user ID, the group ID, a user-specific string,
the home directory and the default shell. If no user with this name or
ID can be found, then @code{#f} is returned.
@end deffn




@node Record locking
@subsection Record locking




@deffn {procedure} file-lock
@lisp
(file-lock PORT [START [LEN]])
@end lisp
Locks the file associated with @code{PORT} for reading or
writing (according to whether @code{PORT} is an input- or
output-port). @code{START} specifies the starting position in the
file to be locked and defaults to 0. @code{LEN} specifies the length
of the portion to be locked and defaults to @code{#t}, which means
the complete file. @code{file-lock} returns a ``lock''-object.

@end deffn
@deffn {procedure} file-lock/blocking
@lisp
(file-lock/blocking PORT [START [LEN]])
@end lisp
Similar to @code{file-lock}, but if a lock is held on the file,
the current process blocks (including all threads) until the lock is released.

@end deffn
@deffn {procedure} file-test-lock
@lisp
(file-test-lock PORT [START [LEN]])
@end lisp
Tests whether the file associated with @code{PORT} is locked for reading
or writing (according to whether @code{PORT} is an input- or output-port)
and returns either @code{#f} or the process-id of the locking process.

@end deffn
@deffn {procedure} file-unlock
@lisp
(file-unlock LOCK)
@end lisp
Unlocks the previously locked portion of a file given in @code{LOCK}.
@end deffn




@node Signal handling
@subsection Signal handling




@deffn {procedure} set-alarm!
@lisp
(set-alarm! SECONDS)
@end lisp
Sets an internal timer to raise the @code{signal/alrm}
after @code{SECONDS} are elapsed.  You can use the
@code{set-signal-handler!} procedure to write a handler for this signal.

@end deffn
@deffn {procedure} set-signal-handler!
@lisp
(set-signal-handler! SIGNUM PROC)
@end lisp
Establishes the procedure of one argument @code{PROC} as the handler
for the signal with the code @code{SIGNAL}. @code{PROC} is called
with the signal number as its sole argument. If the argument @code{PROC} is @code{#f}
then this signal will be ignored.

@end deffn
@deffn {procedure} set-signal-mask!
@lisp
(set-signal-mask! SIGLIST)
@end lisp
Sets the signal mask of the current process to block all signals given
in the list @code{SIGLIST}.  Signals masked in that way will not be
delivered to the current process.
@end deffn

@defvr {signal code} signal/term
@defvrx {signal code} signal/kill
@defvrx {signal code} signal/int
@defvrx {signal code} signal/hup
@defvrx {signal code} signal/fpe
@defvrx {signal code} signal/ill
@defvrx {signal code} signal/segv
@defvrx {signal code} signal/abrt
@defvrx {signal code} signal/trap
@defvrx {signal code} signal/quit
@defvrx {signal code} signal/alrm
@defvrx {signal code} signal/vtalrm
@defvrx {signal code} signal/prof
@defvrx {signal code} signal/io
@defvrx {signal code} signal/urg
@defvrx {signal code} signal/chld
@defvrx {signal code} signal/cont
@defvrx {signal code} signal/stop
@defvrx {signal code} signal/tstp
@defvrx {signal code} signal/pipe
@defvrx {signal code} signal/xcpu
@defvrx {signal code} signal/xfsz
@defvrx {signal code} signal/usr1
@defvrx {signal code} signal/usr2
@defvrx {signal code} signal/winch
These variables contain signal codes for use with @code{process-signal} 
or @code{set-signal-handler!}.
@end defvr




@node Environment access
@subsection Environment access




@deffn {procedure} current-environment
@lisp
(current-environment)
@end lisp
Returns a association list of the environment variables and their
current values. 

Note: Under Mac OS X, this procedure always returns the empty list.

@end deffn
@deffn {procedure} setenv
@lisp
(setenv VARIABLE VALUE)
@end lisp
Sets the environment variable named @code{VARIABLE} to
@code{VALUE}. Both arguments should be strings. If the variable is
not defined in the environment, a new definition is created.

@end deffn
@deffn {procedure} unsetenv
@lisp
(unsetenv VARIABLE)
@end lisp
Removes the definition of the environment variable @code{VARIABLE} from
the environment of the current process. If the variable is not defined,
nothing happens.
@end deffn




@node Memory mapped I/O
@subsection Memory mapped I/O




@deffn {procedure} map-file-to-memory
@lisp
(map-file-to-memory ADDRESS LEN PROTECTION FLAG FILENO [OFFSET])
@end lisp
Maps a section of a file to memory using the C function
@code{mmap()}.  @code{ADDRESS} should be a foreign pointer object
or @code{#f}; @code{LEN} specifies the size of the section to
be mapped; @code{PROTECTION} should be one or more of the flags
@code{prot/read, prot/write, prot/exec} or @code{prot/none}
@b{bitwise-ior}ed together; @code{FLAG} should be one or more of
the flags @code{map/fixed, map/shared, map/private, map/anonymous} or
@code{map/file}; @code{FILENO} should be the file-descriptor of the
mapped file. The optional argument @code{OFFSET} gives the offset of
the section of the file to be mapped and defaults to 0. This procedure
returns an object representing the mapped file section.  The procedure
@code{move-memory!} can be used to access the mapped memory.

@end deffn
@deffn {procedure} memory-mapped-file-pointer
@lisp
(memory-mapped-file-pointer MMAP)
@end lisp
Returns a machine pointer to the start of the memory region to which
the file is mapped.

@end deffn
@deffn {procedure} unmap-file-from-memory
@lisp
(unmap-file-from-memory MMAP [LEN])
@end lisp
Unmaps the section of a file mapped to memory using the C function
@code{munmap()}.  @code{MMAP} should be a mapped file as returned
by the procedure @code{map-file-to-memory}.  The optional argument
@code{LEN} specifies the length of the section to be unmapped and
defaults to the complete length given when the file was mapped.
@end deffn



@node Time routines
@subsection Time routines



@deffn {procedure} seconds->local-time
@lisp
(seconds->local-time SECONDS)
@end lisp
Breaks down the time value represented in @code{SECONDS} into a 10
element vector of the form @code{#(seconds minutes hours mday month
year wday yday dstflag timezone)}, in the following format:

@itemize
@item seconds: the number of seconds after the minute (0 - 59)
@item minutes: the number of minutes after the hour (0 - 59)
@item hours: the number of hours past midnight (0 - 23)
@item mday: the day of the month (1 - 31)
@item month: the number of months since january (0 - 11)
@item year: the number of years since 1900
@item wday: the number of days since Sunday (0 - 6)
@item yday: the number of days since January 1 (0 - 365)
@item dstflag: a flag that is true if Daylight Saving Time is in effect at the time described.
@item timezone: the difference between UTC and the latest local standard
time, in seconds west of UTC.
@end itemize

@end deffn
@deffn {procedure} seconds->string
@lisp
(seconds->string SECONDS)
@end lisp
Converts the local time represented in @code{SECONDS} into a string
of the form @code{"Tue May 21 13:46:22 1991\n"}.

@end deffn
@deffn {procedure} seconds->utc-time
@lisp
(seconds->utc-time SECONDS)
@end lisp
Similar to @code{seconds->local-time}, but interpretes @code{SECONDS}
as UTC time.

@end deffn
@deffn {procedure} time->string
@lisp
(time->string VECTOR)
@end lisp
Converts the broken down time represented in the 10 element vector
@code{VECTOR} into a string of the form @code{"Tue May 21 13:46:22
1991\n"}.
@end deffn




@node Raw exit
@subsection @emph{Raw} exit



@deffn {procedure} _exit
@lisp
(_exit [CODE])
@end lisp
Exits the current process without flushing any buffered output (using
the C function @code{_exit}).  Note that the @code{exit-handler}
is not called when this procedure is invoked. The optional return-code
@code{CODE} defaults to @code{0}.
@end deffn




@node ERRNO values
@subsection ERRNO values



@defvr {error code} errno/perm
@defvrx {error code} errno/noent
@defvrx {error code} errno/srch
@defvrx {error code} errno/intr
@defvrx {error code} errno/io
@defvrx {error code} errno/noexec
@defvrx {error code} errno/badf
@defvrx {error code} errno/child
@defvrx {error code} errno/nomem
@defvrx {error code} errno/acces
@defvrx {error code} errno/fault
@defvrx {error code} errno/busy
@defvrx {error code} errno/notdir
@defvrx {error code} errno/isdir
@defvrx {error code} errno/inval
@defvrx {error code} errno/mfile
@defvrx {error code} errno/nospc
@defvrx {error code} errno/spipe
@defvrx {error code} errno/pipe
@defvrx {error code} errno/again
@defvrx {error code} errno/rofs
@defvrx {error code} errno/wouldblock
These variables contain error codes as returned by @code{errno}.
@end defvr




@node Finding files
@subsection Finding files



@deffn {procedure} find-files
@lisp
(find-files DIRECTORY PREDICATE [ACTION [IDENTITY [LIMIT]]])
@end lisp
Recursively traverses the contents of @code{DIRECTORY} (which should
be a string) and invokes the procedure @code{ACTION} for all files
for which the procedure @code{PREDICATE} is true.  @code{PREDICATE}
may me a procedure of one argument or a regular-expression string.
@code{ACTION} should be a procedure of two arguments: the currently
encountered file and the result of the previous invocation of
@code{ACTION}, or, if this is the first invocation, the value
of @code{IDENTITY}. @code{ACTION} defaults to @code{cons},
@code{IDENTITY} defaults to @code{()}.  @code{LIMIT} should a
procedure of one argument that is called for each nested directory
and which should return true, if that directory is to be traversed
recursively. @code{LIMIT} may also be an exact integer that
gives the maximum recursion depth. A depth of @code{0} means the
files in the specified directory are traversed but not any nested
directories. @code{LIMIT} may also be @code{#f} (the default),
which is equivalent to @code{(constantly #t)}.

Note that @code{ACTION} is called with the full pathname of each file,
including the directory prefix.
@end deffn




@node Getting the hostname and system information
@subsection Getting the hostname and system information



@deffn {procedure} get-host-name
@lisp
(get-host-name)
@end lisp
Returns the hostname of the machine that this process is running on.

@end deffn
@deffn {procedure} system-information
@lisp
(system-information)
@end lisp
Invokes the UNIX system call @code{uname()} and returns 5 values:
system-name, node-name, OS release, OS version and machine.
@end deffn




@node Setting a files buffering mode
@subsection Setting a files buffering mode



@deffn {procedure} set-buffering-mode!
@lisp
(set-buffering-mode! PORT MODE [BUFSIZE])
@end lisp
Sets the buffering-mode for the file associated with @code{PORT} to
@code{MODE}, which should be one of the keywords @code{#:full,
#:line} or @code{#:none}. If @code{BUFSIZE} is specified it
determines the size of the buffer to be used (if any).
@end deffn




@node Terminal ports
@subsection Terminal ports



@deffn {procedure} terminal-name
@lisp
(terminal-name PORT)
@end lisp
Returns the name of the terminal that is connected to @code{PORT}.

@end deffn
@deffn {procedure} terminal-port?
@lisp
(terminal-port? PORT)
@end lisp
Returns @code{#t} if @code{PORT} is connected to a terminal and
@code{#f} otherwise.
@end deffn




@node How Scheme procedures relate to UNIX C functions
@subsection How Scheme procedures relate to UNIX C functions

@c XXX Is there a better way to get rid of the  ?

@table @code
@item change-directory
chdir
@item change-file-mode
chmod
@item change-file-owner
chown
@item create-directory
mkdir
@item create-fifo
mkfifo
@item create-pipe
pipe
@item create-symbolic-link
link
@item current-directory
curdir
@item current-effective-groupd-id
getegid
@item current-effective-user-id
geteuid
@item current-group-id
getgid
@item current-parent-id
getppid
@item current-process-id
getpid
@item current-user-id
getuid
@item delete-directory
rmdir
@item duplicate-fileno
dup/dup2
@item _exit
_exit
@item file-close
close
@item file-execute-access?
access
@item file-open
open
@item file-lock
fcntl
@item file-position
ftell/lseek
@item file-read
read
@item file-read-access?
access
@item file-select
select
@item file-test-lock
fcntl
@item file-truncate
truncate/ftruncate
@item file-unlock
fcntl
@item file-write
write
@item file-write-access?
access
@item get-groups
getgroups
@item get-host-name
gethostname
@item initialize-groups
initgroups
@item map-file-to-memory
mmap
@item open-input-file*
fdopen
@item open-output-file*
fdopen
@item open-input-pipe
popen
@item open-output-pipe
popen
@item port->fileno
fileno
@item process-execute
execvp
@item process-fork
fork
@item process-signal
kill
@item process-wait
waitpid
@item close-input-pipe
pclose
@item close-output-pipe
pclose
@item read-symbolic-link
readlink
@item seconds->local-time
localtime
@item seconds->string
ctime
@item seconds->utc-time
gmtime
@item set-alarm!
alarm
@item set-buffering-mode!
setvbuf
@item set-file-position!
fseek/seek
@item set-groups!
setgroups
@item set-signal-mask!
sigprocmask
@item set-user-id!
setuid
@item setenv
setenv/putenv
@item sleep
sleep
@item system-information
uname
@item terminal-name
ttyname
@item terminal-port?
isatty
@item time->string
asctime
@item unsetenv
putenv
@item unmap-file-from-memory
munmap
@item user-information
getpwnam/getpwuid
@end table


@node Unit utils
@section Unit utils

This unit contains some utility procedures for Shell scripting and for
some file operations.

This unit uses the @code{extras} and @code{regex} units.


@menu
* Pathname operations::         
* Temporary files::             
* Deleting a file without signalling an error::  
* Iterating over input lines and files::  
* Executing shell commands with formatstring and error checking::  
* Reading a file's contents::
@end menu

@node Pathname operations
@subsection Pathname operations




@deffn {procedure} absolute-pathname?
@lisp
(absolute-pathname? PATHNAME)
@end lisp
Returns @code{#t} if the string @code{PATHNAME} names an absolute
pathname, and returns @code{#f} otherwise.

@end deffn
@deffn {procedure} decompose-pathname
@lisp
(decompose-pathname PATHNAME)
@end lisp
Returns three values: the directory-, filename- and extension-components
of the file named by the string @code{PATHNAME}. For any component
that is not contained in @code{PATHNAME}, @code{#f} is returned.

@end deffn
@deffn {procedure} make-pathname
@deffnx {procedure} make-absolute-pathname
@lisp
(make-pathname DIRECTORY FILENAME [EXTENSION])
(make-absolute-pathname DIRECTORY FILENAME [EXTENSION])
@end lisp
Returns a string that names the file with the
components @code{DIRECTORY, FILENAME} and (optionally)
@code{EXTENSION}. @code{DIRECTORY} can be @code{#f} (meaning no
directory component), a string or a list of strings. @code{FILENAME}
and @code{EXTENSION} should be strings or @code{#f}.
@code{make-absolute-pathname} returns always an absolute pathname.
@end deffn

@deffn {procedure} pathname-directory
@lisp
(pathname-directory PATHNAME)
@end lisp
@end deffn
@deffn {procedure} pathname-file
@lisp
(pathname-file PATHNAME)
@end lisp
@end deffn
@deffn {procedure} pathname-extension
@lisp
(pathname-extension PATHNAME)
@end lisp
Accessors for the components of @code{PATHNAME}. If the pathname does
not contain the accessed component, then @code{#f} is returned.

@end deffn
@deffn {procedure} pathname-replace-directory
@lisp
(pathname-replace-directory PATHNAME DIRECTORY)
@end lisp
@end deffn
@deffn {procedure} pathname-replace-file
@lisp
(pathname-replace-file PATHNAME FILENAME)
@end lisp
@end deffn
@deffn {procedure} pathname-replace-extension
@lisp
(pathname-replace-extension PATHNAME EXTENSION)
@end lisp
Return a new pathname with the specified component of @code{PATHNAME}
replaced by a new value.

@end deffn
@deffn {procedure} pathname-strip-directory
@lisp
(pathname-strip-directory PATHNAME)
@end lisp
@end deffn
@deffn {procedure} pathname-strip-extension
@lisp
(pathname-strip-extension PATHNAME)
@end lisp
Return a new pathname with the specified component of @code{PATHNAME}
stripped.
@end deffn




@node Temporary files
@subsection Temporary files



@deffn {procedure} create-temporary-file
@lisp
(create-temporary-file [EXTENSION])
@end lisp
Creates an empty temporary file and returns its pathname. If
@code{EXTENSION} is not given, then @code{.tmp} is used. If the
environment variable @code{TMPDIR, TEMP} or @code{TMP} is set,
then the pathname names a file in that directory.

@end deffn



@node Deleting a file without signalling an error
@subsection Deleting a file without signalling an error



@deffn {procedure} delete-file*
@lisp
(delete-file* FILENAME)
@end lisp
If the file @code{FILENAME} exists, it is deleted and @code{#t}
is returned.  If the file does not exist, nothing happens and @code{#f}
is returned.
@end deffn




@node Iterating over input lines and files
@subsection Iterating over input lines and files



@deffn {procedure} for-each-line
@lisp
(for-each-line PROCEDURE [PORT])
@end lisp
Calls @code{PROCEDURE} for each line read from @code{PORT} (which defaults to the
value of @code{(current-input-port)}. The argument passed to @code{PORCEDURE}
is a string with the contents of the line, excluding any line-terminators.
When all input has been read from the port, @code{for-each-line} returns some unspecified value.

@end deffn
@deffn {procedure} for-each-argv-line
@lisp
(for-each-argv-line PROCEDURE)
@end lisp
 Opens each file listed on the command line in order, passing one line
at a time into @code{PROCEDURE}.  The filename @code{-} is interpreted as
@code{(current-input-port)}.  If no arguments are given on the command line
it again uses the value of @code{(current-input-port)}.

This code will act as a simple Unix cat(1) command:
 
@verbatim
(for-each-argv-line print)
@end verbatim
@end deffn




@node Executing shell commands with formatstring and error checking
@subsection Executing shell commands with formatstring and error checking



@deffn {procedure} system*
@lisp
(system* FORMATSTRING ARGUMENT1 ...)
@end lisp
Similar to @code{(system (sprintf FORMATSTRING ARGUMENT1 ...))},
but signals an error if the invoked program should return a nonzero
exit status.
@end deffn


@node Reading a file's contents
@subsection Reading a file's contents


@deffn {procedure} read-all
@lisp
(read-all [FILE-OR-PORT])
@end lisp
If @code{FILE-OR-PORT} is a string, then this procedure returns the contents of the file
as a string. If @code{FILE-OR-PORT} is a port, all remaining input is read and returned as
a string. The port is not closed. If no argument is provided, input will be read from the
port that is the current value of @code{(current-input-port)}.
@end deffn


@node Unit tcp
@section Unit tcp

This unit provides basic facilities for communicating over TCP sockets.
The socket interface should be mostly compatible to the one found in
PLT Scheme.

This unit uses the @code{extras} unit.

All errors related to failing network operations will raise a condition
of kind @code{(exn i/o network)}.



@deffn {procedure} tcp-listen
@lisp
(tcp-listen TCPPORT [BACKLOG [HOST]])
@end lisp
Creates and returns a TCP listener object that listens for connections on @code{TCPPORT}, which
should be an exact integer. @code{BACKLOG} specifies the number of maximally pending
connections (and defaults to 4). If the optional argument @code{HOST} is given and not
@code{#f}, then only incoming connections for the given host (or IP) are accepted.

@end deffn
@deffn {procedure} tcp-listener?
@lisp
(tcp-listener? X)
@end lisp
Returns @code{#t} if @code{X} is a TCP listener object, or @code{#f} otherwise.

@end deffn
@deffn {procedure} tcp-close
@lisp
(tcp-close LISTENER)
@end lisp
Reclaims any resources associated with @code{LISTENER}.

@end deffn
@deffn {procedure} tcp-accept
@lisp
(tcp-accept LISTENER)
@end lisp
Waits until a connection is established on the port on which @code{LISTENER} is listening and
returns two values: an input- and output-port that can be used to communicate with the
remote process. 

Note: this operation and any I/O on the ports returned will not block other running threads.

@end deffn
@deffn {procedure} tcp-accept-ready?
@lisp
(tcp-accept-ready? LISTENER)
@end lisp
Returns @code{#t} if there are any connections pending on @code{LISTENER}, or @code{#f}
otherwise.

@end deffn
@deffn {procedure} tcp-listener-port
@lisp
(tcp-listener-port LISTENER)
@end lisp
Returns the port number assigned to @code{LISTENER} (If you pass @code{0} to @code{tcp-listen},
then the system will choose a port-number for you).

@end deffn
@deffn {procedure} tcp-connect
@lisp
(tcp-connect HOSTNAME [TCPPORT])
@end lisp
Establishes a client-side TCP connection to the machine with the name @code{HOSTNAME} (a string)
at @code{TCPPORT} (an exact integer) and returns two values: an input- and output-port for communicating
with the remote process.

Note: any I/O on the ports returned will not block other running threads.

@end deffn
@deffn {procedure} tcp-addresses
@lisp
(tcp-addresses PORT)
@end lisp
Returns two values for the input- or output-port @code{PORT} (which should be a port returned
by either @code{tcp-accept} or @code{tcp-connect}): the IP address of the local and the remote
machine that are connected over the socket associated with @code{PORT}. The returned addresses
are strings in @code{XXX.XXX.XXX.XXX} notation.

@end deffn
@deffn {procedure} tcp-abandon-port
@lisp
(tcp-abandon-port PORT)
@end lisp
Marks the socket port @code{PORT} as abandoned. This is mainly useful to close down a port
without breaking the connection.
@end deffn



A very simple example follows. Say we have the two files @code{client.scm}
and @code{server.scm}:

@verbatim
; client.scm
(define-values (i o) (tcp-connect "localhost" 4242))
(write-line "Good Bye!" o)
(print (read-line i))
@end verbatim

@verbatim
; server.scm
(define l (tcp-listen 4242))
(define-values (i o) (tcp-accept l))
(write-line "Hello!" o)
(print (read-line i))
(close-input-port i)
(close-output-port o)

% csi -script server.scm &
[1] 1409
% csi -script client.scm
Good Bye!
Hello!
@end verbatim


@node Unit srfi-37
@section Unit srfi-37

Copyright (c) 2002 Anthony Carrico

A simple and flexible command-line option parsing facility. Options may
be either short one-character options of the form @code{-X[ARGUMENT]}
or long multicharacter ones of the form @code{--XXX[=ARGUMENT]}. Short
options may be coalesced. An argument of the form @code{--} stops
option processing.
For more information take a look at the @uref{http://srfi.schemers.org/srfi-37/srfi-37.html, SRFI-37 documentation }.

An example:

@verbatim
#!/usr/local/bin/csi -script
;;;; secho - display command-line arguments

(define nl 1)

(define help 
  (option 
   '(#\h "help") #f #f
   (lambda _ 
     (print "Usage: secho [OPTION] ARG ...
  -h  --help          show this text
  -n  --newline N     add N newline characters (default: 1)")
     (exit) ) ) )

(define newlines
  (option
   '(#\n "newline") #t #f
   (lambda (o n x vals)
     (set! nl (string->number x))
     vals) ) )

(for-each 
 (lambda (x) (print* x #\space))
 (reverse
  (args-fold
   (command-line-arguments)
   (list help newlines)
   (lambda (o n x vals)
     (error "unrecognized option" n) )
   cons
   '() ) ) )

(display (make-string nl #\newline))
@end verbatim


@node Unit lolevel
@section Unit lolevel


This unit provides a number of handy low-level operations. @b{Use
at your own risk.}


This unit uses the @code{srfi-4} and @code{extras} units.


@menu
* Foreign pointers::            
* Tagged pointers::             
* Extending procedures with data::  
* Bytevectors::                 
* Data in unmanaged memory::    
* Locatives::                   
* Accessing toplevel variables::  
* Low-level data access::       
* Procedure-call- and variable reference hooks::  
* Magic::                       
@end menu

@node Foreign pointers
@subsection Foreign pointers




@deffn {procedure} address->pointer
@lisp
(address->pointer ADDRESS)
@end lisp
Creates a new foreign pointer object initialized to point to the address
given in the integer @code{ADDRESS}.

@end deffn
@deffn {procedure} allocate
@lisp
(allocate BYTES)
@end lisp
Returns a pointer to a freshly allocated region of static memory.
This procedure could be defined as follows:

@verbatim
(define allocate (foreign-lambda c-pointer "malloc" integer))
@end verbatim

@end deffn
@deffn {procedure} free
@lisp
(free POINTER)
@end lisp
Frees the memory pointed to by @code{POINTER}.  This procedure could
be defined as follows:

@verbatim
(define free (foreign-lambda c-pointer "free" integer))
@end verbatim

@end deffn
@deffn {procedure} null-pointer
@lisp
(null-pointer)
@end lisp
Another way to say @code{(address->pointer 0)}.

@end deffn
@deffn {procedure} null-pointer?
@lisp
(null-pointer? PTR)
@end lisp
Returns @code{#t} if @code{PTR} contains a @code{NULL} pointer,
or @code{#f} otherwise.

@end deffn
@deffn {procedure} object->pointer
@lisp
(object->pointer X)
@end lisp
Returns a pointer pointing to the Scheme object X, which should be a
non-immediate object.  Note that data in the garbage collected heap
moves during garbage collection.

@end deffn
@deffn {procedure} pointer?
@lisp
(pointer? X)
@end lisp
Returns @code{#t} if @code{X} is a foreign pointer object, and
@code{#f} otherwise.

@end deffn
@deffn {procedure} pointer->address
@lisp
(pointer->address PTR)
@end lisp
Returns the address, to which the pointer @code{PTR} points.

@end deffn
@deffn {procedure} pointer->object
@lisp
(pointer->object PTR)
@end lisp
Returns the Scheme object pointed to by the pointer @code{PTR}.

@end deffn
@deffn {procedure} pointer-offset
@lisp
(pointer-offset PTR N)
@end lisp
Returns a new pointer representing the pointer @code{PTR} increased
by @code{N}.

@end deffn
@deffn {procedure} pointer-u8-ref
@lisp
(pointer-u8-ref PTR)
@end lisp
Returns the unsigned byte at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-s8-ref
@lisp
(pointer-s8-ref PTR)
@end lisp
Returns the signed byte at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-u16-ref
@lisp
(pointer-u16-ref PTR)
@end lisp
Returns the unsigned 16-bit integer at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-s16-ref
@lisp
(pointer-s16-ref PTR)
@end lisp
Returns the signed 16-bit integer at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-u32-ref
@lisp
(pointer-u32-ref PTR)
@end lisp
Returns the unsigned 32-bit integer at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-s32-ref
@lisp
(pointer-s32-ref PTR)
@end lisp
Returns the signed 32-bit integer at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-f32-ref
@lisp
(pointer-f32-ref PTR)
@end lisp
Returns the 32-bit float at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-f64-ref
@lisp
(pointer-f64-ref PTR)
@end lisp
Returns the 64-bit double at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-u8-set!
@lisp
(pointer-u8-set! PTR N)
@end lisp
Stores the unsigned byte @code{N} at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-s8-set!
@lisp
(pointer-s8-set! PTR N)
@end lisp
Stores the signed byte @code{N} at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-u16-set!
@lisp
(pointer-u16-set! PTR N)
@end lisp
Stores the unsigned 16-bit integer @code{N} at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-s16-set!
@lisp
(pointer-s16-set! PTR N)
@end lisp
Stores the signed 16-bit integer @code{N} at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-u32-set!
@lisp
(pointer-u32-set! PTR N)
@end lisp
Stores the unsigned 32-bit integer @code{N} at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-s32-set!
@lisp
(pointer-s32-set! PTR N)
@end lisp
Stores the 32-bit integer @code{N} at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-f32-set!
@lisp
(pointer-f32-set! PTR N)
@end lisp
Stores the 32-bit floating-point number @code{N} at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} pointer-f64-set!
@lisp
(pointer-f64-set! PTR N)
@end lisp
Stores the 64-bit floating-point number @code{N} at the address designated by @code{PTR}.

@end deffn
@deffn {procedure} align-to-word
@lisp
(align-to-word PTR-OR-INT)
@end lisp
Accepts either a machine pointer or an integer as argument and returns
a new pointer or integer aligned to the native word size of the host
platform.
@end deffn




@node Tagged pointers
@subsection Tagged pointers

``Tagged'' pointers are foreign pointer objects with an extra tag object.



@deffn {procedure} tag-pointer
@lisp
(tag-pointer PTR TAG)
@end lisp
Creates a new tagged pointer object from the foreign pointer @code{PTR} with the
tag @code{TAG}, which may an arbitrary Scheme object.

@end deffn
@deffn {procedure} tagged-pointer?
@lisp
(tagged-pointer? X TAG)
@end lisp
Returns @code{#t}, if @code{X} is a tagged pointer object with the tag @code{TAG}
(using an @code{eq?} comparison), or @code{#f} otherwise.

@end deffn
@deffn {procedure} pointer-tag
@lisp
(pointer-tag PTR)
@end lisp
If @code{PTR} is a tagged pointer object, its tag is returned. If @code{PTR} is a normal,
untagged foreign pointer object @code{#f} is returned. Otherwise an error is signalled.
@end deffn




@node Extending procedures with data
@subsection Extending procedures with data




@deffn {procedure} extend-procedure
@lisp
(extend-procedure PROCEDURE X)
@end lisp
Returns a copy of the procedure @code{PROCEDURE} which contains an
additional data slot initialized to @code{X}. If @code{PROCEDURE}
is already an extended procedure, then its data slot is changed to
contain @code{X} and the same procedure is returned.

@end deffn
@deffn {procedure} extended-procedure?
@lisp
(extended-procedure? PROCEDURE)
@end lisp
Returns @code{#t} if @code{PROCEDURE} is an extended procedure,
or @code{#f} otherwise.

@end deffn
@deffn {procedure} procedure-data
@lisp
(procedure-data PROCEDURE)
@end lisp
Returns the data object contained in the extended procedure
@code{PROCEDURE}.

@end deffn
@deffn {procedure} set-procedure-data!
@lisp
(set-procedure-data! PROCEDURE X)
@end lisp
Changes the data object contained in the extended procedure
@code{PROCEDURE} to @code{X}.

@verbatim
(define foo
  (letrec ((f (lambda () (procedure-data x)))
           (x #f) )
    (set! x (extend-procedure f 123))
    x) )
(foo)                                         ==> 123
(set-procedure-data! foo 'hello)
(foo)                                         ==> hello
@end verbatim
@end deffn




@node Bytevectors
@subsection Bytevectors




@deffn {procedure} byte-vector
@lisp
(byte-vector FIXNUM ...)
@end lisp
Returns a freshly allocated byte-vector with @code{FIXNUM ...} as its
initial contents.

@end deffn
@deffn {procedure} byte-vector?
@lisp
(byte-vector? X)
@end lisp
Returns @code{#t} if @code{X} is a byte-vector object, or
@code{#f} otherwise.

@end deffn
@deffn {procedure} byte-vector-fill!
@lisp
(byte-vector-fill! BYTE-VECTOR N)
@end lisp
Sets each element of @code{BYTE-VECTOR} to @code{N}, which should
be an exact integer.

@end deffn
@deffn {procedure} byte-vector->list
@lisp
(byte-vector->list BYTE-VECTOR)
@end lisp
Returns a list with elements taken from @code{BYTE-VECTOR}.

@end deffn
@deffn {procedure} byte-vector->string
@lisp
(byte-vector->string BYTE-VECTOR)
@end lisp
Returns a string with the contents of @code{BYTE-VECTOR}.

@end deffn
@deffn {procedure} byte-vector-length
@lisp
(byte-vector-length BYTE-VECTOR)
@end lisp
Returns the number of elements in @code{BYTE-VECTOR}.

@end deffn
@deffn {procedure} byte-vector-ref
@lisp
(byte-vector-ref BYTE-VECTOR INDEX)
@end lisp
Returns the byte at the @code{INDEX}th position of @code{BYTE-VECTOR}.

@end deffn
@deffn {procedure} byte-vector-set!
@lisp
(byte-vector-set! BYTE-VECTOR INDEX N)
@end lisp
Sets the byte at the @code{INDEX}th position of @code{BYTE-VECTOR}
to the value of the exact integer @code{n}.

@end deffn
@deffn {procedure} executable-byte-vector->procedure
@lisp
(executable-byte-vector->procedure PBYTE-VECTOR)
@end lisp
Returns a procedure that on invocation will execute the code
in @code{PBYTE-VECTOR}, which should have been allocated using
@code{make-executable-byte-vector}.  The procedure follows the native C
calling convention, and will be called as if declared with the following
prototype:

@verbatim
void <procedure>(int argc, C_word closure, C_word k, C_word arg1, ...)
@end verbatim

@itemize
@item @code{argc} contains the number of arguments @code{arg1, ...}
that are passed plus 2 (including @code{closure} and @code{k}).

@item @code{closure} is the procedure object itself.

@item @code{k} is a continuation closure that should be called when
the code is about to return.

@verbatim
typedef void (*CONTINUATION)(int argc, C_word closure,
                                       C_word result);
((CONTINUATION)k[ 1 ])(2, k, result)
@end verbatim

(@code{k} is a data object with the second word being the actual code
pointer)

@end itemize


An example:

@verbatim
(define x (make-executable-byte-vector 17))
(move-memory! 
 '#u8(#x8b #x44 #x24 #x0c  ; movl 12(%esp), %eax - `k'
      #x8b #x5c #x24 #x10  ; movl 16(%esp), %ebx - `arg1'
      #x53                 ; pushl %ebx          - push result
      #x50                 ; pushl %eax          - push k
      #x6a #x02            ; pushl $2            - push argument count
      #x8b #x40 #x04       ; movl 4(%eax), %eax  - fetch code pointer
      #xff #xd0)           ; call *%eax
 x)
(define y (executable-byte-vector->procedure x))
(y 123)                                         ==> 123
@end verbatim


The result of calling @code{executable-byte-vector->procedure} with
a non-executable statically allocated byte-vector is undefined.

@end deffn
@deffn {procedure} invoke-executable-byte-vector
@lisp
(invoke-executable-byte-vector PBYTE-VECTOR ARG1 ...)
@end lisp
Invokes the machine code stored in the executable byte-vector
@code{PBYTE-VECTOR}. The native C calling conventions are used, but
the invoked code is passed a single argument containing a pointer to an
array of the Scheme objects @code{ARG1 ...}.

@verbatim
(define v (make-executable-byte-vector 7))
(move-memory!
 '#u8(#x8b #x44 #x24 #x04        ; movl 4(%esp), %eax
      #x8b #x00                  ; movl 0(%eax), %eax
      #xc3)                      ; ret
 v)
(invoke-executable-byte-vector v "hello!") ==> "hello!"
@end verbatim

@end deffn
@deffn {procedure} list->byte-vector
@lisp
(list->byte-vector LIST)
@end lisp
Returns a byte-vector with elements taken from @code{LIST}, where the
elements of @code{LIST} should be exact integers.

@end deffn
@deffn {procedure} make-byte-vector
@lisp
(make-byte-vector SIZE [INIT])
@end lisp
Creates a new byte-vector of size @code{SIZE}. If @code{INIT} is
given, then it should be an exact integer with which every element of
the byte-vector is initialized.

@end deffn
@deffn {procedure} make-executable-byte-vector
@lisp
(make-executable-byte-vector SIZE [INIT])
@end lisp
As @code{make-static-byte-vector}, but the code is suitable for
execution.  @b{Note:} this feature is currently only available on
@b{x86} platforms.

Exceptions: @code{(exn bounds)}, @code{(exn runtime)}

@end deffn
@deffn {procedure} make-static-byte-vector
@lisp
(make-static-byte-vector SIZE [INIT])
@end lisp
As @code{make-byte-vector}, but allocates the byte-vector in storage
that is not subject to garbage collection.  To free the allocated memory,
one has to call @code{object-release} explicitly.

Exceptions: @code{(exn bounds)}, @code{(exn runtime)}

@end deffn
@deffn {procedure} static-byte-vector->pointer
@lisp
(static-byte-vector->pointer PBYTE-VECTOR)
@end lisp
Returns a pointer object pointing to the data in the statically allocated
byte-vector @code{PBYTE-VECTOR}.

@end deffn
@deffn {procedure} string->byte-vector
@lisp
(string->byte-vector STRING)
@end lisp
Returns a byte-vector with the contents of @code{STRING}.
@end deffn




@node Data in unmanaged memory
@subsection Data in unmanaged memory




@deffn {procedure} object-evict
@lisp
(object-evict X [ALLOCATOR])
@end lisp
Copies the object @code{X} recursively into the memory pointed
to by the foreign pointer object returned by @code{ALLOCATOR},
which should be a procedure of a single argument (the number of bytes
to allocate). The freshly copied object is returned.  This facility
allows moving arbitrary objects into static memory, but care should be
taken when mutating evicted data: setting slots in evicted vector-like
objects to non-evicted data is not allowed. It @b{is} possible to
set characters/bytes in evicted strings or byte-vectors, though.  It is
advisable @b{not} to evict ports, because they might be mutated by
certain file-operations.  @code{object-evict} is able to handle circular and
shared structures, but evicted symbols are no longer unique: a fresh
copy of the symbol is created, so

@verbatim
(define x 'foo)
(define y (object-evict 'foo))
y                              ==> foo
(eq? x y)                      ==> #f
(define z (object-evict '(bar bar)))
(eq? (car z) (cadr z))         ==> #t
@end verbatim

The @code{ALLOCATOR} defaults to @code{allocate}.

@end deffn
@deffn {procedure} object-evict-to-location
@lisp
(object-evict-to-location X PTR [LIMIT])
@end lisp
As @code{object-evict} but moves the object at the address pointed to by
the machine pointer @code{PTR}. If the number of copied bytes exceeds
the optional @code{LIMIT} then an error is signalled. Two values are
returned: the evicted object and a new pointer pointing to the first
free address after the evicted object.

@end deffn
@deffn {procedure} object-evicted?
@lisp
(object-evicted? X)
@end lisp
Returns @code{#t} if @code{X} is a non-immediate evicted data object,
or @code{#f} otherwise.

@end deffn
@deffn {procedure} object-size
@lisp
(object-size X)
@end lisp
Returns the number of bytes that would be needed to evict the data
object @code{X}.

@end deffn
@deffn {procedure} object-release
@lisp
(object-release X [RELEASER])
@end lisp
Frees memory occupied by the evicted object @code{X} recursively.
@code{RELEASER} should be a procedure of a single argument (a foreign
pointer object to the static memory to be freed) and defaults to the
C-library @code{free()}.

@end deffn
@deffn {procedure} object-unevict
@lisp
(object-unevict X)
@end lisp
Copies the object @code{X} and nested objects back into the normal
Scheme heap.  Symbols are re-interned into the symbol table. Strings
and byte-vectors are @b{not} copied.
@end deffn




@node Locatives
@subsection Locatives


A @emph{locative} is an object that points to an element of a containing object,
much like a ``pointer'' in low-level, imperative programming languages like ``C''. The element can
be accessed and changed indirectly, by performing access or change operations
on the locative. The container object can be computed by calling the
@code{location->object} procedure.

Locatives may be passed to foreign procedures that expect pointer arguments.
The effect of creating locatives for evicted data (see @code{object-evict}) is undefined.



@deffn {procedure} make-locative
@lisp
(make-locative EXP [INDEX])
@end lisp
Creates a locative that refers to the element of the non-immediate object @code{EXP}
at position @code{INDEX}. @code{EXP} may be a vector, symbol, pair, string, byte-vector,
SRFI-4 number-vector, SRFI-25 array, or record. @code{INDEX} should be a fixnum,
or a valid index into
a SRFI-25 array. @code{INDEX} defaults to 0.

@end deffn
@deffn {procedure} make-weak-locative
@lisp
(make-weak-locative EXP [INDEX])
@end lisp
Creates a ``weak'' locative. Even though the locative refers to an element of a container object,
the container object will still be reclaimed by garbage collection if no other references
to it exist.

@end deffn
@deffn {procedure} locative?
@lisp
(locative? X)
@end lisp
Returns @code{#t} if @code{X} is a locative, or @code{#f} otherwise.

@end deffn
@deffn {procedure} locative-ref
@lisp
(locative-ref LOC)
@end lisp
Returns the element to which the locative @code{LOC} refers. If the containing
object has been reclaimed by garbage collection, an error is signalled.

@end deffn
@deffn {procedure} locative-set!
@lisp
(locative-set! LOC X)
@end lisp
Changes the element to which the locative @code{LOC} refers to @code{X}.
If the containing
object has been reclaimed by garbage collection, an error is signalled.

@end deffn
@deffn {procedure} locative->object
@lisp
(locative->object LOC)
@end lisp
Returns the object that contains the element referred to by @code{LOC} or
@code{#f} if the container has been reclaimed by garbage collection.
@end deffn




@node Accessing toplevel variables
@subsection Accessing toplevel variables




@deffn {procedure} global-bound?
@lisp
(global-bound? SYMBOL)
@end lisp
Returns @code{#t}, if the global (``toplevel'') variable with the name @code{SYMBOL}
is bound to a value, or @code{#f} otherwise.

@end deffn
@deffn {procedure} global-ref
@lisp
(global-ref SYMBOL)
@end lisp
Returns the value of the global variable @code{SYMBOL}.
If no variable under that name is bound, an error is signalled.

@end deffn
@deffn {procedure} global-set!
@lisp
(global-set! SYMBOL X)
@end lisp
Sets the global variable named @code{SYMBOL} to the value @code{X}.
@end deffn




@node Low-level data access
@subsection Low-level data access



@deffn {procedure} block-ref
@lisp
(block-ref BLOCK INDEX)
@end lisp
Returns the contents of the @code{INDEX}th slot of the object
@code{BLOCK}.  @code{BLOCK} may be a vector, record structure,
pair or symbol.

@end deffn
@deffn {procedure} block-set!
@lisp
(block-set! BLOCK INDEX X)
@end lisp
Sets the contents of the @code{INDEX}th slot of the object
@code{BLOCK} to the value of @code{X}.  @code{BLOCK} may be a
vector, record structure, pair or symbol.

@end deffn
@deffn {procedure} object-copy
@lisp
(object-copy X)
@end lisp
Copies @code{X} recursively and returns the fresh copy. Objects
allocated in static memory are copied back into garbage collected storage.

@end deffn
@deffn {procedure} make-record-instance
@lisp
(make-record-instance SYMBOL ARG1 ...)
@end lisp
Returns a new instance of the record type @code{SYMBOL}, with its
slots initialized to @code{ARG1 ...}.  To illustrate:

@verbatim
(define-record point x y)
@end verbatim

expands into something quite similar to:

@verbatim
(begin
  (define (make-point x y)
    (make-record-instance 'point x y) )
  (define (point? x)
    (and (record-instance? x)
         (eq? 'point (block-ref x 0)) ) )
  (define (point-x p) (block-ref p 1))
  (define (point-x-set! p x) (block-set! p 1 x))
  (define (point-y p) (block-ref p 2))
  (define (point-y-set! p y) (block-set! p 1 y)) )
@end verbatim

@end deffn
@deffn {procedure} move-memory!
@lisp
(move-memory! FROM TO [BYTES])
@end lisp
Copies @code{BYTES} bytes of memory from @code{FROM} to @code{TO}.
@code{FROM} and @code{TO} may be strings, primitive byte-vectors,
SRFI-4 byte-vectors (see: @ref{Unit srfi-4}), memory mapped files, foreign
pointers (as obtained from a call to @code{foreign-lambda}, for
example) or locatives. if @code{BYTES} is not given and the size of the source
or destination operand is known then the maximal number of bytes will
be copied. Moving memory to the storage returned by locatives will cause havoc, 
if the locative refers to containers of non-immediate data, like vectors
or pairs.

@end deffn
@deffn {procedure} number-of-bytes
@lisp
(number-of-bytes BLOCK)
@end lisp
Returns the number of bytes that the object @code{BLOCK} contains.
@code{BLOCK} may be any non-immediate value.

@end deffn
@deffn {procedure} number-of-slots
@lisp
(number-of-slots BLOCK)
@end lisp
Returns the number of slots that the object @code{BLOCK} contains.
@code{BLOCK} may be a vector, record structure, pair or symbol.

@end deffn
@deffn {procedure} record-instance?
@lisp
(record-instance? X)
@end lisp
Returns @code{#t} if @code{X} is an instance of a record type.
See also: @code{make-record-instance}.
@end deffn

@deffn {procedure} record->vector
@lisp
(record->vector BLOCK)
@end lisp
Returns a new vector with the type and the elements of the record @code{BLOCK}.
@end deffn


@node Procedure-call- and variable reference hooks
@subsection Procedure-call- and variable reference hooks



@deffn {procedure} invalid-procedure-call-handler
@lisp
(invalid-procedure-call-handler PROC)
@end lisp
Sets an internal hook that is invoked when a call to an object other than a procedure
is executed at runtime. The procedure @code{PROC} will in that case be called
with two arguments: the object being called and a list of the passed arguments.

@verbatim
;;; Access sequence-elements as in ARC:

(invalid-procedure-call-handler
  (lambda (proc args)
    (cond [(string? proc) (apply string-ref proc args)]
          [(vector? proc) (apply vector-ref proc args)]
          [else (error "call of non-procedure" proc)] ) ) )

("hello" 4)    ==>  #\o
@end verbatim

This facility does not work in code compiled with the ``unsafe'' setting.

@end deffn
@deffn {procedure} unbound-variable-value
@lisp
(unbound-variable-value [X])
@end lisp
Defines the value that is returned for unbound variables. Normally an error
is signalled, use this procedure to override the check and return @code{X}
instead. To set the default behavior (of signalling an error), call
@code{unbound-variable-value} with no arguments.

This facility does not work in code compiled with the ``unsafe'' setting.
@end deffn




@node Magic
@subsection Magic



@deffn {procedure} object-become!
@lisp
(object-become! ALIST)
@end lisp
Changes the identity of the value of the car of each pair in
@code{ALIST} to the value of the cdr. Both values may not be immediate
(i.e. exact integers, characters, booleans or the empty list).

@verbatim
(define x "i used to be a string")
(define y '#(and now i am a vector))
(object-become! (list (cons x y)))
x                                    ==> #(and now i am a vector)
y                                    ==> #(and now i am a vector)
(eq? x y)                            ==> #t
@end verbatim

Note: this operation invokes a major garbage collection.

The effect of using @code{object-become!} on evicted data (see @code{object-evict})
is undefined.
@end deffn




@node Unit tinyclos
@section Unit tinyclos

This unit is a port of Gregor Kiczales @b{TinyCLOS} with numerous
modifications.

This unit uses the @code{extras} unit.


@menu
* Defining forms::              
* Base language::               
* Introspection::               
* Intercessory protocol::       
* Additional protocol::         
* Utility procedures::          
* Builtin classes::             
@end menu

@node Defining forms
@subsection Defining forms




@deffn {syntax} define-class
@lisp
(define-class NAME (SUPERCLASS1 ...) (SLOTNAME1 ...) [METACLASS])
@end lisp
Sets the variable @code{NAME} to a new class (a new instance of
the class @code{<class>}). @code{SUPERCLASS1 ...} is a list of
superclasses of the newly created class. If no superclasses are given,
then @code{<object>} is assumed.  @code{SLOTNAME1 ...} are the names
of the direct slots of the class. if @code{METACLASS} is provided,
then the new class-instance is an instance of @code{METACLASS} instead
of @code{<class>}.

@verbatim
(define-class NAME (SUPER) (SLOT1 SLOT2) META)
@end verbatim 

is equivalent to

@verbatim
(define NAME
  (make META 
    'name 'NAME
    'direct-supers (list SUPER)
    'direct-slots (list 'SLOT1 'SLOT2)) )
@end verbatim

Note that slots-names are not required to be symbols, so the following
is perfectly valid:

@ifhtml
@html
<pre>
(define hidden-slot (list 'hidden))
(define &lt;myclass&gt;
  (make &lt;class&gt;
     'direct-supers (list &lt;object&gt;)
     'direct-slots (list hidden-slot) ) )
(define x1 (make &lt;myclass&gt;)
(slot-set! x1 hidden-slot 99)
@end html
@end ifhtml

@ifnothtml
@verbatim
(define hidden-slot (list 'hidden))
(define <myclass>
  (make <class>
     'direct-supers (list <object>)
     'direct-slots (list hidden-slot) ) )
(define x1 (make <myclass>)
(slot-set! x1 hidden-slot 99)
@end verbatim
@end ifnothtml

@end deffn
@deffn {syntax} define-generic
@lisp
(define-generic NAME [CLASS])
@end lisp
Sets the variable @code{NAME} to contain a fresh generic function
object without associated methods. If the optional argument @code{CLASS}
is given, then the generic function will be an instance of that class.

@end deffn
@deffn {syntax} define-method
@lisp
(define-method (NAME (VARIABLE1 CLASS1) ... PARAMETERS ...) BODY ...)
@end lisp
Adds a new method with the code @code{BODY ...} to the generic function
that was assigned to the variable @code{name}.  @code{CLASS1 ...} is
a list if classes that specialize this particular method. The method can
have additional parameters @code{PARAMETERS}, which do not specialize
the method any further.  Inside the body of the method the identifier
@code{call-next-method} names a procedure of zero arguments that can
be invoked to call the next applicable method with the same arguments.
If no generic function is defined under this name, then a fresh generic
function object is created and assigned to @code{NAME}.
Note that only @code{define-generic} expands into a valid definition,
so for internal lexically scoped definitions or for definitions for module
exports (see @code{syntax-case}) use @code{define-generic}.
@end deffn




@node Base language
@subsection Base language




@deffn {procedure} add-method
@lisp
(add-method GENERIC METHOD)
@end lisp
Adds the method object @code{METHOD} to the list of applicable methods
for the generic function @code{GENERIC}.

@end deffn
@deffn {procedure} instance?
@lisp
(instance? X)
@end lisp
Returns @code{#t} if @code{X} is an instance of a non-primitive
class.

@end deffn
@deffn {procedure} make
@lisp
(make CLASS INITARG ...)
@end lisp
Creates a new instance of @code{CLASS} and passes @code{INITARG ...}
to the @code{initialize} method of this class.

@end deffn
@deffn {procedure} make-class
@lisp
(make-class SUPERCLASSES SLOTNAMES)
@end lisp
Creates a new class object, where @code{SUPERCLASSES} should be the
list of direct superclass objects and @code{SLOTNAMES} should be a
list of symbols naming the slots of this class.

@end deffn
@deffn {procedure} make-generic
@lisp
(make-generic [NAME])
@end lisp
Creates a new generic function object. If @code{NAME} is specified,
then it should be a string.

@end deffn
@deffn {procedure} make-method
@lisp
(make-method SPECIALIZERS PROC)
@end lisp
Creates a new method object specialized to the list of classes in
@code{SPECIALIZERS}.

@verbatim
(define-method (foo (x <bar>)) 123)
   <=> (add-method foo
                   (make-method
                      (list <bar>)
                      (lambda (call-next-method x) 123)))
@end verbatim

@end deffn
@deffn {procedure} slot-ref
@lisp
(slot-ref INSTANCE SLOTNAME)
@end lisp
Returns the value of the slot @code{SLOTNAME} of the object
@code{INSTANCE}.

@end deffn
@deffn {procedure} slot-set!
@lisp
(slot-set! INSTANCE SLOTNAME VALUE)
@end lisp
Sets the value of the slot @code{SLOTNAME} of the object
@code{INSTANCE} to @code{VALUE}.
@end deffn




@node Introspection
@subsection Introspection




@deffn {procedure} class-cpl
@lisp
(class-cpl CLASS)
@end lisp
Returns the class-precedence-list of @code{CLASS} as a list of classes.

@end deffn
@deffn {procedure} class-direct-slots
@lisp
(class-direct-slots CLASS)
@end lisp
Returns the list of direct slots of @code{CLASS} as a list of lists,
where each sublist contains the name of the slot.

@end deffn
@deffn {procedure} class-direct-supers
@lisp
(class-direct-supers CLASS)
@end lisp
Returns the list of direct superclasses of @code{CLASS}.

@end deffn
@deffn {procedure} class-of
@lisp
(class-of X)
@end lisp
Returns the class that the object @code{X} is an instance of.

@end deffn
@deffn {procedure} class-name
@lisp
(class-name CLASS)
@end lisp
Returns name of @code{CLASS}.

@end deffn
@deffn {procedure} class-slots
@lisp
(class-slots CLASS)
@end lisp
Returns the list of all slots of @code{CLASS} and its superclasses
as a list of lists, where each sublist contains the name of the slot.

@end deffn
@deffn {procedure} generic-methods
@lisp
(generic-methods GENERIC)
@end lisp
Returns the list of all methods associated with the generic function
@code{GENERIC}.

@end deffn
@deffn {procedure} method-specializers
@lisp
(method-specializers METHOD)
@end lisp
Returns the list of classes that specialize @code{METHOD}.

@end deffn
@deffn {procedure} method-procedure
@lisp
(method-procedure METHOD)
@end lisp
Returns the procedure that contains the body of @code{METHOD}.

@end deffn
@deffn {procedure} subclass?
@lisp
(subclass? CLASS1 CLASS2)
@end lisp
Returns @code{#t} is @code{CLASS1} is a subclass of @code{CLASS2},
or @code{#f} otherwise. Note that the following holds:

@verbatim
(subclass? X X) ==> #t
@end verbatim
@end deffn




@node Intercessory protocol
@subsection Intercessory protocol

These definitions allow interfacing to the Meta Object Protocol
of TinyCLOS. For serious use, it is recommended to consult
the source code (@code{tinyclos.scm}).



@deffn {generic} allocate-instance
@lisp
(allocate-instance CLASS)
@end lisp
Allocates storage for an instance of @code{CLASS} and returns the
instance.

@end deffn
@deffn {generic} compute-apply-generic
@lisp
(compute-apply-generic GENERIC)
@end lisp
Returns a procedure that will be called to apply the generic function
methods to the arguments.

@end deffn
@deffn {generic} compute-apply-methods
@lisp
(compute-apply-methods GENERIC)
@end lisp
Returns a procedure of two arguments, a list of applicable methods
and a list of arguments and applies the methods.

@end deffn
@deffn {generic} compute-methods
@lisp
(compute-methods GENERIC)
@end lisp
Returns a procedure of one argument. The procedure is called with the
list of actual arguments passed to the generic function and should
return a list of applicable methods, sorted by precedence.

@end deffn
@deffn {generic} compute-cpl
@lisp
(compute-cpl CLASS)
@end lisp
Computes and returns the class-precedence-list of @code{CLASS}.

@end deffn
@deffn {generic} compute-getter-and-setter
@lisp
(compute-getter-and-setter CLASS SLOT ALLOCATOR)
@end lisp
Returns two values, the procedures that get and set the contents of the
slot @code{SLOT}.  @code{ALLOCATOR} is a procedure of one argument
@emph{(I currently don't know what it does)}.

@end deffn
@deffn {generic} compute-method-more-specific?
@lisp
(compute-method-more-specific? GENERIC)
@end lisp
Returns a procedure of three arguments (two methods and a list of
arguments) that returns @code{#t} if the first method is more specific
than the second one with respect to the list of arguments. Otherwise
the returned predicate returns @code{#f}.

@end deffn
@deffn {generic} compute-slots
@lisp
(compute-slots CLASS)
@end lisp
Computes and returns the list of slots of @code{CLASS}.

@end deffn
@deffn {generic} initialize
@lisp
(initialize INSTANCE INITARGS)
@end lisp
Initializes the object @code{INSTANCE}. @code{INITARGS} is the list of
initialization arguments that were passed to the @code{make} procedure.
@end deffn




@node Additional protocol
@subsection Additional protocol




@deffn {generic} describe-object
@lisp
(describe-object INSTANCE PORT)
@end lisp
Writes a description of @code{INSTANCE} to @code{PORT}.  Execution of
the interpreter command @code{,d} will invoke this generic function.

@end deffn
@deffn {generic} print-object
@lisp
(print-object INSTANCE PORT)
@end lisp
Writes a textual representation of @code{INSTANCE} to @code{PORT}.
Any output of an instance with @code{display, write} and @code{print}
will invoke this generic function.
@end deffn




@node Utility procedures
@subsection Utility procedures




@deffn {procedure} initialize-slots
@lisp
(initialize-slots INSTANCE INITARGS)
@end lisp
This procedure takes a sequence of alternating slot-names and
initialization values in @code{INITARGS} and initializes the
corresponding slots in @code{INSTANCE}.

@verbatim
(define-class <pos> () (x y))

(define-method (initialize (pos <pos>) initargs)
  (call-next-method)
  (initialize-slots pos initargs))

(define p1 (make <pos> 'x 1 'y 2))
(define p2 (make <pos> 'x 3 'y 5))
@end verbatim
@end deffn




@node Builtin classes
@subsection Builtin classes


The class hierarchy of builtin classes looks like this:

@ifhtml
@html
<pre>
&lt;top&gt;
  &lt;object&gt;
    &lt;class&gt;
      &lt;procedure-class&gt;
        &lt;procedure&gt;
        &lt;entity-class&gt;
          &lt;generic&gt;
      &lt;primitive-class&gt;
    &lt;c++-object&gt;
  &lt;primitive&gt;
    &lt;void&gt;
    &lt;boolean&gt;
    &lt;symbol&gt;
    &lt;char&gt;
    &lt;vector&gt;
    &lt;pair&gt;
    &lt;number&gt;
      &lt;integer&gt;
        &lt;exact&gt;
      &lt;inexact&gt;
    &lt;string&gt;
    &lt;port&gt;
      &lt;input-port&gt;
      &lt;output-port&gt;
    &lt;pointer&gt;
      &lt;tagged-pointer&gt;
    &lt;locative&gt;
    &lt;byte-vector&gt;
      &lt;u8vector&gt;
      &lt;s8vector&gt;
      &lt;u16vector&gt;
      &lt;s16vector&gt;
      &lt;u32vector&gt;
      &lt;s32vector&gt;
      &lt;f32vector&gt;
      &lt;f64vector&gt;
    &lt;structure&gt;
      &lt;array&gt;
      &lt;char-set&gt;
      &lt;condition&gt;
      &lt;environment&gt;
      &lt;hash-table&gt;
      &lt;lock&gt;
      &lt;mmap&gt;
      &lt;promise&gt;
      &lt;queue&gt;
      &lt;tcp-listener&gt;
      &lt;time&gt;
    &lt;end-of-file&gt;
@end html
@end ifhtml

@ifnothtml
@verbatim
<top>
  <object>
    <class>
      <procedure-class>
        <procedure>
        <entity-class>
          <generic>
      <primitive-class>
    <c++-object>
  <primitive>
    <void>
    <boolean>
    <symbol>
    <char>
    <vector>
    <pair>
    <number>
      <integer>
        <exact>
      <inexact>
    <string>
    <port>
      <input-port>
      <output-port>
    <pointer>
      <tagged-pointer>
    <locative>
    <byte-vector>
      <u8vector>
      <s8vector>
      <u16vector>
      <s16vector>
      <u32vector>
      <s32vector>
      <f32vector>
      <f64vector>
    <structure>
      <array>
      <char-set>
      <condition>
      <environment>
      <hash-table>
      <lock>
      <mmap>
      <promise>
      <queue>
      <tcp-listener>
      <time>
    <end-of-file>
@end verbatim
@end ifnothtml


@defvr {class} <primitive>           @pointrightarrow{} <top>
The parent class of the classes of all primitive Scheme objects.
@end defvr

@defvr {class} <boolean>             @pointrightarrow{} <primitive>
@defvrx {class} <symbol>              @pointrightarrow{} <primitive>
@defvrx {class} <char>                @pointrightarrow{} <primitive>
@defvrx {class} <vector>              @pointrightarrow{} <primitive>
@defvrx {class} <null>                @pointrightarrow{} <primitive>
@defvrx {class} <pair>                @pointrightarrow{} <primitive>
@defvrx {class} <number>              @pointrightarrow{} <primitive>
@defvrx {class} <integer>             @pointrightarrow{} <primitive>
@defvrx {class} <exact>               @pointrightarrow{} <integer>
@defvrx {class} <inexact>             @pointrightarrow{} <number>
@defvrx {class} <string>              @pointrightarrow{} <primitive>
@defvrx {class} <port>                @pointrightarrow{} <primitive>
@defvrx {class} <environment>         @pointrightarrow{} <structure>
@defvrx {class} <end-of-file>         @pointrightarrow{} <primitive>
@defvrx {class} <input-port>          @pointrightarrow{} <port>
@defvrx {class} <output-port>         @pointrightarrow{} <port>
@defvrx {class} <procedure>           @pointrightarrow{} <procedure-class>
The classes of primitive Scheme objects.
@end defvr

@defvr {class} <byte-vector>          @pointrightarrow{} <primitive>
@defvrx {class} <structure>           @pointrightarrow{} <primitive>
@defvrx {class} <hash-table>          @pointrightarrow{} <structure>
@defvrx {class} <queue>               @pointrightarrow{} <structure>
The classes of extended data types provided by the various library units.
@end defvr

@defvr {class} <class>               @pointrightarrow{} <object>
The parent class of all class objects.
@end defvr

@defvr {class} <entity-class>        @pointrightarrow{} <class>
The parent class of objects that can be invoked as a procedure and have slots.
@end defvr

@defvr {class} <generic>             @pointrightarrow{} <entity-class>
The parent class of generic function objects.
@end defvr

@defvr {class} <method>              @pointrightarrow{} <class>
The parent class of method objects.
@end defvr

@defvr {class} <object>              @pointrightarrow{} <class>
The parent class of all objects.
@end defvr

@defvr {class} <procedure-class>     @pointrightarrow{} <class>
The parent class of objects that can be invoked as a procedure.
@end defvr

@defvr {class} <condition>           @pointrightarrow{} <structure>
Class of condition objects.
@end defvr

@defvr {class} <array>               @pointrightarrow{} <structure>
@defvrx {class} <char-set>            @pointrightarrow{} <structure>
@defvrx {class} <time>                @pointrightarrow{} <structure>
@defvrx {class} <u8vector>            @pointrightarrow{} <byte-vector>
@defvrx {class} <s8vector>            @pointrightarrow{} <byte-vector>
@defvrx {class} <u16vector>           @pointrightarrow{} <byte-vector>
@defvrx {class} <s16vector>           @pointrightarrow{} <byte-vector>
@defvrx {class} <u32vector>           @pointrightarrow{} <byte-vector>
@defvrx {class} <s32vector>           @pointrightarrow{} <byte-vector>
@defvrx {class} <f32vector>           @pointrightarrow{} <byte-vector>
@defvrx {class} <f64vector>           @pointrightarrow{} <byte-vector>
The classes of data objects provided by the various supported SRFIs.
@end defvr

@defvr {class} <lock>                @pointrightarrow{} <structure>
@defvrx {class} <mmap>                @pointrightarrow{} <structure>
Classes of objects used in the @code{posix} library unit.
@end defvr

@defvr {class} <pointer>             @pointrightarrow{} <primitive>
@defvrx {class} <tagged-pointer>      @pointrightarrow{} <pointer>
A machine pointer (untagged, or tagged).
@end defvr

@defvr {class} <locative>            @pointrightarrow{} <primitive>
A locative.
@end defvr

@defvr {class} <promise>             @pointrightarrow{} <structure>
The class of objects returned by @code{delay}.
@end defvr

@defvr {class} <tcp-listener>        @pointrightarrow{} <structure>
The class of an object returned by @code{tcp-listen}.
@end defvr

@defvr {class} <c++-class>           @pointrightarrow{} <object>
The class of generated wrappers for C++ classes parsed by the ``easy''
Foreign Function interface.
@end defvr



The CHICKEN distribution provides several examples in the file
@code{tinyclos-examples.scm}.


@node Interface to external functions and variables
@chapter Interface to external functions and variables

@menu
* Accessing external objects::  
* Foreign type specifiers::     
* Entry points::                
* Callbacks::                   
* Locations::                   
* Other support procedures::    
* The Easy Foreign Function Interface::  
* C interface::                 
@end menu

@node Accessing external objects
@section Accessing external objects



@deffn {syntax} foreign-code
@lisp
(foreign-code STRING)
@end lisp
Executes the embedded C/C++ code @code{STRING}, which should
be a sequence of C statements, which are executed and return an unspecified result.

@verbatim
(foreign-code "doSomeInitStuff();")     =>  #<unspecified>
@end verbatim

@end deffn
@deffn {syntax} foreign-value
@lisp
(foreign-value STRING TYPE)
@end lisp
Evaluates the embedded C/C++ expression @code{STRING}, returning a value of type given
in the foreign-type specifier @code{TYPE}.

@verbatim
(print (foreign-value "my_version_string" c-string))
@end verbatim

@end deffn
@deffn {syntax} define-foreign-type
@lisp
(define-foreign-type NAME TYPE [ARGCONVERT [RETCONVERT]])
@end lisp
Defines an alias for @code{TYPE} with the name @code{NAME} (a symbol). 
@code{TYPE} may be a type-specifier
or a string naming a C type. The namespace of foreign type specifiers
is separate from the normal Scheme namespace.  The optional arguments
@code{ARGCONVERT} and @code{RETCONVERT} should evaluate to procedures
that map argument- and result-values to a value that can be transformed
to @code{TYPE}:

@verbatim
(require-extension extras)

(define-foreign-type char-vector 
  nonnull-c-string
  (compose list->string vector->list)
  (compose list->vector string->list) )

(define strlen
  (foreign-lambda int "strlen" char-vector) )

(strlen '#(#\a #\b #\c))                      ==> 3

(define memset
  (foreign-lambda char-vector "memset" char-vector char int) )

(memset '#(#_ #_ #_) #\X 3)                ==> #(#\X #\X #\X)
@end verbatim                 

Foreign type-definitions are only visible in the compilation-unit in which
they are defined, so use @code{include} to use the same definitions
in multiple files.

@end deffn
@deffn {syntax} define-foreign-variable
@lisp
(define-foreign-variable NAME TYPE [STRING])
@end lisp
Defines a foreign variable of name @code{NAME} (a symbol). @code{STRING}
should be the real name of a foreign variable or parameterless macro. If
@code{STRING} is not given, then the variable name @code{NAME} will
be converted to a string and used instead. All references and assignments
(via @code{set!}) are modified to correctly convert values between
Scheme and C representation. This foreign variable can only be accessed
in the current compilation unit, but the name can be lexically shadowed.
Note that @code{STRING} can name an arbitrary C expression. If no
assignments are performed, then @code{STRING} doesn't even have to
specify an lvalue.

@verbatim
#>
enum { abc=3, def, ghi };
<#

(define-macro (define-foreign-enum . items)
  `(begin
     ,@(map (match-lambda 
              [(name realname) `(define-foreign-variable ,name int ,realname)]
              [name `(define-foreign-variable ,name int)] )
     items) ) )

(define-foreign-enum abc def ghi)

ghi                               ==> 5
@end verbatim

@end deffn
@deffn {syntax} define-foreign-record
@lisp
(define-foreign-record NAME SLOT ...)
@end lisp
Defines accessor procedures for a C structure definition. @code{NAME} should either be a symbol
or a list of the form @code{(TYPENAME FOREIGNNAME)}. If @code{NAME} is a symbol, then a C declaration
will be generated that defines a C struct named @code{struct NAME}. If @code{NAME} is a list, then
no struct declaration will be generated. 
A foreign-type specifier named @code{NAME} (or @code{TYPENAME}) will be defined as a pointer to
the given C structure.
A @code{SLOT} definition should be a list of one of the following forms:

@verbatim
(TYPE SLOTNAME)
@end verbatim

or

@verbatim
(TYPE SLOTNAME SIZE)
@end verbatim

The latter form defines an array of SIZE elements of the type TYPE embedded in the
structure.
For every slot, the following accessor procedures will be generated:



@deffn {procedure} TYPENAME-SLOTNAME
@lisp
(TYPENAME-SLOTNAME FOREIGN-RECORD-POINTER [INDEX])
@end lisp
A procedure of one argument (a pointer to a C structure), that returns
the slot value of the slot @code{SLOTNAME}. If a @code{SIZE} has been given in the slot definition, then
an additional argument @code{INDEX} is required that specifies the index of an array-element.
@end deffn

@deffn {procedure} TYPENAME-SLOTNAME-set!
@lisp
(TYPENAME-SLOTNAME-set! FOREIGN-RECORD-POINTER [INXDEX] VALUE)
@end lisp
A procedure of two arguments (a pointer to a C structure) and a value, that
sets the slot value of the slot @code{SLOTNAME} in the structure. If a @code{SIZE} has been given in
the slot definition, then an additional argument @code{INDEX} is required for the array index.
@end deffn



If a slot type is of the form @code{(const ...)}, then no setter procedure will be generated.
Slots of the types @code{(struct ...)} or @code{(union ...)} are accessed as pointers to the embedded
struct (or union) and no setter will be generated. 

@end deffn
@deffn {syntax} foreign-callback-lambda
@lisp
(foreign-callback-lambda RETURNTYPE NAME ARGTYPE ...)
@end lisp
This is similar to @code{foreign-lambda}, but also allows the called
function to call Scheme functions. See @ref{Callbacks}.

@end deffn
@deffn {syntax} foreign-callback-lambda*
@lisp
(foreign-callback-lambda* RETURNTYPE ((ARGTYPE VARIABLE)...) STRING ...)
@end lisp
This is similar to @code{foreign-lambda*}, but also allows the called
function to call Scheme functions. See @ref{Callbacks}.

@end deffn
@deffn {syntax} foreign-lambda
@lisp
(foreign-lambda RETURNTYPE NAME ARGTYPE ...)
@end lisp
Represents a
binding to an external routine. This form can be used in the position
of an ordinary @code{lambda} expression. @code{NAME} specifies the
name of the external procedure and should be a string or a symbol.

@end deffn
@deffn {syntax} foreign-lambda*
@lisp
(foreign-lambda* RETURNTYPE ((ARGTYPE VARIABLE) ...) STRING ...)
@end lisp
Similar to @code{foreign-lambda}, but instead of generating code to
call an external function, the body of the C procedure is directly given
in @code{STRING ...}:

@verbatim
(define my-strlen
  (foreign-lambda* int ((c-string str))
    "int n = 0;
     while(*(str++)) ++n;
     return(n);") )

(my-strlen "one two three")             ==> 13
@end verbatim

For obscure technical reasons any use of the @code{return} statement
should enclose the result value in parentheses. For the same reasons
@code{return} without an argument is not allowed.
@end deffn



@node Foreign type specifiers
@section Foreign type specifiers

Here is a list of valid foreign type specifiers:

@table @code

@item scheme-object

An arbitrary Scheme data object (immediate or non-immediate). 

@item bool

As argument: any value (@code{#f} is false, anything else is true).
As result: anything different from 0 and the @code{NULL}-pointer
is @code{#t}.

@item byte unsigned-byte

A byte.

@item char unsigned-char

A character.

@item short unsigned-short

A short integer number.

@item int unsigned-int

An small integer number in fixnum range (at least 30 bit).

@item integer unsigned-integer

Either a fixnum or a flonum in the range of a (unsigned) machine ``int''.

@item long unsigned-long

Either a fixnum or a flonum in the range of a (unsigned) machine ``long''.

@item float double

A floating-point number. If an exact integer is passed as an argument,
then it is automatically converted to a float.

@item pointer

An untyped pointer to the contents of a non-immediate Scheme object
(not allowed as return type).  The value @code{#f} is also allowed
and is passed as a @code{NULL} pointer. 

@item nonnull-pointer

As @code{pointer}, but guaranteed not to be @code{#f}.

@item c-pointer

An untyped operating-system pointer or a locative.  The value @code{#f} is also
allowed and is passed as a @code{NULL} pointer.  If uses as the type of
a return value, a @code{NULL} pointer will be returned as @code{#f}.

@item nonnull-c-pointer

As @code{c-pointer}, but guaranteed not to be @code{#f/NULL}.

@item [nonnull-] byte-vector
A byte-vector object, passed as a pointer to its contents. Arguments
of type @code{byte-vector} may optionally be @code{#f}, which is
passed as a NULL pointer.  This is not allowed as a return type.
@c @end deffn

@item  [nonnull-] u8vector
@itemx [nonnull-] u16vector
@itemx [nonnull-] u32vector
@itemx [nonnull-] s8vector
@itemx [nonnull-] s16vector
@itemx [nonnull-] s32vector
@itemx [nonnull-] f32vector
@itemx [nonnull-] f64vector
A SRFI-4 number-vector object, passed as a pointer to its
contents. Arguments of type @code{byte-vector} may optionally be
@code{#f}, which is passed as a NULL pointer.  These are not allowed
as return types.

@item c-string

A C string (zero-terminated). The value @code{#f}
is also allowed and is passed as a @code{NULL} pointer. If uses as
the type of a return value, a @code{NULL} pointer will be returned as
@code{#f}. Note that the string is copied (with a zero-byte appended)
when passed as an argument to a foreign function. Also a return value
of this type is copied into garbage collected memory.

@item nonnull-c-string

As @code{c-string}, but guaranteed not to be @code{#f/NULL}.

@item [nonnull-] c-string*
Similar to @code{[nonnull-]c-string}, but if used as a result-type,
the pointer returned by the foreign code will be freed (using the
C-libraries @code{free()})
after copying.
@c @end deffn

@item void

Specifies an undefined return value. Not allowed as argument type.

@item (const TYPE)

The foreign type @code{TYPE} with an additional @code{const} specifier.

@item (enum NAME)

An enumeration type. Handled internally as an @code{integer}.

@item (pointer TYPE)

@item (c-pointer TYPE)

An operating-system pointer or a locative to an object of @code{TYPE}.

@item (nonnull-pointer TYPE)

@item (nonnull-c-pointer TYPE)

As @code{(pointer TYPE)}, but guaranteed not to be @code{#f/NULL}.

@item (ref TYPE)

A C++ reference type. Reference types are handled the same way as pointers
inside Scheme code.

@item (struct NAME)

A struct of the name @code{NAME}, which should be a string. Structs
can not be directly passed as arguments to foreign function, neither
can they be result values. Pointers to structs are allowed, though.

@item (template TYPE ARGTYPE ...)

A C++ template type. For example @code{vector<int>} would be specified
as @code{(template "vector" int)}. Template types can not be directly passed
as arguments or returned as results.

@item (union NAME)

A union of the name @code{NAME}, which should be a string. Unions can
not be directly passed as arguments to foreign function, neither can
they be result values. Pointers to unions are allowed, though.

@item (instance CNAME SCHEMECLASS)

A pointer to a C++ class instance. @code{CNAME} should designate
the name of the C++ class, and @code{SCHEMECLASS} should be the class
that wraps the instance pointer. Normally @code{SCHEMECLASS}
should be a subclass of @code{<c++-object>}.

@item (function RESULTTYPE (ARGUMENTTYPE1 ... [...]) [CALLCONV])
A function pointer. @code{CALLCONV} specifies an optional calling
convention and should be a string. The meaning of this string is entirely
platform dependent.  The value @code{#f} is also allowed and is passed
as a @code{NULL} pointer.

@end table

Foreign types are mapped to C types in the following manner:

@c % XXX figure out  if this is the right way to do this...

@table @code
@item bool
int
@item [unsigned-]char
[unsigned] char
@item [unsigned-]short
[unsigned] short
@item [unsigned-]int
[unsigned] int
@item [unsigned-]integer
[unsigned] int
@item [unsigned-]long
[unsigned] long
@item float
float
@item double
double
@item [nonnull-]pointer
void *
@item [nonnull-]c-pointer
void *
@item [nonnull-]byte-vector
unsigned char *
@item [nonnull-]u8vector
unsigned char *
@item [nonnull-]s8vector
char *
@item [nonnull-]u16vector
unsigned short *
@item [nonnull-]s16vector
short *
@item [nonnull-]u32vector
uint32_t *
@item [nonnull-]s32vector
int32_t *
@item [nonnull-]f32vector
float *
@item [nonnull-]f64vector
double *
@item [nonnull-]c-string
char *
@item void
void
@item ([nonnull-]pointer TYPE)
TYPE *
@item (enum NAME)
enum NAME
@item (struct NAME)
struct NAME
@item (ref TYPE)
TYPE &
@item (template T1 T2 ...)
T1<T2, ...>
@item (union NAME)
union NAME
@item (function RTYPE (ATYPE ...) [CALLCONV])
[CALLCONV] RTYPE (*)(ATYPE, ...)
@end table


@node Entry points
@section Entry points 

To simplify embedding compiled Scheme code into arbitrary programs, one
can define so called ``entry points'', which provide a uniform interface
and parameter conversion facilities. To use this facility, add

@verbatim
(include "chicken-entry-points")
@end verbatim

to the beginning of your code.



@deffn {syntax} define-entry-point
@lisp
(define-entry-point INDEX ((VAR1 TYPE1) ...)
                          (RTYPE1 ...)
                          EXP1 EXP2 ...)
@end lisp
Defines a new entry-point with index @code{INDEX} which should evaluate
to an exact integer. During execution of the body @code{EXP1 EXP2 ...}
the variables @code{VAR1 ...} are bound to the parameters passed from
the host program to the invoked entry point. The parameters passed
are converted according to the foreign type specifiers @code{TYPE1
...}. The expressions should return as many values as foreign type
specifiers are given in @code{RTYPE1 ...}, with the exception that if the list
of return types is empty, a single value is expected to be returned from the body
(there is no need to add a @code{(values)} form at the end).
The results are then transformed into values that can be used in the host program.

@b{Note:} if one or more of the result types @code{RTYPE ...}
specify the type @code{c-string}, then the parameter types at the same
positions in @code{TYPE1 ...} have to be @code{c-string}s as well,
because the result strings are copied into the same area in memory.
You should also take care that the passed buffer is long enough to hold
the result string or unpredictable things will happen.

If entry points were defined then the program will not terminate after
execution of the last toplevel expression, but instead it will enter a
loop that waits for the host to invoke one of the defined entry points.

@end deffn
@deffn {syntax} define-embedded
@lisp
(define-embedded [QUALIFIER ... ] ([CCONV] NAME (TYPE1 VAR1) ...) RTYPE BODY ...)
@end lisp
Defines a named entry-point that can be accessed from external code with a normal C/C++ function call.
@code{QUALIFIER} may be a string for special function declarations (like @code{__declspec(dllexport)}
on Windows, for example) and @code{CCONV} may be a string designating a calling convention (like @code{__cdecl}).
During the execution of the @code{BODY} the variables @code{VAR1 ...} are bound to the arguments
passed to the function, which should be of types compatible to the type specifiers @code{TYPE1 ...}.
@code{RTYPE} specifies the result type of the entry-point. The return type specifiers @code{[nonnull-]c-string}
and @code{[nonnull-]c-string*} are handled specially: if the return type is @code{c-string}, a heap-allocated
pointer to a zero-terminated string will be returned, which will be valid until the next invocation
of an entry-point into the Scheme code. If the return type is @code{c-string*}, a buffer allocated
with @code{malloc} will be returned, and freeing the string is the responsibility of the caller.

All entry-point definitions with @code{define-embedded} should be put into the same source file. 
@code{define-embedded} expands into a @code{define-entry-point} form and the entry-point index is
provided by the macro (starting from 1). If @code{define-embedded} is used in multiple source files
then the index is counted from 1 in each of the files, resulting in multiple entry-points with the
same index.
@end deffn



The following C functions and data types are provided:



@deftypefn {C function} void CHICKEN_parse_command_line (int argc, char *argv[], int *heap, int *stack int *symbols)
Parse the programs command-line contained in @code{argc} and
@code{argv} and return the heap-, stack- and symbol table limits
given by runtime options of the form @code{-:...}, or choose default
limits. The library procedure @code{argv} can access the command-line
only if this function has been called by the containing application.
@end deftypefn

@deftypefn {C function} int CHICKEN_initialize (int heap, int stack, int symbols, void *toplevel)
Initializes the Scheme execution context and memory. @code{heap}
holds the number of bytes that are to be allocated for the secondary
heap. @code{stack} holds the number of bytes for the primary
heap. @code{symbols} contains the size of the symbol table. Passing
@code{0} to one or more of these parameters will select a default
size. 
@code{toplevel} should be a pointer to the toplevel entry point
procedure. You should pass @code{C_toplevel} here. In any subsequent
call to @code{CHICKEN_run} or @code{CHICKEN_invoke} you can simply
pass @code{NULL}.
Calling this function more than once has no effect. If enough
memory is available and initialization was successful, then @code{1}
is returned, otherwise this function returns @code{0}.
@end deftypefn

@deftypefn {C function} void CHICKEN_run (void **data, int *bytes, int *maxlen, void *toplevel)
Starts the Scheme program. @code{data, bytes} and @code{maxlen}
contain invocation parameters in raw form. Pass @code{NULL} here.
Call this function once to execute all toplevel expressions in your
compiled Scheme program. If the runtime system was not initialized before,
then @code{CHICKEN_initialize} is called with default sizes.
@code{toplevel} is the toplevel entry-point procedure.
@end deftypefn

@deftypefn {C function} void CHICKEN_invoke (int index, C_parameter *params, int count, void *toplevel)
Invoke the entry point with index @code{index}. @code{count} should
contain the maximum number of arguments or results (whatever is higher). @code{params} is a pointer
to parameter data:

@verbatim
typedef union
{
  C_word x;           /* parameter type scheme-object */
  long i;             /* parameter type bool, [unsigned] int/short/long */
  long c;             /* parameter type [unsigned] char */
  double f;           /* parameter type float/double */
  void *p;            /* any pointer parameter type and C strings */
} C_parameter;
@end verbatim

This function calls @code{CHICKEN_run} if it was not called at least
once before.
@end deftypefn

@deftypefn {C function} int CHICKEN_is_running ()
Returns @code{1}, if called inside a dynamic context invoked via @code{CHICKEN_run}
or @code{CHICKEN_invoke} (i.e. if running inside a call from Scheme to C). If no
Scheme stack frame is currently active, then this function returns @code{0}.
@end deftypefn



Here is a simple example (assuming a UNIX-like environment):

@verbatim
% cat foo.c
#include <stdio.h>
#include "chicken.h"

int main(void)
{
  C_parameter p[ 3 ];
  char str[ 32 ] = "hello!";  /* We need some space for the result string! */

  memset(p, 0, sizeof(p));
  p[ 0 ].i = -99;
  p[ 1 ].p = str;
  p[ 2 ].f = 3.14;
  CHICKEN_invoke(1, p, 3, C_toplevel);
  printf("->\n%d\n%s\n", p[ 0 ].i, p[ 1 ].p);
  return 0;
}

% cat bar.scm
(include "chicken-entry-points")

(define-entry-point 1
    ((a integer) (b c-string) (c double))
    (int c-string)
  (print (list a b c))
  (values 123 "good bye!") )

% chicken bar.scm -quiet
% gcc foo.c bar.c -o foo `chicken-config -cflags -libs -embedded`
% foo
(-99 "hello!" 3.14)
->
123
good bye!
@end verbatim

Note the use of @code{-embedded}. We have to compile with additional compiler
options, because the host program provides the @code{main}
function.

Here another example that uses named entry-points defined with @code{define-embedded}:

@verbatim
% cat foo.c
extern int foo(int, char *);
extern unsigned int square(double);

int main() { foo(square(9), "yo!"); return 0; }

% cat bar.scm
(include "chicken-entry-points")

(define-embedded (foo (int x) (c-string y)) int
  (print x ": " y) 
  x)

(define-embedded (square (double x)) unsigned-int
  (* x x))

% chicken bar.scm
compiling `bar.scm' ...
% gcc foo.c bar.c `chicken-config -cflags -libs -embedded`
% a.out
81: yo!
@end verbatim

CHICKEN also provides ``boilerplate'' entry points, that simplify invoking Scheme
code embedded in a C or C++ application tremendously. The include file @code{default-entry-points.scm}
will define entry-points for common usage patterns, like loading a file, evaluating an expression
or calling a procedure.



@deftypefn {C macro} void CHICKEN_eval (C_word exp, C_word *result, int *status)
Evaluates the Scheme object passed in @code{exp}, writing the result value to @code{result}.
@code{status} is set to 1 if the operation succeeded,
or 0 if an error occurred. Call @code{CHICKEN_get_error_message} to obtain a description
of the error.
@end deftypefn

@deftypefn {C macro} void CHICKEN_eval_string (char *str, C_word *result, int *status)
Evaluates the Scheme expression passed in the string @code{str}, writing the result value to @code{result}.
@end deftypefn

@deftypefn {C macro} void CHICKEN_eval_to_string (C_word exp, char *result, int size, int *status)
Evaluates the Scheme expression passed in @code{exp}, writing a textual representation
of the result into @code{result}. @code{size} should specify the maximal size of the result string.
@end deftypefn

@deftypefn {C macro} void CHICKEN_eval_string_to_string (char *str, char *result, int size, int *status)
Evaluates the Scheme expression passed in the string @code{str}, writing a textual representation
of the result into @code{result}. @code{size} should specify the maximal size of the result string.
@end deftypefn

@deftypefn {C macro} void CHICKEN_apply (C_word func, C_word args, C_word *result, int *status)
Applies the procedure passed in @code{func} to the list of arguments @code{args}, writing the result value to @code{result}.
@end deftypefn

@deftypefn {C macro} void CHICKEN_apply_to_string (C_word func, C_word args, char *result, int size, int *status)
Applies the procedure passed in @code{func} to the list of arguments @code{args}, writing a textual 
representation of the result into @code{result}.
@end deftypefn

@deftypefn {C macro} void CHICKEN_read (char *str, C_word *result, int *status)
Reads a Scheme object from the string @code{str}, writing the result value to @code{result}.
@end deftypefn

@deftypefn {C macro} void CHICKEN_load (char *filename, int *status)
Loads the Scheme file @code{filename} (either in source form or compiled).
@end deftypefn

@deftypefn {C macro} void CHICKEN_get_error_message (char *result, int size)
Returns a textual description, in case an error occurred while invoking embedded Scheme code.
@end deftypefn

@deftypefn {C macro} void CHICKEN_yield (int *status)
If threads have been spawned during earlier invocations of embedded Scheme code, then this function
will run the next scheduled thread for one complete time-slice. This is useful, for example, inside
an ``idle'' handler in a GUI application with background Scheme threads.
@end deftypefn


An example:

@verbatim
% cat x.scm
;;; x.scm

(include "chicken-default-entry-points")
(define (bar x) (gc) (* x x))

% cat y.c
/* y.c */

#include "chicken.h"
#include <assert.h>

int main() {
  char buffer[ 256 ];
  int status;
  C_word val = C_SCHEME_UNDEFINED;
  C_word *data[ 1 ];
  
  data[ 0 ] = &val;

  CHICKEN_read("(bar 99)", &val, &status);
  assert(status);

  C_gc_protect(data, 1);

  printf("data: %08x\n", val);

  CHICKEN_eval_string_to_string("(bar)", buffer, 255, &status);
  assert(!status);

  CHICKEN_get_error_message(buffer, 255);
  printf("ouch: %s\n", buffer);

  CHICKEN_eval_string_to_string("(bar 23)", buffer, 255, &status);
  assert(status);

  printf("-> %s\n", buffer);
  printf("data: %08x\n", val);

  CHICKEN_eval_to_string(val, buffer, 255, &status);
  assert(status);
  printf("-> %s\n", buffer);

  return 0;
}

% csc x.scm y.c -embedded
@end verbatim


A simpler interface For handling GC-safe references to Scheme data are the so called ``gc-roots'':

@deftypefn {C function} void* CHICKEN_new_gc_root ()
Returns a pointer to a ``GC root'', which is an object that holds a reference to a Scheme value
that will always be valid, even after a garbage collection. The content of the gc root is initialized to
an unspecified value.
@end deftypefn

@deftypefn {C function} void CHICKEN_delete_gc_root (void *root)
Deletes the gc root.
@end deftypefn

@deftypefn {C macro} C_word CHICKEN_gc_root_ref (void *root)
Returns the value stored in the gc root.
@end deftypefn

@deftypefn {C macro} void CHICKEN_gc_root_set (void *root, C_word value)
Sets the content of the GC root to a new value.
@end deftypefn


Sometimes it is handy to access global variables from C code:

@deftypefn {C function} void* CHICKEN_global_lookup (char *name)
Returns a GC root that holds the global variable with the name @code{name}. If no such variable
exists, @code{NULL} is returned.
@end deftypefn

@deftypefn {C function} C_word CHICKEN_global_ref (void *global)
Returns the value of the global variable referenced by the GC root @code{global}.
@end deftypefn

@deftypefn {C function} void CHICKEN_global_set (void *global, C_word value)
Sets the value of the global variable referenced by the GC root @code{global} to @code{value}.
@end deftypefn


@node Callbacks
@section Callbacks 


To enable an external C function to call back to Scheme, the form
@code{foreign-callback-lambda} (or @code{foreign-callback-lambda*})
has to be used. This generates special code to save and restore important
state information during execution of C code. There are two ways of
calling Scheme procedures from C: the first is to invoke the runtime
function @code{C_callback} with the closure to be called and the number
of arguments.  The second is to define an externally visible wrapper
function around a Scheme procedure with the @code{define-external}
or @code{foreign-callback-wrapper} forms.

Note: the names of all functions, variables and macros exported by the
CHICKEN runtime system start with ``@code{C_}''. It is advisable to
use a different naming scheme for your own code to avoid name clashes.
Callbacks (either defined by @code{define-external} or @code{foreign-callback-wrapper}
do not capture the lexical environment.



@deffn {syntax} define-external
@lisp
(define-external [QUALIFIERS] (NAME (ARGUMENTTYPE1 VARIABLE1) ...) RETURNTYPE BODY ...)
(define-external NAME TYPE [INIT])
@end lisp
The first form defines an externally callable Scheme
procedure. @code{NAME} should be a symbol, which, when converted to a
string, represents a legal C identifier. @code{ARGUMENTTYPE1 ...} and
@code{RETURNTYPE} are foreign type specifiers for the argument variables
@code{VAR1 ...} and the result, respectively.  @code{QUALIFIERS}
is an optional qualifier for the foreign procedure definition, like
@code{__stdcall}.

@verbatim
(define-external (foo (c-string x)) int (string-length x))
@end verbatim

is equivalent to

@verbatim
(define foo 
  (foreign-callback-wrapper int "foo" 
    (c-string) (lambda (x) (string-length x))))
@end verbatim

The second form of @code{define-external} can be used to define
variables that are accessible from foreign code. It declares
a global variable named by the symbol @code{NAME} that
has the type @code{TYPE}. @code{INIT} can be an arbitrary
expression that is used to initialize the variable. @code{NAME} is
accessible from Scheme just like any other foreign variable defined by
@code{define-foreign-variable}.  

@verbatim
(define-external foo int 42)
((foreign-lambda* int ()
  "return(foo);"))           ==> 42
@end verbatim

@b{Note:} don't be tempted to
assign strings or bytevectors to external variables. Garbage collection
moves those objects around, so it is very bad idea to assign pointers
to heap-data. If you have to do so, then copy the data object into
statically allocated memory (for example by using @code{object-evict}).

@end deffn
@deffn {syntax} foreign-callback-wrapper
@lisp
(foreign-callback-wrapper RETURNTYPE NAME [QUALIFIERS] (ARGUMENTTYPE1 ...) EXP)
@end lisp
Defines an externally callable wrapper around the procedure
@code{EXP}. @code{EXP} @b{must} be a lambda expression
of the form @code{(lambda @dots{})}. The wrapper will have the name
@code{NAME} and will have a signature as specified in the return- and
argument-types given in @code{RETURNTYPE} and @code{ARGUMENTTYPE1
...}.  @code{QUALIFIERS} is a qualifier string for the function
definition (see @code{define-external}).
@end deffn

@deftypefn {C function} C_word C_callback (C_word closure, int argc)
This function can be used to invoke the Scheme procedure @code{closure}.
@code{argc} should contain the number of arguments that are passed to
the procedure on the temporary stack. Values are put onto the temporary
stack with the @code{C_save} macro.
@end deftypefn




@node Locations
@section Locations 


It is also possible to define variables containing unboxed C data,
so called @emph{locations}. It should be noted that locations may
only contain simple data, that is: everything that fits into a
machine word, and double-precision floating point values. 



@deffn {syntax} define-location
@lisp
(define-location NAME TYPE [INIT])
@end lisp
Identical to @code{(define-external NAME TYPE [INIT])}, but the variable
is not accessible from outside of the current compilation unit (it is 
declared @code{static}).

@end deffn
@deffn {syntax} let-location
@lisp
(let-location ((NAME TYPE [INIT]) ...) BODY ...)
@end lisp
Defines a lexically bound location.

@end deffn
@deffn {syntax} location
@lisp
(location NAME)
(location X)
NAME
define-external
@end lisp
or @code{let-location}.  This form returns a pointer object
that contains the address of the variable @code{NAME}. 
If the argument to @code{location} is not a location defined by @code{define-location},
@code{define-external} or @code{let-location}, then

@verbatim
(location X)
@end verbatim

is essentially equivalent to 

@verbatim
(make-locative X)
@end verbatim

(See the manual chapter or @code{locatives} for more information about
locatives.

Note that @code{(location X)} may be abbreviated as @code{#$X}.

@verbatim
(define-external foo int)
((foreign-lambda* void (((pointer int) ip)) "*ip = 123;") 
  (location foo))
foo                                                                               ==> 123
@end verbatim

This facility is especially useful in situations, where a C function
returns more than one result value:

@verbatim
#>
#include <math.h>
<#

(define modf
  (foreign-lambda double "modf" double (pointer double)) )

(let-location ([i double])
  (let ([f (modf 1.99 (location i))])
    (print "i=" i ", f=" f) ) )
@end verbatim
@end deffn



@code{location} returns a value of type @code{c-pointer}, when given
the name of a callback-procedure defined with @code{define-external}.

@node Other support procedures
@section Other support procedures


@deffn {procedure} argc+argv
@lisp
(argc+argv)
@end lisp
Returns two values: an integer and a foreign-pointer object representing the @code{argc}
and @code{argv} arguments passed to the current process.
@end deffn



@node The Easy Foreign Function Interface
@section The @emph{Easy} Foreign Function Interface

The compiler contains a builtin parser for a restricted subset of C and C++ that
allows the easy generation of foreign variable declarations, procedure bindings and
C++ class wrappers. The parser is invoked via the declaration-specifier
@code{foreign-parse}, which extracts binding information and generates
the necessary code. An example:

@verbatim
(declare 
  (foreign-declare "
#include <math.h>

#define my_pi 3.14
")
  (foreign-parse "extern double sin(double);") )

(print (sin 3.14))
@end verbatim

The parser would generate code that is equivalent to

@verbatim
(declare 
  (foreign-declare "
#include <math.h>

#define my_pi 3.14
")

(define-foreign-variable my_pi float "my_pi")
(define sin (foreign-lambda double "sin" double))
@end verbatim

Note that the read syntax @code{#>[SPEC] ... <#}
provides a somewhat simpler way of using the parser. The example above could
alternatively be expressed as

@verbatim
#>!
#define my_pi 3.14

extern double sin(double);
<#

(print (sin 3.14))
@end verbatim

Another example, here using C++. Consider the following class:

@verbatim
// file: foo.h

class Foo {
 private:
  int x_;
 public:
  Foo(int x);
  void setX(int x);
  int getX();
};
@end verbatim

To generate a wrapper class that provides generic functions for the
constructor and the @code{setX} and @code{getX} methods, we
can use the following class definition:

@verbatim
; file: test-foo.scm

#>!
#include "Foo.h"
<#

(define x (make <Foo> 99))
(print (getX x))              ; prints ``99''
(setX x 42)
(print (getX x))              ; prints ``42''
(destroy x)
@end verbatim

Provided the file @code{foo.o} contains the implementation of the class @code{Foo}, the
given example could be compiled like this (assuming a UNIX like environment):

@verbatim
% csc test-foo.scm foo.o -c++
@end verbatim

Here is another example, a minimal ``Hello world'' application for QT. We can
see the three different ways of embedding C/C++ code in Scheme:

@verbatim
; compile like this: 
; csc hello.scm -c++ -C -IQTDIR/include -L "-LQTDIR/lib -lqt"

; Include into generated code, but don't parse:
#>
#include <qapplication.h>
#include <qpushbutton.h>
<#

; Parse but don't embed: we only want wrappers for a few classes:
#>?
class QWidget 
{
public:
  void resize(int, int);
  void show();
};

class QApplication 
{
public:
  QApplication(int, char **);
  ~QApplication();
  void setMainWidget(QWidget *);
  void exec();
};

class QPushButton : public QWidget
{
public:
  QPushButton(char *, QWidget *);
  ~QPushButton();
}
<#

(define a (apply make <QApplication> (receive (argc+argv))))
(define hello (make <QPushButton> "hello world!" #f))
(resize hello 100 30)
(setMainWidget a hello)
(show hello)
(exec a)
(destroy hello)
(destroy a)
@end verbatim


@menu
* #> ... <# Syntax::            
* General operation::           
* Pseudo declarations::         
* Grammar::                     
* C notes::                     
* C++ notes::                   
@end menu

@node #> ... <# Syntax
@subsection @code{#> ... <#} Syntax

Occurrences of the special read syntax @code{#>[SPEC ...] ...<#} will be handled according to
@code{SPEC}: 

If @code{SPEC} is the @code{?} character, the text following up to the next @code{<#}
will be processed as a @code{(declare (foreign-parse "..."))} declaration (the code will be processed
by the FFI parser described in this section).

If @code{SPEC} is the @code{!} character, the text will be embedded as 

@verbatim
(declare
  (foreign-declare "...")
  (foreign-parse "...") )
@end verbatim

It will be both included verbatim in the declaration section of the generated C/C++ file and processed by the FFI parser.

If @code{SPEC} is the @code{:} character the text will be embedded as a @code{(foreign-code "...")} form,
so it will be executed at the location where it appears.

If @code{SPEC} is a list of the form @code{(TAG ...)}, then each @code{TAG} (which should be a symbol)
specifies what should be done with the text: 

@table @code
@item declare
(declare (foreign-declare "..."))
@item parse
(declare (foreign-parse "..."))
@item execute
(foreign-code "...")
@end table


If any other character follows the @code{#>}, then the complete text will be included verbatim in the declaration
part of the generated file (as in a @code{foreign-declare} declaration). 


@node General operation
@subsection General operation

The parser will generally perform the following functions

1) Translate macro, enum-definitions and constants into @code{define-foreign-variable} or @code{define-constant} forms

2) Translate function prototypes into @code{foreign-lambda} forms

3) Translate variable declarations into accessor procedures

4) Handle basic preprocessor operations

5) Translate simple C++ class definitions into TinyCLOS wrapper classes and methods

Basic token-substitution of macros defined via @code{#define} is performed. The
preprocessor commands @code{#ifdef}, @code{#ifndef}, @code{#else}, @code{#endif}, @code{#undef} and @code{#error}
are handled. The preprocessor commands @code{#if} and @code{#elif} are not supported and will signal 
an error when encountered by the parser, because C expressions (even if constant) are not parsed.
The preprocessor command @code{#pragma} is allowed but will be ignored.

During processing of @code{foreign-parse} declarations the macro @code{CHICKEN} is defined (similar
to the C compiler option @code{-DCHICKEN}).

Macro- and type-definitions are available in subsequent @code{foreign-parse} forms.
C variables declared generate a procedure with zero or one argument with the same name
as the variable. When called with no arguments, the procedure returns the current value of the
variable. When called with an argument, then the variable is set to the value of that argument.
Structs are not supported. C and C++ style comments are supported. Variables declared as @code{const}
will generate normal Scheme variables, bound to the initial value of the variable.

Function-, member-function and constructor/destructor definitions may be preceded by the @code{__callback}
qualifier, which marks the function as performing a callback into Scheme. If a wrapped function
calls back into Scheme code, and @code{__callback} has not been given very strange and hard to debug
problems will occur. Member functions prefixed with @code{__discard} and a result type that maps to
a Scheme string (@code{c-string}), will have their result type changed to @code{c-string*} instead.

Constants (as declared by @code{#define} or @code{enum}) are not visible outside of the current
Compilation units unless the @code{export_constants} pseudo declaration has been used.

When given the option @code{-ffi}, CHICKEN will compile a C/C++ file in ``Scheme'' mode, that is,
it wraps the C/C++ source inside @code{#>! ... <#} and compiles it while generating Scheme
bindings for exported definitions.

Keep in mind that this is not a fully general C/C++ parser. Taking an arbitrary headerfile and feeding
it to CHICKEN will in most cases not work or generate riduculuous amounts of code. This FFI
facility is for carefully written headerfiles, and for declarations directly embedded into
Scheme code.

@node Pseudo declarations
@subsection Pseudo declarations

Using the @code{__declare(DECL, VALUE)} form, pseudo declarations can be embedded into
processed C/C++ code to provide additional control over the wrapper generation. Pseudo declarations
will be ignored when processed by the system's C/C++ compiler.

@itemize

@item abstract [values: <string>]
Marks the C++ class given in @code{<string>} as being abstract, i.e. no constructor will
be defined. Alternatively, a class definition may be prefixed with @code{__abstract}.

@item class_finalizers [values: yes, no]
Automatically generates calls to @code{set-finalizer!} so that any unused references to
instances of subsequently defined C++ class wrappers will be destroyed. This should be used
with care: if the embedded C++ object which is represented by the reclaimed TinyCLOS instance
is still in use in foreign code, then unpredictable things will happen.

@item destructor_name [values: <string>]
Specifies an alternative name for destructor methods (the default is @code{destroy}.

@item export_constants [values: yes, no]
Define a global variable for constant-declarations (as with @code{#define} or @code{enum}),
making the constant available outside the current compilation unit. Use the values
@code{yes}/@code{1} for switching constant export on, or @code{no}/@code{0} for switching
it off.

@item exception_handler [values: <string>]
Defines C++ code to be executed when an exception is triggered inside a C++ class member
function. The code should be one or more @code{catch} forms that perform any actions 
that should be taken in case an exception is thrown by the wrapped member function:

@verbatim
#>!
__declare(exception_handler, "catch(...) { return 0; }")

class Foo {
 public:
  Foo *bar(bool f) { if(f) throw 123; else return this; }
};
<#

(define f1 (make <Foo>))
(print (bar f1 #f))
(print (bar f1 #t))
@end verbatim

will print @code{<Foo>} and @code{#f}, respectively.

@item full_specialization [values: yes, no]
Enables ``full specialization'' mode. In this mode all wrappers for functions, member functions
and static member functions are created as fully specialized TinyCLOS methods. This can be
used to handle overloaded C++ functions properly. Only a certain set of foreign argument types
can be mapped to TinyCLOS classes, as listed in the following table:

@table @code
@item char
<char>
@item bool
<bool>
@item c-string
<string>
@item unsigned-char
<exact>
@item byte
<exact>
@item unsigned-byte
<exact>
@item [unsigned-]int
<exact>
@item [unsigned-]short
<exact>
@item [unsigned-]long
<integer>
@item [unsigned-]integer
<integer>
@item float
<inexact>
@item double
<inexact>
@item (enum _)char
<exact>
@item (const T)char
(as T)
@item (function ...)
<pointer>
@item c-pointer
<pointer>
@item (pointer _)
<pointer>
@item (c-pointer _)
<pointer>
@item u8vector
<u8vector>
@item s8vector
<s8vector>
@item u16vector
<u16vector>
@item s16vector
<s16vector>
@item u32vector
<u32vector>
@item s32vector
<s32vector>
@item f32vector
<f32vector>
@item f64vector
<f64vector>
@end table


All other foreign types are specialized as @code{<top>}.

Full specialization can be enabled globally, or only for sections of code by
enclosing it in

@verbatim
__declare(full_specialization, yes)
...
int foo(int x);
int foo(char *x);
...
__declare(full_specialization, no)
@end verbatim

Alternatively, member function definitions may be prefixed by @code{__specialize} for specializing
only specific members.

@item prefix [values: <string>, no, 0]

Sets a prefix that should be be added to all generated Scheme identifiers. For example

@verbatim
__declare(prefix, "mylib:")
#define SOME_CONST     42
@end verbatim

would generate the following code:

@verbatim
(define-constant mylib:SOME_CONST 42)
@end verbatim

To switch prefixing off, use the values @code{no} or @code{0}.

@item rename [value: <string>]

Defines to what a certain C/C++ name should be renamed. The value for this declaration
should have the form @code{"<c-name>;<scheme-name>"}, where @code{<c-name>} specifies
the C/C++ identifier occurring in the parsed text and @code{<scheme-name>} gives
the name used in generated wrapper code.

@item scheme [value: <string>]

Embeds the Scheme expression @code{<string>} in the generated Scheme code.

@item substitute [value: <string>]

Declares a name-substitution for all generated Scheme identifiers. The value for this
declaration should be a string containing a regular expression and a replacement string
(seperated by the @code{;} character):

@verbatim
__declare(substitute, "^SDL_;sdl:")

extern void SDL_Quit();
@end verbatim

generates

@verbatim
(define sdl:Quit
  (foreign-lambda integer "SDL_Quit") )
@end verbatim

@item transform [values: <string>]

Defines an arbitrary transformation procedure for names that match a given regular expression.
The value should be a string containing a regular expression and a Scheme expression that
evaluates to a procedure of one argument. If the regex matches, the procedure will be called
at compile time with the match-result (as returned by @code{string-match}) and should return
a string with the desired transformations applied:

@verbatim
(require-for-syntax 'srfi-13)

#>!
__declare(transform, "([A-Z]+)_(.*);(lambda (x) (string-append (cadr x) \"-\" (string-downcase (caddr x))))")

void FOO_Bar(int x) { return x * 2; }
<#

(print (FOO-bar 33))
@end verbatim

@item type [value: <string>]

Declares a foreign type transformation, similar to @code{define-foreign-type}. 
The value should be a list of two to four items, separated by the @code{;} character:
a C typename, a Scheme foreign type specifier and optional argument- and result-value
conversion procedures.

@verbatim
;;;; foreign type that converts to unicode (assumes 4-byte wchar_t):
;
; - Note: this is rather kludgy is only meant to demonstrate the `type'
;         pseudo-declaration

(require-extension srfi-4)

(define mbstowcs (foreign-lambda int "mbstowcs" nonnull-u32vector c-string int))

(define (str->ustr str)
  (let* ([len (string-length str)]
         [us (make-u32vector (add1 len) 0)] )
    (mbstowcs us str len)
    us) )

#>!
__declare(type, "unicode;nonnull-u32vector;str->ustr")

static void foo(unicode ws)
{
  printf("\"%ls\"\n", ws);
}
<#

(foo "this is a test!")
@end verbatim

@end itemize

@node Grammar
@subsection Grammar

The parser understand the following grammar:

@verbatim
PROGRAM = PPCOMMAND
        | DECLARATION ";"

PPCOMMAND = "#define" ID [TOKEN ...]
          | "#ifdef" ID
          | "#ifndef" ID
          | "#else"
          | "#endif"
          | "#undef" ID
          | "#error" TOKEN ...
          | "#include" INCLUDEFILE
          | "#pragma" TOKEN ...

DECLARATION = FUNCTION
            | VARIABLE
            | ENUM
            | TYPEDEF
            | CLASS
            | CONSTANT
            | "struct" ID
            | "__declare" "(" PSEUDODECL "," <tokens> ")"

INCLUDEFILE = "\"" ... "\""
            | "<" ... ">"

FUNCTION = {"__callback" | "__specialize" | "__discard"} [STORAGE] TYPE ID "(" TYPE [ID] "," ... ")" [CODE]
         | {"__callback" | "__specialize" | "__discard"} [STORAGE] TYPE ID "(" "void" ")" [CODE]

VARIABLE = [STORAGE] TYPE ID ["=" INITDATA]

STORAGE = "extern" | "static" | "volatile" | "inline"

CONSTANT = "const" TYPE ID "=" INITDATA

PSEUDODECL = "export_constants"
           | "prefix"
           | "substitute"
           | "abstract"
           | "type"
           | "scheme"
           | "rename"
           | "transform"
           | "full_specialization"
           | "destructor_name"
           | "class_finalizers"
           | "exception_handler"

ENUM = "enum" "{" ID ["=" NUMBER] "," ... "}"

TYPEDEF = "typedef" TYPE ["*" ...] ID

TYPE = ["const"] BASICTYPE [("*" ... | "&" | "<" TYPE "," ... ">" | "(" "*" [ID] ")" "(" TYPE "," ... ")")]

BASICTYPE = ["unsigned" | "signed"] "int" 
          | ["unsigned" | "signed"] "char" 
          | ["unsigned" | "signed"] "short" 
          | ["unsigned" | "signed"] "long" 
          | ["unsigned" | "signed"] "__byte" 
          | "float"
          | "double"
          | "void"
          | "bool"
          | "__bool"
          | "__scheme_value"
          | "__fixnum"
          | "struct" ID
          | "union" ID
          | "enum" ID
          | ID

CLASS = ["__abstract"] "class" ID [":" [QUALIFIER] ID "," ...] "{" MEMBER ... "}"

MEMBER = [QUALIFIER ":"] ["virtual"] (MEMBERVARIABLE | CONSTRUCTOR | DESTRUCTOR | MEMBERFUNCTION)

MEMBERVARIABLE = TYPE ID ["=" INITDATA]

MEMBERFUNCTION = {"__callback" | "static" | "__specialize" | "__discard"} TYPE ID "(" TYPE [ID] "," ... ")" ["const"] ["=" "0"] [CODE]
               | {"__callback" | "static" | "__specialize" | "__discard"} TYPE ID "(" "void" ")" ["const"] ["=" "0"] [CODE]

CONSTRUCTOR = ["__callback"] ["explicit"] ID "(" TYPE [ID] "," ... ")" [BASECONSTRUCTORS] [CODE]

DESTRUCTOR = ["__callback"] "~" ID "(" ["void"] ")" [CODE]

QUALIFIER = ("public" | "private" | "protected")

NUMBER = <a C integer or floating-point number, in decimal, octal or hexadecimal notation>

INITDATA = <everything up to end of chunk>

BASECONSTRUCTORS = <everything up to end of chunk>

CODE = <everything up to end of chunk>
@end verbatim

The following table shows how argument-types are translated:


@table @code
@item [unsigned] char
char
@item [unsigned] short
[unsigned-]short
@item [unsigned] int
[unsigned-]integer
@item [unsigned] long
[unsigned-]long
@item float
float
@item double
double
@item bool
int
@item __bool
int
@item __fixnum
int
@item __scheme_value
scheme-object
@item char *
c-string
@item signed char *
s8vector
@item [signed] short *
s16vector
@item [signed] int *
s32vector
@item [signed] long *
s32vector
@item unsigned char *
u8vector
@item unsigned short *
u16vector
@item unsigned int *
u32vector
@item unsigned long *
u32vector
@item float *
f32vector
@item double *
f64vector
@item CLASS *
(instance CLASS <CLASS>)
@item TYPE *
(pointer TYPE)
@item TYPE 
&(ref TYPE)
@item TYPE<T1, ...>
(template TYPE T1 ...)
@item TYPE1 (*)(TYPE2, ...)
(function TYPE1 (TYPE2 ...))
@end table


The following table shows how result-types are translated:

@table @code
@item void
void
@item [unsigned] char
char
@item [unsigned] short
[unsigned-]short
@item [unsigned] int
[unsigned-]integer
@item [unsigned] long
[unsigned-]long
@item float
float
@item double
double
@item bool
bool
@item __bool
bool
@item __fixnum
int
@item __scheme_value
scheme-object
@item char *
c-string
@item CLASS *
(instance CLASS <CLASS>)
@item TYPE *
(pointer TYPE)
@item TYPE 
&(ref TYPE)
@item TYPE<T1, ...>
(template TYPE T1 ...)
@item TYPE1 (*)(TYPE2, ...)
(function TYPE1 (TYPE2 ...))
@end table


@node C notes
@subsection C notes

Foreign variable definitions for macros are not exported from the current compilation unit, but
definitions for C variables and functions are. 

@code{foreign-parse} does not embed the text into
the generated C file, use @code{foreign-declare} for that (or even better, use the @code{#>! ... <#} syntax
which does both).

Functions with variable number of arguments are not supported.

@node C++ notes
@subsection C++ notes

Each C++ class defines a TinyCLOS class, which is a subclass of @code{<c++-object>}. Instances of this class
contain a single slot named @code{this}, which holds a pointer to a heap-allocated C++ instance.
The name of the TinyCLOS class is obtained by putting the C++ classname between angled brackets (@code{<...>}).
TinyCLOS classes are not seen by C++ code.

The C++ constructor is invoked by the @code{initialize} generic, which accepts as many arguments
as the constructor. If no constructor is defined, a default-constructor will be provided taking no arguments.
To allow creating class instances from pointers created in foreign code, the @code{initialize}
generic will optionally accept an arguments list of the form @code{'this POINTER}, where @code{POINTER}
is a foreign pointer object. This will create a TinyCLOS instance for the given C++ object.

To release the storage allocated for a C++ instance invoke the @code{destroy} generic
(the name can be changed by using the @code{destructor_name} pseudo declaration).

Static member functions are wrapped in a Scheme procedure named @code{<class>::<member>}.

Member variables and non-public member functions are ignored. 

Virtual member functions are not seen by C++ code. Overriding a virtual member function with a TinyCLOS
method will not work when the member function is called by C++.

Operator functions and default arguments are not supported.

Exceptions must be explicitly handled by user code and may not be thrown beyond an invocation
of C++ by Scheme code.


@node C interface
@section C interface


The following functions and macros are available for C code that invokes
Scheme:



@deftypefn {C function} void C_save (C_word x)
Saves the Scheme data object @code{x} on the temporary stack.
@end deftypefn

@deftypefn {C macro} C_word C_fix (int integer)
@deftypefnx {C macro} C_word C_make_character (int char_code)
@deftypefnx {C macro} C_word C_SCHEME_END_OF_LIST
@deftypefnx {C macro} C_word C_SCHEME_END_OF_FILE
@deftypefnx {C macro} C_word C_SCHEME_FALSE
@deftypefnx {C macro} C_word C_SCHEME_TRUE
These macros return immediate Scheme data objects.
@end deftypefn

@deftypefn {C function} C_word C_string (C_word **ptr, int length, char *string)
@deftypefnx {C function} C_word C_string2 (C_word **ptr, char *zero_terminated_string)
@deftypefnx {C function} C_word C_intern2 (C_word **ptr, char *zero_terminated_string)
@deftypefnx {C function} C_word C_intern3 (C_word **ptr, char *zero_terminated_string, C_word initial_value)
@deftypefnx {C function} C_word C_pair (C_word **ptr, C_word car, C_word cdr)
@deftypefnx {C function} C_word C_flonum (C_word **ptr, double number)
@deftypefnx {C function} C_word C_int_to_num (C_word **ptr, int integer)
@deftypefnx {C function} C_word C_mpointer (C_word **ptr, void *pointer)
@deftypefnx {C function} C_word C_vector (C_word **ptr, int length, ...)
@deftypefnx {C function} C_word C_list (C_word **ptr, int length, ...)
These functions allocate memory from @code{ptr} and initialize a fresh
data object. The new data object is returned. @code{ptr} should be the
@b{address} of an allocation pointer created with @code{C_alloc}.
@end deftypefn

@deftypefn {C macro} C_word* C_alloc (int words)
Allocates memory from the C stack (@code{C_alloc}) and returns a pointer to
it. @code{words} should be the number of words needed for all data
objects that are to be created in this function.  Note that stack-allocated
data objects have to be passed to Scheme callback functions, or they will
not be seen by the garbage collector. This is really only usable for
callback procedure invocations, make sure not to use it in normal code,
because the allocated memory will be re-used after the foreign procedure
returns. When invoking Scheme callback procedures a minor garbage
collection is performed, so data allocated with @code{C_alloc}
will already have moved to a safe place.
@end deftypefn

@deftypefn {C macro} int C_SIZEOF_LIST (int length)
@deftypefnx {C macro} int C_SIZEOF_STRING (int length)
@deftypefnx {C macro} int C_SIZEOF_VECTOR (int length)
@deftypefnx {C macro} int C_SIZEOF_INTERNED_SYMBOL (int length)
@deftypefnx {C macro} int C_SIZEOF_PAIR
@deftypefnx {C macro} int C_SIZEOF_FLONUM
@deftypefnx {C macro} int C_SIZEOF_POINTER
@deftypefnx {C macro} int C_SIZEOF_LOCATIVE
@deftypefnx {C macro} int C_SIZEOF_TAGGED_POINTER
These are macros that return the size in words needed for a data object
of a given type.
@end deftypefn

@deftypefn {C macro} int C_character_code (C_word character)
@deftypefnx {C macro} int C_unfix (C_word fixnum)
@deftypefnx {C macro} double C_flonum_magnitude (C_word flonum)
@deftypefnx {C function} char* C_c_string (C_word string)
@deftypefnx {C function} int C_num_to_int (C_word fixnum_or_flonum)
@deftypefnx {C function} void* C_pointer_address (C_word pointer)
These macros and functions can be used to convert Scheme data objects
back to C data.
@end deftypefn

@deftypefn {C macro} int C_header_size (C_word x)
@deftypefnx {C macro} int C_header_bits (C_word x)
Return the number of elements and the type-bits of the non-immediate
Scheme data object @code{x}.
@end deftypefn

@deftypefn {C macro} C_word C_block_item (C_word x, int index)
This macro can be used to access slots of the non-immediate Scheme data
object @code{x}.  @code{index} specifies the index of the slot to
be fetched, starting at 0. Pairs have 2 slots, one for the @b{car}
and one for the @b{cdr}. Vectors have one slot for each element.
@end deftypefn

@deftypefn {C macro} void* C_data_pointer (C_word x)
Returns a pointer to the data-section of a non-immediate Scheme object.
@end deftypefn

@deftypefn {C macro} C_word C_make_header (C_word bits, C_word size)
A macro to build a Scheme object header from its bits and size parts.
@end deftypefn

@deftypefn {C function} C_word C_mutate (C_word *slot, C_word val)
Assign the Scheme value @code{val} to the location specified by
@code{slot}.  If the value points to data inside the nursery (the first
heap-generation), then the garbage collector will remember to handle the
data appropriately. Assigning nursery-pointers directly will otherwise
result in lost data.
@end deftypefn

@deftypefn {C macro} C_word C_symbol_value (C_word symbol)
Returns the global value of the variable with the name @code{symbol}.
@end deftypefn

@deftypefn {C function} void C_gc_protect (C_word *ptrs[], int n)
Registers @code{n} variables at address @code{ptrs} to be garbage collection roots.
The locations should not contain pointers to data allocated in the nursery, only
immediate values or pointers to heap-data are valid. Any
assignment of potential nursery data into a root-array should be done
via @code{C_mutate()}. The variables have to be initialized to sensible values
before the next garbage collection starts (when in doubt, set all locations
in @code{ptrs} to @code{C_SCHEME_UNDEFINED})
@code{C_gc_protect} may not called before the runtime system has been
iniitalized (either by @code{CHICKEN_initialize}, @code{CHICKEN_run} or
@code{CHICKEN_invoke}.
@end deftypefn

@deftypefn {C function} void C_gc_unprotect (int n)
Removes the last @code{n} registered variables from the set of
root variables.
@end deftypefn




An example:

@verbatim
% cat foo.scm
#>
extern int callout(int, int, int);
<#

(define callout (foreign-callback-lambda int "callout" int int int))

(define-external (callin (scheme-object xyz)) int
  (print "This is 'callin': " xyz)
  123)

(print (callout 1 2 3))

% cat bar.c
#include <stdio.h>
#include "chicken.h"

extern int callout(int, int, int);
extern int callin(C_word x);

int callout(int x, int y, int z)
{
  C_word *ptr = C_alloc(C_SIZEOF_LIST(3));
  C_word lst;

  printf("This is 'callout': %d, %d, %d\n", x, y, z);
  lst = C_list(&ptr, 3, C_fix(x), C_fix(y), C_fix(z));
  return callin(lst);  /* Note: `callin' will have GC'd the data in `ptr' */
}

% chicken foo.scm -quiet
% gcc foo.c bar.c -o foo `chicken-config -cflags -libs`
% foo
This is 'callout': 1, 2, 3
This is 'callin': (1 2 3)
123
@end verbatim


@b{Notes:}
@itemize

@item Scheme procedures can call C functions, and C functions can call
Scheme procedures, but for every pending C stack frame, the available
size of the first heap generation (the ``nursery'') will be decreased,
because the C stack is identical to the nursery. On systems with a small
nursery this might result in thrashing, since the C code between the
invocation of C from Scheme and the actual calling back to Scheme might
build up several stack-frames or allocates large amounts of stack data.
To prevent this it is advisable to increase the default nursery size,
either when compiling the file (using the @code{-nursery} option)
or when running the executable (using the @code{-:s} runtime option).

@item Calls to Scheme/C may be nested arbitrarily, and Scheme
continuations can be invoked as usual, but keep in mind that C stack
frames will not be recovered, when a Scheme procedure call from C does
not return normally.

@item When multiple threads are running concurrently, and control switches
from one thread to another, then the continuation of the current thread
is captured and saved. Any pending C stack frame still active from a
callback will remain on the stack until the threads is re-activated
again. This means that in a multithreading situation, when C callbacks
are involved, the available nursery space can be smaller than expected.
So doing many nested Scheme->C->Scheme calls can reduce the available
memory up to the point of thrashing. It is advisable to have only a
single thread with pending C stack-frames at any given time.

@item Pointers to Scheme data objects should not be stored in local or
global variables while calling back to Scheme.  Any Scheme object not
passed back to Scheme will be reclaimed or moved by the garbage collector.

@item Calls from C to Scheme are never tail-recursive.

@item Continuations captured via @code{call-with-current-continuation}
and passed to C code can be invoked like any other Scheme procedure.

@end itemize


@node chicken-setup
@chapter chicken-setup

@menu
* Extension libraries::
* Installing extensions::
* Creating extensions::
* Procedures and macros available in setup scripts::
* Examples for extensions::
* @code{chicken-setup} reference::
@end menu


@node Extension libraries
@section Extension libraries

Extension libraries are extensions to the core functionality provided
by the basic CHICKEN system, to be built and installed separately.
The mechanism for loading compiled extensions is based on dynamically
loadable code and as such is only available on systems on which
loading compiled code at runtime is supported. Currently this are
most UNIX-compatible platforms that provide the @code{libdl} functionality
like Linux, Solaris, BSD or Mac OS X. Windows with Cygwin is supported as well. 

Note: Extension may also be normal applications or shell scripts.


@node Installing extensions
@section Installing extensions

To install an extension library, run the @code{chicken-setup} program
with the extension name as argument. If the extension consists of a 
single Scheme file, then it is compiled and installed in the extension
@emph{repository}. If it is an archive containing addition files, then
the files are extracted and the contained @emph{setup} script is
executed. This setup script is a normal Scheme source file, which
will be interpreted by @code{chicken-setup}. The complete language supported
by @code{csi} is available, and the library units 
@code{srfi-1 regex utils posix tcp} are loaded. Additional
libraries can of course be loaded at run-time.

The setup script should perform all necessary steps to build the 
new library (or application). After a successful build, the extension
can be installed by invoking one of the procedures
@code{install-extension}, @code{install-program} or @code{install-script}.
These procedures will copy a number of given files into the extension
repository or in the path where the CHICKEN executables are located (in the
case of executable programs or scripts). Additionally the list of
installed files, and user-defined metadata is stored in the repository.


@node Creating extensions
@section Creating extensions

Extensions can be created by creating an archive named @code{EXTENSION.egg}
containing all needed files plus a @code{.setup} script in the root directory.
After @code{chicken-setup} has extracted the files, the setup script will be
invoked. There are no additional constraints on the structure of the archive,
but the setup script has to be in the root path of the archive.


@node Procedures and macros available in setup scripts
@section Procedures and macros available in setup scripts

@deffn {procedure} install-extension
@lisp
(install-extension ID FILELIST [INFOLIST])
@end lisp
Installs extension library with the name @code{ID}. All files given in the list of strings
@code{FILELIST} will be copied to the extension repository.
The optional argument @code{INFOLIST} should be an association list that
maps symbols to values, this list will be stored as @code{ID.setup} at the same
location as the extension code. Currently the following properties are used:

@deffn {property} syntax
@lisp
(syntax)
@end lisp
Marks the extension as syntax-only. No code is compiled, the extension is intended
as a file containing macros to be loaded at compile/macro-expansion time.
@end deffn

@deffn {property} require-at-runtime
@lisp
(require-at-runtime ID ...)
@end lisp
Specifies extensions that should be loaded (via @code{require}) at runtime. This is mostly
useful for syntax extensions that need additional support code at runtime.
@end deffn

@deffn {property} version
@lisp
(version STRING)
@end lisp
Specifies version string.
@end deffn

All other properties are currently ignored. The @code{FILELIST} argument may also be a single
string.

@end deffn

@deffn {procedure} install-program
@lisp
(install-program ID FILELIST [INFOLIST])
@end lisp
Similar to @code{install-extension}, but installs an executable program in the
executable path (usually @code{/usr/local/bin}.
@end deffn

@deffn {procedure} install-script
@lisp
(install-program ID FILELIST [INFOLIST])
@end lisp
Similar to @code{install-program}, but additionally changes the file permissions of all
files in @code{FILELIST} to executable (for installing shell-scripts).
@end deffn


@deffn {syntax} run
@lisp
(run FORM ...)
@end lisp
Runs the shell command @code{FORM}, which is wrapped in an implicit @code{quasiquote}. 
@end deffn

@deffn {syntax} make
@lisp
(make ((TARGET (DEPENDENT ...) COMMAND ...) ...) ARGUMENTS)
@end lisp
A ``make'' macro that executes the expressions @code{COMMAND ...}, when any of the dependents
@code{DEPENDENT ...} have changed, to build @code{TARGET}. This is the same as the @code{make}
extension, which is available separately. For more information, see
@uref{http://www.call-with-current-continuation.org/eggs/make.html, make}.
@end deffn

@deffn {procedure} patch
@lisp
(patch WHICH REGEX SUBST)
@end lisp
Replaces all occurrences of the regular expression @code{REGEX} with the string @code{SUBST},
in the file given in @code{WHICH}. If @code{WHICH} is a string, the file will be patched and
overwritten. If @code{WHICH} is a list of the form @code{OLD NEW}, then a different file named
@code{NEW} will be generated.
@end deffn


@node Examples for extensions
@section Examples for extensions

The simplest case is a single file that does not export any syntax. For example

@lisp
;;;; hello.scm

(define (hello name)
  (print "Hello, " name " !") )
@end lisp

After entering 

@verbatim
$ chicken-setup hello
@end verbatim

at the shell prompt, the file @code{hello.scm} will be compiled into a dynamically loadable library,
with the default compiler options @code{-optimize-level 2 -debug-level 0 -shared}. If the
compilation succeeds, @code{hello.so} will be stored in the repository, together with a file named
@code{hello.setup} (not to be confused with a setup script - this @code{.setup} file just contains
an a-list with metadata).

Use it like any other CHICKEN extension:

@verbatim
$ csi -quiet
#;> (require-extension hello)
; loading /usr/local/lib/chicken/hello.so ...
#;> (hello "me")
Hello, me!
#;>
@end verbatim

For more elaborate build operations, when installing applications or scripts, or when
additional metadata should be stored for an extension, a @code{setup} script is required
and the script and all additional files should be packaged in a gzipped @code{tar} archive.

Here we create a simple application:

@lisp
;;;; hello2.scm

(require-extension extras)  ; needed for `printf'

(print "Hello, ")
(for-each (lambda (x) (printf "~A " x)) (command-line-arguments))
(print "!")
@end lisp

We also need a setup script:

@lisp
;;;; hello2.setup

(run (csc hello2.scm))  ; compile `hello2'
(install-program 'hello2 "hello2") ; name of the extension and files to be installed
@end lisp

To use it, just run @code{chicken-setup} in the same directory:

@verbatim
$ chicken-setup hello2
@end verbatim

Now the program @code{hello2} will be installed in the same location as the other CHICKEN
tools (like @code{chicken}, @code{csi}, etc.), which will normally be @code{/usr/local/bin}.
Note that you need write-permissions for those locations.

Uninstallation is just as easy:

@verbatim
$ chicken-setup -uninstall hello2
@end verbatim

@code{chicken-setup} provides a @code{make} tool, so building operations can be of
arbitrary complexity. When running @code{chicken-setup} with an argument @code{NAME},
for which no associated file @code{NAME.setup}, @code{NAME.egg} or @code{NAME.scm}
exists will ask you to download the extension via HTTP from the default URL
@code{http://www.call-with-current-continuation.org/eggs}. You can use the 
@code{-host} option to specify an alternative source location.

Finally a somewhat more complex example: We want to package a syntax extension with
additional support code that is to be loaded at run-time of any Scheme code that
uses that extension. We create a ``glass'' lambda, a procedure with free variables
that can be manipulated from outside:

@lisp
;;;; glass.scm

(define-macro (glass-lambda llist vars . body)
  ;; Low-level macros are fun!
  (let ([lvar (gensym)]
	[svar (gensym)] 
	[x (gensym)]
	[y (gensym)] 
	[yn (gensym)] )
    `(let ,(map (lambda (v) (list v #f)) vars)
       (define (,svar ,x . ,y)
	 (let* ([,yn (pair? ,y)]
		[,y (and ,yn (car ,y))] )
	   (case ,x
	     ,@@(map (lambda (v)
		      `([,v] (if ,yn 
				 (set! ,v ,y)
				 ,v) ) )
		    vars)
	     (else (error "variable not found" ,x)) ) ) )
       (define ,lvar (lambda ,llist ,@@body))
       (extend-procedure ,lvar ,svar) ) ) )
@end lisp

Here some support code that needs to be loaded at runtime:

@lisp
;;;; glass-support.scm

(require-extension lolevel)

(define glass-lambda-accessor procedure-data)
(define (glass-lambda-ref gl v) ((procedure-data gl) v))
(define (glass-lambda-set! gl v x) ((procedure-data gl) v x))
@end lisp

The setup script looks like this:

@lisp
(run (csc -s -O2 -d0 glass-support.scm))

(install-extension
  'glass
  '("glass.scm" "glass-support.so")
  '((syntax) (require-at-runtime glass-support)) )
@end lisp

The invocation of @code{install-extension} provides the files that
are to be copied into the extension repository, and a metadata list that
specifies that the extension @code{glass} is a syntax extension and that,
if it is declared to be used by other code (either with the @code{require-extension}
or @code{require-for-syntax} form), then client code should perform an implicit
@code{(require 'glass-support)} at startup.

This can be conveniently packaged as an ``egg'':

@verbatim
$ tar cfz glass.egg glass.setup glass.scm glass-support.scm
@end verbatim

And now we use it:

@verbatim
$ csi -quiet
#;> (require-extension glass)
; loading /usr/local/lib/chicken/glass.scm ...
; loading /usr/local/lib/chicken/glass-support.so ...
#;> (define foo (glass-lambda (x) (y) (+ x y)))
#;> (glass-lambda-set! foo 'y 99)
#;> (foo 33)
132
@end verbatim


@node @code{chicken-setup} reference
@section @code{chicken-setup} reference

Available options:

@itemize
@item @code{-help}
Show usage information and exit.
@item @code{-version}
Display version and exit.
@item @code{-repository [PATHNAME]}
When used without an argument, the path of the extension repository is displayed on standard
output. When given an argument, the repository pathname (and the @code{repository-path} parameter)
will be set to @code{PATHNAME} for all subsequent operations. The default repository path is
the installation library directory (usually @code{/usr/local/lib/chicken}), or (if set) the
directory given in the environment variable @code{CHICKEN_REPOSITORY}.
@item @code{-program-path [PATHNAME]}
When used without an argument, the path for executables is displayed on standard output. 
When given an argument, the program path for installing executables and scripts will be set to
@code{PATHNAME} for all subsequent operations.
@item @code{-host HOSTNAME[:PORT]}
Specifies alternative host for downloading extensions, optionally with a TCP port number (which
defaults to 80).
@item @code{-uninstall EXTENSION}
Removes all files that were installed for @code{EXTENSION} from the file-system, together
with any metadata that has been stored.
@item @code{-list}
List all installed extensions and exit.
@item @code{-run FILENAME}
Load and execute given file.
@item @code{-script FILENAME}
Executes the given Scheme source file with all remaining arguments and exit. The ``she-bang''
shell script header is recognized, so you can write Scheme scripts that use @code{chicken-setup}
just as with @code{csi}.
@item @code{-verbose}
Display additional debug information.
@item @code{-keep}
Keep temporary files and directories.
@end itemize

Note that the options are processed exactly in the order in which they appear in the command-line.


@node Additional files
@chapter Additional files


In addition to library units the following files are provided. Use them
by including the file in your code with the @code{include} special form.


@menu
* srfi-13-syntax.scm::          
* chicken-highlevel-macros.scm::  
* chicken-more-macros.scm::     
* chicken-ffi-macros.scm::      
* chicken-entry-points.scm::    
* chicken-default-entry-points.scm::  
* test-infrastructure.scm::     
@end menu

@node  srfi-13-syntax.scm
@section @code{srfi-13-syntax.scm}

This file provides the @code{let-string-start+end} syntax defined
in SRFI-13. @xref{Unit srfi-13}.


@node  chicken-highlevel-macros.scm
@section @code{chicken-highlevel-macros.scm}

This file contains highlevel (@code{syntax-case}) macro definitions
for all non-standard macros CHICKEN provides. Normally you don't directly use
this file, since it is loaded automatically by the compiler or interpreter,
when the @code{-hygienic} option is used.

If you intend to make highlevel macros (R5RS and/or @code{syntax-case}) available
at run-time (for example, for evaluating code at runtime that contains highlevel macros),
declare the @code{syntax-case} unit as used and install the macro system by hand,
as in this example:

@verbatim
(require-extension syntax-case)

(install-highlevel-macro-system)
@end verbatim

(This is basically what the @code{-hygienic-at-run-time} option does, but this
procedure gives you a little more control.)



@deffn {procedure} install-highlevel-macro-system
@lisp
(install-highlevel-macro-system FEATURE ...)
@end lisp
Installs the highlevel (R5RS / @code{syntax-case}) macro system in the running
program. @code{FEATURE} should be a symbol and selects the amount of non-standard
macros being provided. Possible features are:

@itemize
@item @code{r5rs}

The R5RS standard derived syntax, and only those.
@item @code{srfi-0}

SRFI-0 (@code{cond-expand})
@item @code{extensions}

R5RS standard derived syntax and all non-standard extension provided in CHICKEN
@end itemize

If no feature is give, @code{'r5rs} is assumed.
@end deffn




@node  chicken-more-macros.scm
@section @code{chicken-more-macros.scm}

This file contains the definitions of all non-standard syntax forms.
You normally don't use this file directly.


@node  chicken-ffi-macros.scm
@section @code{chicken-ffi-macros.scm}

This file contains the definitions of macros for interfacing to foreign code,
and the definitions contained in this file are automatically made
available in compiled code.


@node  chicken-entry-points.scm
@section @code{chicken-entry-points.scm}

This file contains the definition of the macros @code{define-entry-point}
and @code{define-embedded}. See the section ``Entry points'' earlier in this manual.


@node  chicken-default-entry-points.scm
@section @code{chicken-default-entry-points.scm}

This file contains boilerplate entry point definitions. See the section
``Entry points''. This file automatically includes @code{entry-points.scm}.


@node  test-infrastructure.scm
@section @code{test-infrastructure.scm}

This file provides a macro based unit testing facility based upon
expectations concerning evaluations of expressions. These functions return
tagged lists which contain the results of the test package, test case,
or expectations evaluated(there are a few other types of results dealing
with the gloss, todo, and skip macros detailed below). These result
lists are wired together during evaluation to form a large hierarchical
tree in memory.  This result tree is then passed to either user defined
functions which traverse the tree manipulating it in any way desired, or
passed to a supplied (read: defined already in test-infrastructure.scm)
function which manipulates it in a simple way usually producing human
readable or html generated output. API functions to deal with the result
types are supplied and the representation of the result is black boxed to
the user. It is a violation of encapsulation to inspect the representation
directly, and it may change unpredictably in the future.

@menu
* The Test Package Macro API::  
* The Test Case Macro API::     
* The Expectation Macro API::   
* Result Object API::           
* Test Package Result Object API::  
* Test Case Result Object API::  
* Single Clause Style Expectation::  
* Equivalence Style Expectation::  
* Tolerance Style Expectation::  
* Various Helper API::          
* Termination API::             
* Destructor Object API::       
* Todo API::                    
* Gloss API::                   
* Skip API::                    
* Side Effect API::             
* Miscellaneous API::           
* Analysis of the Result Tree::  
* Output Generation API::       
* Example Usages of the Test Suite Infrastructure::  
@end menu

@node The Test Package Macro API
@subsection The Test Package Macro API

This macro will evaluate in a left to right fashion the clauses inside
it. Clauses can only be certain things, detailed below. All of the clauses
are executed, except of course if you bail out of the test package with
the escape procedure mechanism.  Test packages may nest indefinitely.


@deffn {macro} test-package
@lisp
(test-package MESSAGE DESTNAME TERMNAME CLAUSES)
(test-package MESSAGE DESTNAME TERMNAME (BINDINGS) CLAUSES)
(test-package MESSAGE DESTNAME TERMNAME (warn MESSAGE) CLAUSES)
(test-package MESSAGE DESTNAME TERMNAME (warn MESSAGE) (BINDINGS) CLAUSES)
@end lisp
@itemize
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{DESTNAME} is an unquoted symbol for an automatic destructor 
object that gets called when the test package completes for any reason. 
This symbol is bound to a destructor object and is available to you in 
the CLAUSES section of the test package. See below for the description
of the destructor object interface.
@item @code{TERMNAME} is an unquoted symbol for an escape procedure
available in the body of the test package, usually, this escape
procedure is passed to @code{(terminate ...)} which calls it
for you and performs other tasks. It is not recommended to call the escape
procedure directly.
@item @code{(warn MESSAGE)} allows you to specify a warning object, usually
a string, that gets associated with the test package. The
@code{warn} function name is actually a syntax reserved word
in the macro.
@item @code{BINDINGS} are let-style bindings that you may create and exist in
the lexical scope of the test package.
@item @code{CLAUSES} are uses of @code{(test-case ...)} macros
along with @code{(gloss ...)}, @code{(todo ...)},
@code{(skip ...)}, and @code{(terminate ...)} macros. While
you may use the @code{(expect-* ...)} style macros directly in
a test package, doing so is not recommended. If the expectation
fails, the test package macro will continue evaluating until
all clauses are evaluated or the escape procedure mechanism is
activated. This is different than a test-case macro where upon
discovery of a failed expectation, evaluation stops immediately.
@end itemize
@end deffn


@node The Test Case Macro API
@subsection The Test Case Macro API

This macro will evaluate in a left to right fashion the clauses inside
it @b{stopping at the first failed expectation}. Clauses can only
be certain things as detailed below. You may also stop the execution of
expectations if you bail out of the test case with the escape procedure
mechanism.  Test cases may @b{NOT} nest.


@deffn {macro} test-case
@lisp
(test-case MESSAGE DESTNAME TERMNAME CLAUSES)
(test-case MESSAGE DESTNAME TERMNAME (BINDINGS) CLAUSES)
(test-case MESSAGE DESTNAME TERMNAME (warn MESSAGE) CLAUSES)
(test-case MESSAGE DESTNAME TERMNAME (warn MESSAGE) (BINDINGS) CLAUSES)
@end lisp
@itemize
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{DESTNAME} is an unquoted symbol for an automatic destructor 
object that gets called when the test case completes for any reason. 
This symbol is bound to a destructor object and is available to you in 
the CLAUSES section of the test package. See below for the description
of the destructor object interface.
@item @code{TERMNAME} is an unquoted symbol for an escape procedure
available in the body of the test case, usually, this escape
procedure is passed to @code{(terminate ...)} which calls it
for you and performs other tasks. It is not recommended to call the escape
procedure directly.
@item @code{(warn MESSAGE)} allows you to specify a warning object, usually
a string, that gets associated with the test case. The
@code{warn} function name is actually a syntax reserved word
in the macro.
@item @code{BINDINGS} are let-style bindings that you may create and exist in
the lexical scope of the test case.
@item @code{CLAUSES} are uses of @code{(expect-* ...)} macros
along with @code{(gloss ...)}, @code{(todo ...)},
@code{(skip ...)}, and @code{(terminate ...)} macros. It is
important to note that upon discovery of a failed expectation,
the test case stops its evaluation and returns with the previous
successful, and including the failed, expectations.
@end itemize
@end deffn



@node The Expectation Macro API
@subsection The Expectation Macro API

An expectation at its core simply evaluates its arguments and check to
see if it matches the expectation. The positive or negative result is
encapsulated, along with other things such as the unevaluated expressions
being checked and some messages supplied with each expectation into
a particular type of black box object that one can query with the
appropriate API calls(detailed below).

Expectations all have a descriptive message that can be bound to them,
along with an optional warning syntax detailed below. A design decision
was made to supply expectation macros for the usual types of expectations
a user needs because this reduced the abstractness of an expectation
into something more manageable. In a future release however, I will
supply a special expectation macro where you may supply any predicate
you wish along with a ``type tag'' of the predicate.


@deffn {macro} expect-zero
@lisp
(expect-zero MESSAGE CLAUSE)
(expect-zero MESSAGE (warn MESSAGE) CLAUSE)
@end lisp
@itemize
@item This expectation checks to see if the evaluated expression passed to it
is numerically equal to the exact integer zero.
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn MESSAGE)} allows you to specify a warning object, usually
a string, that gets associated with the expectation. The
@code{warn} function name is actually a syntax reserved word
in the macro.
@item @code{CLAUSE} is a single expression which should return a exact or
inexact integer.
@end itemize
@end deffn



@deffn {macro} expect-nonzero
@lisp
(expect-nonzero MESSAGE CLAUSE)
(expect-nonzero MESSAGE (warn MESSAGE) CLAUSE)
@end lisp
@itemize
@item This expectation checks to see if the evaluated expression passed to it
is numerically not equal to the exact integer zero.
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn MESSAGE)} allows you to specify a warning object, usually
a string, that gets associated with the expectation. The
@code{warn} function name is actually a syntax reserved word
in the macro.
@item @code{CLAUSE} is a single expression which should return an exact or
inexact integer.
@end itemize
@end deffn



@deffn {macro} expect-true
@lisp
(expect-true MESSAGE CLAUSE)
(expect-true MESSAGE (warn MESSAGE) CLAUSE)
@end lisp
@itemize
@item This expectation checks to see if the evaluated expression passed to it
is the value #t.
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn MESSAGE)} allows you to specify a warning object, usually
a string, that gets associated with the expectation. The
@code{warn} function name is actually a syntax reserved word
in the macro.
@item @code{CLAUSE} is a single expression which should return #t.
@end itemize
@end deffn



@deffn {macro} expect-false
@lisp
(expect-false MESSAGE CLAUSE)
(expect-false MESSAGE (warn MESSAGE) CLAUSE)
@end lisp
@itemize
@item This expectation checks to see if the evaluated expression passed to it
is the value #f.
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn MESSAGE)} allows you to specify a warning object, usually
a string, that gets associated with the expectation. The
@code{warn} function name is actually a syntax reserved word
in the macro.
@item @code{CLAUSE} is a single expression which should return #t.
@end itemize
@end deffn



@deffn {macro} expect-eq?
@lisp
(expect-eq? MESSAGE EXPECTED CLAUSE)
(expect-eq? MESSAGE (warn MESSAGE) EXPECTED CLAUSE)
@end lisp
@itemize
@item This expectation checks to see if @code{(eq? EXPECTED CLAUSE)} is true.
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn MESSAGE)} allows you to specify a warning object, usually
a string, that gets associated with the expectation. The
@code{warn} function name is actually a syntax reserved word
in the macro.
@item @code{EXPECTED} is a single expression which is evaluated and represents
the value the @code{CLAUSE} @b{must} be eq? to in order for this
expectation to return a positive result.
@item @code{CLAUSE} is a single expression which, when evaluated must return
an object where an eq? of this result and the @code{EXPECTED} expression
is #t.
@item The result object this macro produce shall contain the unevaluated 
@code{CLAUSE} expression as a field, but not an unevaluated @code{EXPECTED}
expression.
@end itemize
@end deffn



@deffn {macro} expect-eqv?
@lisp
(expect-eqv? MESSAGE EXPECTED CLAUSE)
(expect-eqv? MESSAGE (warn MESSAGE) EXPECTED CLAUSE)
@end lisp
@itemize
@item This expectation checks to see if @code{(eqv? EXPECTED CLAUSE)} is 
true.
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn MESSAGE)} allows you to specify a warning object, usually
a string, that gets associated with the expectation. The
@code{warn} function name is actually a syntax reserved word
in the macro.
@item @code{EXPECTED} is a single expression which is evaluated and represents
the value the @code{CLAUSE} @b{must} be eqv? to in order for this
expectation to return a positive result.
@item @code{CLAUSE} is a single expression which, when evaluated must return
an object where an eqv? of this result and the @code{EXPECTED} expression
is #t.
@item The result object this macro produce shall contain the unevaluated 
@code{CLAUSE} expression as a field, but not an unevaluated @code{EXPECTED}
expression.
@end itemize
@end deffn



@deffn {macro} expect-equal?
@lisp
(expect-equal? MESSAGE EXPECTED CLAUSE)
(expect-equal? MESSAGE (warn MESSAGE) EXPECTED CLAUSE)
@end lisp
@itemize
@item This expectation checks to see if @code{(equal? EXPECTED CLAUSE)} is 
true.
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn MESSAGE)} allows you to specify a warning object, usually
a string, that gets associated with the expectation. The
@code{warn} function name is actually a syntax reserved word
in the macro.
@item @code{EXPECTED} is a single expression which is evaluated and represents
the value the @code{CLAUSE} @b{must} be equal? to in order for this
expectation to return a positive result.
@item @code{CLAUSE} is a single expression which, when evaluated must return
an object where an equal? of this result and the @code{EXPECTED} expression
is #t.
@item The result object this macro produce shall contain the unevaluated 
@code{CLAUSE} expression as a field, but not an unevaluated @code{EXPECTED}
expression.
@end itemize
@end deffn



@deffn {macro} expect-near?
@lisp
(expect-near? MESSAGE EXPECTED TOL CLAUSE)
(expect-near? MESSAGE (warn MESSAGE) EXPECTED TOL CLAUSE)
@end lisp
@itemize
@item This expectation checks to see if 
@code{(< (abs (- EXPECTED CLAUSE)) TOL)))} is true.
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn MESSAGE)} allows you to specify a warning object, usually
a string, that gets associated with the expectation. The
@code{warn} function name is actually a syntax reserved word
in the macro.
@item @code{EXPECTED} is a single expression which is evaluated and represents
the value the @code{CLAUSE} @b{must} be ``near'' to in order for this
expectation to return a positive result.
@item @code{CLAUSE} is a single expression which should return an inexact or 
exact number.
@item @code{TOL} is a single expression which, when evaluated must return a
tolerance value(usually a small inexact number like .0001).
@item The result object this macro produce shall contain the unevaluated 
@code{CLAUSE} expression as a field, but not the unevaluated @code{EXPECTED}
or @code{TOL} expression.
@end itemize
@end deffn



@deffn {macro} expect-positive
@lisp
(expect-positive MESSAGE CLAUSE)
(expect-positive MESSAGE (warn MESSAGE) CLAUSE)
@end lisp
@itemize
@item This expectation checks to see if the evaluated expression passed to it
is a positive value greater than zero.
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn MESSAGE)} allows you to specify a warning object, usually
a string, that gets associated with the expectation. The
@code{warn} function name is actually a syntax reserved word
in the macro.
@item @code{CLAUSE} is a single expression which should return an inexact or
exact number.
@end itemize
@end deffn



@deffn {macro} expect-negative
@lisp
(expect-negative MESSAGE CLAUSE)
(expect-negative MESSAGE (warn MESSAGE) CLAUSE)
@end lisp
@itemize
@item This expectation checks to see if the evaluated expression passed to it
is a negative value less than zero.
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn MESSAGE)} allows you to specify a warning object, usually
a string, that gets associated with the expectation. The
@code{warn} function name is actually a syntax reserved word
in the macro.
@item @code{CLAUSE} is a single expression which should return an inexact or
exact number.
@end itemize
@end deffn


@node Result Object API
@subsection Result Object API

Expectations, test cases, test packages, and helper macros(@code{gloss,
todo, etc}) all return an object that contains the results and other various
aspects of the action performed which ultimately get wired together to
form the result tree. This collection of functions forming the rest of the
test infrastructure API allows manipulation of these results in an abstracted
way as to allow changing of the representation in the future.

@node Test Package Result Object API
@subsection Test Package Result Object API

If any of these API functions, except @b{test-package-result?},
are passed something that isn't a test package result object, they will
return 'not-a-test-package-result.



@deffn {procedure} test-package-result?
@lisp
(test-package-result? RESULT)
@end lisp
If @code{RESULT} is a result object from the invocation
of a test package macro, then this function will return
#t. Otherwise, it will return #f.
@end deffn

@deffn {procedure} test-package-result-result-ref
@lisp
(test-package-result-result-ref RESULT)
@end lisp
Returns the boolean result associated with the test package @code{RESULT}
object.
@end deffn

@deffn {procedure} test-package-result-message-ref
@lisp
(test-package-result-message-ref RESULT)
@end lisp
Returns the message object associated with the test package @code{RESULT}
object.
@end deffn

@deffn {procedure} test-package-result-exps-ref
@lisp
(test-package-result-exps-ref RESULT)
@end lisp
Returns the list of result objects associated with the test package 
@code{RESULT} object.
@end deffn

@deffn {procedure} test-package-result-warning?
@lisp
(test-package-result-warning? RESULT)
@end lisp
If a warning had been attached to this test package, this function
will return #t, otherwise it will be #f.
@end deffn

@deffn {procedure} test-package-result-warning-ref
@lisp
(test-package-result-warning-ref RESULT)
@end lisp
If a warning had been attached to this test package, this function
will return the warning object supplied by the user, otherwise it 
shall return @b{'()}.
@end deffn



@node Test Case Result Object API
@subsection Test Case Result Object API

If any of these API functions, except @b{test-case-result?},
are passed something that isn't a test case result object, they will
return 'not-a-test-case-result.



@deffn {procedure} test-case-result?
@lisp
(test-case-result? RESULT)
@end lisp
If @code{RESULT} is a result object from the invocation
of a test case macro, then this function will return
#t. Otherwise, it will return #f.
@end deffn

@deffn {procedure} test-case-result-result-ref
@lisp
(test-case-result-result-ref RESULT)
@end lisp
Returns the boolean result associated with the test case @code{RESULT}
object.
@end deffn

@deffn {procedure} test-case-result-message-ref
@lisp
(test-case-result-message-ref RESULT)
@end lisp
Returns the message object associated with the test case @code{RESULT}
object.
@end deffn

@deffn {procedure} test-case-result-expectations-ref
@lisp
(test-case-result-expectations-ref RESULT)
@end lisp
Returns the list of expctation result objects associated with the test
case @code{RESULT} object.
@end deffn

@deffn {procedure} test-case-result-warning?
@lisp
(test-case-result-warning? RESULT)
@end lisp
If a warning had been attached to this test case, this function
will return #t, otherwise it will be #f.
@end deffn

@deffn {procedure} test-case-result-warning-ref
@lisp
(test-case-result-warning-ref RESULT)
@end lisp
If a warning had been attached to this test case, this function
will return the warning object supplied by the user, otherwise it 
shall return @b{'()}.
@end deffn



@node Single Clause Style Expectation
@subsection Expect Result Object API: Single Clause Style Expectation

These expectations all take the form of passing a single expression to
them to see if they match some a priori expectation.  If any of these
API functions, except @b{expect-result?}, are passed something that
isn't a single clause style expectation result object, they will return
'not-an-expect-result.



@deffn {procedure} expect-result?
@lisp
(expect-result? RESULT)
@end lisp
If @code{RESULT} is a single clause style result object from
the invocation of an expectation macro, then this function will
return #t. Otherwise, it will return #f.
@end deffn

@deffn {procedure} expect-result-result-ref
@lisp
(expect-result-result-ref RESULT)
@end lisp
Returns the boolean result associated with the single clause
style expectation @code{RESULT} object.
@end deffn

@deffn {procedure} expect-result-specific-ref
@lisp
(expect-result-specific-ref RESULT)
@end lisp
This retrieves the ``specific'' field of a particular single clause
style expectation.  For example, if you had a result object from
an invocation of a @code{(expect-zero? "foobar" (- 1 1))}
expectation, then the ``specific'' field of the expectation
result object will be the string @b{"zero"}. Here is a
table describing what the ``specific'' fields are for each kind
of single clause style expectation:


@multitable {Single Clause Style Expectation} {Associated Specific String}
@item Single Clause Style Expectation @tab Associated Specific String
@item expect-zero                     @tab "zero" 
@item expect-nonzero                  @tab "nonzero" 
@item expect-true                     @tab "true" 
@item expect-false                    @tab "false" 
@item expect-positive                 @tab "positive" 
@item expect-negative                 @tab "negative"
@end multitable


@end deffn

@deffn {procedure} expect-result-message-ref
@lisp
(expect-result-message-ref RESULT)
@end lisp
Returns the message object associated with the single clause
style expectation @code{RESULT} object.
@end deffn

@deffn {procedure} expect-result-unevaled-ref
@lisp
(expect-result-unevaled-ref RESULT)
@end lisp
Returns the unevaluated expression supplied to a single clause style
expectation macro.
@end deffn

@deffn {procedure} expect-result-evaled-ref
@lisp
(expect-result-evaled-ref RESULT)
@end lisp
Returns the evaluated expression supplied to a single clause style
expectation macro.
@end deffn

@deffn {procedure} expect-result-warning?
@lisp
(expect-result-warning? RESULT)
@end lisp
If a warning had been attached to this expectation, this function
will return #t, otherwise it will be #f.
@end deffn

@deffn {procedure} expect-result-warning-ref
@lisp
(expect-result-warning-ref RESULT)
@end lisp
If a warning had been attached to this expectation, this function
will return the warning object supplied by the user, otherwise it 
shall return @b{'()}.
@end deffn



@node Equivalence Style Expectation
@subsection Expect Result Object API: Equivalence Style Expectation

These expectations all take the form of passing a two expressions,
the ``left hand side'' and the ``right hand side'' to them to see
if they match some a priori equivalence.  The left hand side is that
which you expect the right hand side to be equivalent. If any of these
API functions, except @b{expect-equivalence-result?}, are passed
something that isn't a single clause style expectation result object,
they will return 'not-an-expect-equivalence-result.



@deffn {procedure} expect-equivalence-result?
@lisp
(expect-equivalence-result? RESULT)
@end lisp
If @code{RESULT} is a comparison style result object from
the invocation of an expectation macro, then this function will
return #t. Otherwise, it will return #f.
@end deffn

@deffn {procedure} expect-equivalence-result-result-ref
@lisp
(expect-equivalence-result-result-ref RESULT)
@end lisp
Returns the boolean result associated with the comparison style
expectation @code{RESULT} object.
@end deffn

@deffn {procedure} expect-equivalence-result-specific-ref
@lisp
(expect-equivalence-result-specific-ref RESULT)
@end lisp
This retrieves the ``specific'' field of a particular equivalence
style expectation. For example, if you had a result object from
an invocation of a @code{(expect-equal? "foobar" 0 (- 1 1))}
expectation, then the ``specific'' field of the expectation
result object will be the string @b{"equal"}. Here is a
table describing what the ``specific'' fields are for each kind
of equivalence style expectation:


@multitable {Equivalence Style Expectation} {Associated Specific String}
@item Equivalence Style Expectation @tab Associated Specific String
@item expect-eq                     @tab "eq" 
@item expect-eqv                    @tab "eqv" 
@item expect-equal                  @tab "equal"
@end multitable

@end deffn

@deffn {procedure} expect-equivalence-result-message-ref
@lisp
(expect-equivalence-result-message-ref RESULT)
@end lisp
Returns the message object associated with the equivalence
style expectation @code{RESULT} object.
@end deffn

@deffn {procedure} expect-equivalence-result-lhs-evaled-ref
@lisp
(expect-equivalence-result-lhs-evaled-ref RESULT)
@end lisp
Returns the evaluated ``left hand side'' expression supplied to 
an equivalence style expectation.
@end deffn

@deffn {procedure} expect-equivalence-result-rhs-unevaled-ref
@lisp
(expect-equivalence-result-rhs-unevaled-ref RESULT)
@end lisp
Returns the unevaluated ``right hand side'' expression supplied
to an equivalence style expectation.
@end deffn

@deffn {procedure} expect-equivalence-result-rhs-evaled-ref
@lisp
(expect-equivalence-result-rhs-evaled-ref RESULT)
@end lisp
Returns the evaluated ``right hand side'' expression supplied
to an equivalence style expectation.
@end deffn

@deffn {procedure} expect-equivalence-result-warning?
@lisp
(expect-equivalence-result-warning? RESULT)
@end lisp
If a warning had been attached to this expectation, this function
will return #t, otherwise it will be #f.
@end deffn

@deffn {procedure} expect-equivalence-result-warning-ref
@lisp
(expect-equivalence-result-warning-ref RESULT)
@end lisp
If a warning had been attached to this expectation, this function
will return the warning object supplied by the user, otherwise it 
shall return @b{'()}.
@end deffn



@node Tolerance Style Expectation
@subsection Expect Result Object API: Tolerance Style Expectation

This is a specialized expectation which accepts three expressions and
checks to see if the ``right hand side'' is within a ``tolerance''
of the ``left hand side''. There is only one expectation in the
tolerance style currently.  If any of these API functions, except
@b{expect-tolerance-result?}, are passed something that isn't
a tolerance style expectation result object, they will return
'not-an-expect-tolerance-result.



@deffn {procedure} expect-tolerance-result?
@lisp
(expect-tolerance-result? RESULT)
@end lisp
If @code{RESULT} is a tolerance style result object from
the invocation of an expectation macro, then this function will
return #t. Otherwise, it will return #f.
@end deffn

@deffn {procedure} expect-tolerance-result-result-ref
@lisp
(expect-tolerance-result-result-ref RESULT)
@end lisp
Returns the boolean result associated with the tolerance style
expectation @code{RESULT} object.
@end deffn

@deffn {procedure} expect-tolerance-result-specific-ref
@lisp
(expect-tolerance-result-specific-ref RESULT)
@end lisp
This retrieves the ``specific'' field of a particular tolerance
style expectation. For example, if you had a result object from
an invocation of a @code{(expect-near? "foobar" 100 .01 100.001)}
expectation, then the ``specific'' field of the expectation
result object will be the string @b{"near"}. Here is a
table describing what the ``specific'' fields are for each kind
of tolerance style expectation:


@multitable {Tolerance Style Expectation} {Associated Specific String}
@item Tolerance Style Expectation @tab Associated Specific String@
@item expect-near                 @tab "near"
@end multitable


@end deffn

@deffn {procedure} expect-tolerance-result-message-ref
@lisp
(expect-tolerance-result-message-ref RESULT)
@end lisp
Returns the message object associated with a tolerance
style expectation @code{RESULT} object.
@end deffn

@deffn {procedure} expect-tolerance-result-lhs-evaled-ref
@lisp
(expect-tolerance-result-lhs-evaled-ref RESULT)
@end lisp
Returns the evaluated ``left hand side'' expression supplied to 
a tolerance style expectation.
@end deffn

@deffn {procedure} expect-tolerance-result-lhs-tol-evaled-ref
@lisp
(expect-tolerance-result-lhs-tol-evaled-ref RESULT)
@end lisp
Returns the evaluated ``tolerance'' expression supplied to 
a tolerance style expectation.
@end deffn

@deffn {procedure} expect-tolerance-result-rhs-unevaled-ref
@lisp
(expect-tolerance-result-rhs-unevaled-ref RESULT)
@end lisp
Returns the unevaluated ``right hand side'' expression supplied
to a tolerance style expectation.
@end deffn

@deffn {procedure} expect-tolerance-result-rhs-evaled-ref
@lisp
(expect-tolerance-result-rhs-evaled-ref RESULT)
@end lisp
Returns the evaluated ``right hand side'' expression supplied
to a tolerance style expectation.
@end deffn

@deffn {procedure} expect-tolerance-result-warning?
@lisp
(expect-tolerance-result-warning? RESULT)
@end lisp
If a warning had been attached to this expectation, this function
will return #t, otherwise it will be #f.
@end deffn

@deffn {procedure} expect-tolerance-result-warning-ref
@lisp
(expect-tolerance-result-warning-ref RESULT)
@end lisp
If a warning had been attached to this expectation, this function
will return the warning object supplied by the user, otherwise it 
shall return @b{'()}.
@end deffn



@node Various Helper API
@subsection Various Helper API

These upcoming macros and functions allow the author of the test suite to
better control both the execution flow of the test suite and ``decoration''
of the test suite with important information like things yet to do, or just
plain documentation.

@node Termination API
@subsection Termination API

When executing in a test package or a test case, one might discover some
catastrophic failure of such proportions that it is utterly impossible
to continue executing the test case or test package. When that happens
you can use the termination facility to exit the test case or test
package. Of course, no more expressions will be evaluated in the scope of
the termination. It is recommended that you use this method of terminating
the test case or test package evaluation since it wraps some contextual
information up into the termination result so you can figure out what
happened(and where) later when analyzing the result tree.

When using the manipulation API for a terminate result, if you pass a
result to one of these function that is not a terminate result, it will
return 'not-a-terminate-result.


@deffn {procedure} terminate
@lisp
(terminate TERMFUNC MESSAGE)
@end lisp
@itemize
@item This is the recommended termination method for a test case or a test
package.
@item @code{TERMFUNC} is the name of the termination procedure that you
specified in a test case or test package. You may pass any test package
or test case termination function available to you in the lexical scope
in which you call this function. The termination will take effect in the
scope of the created termination function.
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@end itemize
@end deffn

@deffn {procedure} terminate-result?
@lisp
(terminate-result? RESULT)
@end lisp
If @code{RESULT} is a termination result object from the
invocation of a termination function, then this function will
return #t. Otherwise, it will return #f.
@end deffn

@deffn {procedure} terminate-result-result-ref
@lisp
(terminate-result-result-ref RESULT)
@end lisp
Returns the boolean result associated with the termination
function @code{RESULT} object. This is currently hard coded to
be #f.
@end deffn

@deffn {procedure} terminate-result-scope-ref
@lisp
(terminate-result-scope-ref RESULT)
@end lisp
The ``scope'' of the termination result is exactly the @code{MESSAGE}
parameter supplied to the test case or test package associated with the
@code{TERMFUNC}.
@end deffn

@deffn {procedure} terminate-result-container-ref
@lisp
(terminate-result-container-ref RESULT)
@end lisp
The ``container'' of the termination result is going to be
either 'test-package or 'test-case depending upon which the
@code{TERMFUNC} was associated.
@end deffn

@deffn {procedure} terminate-result-message-ref
@lisp
(terminate-result-message-ref RESULT)
@end lisp
Returns the message object associated with the termination
@code{RESULT} object.
@end deffn



@node Destructor Object API
@subsection Destructor Object API
The destructor object allows for you to create helper functions
which clean up for you usually in case of aborting of a test case
or package. For example, suppose you are testing whether or not file
writing to a file works correctly in a test case, so, you'd perform an
expectation to open the file, and then queue a function in the destructor
to remove the file, and then perform the expectation of the write. If
the write(or subsequent) expectation fails, then the test case will
@b{automatically} invoke the helper cleanup function specified in
the destructor object that removes the file.

@b{NOTE:} This API is still a little experimental in the sense
that eventually he destructor object should return a typed result that
contains the success of the individual destructor calls. But for now,
it is functional for what it does. Also, be @b{VERY CAREFUL} that
you specify the arguments to these API calls correctly since due to
lambda functions not being comparable, this API cannot garuantee that
a true destructor object name had been passed to it. So if you call one
of the following API calls incorrectly, the behavior will be undefined.



@deffn {procedure} destructor-atexit!
@lisp
(destructor-atexit! DESTNAME FUNC ARGS ...)
@end lisp
This will insert a promise to calculate the @code{FUNC} with the
supplied @code{ARGS ...} into a queue in the @code{DESTNAME}
destructor object. Multiple invocations of this API call will 
continue to queue up @code{(FUNC ARGS ...)} promises indefinitely.
This function returns a special @b{ignore} type that is ignored
by the test infrastructure system.
@end deffn

@deffn {procedure} destructor-activate!
@lisp
(destructor-activate! DESTNAME)
@end lisp
This function will call, in order of queueing, all the promises
embedded into this destructor object, and then delete the
queue. This function is @b{ALWAYS} called at the completion
of a test package or test case; so be careful that the destructor
object doesn't contain anything harmful.  However, you may call
it yourself and if you do, it will execute all of the queued
promises and then @code{clear} itself. This function returns
a special @b{ignore} type that is ignored by the test
infrastructure system.
@end deffn

@deffn {procedure} destructor-clear!
@lisp
(destructor-clear! DESTNAME)
@end lisp
This function completely removes all of the promises associated
with the destructor object @code{DESTNAME}. This function
returns a special @b{ignore} type that is ignored by the
test infrastructure system.
@end deffn

@deffn {procedure} destructor-dump
@lisp
(destructor-dump DESTNAME)
@end lisp
This function, mostly used for debugging purposes, prints out
a simple representation of the queued atexit functions to the
current port.  This function returns a special @b{ignore}
type that is ignored by the test infrastructure system.
@end deffn



@node Todo API
@subsection Todo API

The purpose of the todo API is to allow the author of a test suite the
ability to record into the result tree for later analysis that something
still needs to be done. This way you can count/manipulate this information
at a later date.  Todo macro invocations can occur inside of test cases
or test packages.


@deffn {macro} todo
@lisp
(todo MESSAGE)
(todo (warn WARNING) MESSAGE)
@end lisp
@itemize
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn WARNING)} allows you to specify a warning object, usually
a string, that gets associated with the todo. The @code{warn}
function name is actually a syntax reserved word in the macro.
@end itemize
@end deffn

@deffn {procedure} todo-result?
@lisp
(todo-result? RESULT)
@end lisp
If @code{RESULT} is a todo result object from the
invocation of a todo macro, then this function will
return #t. Otherwise, it will return #f.
@end deffn

@deffn {procedure} todo-result-message-ref
@lisp
(todo-result-message-ref RESULT)
@end lisp
Returns the message object associated with the todo
@code{RESULT} object.
@end deffn

@deffn {procedure} todo-result-warning?
@lisp
(todo-result-warning? RESULT)
@end lisp
If a warning had been attached to this todo, this function
will return #t, otherwise it will be #f.
@end deffn

@deffn {procedure} todo-result-warning-ref
@lisp
(todo-result-warning-ref RESULT)
@end lisp
If a warning had been attached to this todo, this function
will return the warning object supplied by the user, otherwise it 
shall return @b{'()}.
@end deffn



@node Gloss API
@subsection Gloss API

The purpose of the gloss API is to allow the author of a test suite the
ability to record messages into the result tree purely for documentation
purposes.  Gloss macro invocations can occur inside of test cases or
test packages.


@deffn {macro} gloss
@lisp
(gloss MESSAGE)
(gloss (warn WARNING) MESSAGE)
@end lisp
@itemize
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn WARNING)} allows you to specify a warning object, usually
a string, that gets associated with the gloss. The @code{warn}
function name is actually a syntax reserved word in the macro.
@end itemize
@end deffn

@deffn {procedure} gloss-result?
@lisp
(gloss-result? RESULT)
@end lisp
If @code{RESULT} is a gloss result object from the
invocation of the gloss macro, then this function will
return #t. Otherwise, it will return #f.
@end deffn

@deffn {procedure} gloss-result-message-ref
@lisp
(gloss-result-message-ref RESULT)
@end lisp
Returns the message object associated with the gloss
@code{RESULT} object.
@end deffn

@deffn {procedure} gloss-result-warning?
@lisp
(gloss-result-warning? RESULT)
@end lisp
If a warning had been attached to this gloss, this function
will return #t, otherwise it will be #f.
@end deffn

@deffn {procedure} gloss-result-warning-ref
@lisp
(gloss-result-warning-ref RESULT)
@end lisp
If a warning had been attached to this gloss, this function
will return the warning object supplied by the user, otherwise it 
shall return @b{'()}.
@end deffn



@node Skip API
@subsection Skip API

The purpose of the skip API is to allow the author of a test suite
to completely skip evaluation of a set of expresssions.  Skip macro
invocations can occur inside of test cases or test packages.


@deffn {macro} skip
@lisp
(skip MESSAGE CLAUSES)
(skip (warn WARNING) MESSAGE CLAUSES)
@end lisp
@itemize
@item @code{MESSAGE} can be any scheme object, though usually it is a string.
@item @code{(warn WARNING)} allows you to specify a warning object, usually
a string, that gets associated with the gloss. The @code{warn}
function name is actually a syntax reserved word in the macro.
@item @code{CLAUSES} can be more than one expression(as in a lambda form)
that does @b{NOT} get evaluated at any time.
@end itemize
@end deffn

@deffn {procedure} skip-result?
@lisp
(skip-result? RESULT)
@end lisp
If @code{RESULT} is a skip result object from the
invocation of the skip macro, then this function will
return #t. Otherwise, it will return #f.
@end deffn

@deffn {procedure} skip-result-message-ref
@lisp
(skip-result-message-ref RESULT)
@end lisp
Returns the message object associated with the skip
@code{RESULT} object. Hopefully, it was stated why this
set of clauses had been skipped.
@end deffn

@deffn {procedure} skip-result-warning?
@lisp
(skip-result-warning? RESULT)
@end lisp
If a warning had been attached to this skip, this function
will return #t, otherwise it will be #f.
@end deffn

@deffn {procedure} skip-result-warning-ref
@lisp
(skip-result-warning-ref RESULT)
@end lisp
If a warning had been attached to this skip, this function
will return the warning object supplied by the user, otherwise it 
shall return @b{'()}.
@end deffn



@node Side Effect API
@subsection Side Effect API

This section of the API just contains a single macro currently since
it is considered a little experimental for now.  The side effecting
evaluates all of its arguments as in a @code{(begin ...)} form, it
returns a result that is completely ignored by the system and unavailable
to the output analysis code.

@deffn {macro} side-effect
@lisp
(side-effect CLAUSES)
@end lisp
This macro expands into a begin form the clauses in order and when it
finishes evaluating them, returns a result that is silently ignored by 
the testing infrastructure system. Usually this is used in conjunction with
@code{(set! ...)} or with complicated situations where a lot of setup
work must happen for an expectation to be performed.
@end deffn

@node Miscellaneous API
@subsection Miscellaneous API

This section contains a few functions whose purpose is to simplify certain
kinds of manipulations of result objects.

@deffn {procedure} *-restult?
@lisp
(*-result? RESULTOBJ)
@end lisp
This function will return #t of @code{RESULTOBJ} is any kind of an
evaluated result object. Otherwise, it shall return #f.
@end deffn

@deffn {procedure} *-result-ref
@lisp
(*-result-ref RESULTOBJ)
@end lisp
This function will return the result of any kind of @code{RESULTOBJ}
passed to it if it is indeed a true result object. Otherwise, it
shall emit an error to the current port, and return #f.
@end deffn

@deffn {procedure} all-testpackage-results-true?
@lisp
(all-testpackage-results-true? RESULTLIST)
@end lisp
This function takes the result of a call to 
@code{(test-package-result-result-ref PACKAGERESULTOBJ)} and returns
#t if every single contained result in that list had been true, or #f
otherwise.
@end deffn

@deffn {procedure} all-testcase-expectations-true?
@lisp
(all-testcase-expectations-true? RESULTLIST)
@end lisp
This function takes the result of a call to 
@code{(test-case-result-result-ref CASERESULTOBJ)} and returns
#t if every single contained result in that list had been true, or #f
otherwise.
@end deffn


@node Analysis of the Result Tree
@subsection Analysis of the Result Tree
        
Once a result tree has been evaluated and constructed in memory, what
do you do with it? Well, you can do anything you want with it if you
choose to write the analysis or output generation functions and pass it
the evaluated result tree, and this is, in fact, encouraged. However,
usually you just want to print out the tree in a human readable format so
you can check things before the serious analysis code gets written. So,
to save work for the test suite designer, a tiny API has been written
to produce human readable output given a tree of results rooted in a
single test package. Of course the single test package may have many
other test packages and test cases embedded within it.

@node Output Generation API
@subsection Output Generation API


@deffn {procedure} printnl
@lisp
(printnl CLAUSES)
@end lisp
This function will print all of the evaluated @code{CLAUSES}
in order with a newline at the end of it.
@end deffn

@deffn {procedure} printinl
@lisp
(printinl INDENT CLAUSES)
@end lisp
This function will @code{INDENT} a number of spaces and then
print all of the evaluated @code{CLAUSES} in order with a
newline at the end of it.
@end deffn

@deffn {procedure} output-style-human
@lisp
(output-style-human RESULTTREE)
@end lisp
This function will print out a human readable rendering of the
@code{RESULTTREE} and return the toplevel package result.
@end deffn


@node Example Usages of the Test Suite Infrastructure
@subsection Example Usages of the Test Suite Infrastructure

This section contains some simple examples of how to author test suites.

Here is a simple example:

@verbatim
(let ((result
        ;; output-style-human function requires a single test package
        ;; to encapsulate everything.
        (test-package "Arithmetic Operators" pd pe

                (test-case "Testing '+'" d e
                        (expect-equal "Adding two positive numbers" 2 (+ 1 1))
                        (expect-equal "Adding two negative numbers" -2 (+ -1 -1))
                        (expect-zero "Adding positive and negative" (+ -1 1)))

                (test-case "Testing '-'" d e
                        (expect-zero "Subtracting two positive numbers" (- 1 1))
                        (expect-zero "Subtracting two negative numbers" (- -1 -1))
                        (expect-equal "Subtracting positive and negative" -2 (- -1 1))))))
        (output-style-human result))
@end verbatim

The above example, when evaluated, will produce some human readable output
and the a #t value as the result of the top level package. The @code{result}
variable contains the tree of evaluated expectations, test cases, and the
package arranged in a hierarchy extremely similar to the nesting of the
above macros. If you desire to manipulate the result tree yourself, you
may use the various APIs to manipulate the various results. Please see the
implementation of @code{(output-style-human ...)} (it isn't large) in the
test-infrastructure.scm file to see an example of this.

The variables: @code{pe, e} are the escape functions you may use with the
@code{(terminate ...)} function call if you wish to abort the above code
somewhere.

The variables: @code{pd, d} allow use of a "destructor" object which allows
you to run side effecting functions at the "finishing" point of the evaluation
of the test case or test package. These functions are run no matter if the code
succeeded correctly or not, so be careful to manage the destructor object
carefully so you don't perform unwanted side effects. The names of the
destructor objects you supply are lexically scoped in the bodies of the
test case or test package.

Now, here is some example output that @code{(output-style-human ...)} might
generate with the above testing code:

@verbatim
Begin Package: Arithmetic Operators
  Begin Test Case: Testing '+'
    Begin Expectation: Adding two positive numbers
    Expect equal
      Expected Value: 
      2
      Unevaluated: 
      (+ 1 1)
      Evaluated: 
      2
    Result: #t
    End Expectation: Adding two positive numbers

    Begin Expectation: Adding two negative numbers
    Expect equal
      Expected Value: 
      -2
      Unevaluated: 
      (+ -1 -1)
      Evaluated: 
      -2
    Result: #t
    End Expectation: Adding two negative numbers

    Begin Expectation: Adding positive and negative
    Expect zero
      Unevaluated: 
      (+ -1 1)
      Evaluated: 
      0
    Result: #t
    End Expectation: Adding positive and negative

  Result: #t
  End Test Case: Testing '+'

  Begin Test Case: Testing '-'
    Begin Expectation: Subtracting two positive numbers
    Expect zero
      Unevaluated: 
      (- 1 1)
      Evaluated: 
      0
    Result: #t
    End Expectation: Subtracting two positive numbers

    Begin Expectation: Subtracting two negative numbers
    Expect zero
      Unevaluated: 
      (- -1 -1)
      Evaluated: 
      0
    Result: #t
    End Expectation: Subtracting two negative numbers

    Begin Expectation: Subtracting positive and negative
    Expect equal
      Expected Value: 
      -2
      Unevaluated: 
      (- -1 1)
      Evaluated: 
      -2
    Result: #t
    End Expectation: Subtracting positive and negative

  Result: #t
  End Test Case: Testing '-'

Result: #t
End Package: Arithmetic Operators

#t
@end verbatim


@node Data Representation
@chapter Data Representation


There exist two different kinds of data objects in the CHICKEN system:
immediate and non-immediate objects. Immediate objects are represented
by a tagged machine word, which is usually of 32 bits length (64 bits
on 64-bit architectures). The immediate objects come in four different
flavors:

@itemize

@item @b{fixnums}, that is, small exact integers, distinguished by
the lowest order bit in the machine word set to 1. This gives fixnums
a range of 31 bits for the actual numeric value (63 bit on 64 bit
architectures).

@item @b{characters}, where the lowest four bits of machine words
containing characters are equal to @code{C_CHARACTER_BITS}. The
ASCII code of the character is encoded in bits 9 to 16, counting from
1 and starting at the lowest order position.

@item @b{booleans}, where the lowest four bits of machine words
containing booleans are equal to @code{C_BOOLEAN_BITS}. Bit 5
(counting from 0 and starting at the lowest order position) is one if
the boolean designates true, or 0 if it is false.

@item other values: the empty list, void and end-of-file. The lowest
four bits of machine words containing these values are equal to
@code{C_SPECIAL_BITS}. Bits 5 to 8 contain an identifying
number for this type of object.  The following constants are
defined: @code{C_SCHEME_END_OF_LIST C_SCHEME_UNDEFINED
C_SCHEME_END_OF_FILE}

@end itemize

Non-immediate objects are blocks of data represented by a pointer into
the heap. The first word of the data block contains a header, which gives
information about the type of the object. The header has the size of a
machine word, usually 32 bits (64 bits on 64 bit architectures).

@itemize

@item bits 1 to 24 (starting at the lowest order position) contain the
length of the data object, which is either the number of bytes in a
string (or byte-vector) or the the number of elements for a vector or
for a structure type.

@item bits 25 to 28 contain the type code of the object.

@item bits 29 to 32 contain miscellaneous flags used for garbage
collection or internal data type dispatching.
These flags are:
@table @code

@item C_GC_FORWARDING_BIT

Flag used for forwarding garbage collected object pointers.

@item C_BYTEBLOCK_BIT

Flag that specifies whether this data object contains raw bytes (a string
or byte-vector) or pointers to other data objects.

@item C_SPECIALBLOCK_BIT

Flag that specifies whether this object contains a ``special'' non-object
pointer value in its first slot. An example for this kind of objects
are closures, which are a vector-type object with the code-pointer as
the first item.

@item C_8ALIGN_BIT

Flag that specifies whether the data area of this block should be aligned
on an 8-byte boundary (floating-points numbers, for example).

@end table

@end itemize


The actual data follows immediately after the header. Note that
block-addresses are always aligned to the native machine-word
boundary. Scheme data objects map to blocks in the following manner:

@itemize

@item pairs: vector-like object (type bits @code{C_PAIR_TYPE}),
where the car and the cdr are contained in the first and second slots,
respectively.

@item vectors: vector object (type bits @code{C_VECTOR_TYPE}).

@item strings: byte-vector object (type bits @code{C_STRING_TYPE}).

@item procedures: special vector object (type bits
@code{C_CLOSURE_TYPE}). The first slot contains a pointer to a
compiled C function. Any extra slots contain the free variables (since
a flat closure representation is used).

@item flonum: a byte-vector object (type bits
@code{C_FLONUM_BITS}). Slots one and two (or a single slot on
64 bit architectures) contain a 64-bit floating-point number, in the
representation used by the host systems C compiler.

@item symbol: a vector object (type bits @code{C_SYMBOL_TYPE}). Slots
one and two contain the toplevel variable value and the print-name
(a string) of the symbol, respectively.

@item port: a special vector object (type bits
@code{C_PORT_TYPE}). The first slot contains a pointer to a file-
stream, if this is a file-pointer, or NULL if not. The other slots
contain housekeeping data used for this port.

@item structure: a vector object (type bits
@code{C_STRUCTURE_TYPE}). The first slot contains a symbol that
specifies the kind of structure this record is an instance of. The other
slots contain the actual record items.

@item pointer: a special vector object (type bits
@code{C_POINTER_TYPE}). The single slot contains a machine pointer.

@item tagged pointer: similar to a pointer (type bits 
@code{C_TAGGED_POINTER_TYPE}), but the object contains an additional
slot with a tag (an arbitrary data object) that identifies the type
of the pointer.

@end itemize


Data objects may be allocated outside of the garbage collected heap, as
long as their layout follows the above mentioned scheme. But care has to
be taken not to mutate these objects with heap-data (i.e. non-immediate
objects), because this will confuse the garbage collector.


For more information see the header file @code{chicken.h}.


@node Bugs and limitations
@chapter Bugs and limitations


@itemize

@item Compiling large files takes too much time.

@item There is no support for rationals, complex numbers or
extended-precision integers (bignums).

@item The maximal number of arguments that may be passed to a compiled
procedure or macro is 126 (or 1024 on x86 platforms).  A macro-definition
that has a single rest-parameter can have any number of arguments.

@item The maximum number of values that can be passed to continuations
captured using @code{call-with-current-continuation} is 126.

@item Some numeric procedures are missing since CHICKEN does not support
the full numeric tower.

@item If a known procedure has unused arguments, but is always called
without those parameters, then the optimizer ``repairs'' the procedure
in certain situations and removes the parameter from the lambda-list.

@item @code{eval-when} doesn't allow toplevel definitions inside its
body in combination with hygienic macros.

@item @code{port-position} currently works only for input ports.

@item Leaf routine optimization can theoretically result in code that
thrashes, if tight loops perform excessively many mutations.

@item Building CHICKEN on RS/6000 systems under AIX is currently not
possible, due to strange assembler errors during compilation of the
compiler sources.

@item If @code{eval} is invoked with @code{scheme-report-environment}
or @code{null-environment} inside the interpreter, then non-standard
syntax is still visible, unless the interpreter has been started with
the @code{-strict} option.

@item When the highlevel macro system is used,
line number information is not properly maintained.

@item @code{format} is not reentrant. This means that recursive invocation
of this procedure (either inside @code{print-object} methods or
record-printer defined with @code{define-record-printer} will
not work.

@item User-defined types are currently not supported in the argument and result
specifications for entry-points defined with @code{define-entry-point}.

@end itemize


@node Acknowledgements
@chapter Acknowledgements

@itemize

@item Jonah Beckford added CHICKEN-support to @uref{http://www.swig.org, SWIG} and
provided support for shared libraries and dynamic loading under Windows.

@item ``Category 5'' ported CHICKEN to several BSD platforms and suggested a great many improvements.

@item Linh Dang translated the TeX manual into texinfo format and wrote the hen emacs mode.

@item Steve Elkins ported CHICKEN to OpenBSD.

@item Tollef Fog Heen and Thomas Weidner helped porting CHICKEN to the AMD-64 platform.

@item Tony Garnock-Jones ported CHICKEN to HP-UX and provided countless
fixes and improvements.

@item Sven Hartrumpf helped porting CHICKEN to the UltraSparc, suggested
many improvements and helped fixing numerous bugs.

@item Bruce Hoult fixed several bugs and pointed out performance improvements.

@item Dale Jordan pointed out several bugs, helped fixing problems on the
Cygwin platform and contributed the @code{calendar.scm} example script.

@item Peter Keller translated the manual from HTML into LaTeX and contributed
the testing infrastructure code.

@item Kirill Lisovsky found a couple of bugs while porting Oleg Kiselyov's
SSAX XML parser to CHICKEN.

@item Dennis Marti ported CHICKEN to Mac OS X.

@item Chris Moline and Bakul Shah helped porting CHICKEN to FreeBSD.

@item Davide Puricelli maintains the Debian package.

@item Doug Quale contributed the configuration scripts for installation
on UNIX-like systems, suggested numerous improvements and was generally
very helpful.

@item Benedikt Rosenau found several bugs and spent a lot of time testing
the system and pointing out improvements.

@item Michele Simionato discovered several bugs and provided numerous helpful suggestions.

@item Dorai Sitaram pointed out several improvements in the TeX manual.

@item Mike Thomas ported CHICKEN to the Mingw32 platform.

@item John Tobey ported CHICKEN to MIPS.

@item Panagiotis Vossos ported CHICKEN to Alpha/Linux.

@item Peter Wang produced countless bugfixes and helpful suggestions.

@item Jorg Wittenberger found and fixed countless bugs in the runtime system.


@item CHICKEN contains code from several people:
@itemize
@item Eli Barzilay: some performance tweaks used in TinyCLOS.
@item Anthony Carrico: the option parsing facility.
@item Mikael Djurfeldt: topological sort used by compiler.
@item Marc Feeley: pretty-printer.
@item Aubrey Jaffer: implementation of @code{dynamic-wind}.
@item R. Kent Dybvig, Oscar Waddel, Robert Hieb & Carl Bruggeman: @code{syntax-case} macro system.
@item Gregor Kiczales: original implementation of TinyCLOS.
@item Dirk Lutzebaeck: Common LISP @code{format}.
@item Richard O'Keefe: sorting routines.
@item Jussi Piitulainen: reference implementation for SRFI-25.
@item Olin Shivers: implementation of @code{let-optionals[*]} and
reference implementations of SRFI-1, SRFI-13 and SRFI-14.
@item Dorai Sitaram: the PREGEXP regular expression package and
TeX2page, which was used to generate the HTML documentation.
@item Andrew Wilcox: queues.
@item Andrew Wright: pattern matcher.
@end itemize

@end itemize


Thanks also to:

William Annis, Marc Baily, Peter Barabas, Peter Bex, Dave Bodenstab, T. Kurt Bond, Terence Brannon, Roy Bryant, Taylor Campbell, Franklin Chen, Grzegorz Chrupala,
James Crippen, Alejandro Forero Cuervo,
Brian Denheyer, Chris Double, Petter Egesund, Daniel B. Faken, Fizzie, Kimura Fuyuki, Martin Gasbichler, Joey Gibson, 
Johannes Groedem, Andreas Gustafsson, Jun-ichiro itojun Hagino, Matthias Heiler, Karl M. Hegbloom, William P. Heinemann, Dale
Jordan, Valentin Kamyshenko, Ron Kneusel, Matthias Koeppe, Todd R. Kueny Sr, Charles Martin, Alain Mellan, Perry Metzger,
Scott G. Miller, Mikael, Bruce Mitchener, Eric Merrit,
Eric E. Moore, o.t., David Rush, Lars Rustemeier, Oskar Schirmer, Burton Samograd, Ronald Schroder,
Spencer Schumann, Shmul, Jeffrey B. Siegal, Robert Skeels, Jason Songhurst, Clifford Stein, Christian Tismer, Vladimir Tsichevsky, 
Neil van Dyke, Sander Vesik, Shawn Wagner, Matthew Welland, 
Richard Zidlicky and Houman Zolfaghari for bug-fixes, tips, suggestions and moral support.

@node Bibliography
@unnumbered Bibliography

@table @asis
@item Henry Baker: @emph{CONS Should Not CONS Its Arguments, Part II: Cheney on the M.T.A.}
@code{http://home.pipeline.com/\~hbaker1/CheneyMTA.html}
@item Revised^5 Report on the Algorithmic Language Scheme
@code{http://www.schemers.org/Documents/Standards/R5RS}
@end table

@node Index
@unnumbered Index
@printindex fn

@bye