File: chap-21.texi

package info (click to toggle)
gclinfo 2.2-9
  • links: PTS
  • area: main
  • in suites: potato
  • size: 3,928 kB
  • ctags: 15
  • sloc: sed: 1,681; makefile: 127; lisp: 58; sh: 40
file content (3622 lines) | stat: -rw-r--r-- 113,741 bytes parent folder | download | duplicates (4)
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


@node Streams, Printer, Files, Top
@chapter Streams

@menu
* Stream Concepts::		
* Streams Dictionary::		
@end menu

@node Stream Concepts, Streams Dictionary, Streams, Streams
@section Stream Concepts

@c including concept-streams

@menu
* Introduction to Streams::	
* Stream Variables::		
* Stream Arguments to Standardized Functions::	
* Restrictions on Composite Streams::  
@end menu

@node Introduction to Streams, Stream Variables, Stream Concepts, Stream Concepts
@subsection Introduction to Streams

A @i{stream}
@IGindex{stream}
 is an @i{object} that can be used with an input or output
function to identify an appropriate source or sink of @i{characters} or 
@i{bytes} for that operation.
A @i{character}
@IGindex{character}
 @i{stream}
@IGindex{stream}
 is a source or sink of @i{characters}.
A @i{binary}
@IGindex{binary}
 @i{stream}
@IGindex{stream}
 is a source or sink of @i{bytes}.

Some operations may be performed on any kind of @i{stream};
Figure 21--1 provides a list of @i{standardized} operations
that are potentially useful with any kind of @i{stream}.

@group
@noindent
@w{  close                 stream-element-type  }
@w{  input-stream-p        streamp              }
@w{  interactive-stream-p  with-open-stream     }
@w{  output-stream-p                            }

@noindent
@w{  Figure 21--1: Some General-Purpose Stream Operations}

@end group

Other operations are only meaningful on certain @i{stream} @i{types}.
For example, @b{read-char} is only defined for @i{character} @i{streams}
and @b{read-byte} is only defined for @i{binary} @i{streams}.

@menu
* Abstract Classifications of Streams (Introduction to Streams)::  
* Input::			
* Open and Closed Streams::	
* Interactive Streams::		
* Abstract Classifications of Streams::	 
* File Streams::		
* Other Subclasses of Stream::	
@end menu

@node Abstract Classifications of Streams (Introduction to Streams), Input, Introduction to Streams, Introduction to Streams
@subsubsection Abstract Classifications of Streams

@node Input, Open and Closed Streams, Abstract Classifications of Streams (Introduction to Streams), Introduction to Streams
@subsubsection Input, Output, and Bidirectional Streams

A @i{stream}, whether a @i{character} @i{stream} or a @i{binary} @i{stream},
can be an @i{input}
@IGindex{input}
 @i{stream}
@IGindex{stream}
 (source of data),
       an @i{output}
@IGindex{output}
 @i{stream}
@IGindex{stream}
 (sink for data),
       both, 
    or (@i{e.g.}, when ``@t{:direction :probe}'' is given to @b{open}) neither.

Figure 21--2 shows @i{operators} relating to
@i{input} @i{streams}.

@group
@noindent
@w{  clear-input  read-byte            read-from-string            }
@w{  listen       read-char            read-line                   }
@w{  peek-char    read-char-no-hang    read-preserving-whitespace  }
@w{  read         read-delimited-list  unread-char                 }

@noindent
@w{        Figure 21--2: Operators relating to Input Streams.      }

@end group

Figure 21--3 shows @i{operators} relating to
@i{output} @i{streams}.

@group
@noindent
@w{  clear-output   prin1            write            }
@w{  finish-output  prin1-to-string  write-byte       }
@w{  force-output   princ            write-char       }
@w{  format         princ-to-string  write-line       }
@w{  fresh-line     print            write-string     }
@w{  pprint         terpri           write-to-string  }

@noindent
@w{  Figure 21--3: Operators relating to Output Streams.}

@end group

A @i{stream} that is both an @i{input} @i{stream} and an @i{output} @i{stream}
is called a @i{bidirectional}
@IGindex{bidirectional}
 @i{stream}
@IGindex{stream}
.
See the @i{functions} @b{input-stream-p} and @b{output-stream-p}.

Any of the @i{operators} listed in @i{Figure~21--2} or @i{Figure~21--3}
can be used with @i{bidirectional} @i{streams}.  In addition, Figure 21--4
shows a list of @i{operators} that relate specificaly to 
@i{bidirectional} @i{streams}.

@group
@noindent
@w{  y-or-n-p  yes-or-no-p    }

@noindent
@w{  Figure 21--4: Operators relating to Bidirectional Streams.}

@end group

@node Open and Closed Streams, Interactive Streams, Input, Introduction to Streams
@subsubsection Open and Closed Streams

@i{Streams} are either @i{open}
@IGindex{open}
 or @i{closed}
@IGindex{closed}
.  

Except as explicitly specified otherwise,
operations that create and return @i{streams} return @i{open} @i{streams}.

The action of @i{closing} a @i{stream} marks the end of its use as a source
or sink of data, permitting the @i{implementation} to reclaim its internal data
structures, and to free any external resources which might have been locked by the
@i{stream} when it was opened.

Except as explicitly specified otherwise,
the consequences are undefined when a @i{closed} @i{stream} 
is used where a @i{stream} is called for.

Coercion of @i{streams} to @i{pathnames} 
is permissible for @i{closed} @i{streams};
in some situations, such as for a @i{truename} computation, 
the result might be different for an @i{open} @i{stream}
and for that same @i{stream} once it has been @i{closed}.

@node Interactive Streams, Abstract Classifications of Streams, Open and Closed Streams, Introduction to Streams
@subsubsection Interactive Streams

An @i{interactive stream}
@IGindex{interactive stream}
 is one on which it makes sense to perform
interactive querying.

The precise meaning of an @i{interactive stream} is
@i{implementation-defined}, and may depend on the underlying
operating system.  Some examples of the things that an
@i{implementation} might choose to use as identifying characteristics
of an @i{interactive stream} include:

@table @asis

@item @t{*}  
The @i{stream} is connected to a person (or equivalent) in such a way
  that the program can prompt for information and expect to receive different
  input depending on the prompt.

@item @t{*}  
The program is expected to prompt for input and support ``normal input editing''.

@item @t{*}  
@b{read-char} might wait for the user to type something before returning
  instead of immediately returning a character or end-of-file. 

@end table

The general intent of having some @i{streams} be classified as
@i{interactive streams} is to allow them to be distinguished from
streams containing batch (or background or command-file) input.
Output to batch streams is typically discarded or saved for later viewing, 
so interactive queries to such streams might not have the expected effect.

@i{Terminal I/O} might or might not be an @i{interactive stream}.

@node Abstract Classifications of Streams, File Streams, Interactive Streams, Introduction to Streams
@subsubsection Abstract Classifications of Streams

@node File Streams, Other Subclasses of Stream, Abstract Classifications of Streams, Introduction to Streams
@subsubsection File Streams

Some @i{streams}, called @i{file streams}
@IGindex{file stream}
, provide access to @i{files}.
An @i{object} of @i{class} @b{file-stream} is used to represent a @i{file stream}.

The basic operation for opening a @i{file} is @b{open},
which typically returns a @i{file stream} 
(see its dictionary entry for details).
The basic operation for closing a @i{stream} is @b{close}.
The macro @b{with-open-file} is useful 
to express the common idiom of opening a @i{file} 
for the duration of a given body of @i{code}, 
and assuring that the resulting @i{stream} is closed upon exit from that body.

@node Other Subclasses of Stream,  , File Streams, Introduction to Streams
@subsubsection Other Subclasses of Stream

The @i{class} @b{stream} has a number of @i{subclasses} defined 
by this specification.  Figure 21--5 shows some information 
about these subclasses.

@group
@noindent
@w{  Class                Related Operators             }
@w{  @b{broadcast-stream}     @b{make-broadcast-stream}         }
@w{                       @b{broadcast-stream-streams}      }
@w{  @b{concatenated-stream}  @b{make-concatenated-stream}      }
@w{                       @b{concatenated-stream-streams}   }
@w{  @b{echo-stream}          @b{make-echo-stream}              }
@w{                       @b{echo-stream-input-stream}      }
@w{                       @b{echo-stream-output-stream}     }
@w{  @b{string-stream}        @b{make-string-input-stream}      }
@w{                       @b{with-input-from-string}        }
@w{                       @b{make-string-output-stream}     }
@w{                       @b{with-output-to-string}         }
@w{                       @b{get-output-stream-string}      }
@w{  @b{synonym-stream}       @b{make-synonym-stream}           }
@w{                       @b{synonym-stream-symbol}         }
@w{  @b{two-way-stream}       @b{make-two-way-stream}           }
@w{                       @b{two-way-stream-input-stream}   }
@w{                       @b{two-way-stream-output-stream}  }

@noindent
@w{  Figure 21--5: Defined Names related to Specialized Streams}

@end group

@node Stream Variables, Stream Arguments to Standardized Functions, Introduction to Streams, Stream Concepts
@subsection Stream Variables

@i{Variables} whose @i{values} must be @i{streams} are sometimes called 
@i{stream variables}
@IGindex{stream variable}
.

Certain @i{stream variables} are defined by this specification 
to be the proper source of input or output in various @i{situations} 
where no specific @i{stream} has been specified instead.
A complete list of such @i{standardized} @i{stream variables}
appears in Figure 21--6.  
The consequences are undefined if at any time
the @i{value} of any of these @i{variables} is not an @i{open} @i{stream}.

@group
@noindent
@w{  Glossary Term    Variable Name      }
@w{  @i{debug I/O}        @b{*debug-io*}         }
@w{  @i{error output}     @b{*error-output*}     }
@w{  @i{query I/O}        @b{*query-io*}         }
@w{  @i{standard input}   @b{*standard-input*}   }
@w{  @i{standard output}  @b{*standard-output*}  }
@w{  @i{terminal I/O}     @b{*terminal-io*}      }
@w{  @i{trace output}     @b{*trace-output*}     }

@noindent
@w{  Figure 21--6: Standardized Stream Variables}

@end group

Note that, by convention, @i{standardized} @i{stream variables} have names 
    ending in ``@t{-input*}''  if they must be @i{input} @i{streams},
    ending in ``@t{-output*}'' if they must be @i{output} @i{streams},
 or ending in ``@t{-io*}''     if they must be @i{bidirectional} @i{streams}.

User programs may @i{assign} or @i{bind} any @i{standardized} @i{stream variable}
except @b{*terminal-io*}.

@node Stream Arguments to Standardized Functions, Restrictions on Composite Streams, Stream Variables, Stream Concepts
@subsection Stream Arguments to Standardized Functions

The @i{operators} in Figure 21--7 accept @i{stream} @i{arguments} that
might be either @i{open} or @i{closed} @i{streams}.

@group
@noindent
@w{  broadcast-stream-streams     file-author       pathnamep                     }
@w{  close                        file-namestring   probe-file                    }
@w{  compile-file                 file-write-date   rename-file                   }
@w{  compile-file-pathname        host-namestring   streamp                       }
@w{  concatenated-stream-streams  load              synonym-stream-symbol         }
@w{  delete-file                  logical-pathname  translate-logical-pathname    }
@w{  directory                    merge-pathnames   translate-pathname            }
@w{  directory-namestring         namestring        truename                      }
@w{  dribble                      open              two-way-stream-input-stream   }
@w{  echo-stream-input-stream     open-stream-p     two-way-stream-output-stream  }
@w{  echo-stream-ouput-stream     parse-namestring  wild-pathname-p               }
@w{  ed                           pathname          with-open-file                }
@w{  enough-namestring            pathname-match-p                                }

@noindent
@w{        Figure 21--7: Operators that accept either Open or Closed Streams      }

@end group

The @i{operators} in Figure 21--8 accept @i{stream} @i{arguments} that
must be @i{open} @i{streams}.

@group
@noindent
@w{ clear-input              output-stream-p         read-char-no-hang          }
@w{ clear-output             peek-char               read-delimited-list        }
@w{ file-length              pprint                  read-line                  }
@w{ file-position            pprint-fill             read-preserving-whitespace }
@w{ file-string-length       pprint-indent           stream-element-type        }
@w{ finish-output            pprint-linear           stream-external-format     }
@w{ force-output             pprint-logical-block    terpri                     }
@w{ format                   pprint-newline          unread-char                }
@w{ fresh-line               pprint-tab              with-open-stream           }
@w{ get-output-stream-string pprint-tabular          write                      }
@w{ input-stream-p           prin1                   write-byte                 }
@w{ interactive-stream-p     princ                   write-char                 }
@w{ listen                   print                   write-line                 }
@w{ make-broadcast-stream    print-object            write-string               }
@w{ make-concatenated-stream print-unreadable-object y-or-n-p                   }
@w{ make-echo-stream         read                    yes-or-no-p                }
@w{ make-synonym-stream      read-byte                                          }
@w{ make-two-way-stream      read-char                                          }

@noindent
@w{             Figure 21--8: Operators that accept Open Streams only            }

@end group

@node Restrictions on Composite Streams,  , Stream Arguments to Standardized Functions, Stream Concepts
@subsection Restrictions on Composite Streams

The consequences are undefined if any @i{component} of a @i{composite stream}
is @i{closed} before the @i{composite stream} is @i{closed}.

The consequences are undefined if the @i{synonym stream symbol} is not @i{bound}
to an @i{open} @i{stream} from the time of the @i{synonym stream}'s creation
until the time it is @i{closed}.

@c end of including concept-streams

@node Streams Dictionary,  , Stream Concepts, Streams
@section Streams Dictionary

@c including dict-streams

@menu
* stream::			
* broadcast-stream::		
* concatenated-stream::		
* echo-stream::			
* file-stream::			
* string-stream::		
* synonym-stream::		
* two-way-stream::		
* input-stream-p::		
* interactive-stream-p::	
* open-stream-p::		
* stream-element-type::		
* streamp::			
* read-byte::			
* write-byte::			
* peek-char::			
* read-char::			
* read-char-no-hang::		
* terpri::			
* unread-char::			
* write-char::			
* read-line::			
* write-string::		
* read-sequence::		
* write-sequence::		
* file-length::			
* file-position::		
* file-string-length::		
* open::			
* stream-external-format::	
* with-open-file::		
* close::			
* with-open-stream::		
* listen::			
* clear-input::			
* finish-output::		
* y-or-n-p::			
* make-synonym-stream::		
* synonym-stream-symbol::	
* broadcast-stream-streams::	
* make-broadcast-stream::	
* make-two-way-stream::		
* two-way-stream-input-stream::	 
* echo-stream-input-stream::	
* make-echo-stream::		
* concatenated-stream-streams::	 
* make-concatenated-stream::	
* get-output-stream-string::	
* make-string-input-stream::	
* make-string-output-stream::	
* with-input-from-string::	
* with-output-to-string::	
* *debug-io*::			
* *terminal-io*::		
* stream-error::		
* stream-error-stream::		
* end-of-file::			
@end menu

@node stream, broadcast-stream, Streams Dictionary, Streams Dictionary
@subsection stream                                                       [System Class]

@subsubheading  Class Precedence List::
@b{stream},
@b{t}

@subsubheading  Description::

A @i{stream} is an @i{object} that can be used with an input or output
function to identify an appropriate source or sink of @i{characters} or 
@i{bytes} for that operation.

For more complete information, see @ref{Stream Concepts}.

@subsubheading  See Also::

@ref{Stream Concepts},
@ref{Printing Other Objects},
{@ref{Printer}},
{@ref{Reader}}

@node broadcast-stream, concatenated-stream, stream, Streams Dictionary
@subsection broadcast-stream                                             [System Class]

@subsubheading  Class Precedence List::

@b{broadcast-stream},
@b{stream},
@b{t}

@subsubheading  Description::

A @i{broadcast stream} is an @i{output} @i{stream} which 
has associated with it a set of zero or more @i{output} @i{streams} 
such that any output sent to the @i{broadcast stream} gets passed on
as output to each of the associated @i{output} @i{streams}.
(If a @i{broadcast stream} has no @i{component streams},
then all output to the @i{broadcast stream} is discarded.)

The set of operations that may be performed on a @i{broadcast stream} 
is the intersection of those for its associated @i{output} @i{streams}.

Some output operations (@i{e.g.}, @b{fresh-line}) return @i{values} based on the
state of the @i{stream} at the time of the operation.

Since these @i{values} might differ for each of the @i{component streams},
it is necessary to describe their return value specifically:

@table @asis

@item @t{*}  
@b{stream-element-type} returns
    the value from the last component stream, 
    or @b{t} if there are no component streams.

@item @t{*}  
@b{fresh-line} returns
     the value from the last component stream, 
     or @b{nil} if there are no component streams.

@item @t{*}  
The functions
          @b{file-length},
          @b{file-position},
          @b{file-string-length},
      and @b{stream-external-format}
   return the value from the last component stream;
   if there are no component streams,
       @b{file-length} and @b{file-position} return @t{0},
       @b{file-string-length} returns @t{1},
   and @b{stream-external-format} returns @t{:default}.

@item @t{*}  
The functions @b{streamp} and @b{output-stream-p} 
  always return @i{true} for @i{broadcast streams}.

@item @t{*}  
The functions @b{open-stream-p} tests whether the @i{broadcast stream}
  is @i{open}_2, not whether its component streams are @i{open}.

@item @t{*}  
The functions @b{input-stream-p} and @i{interactive-stream-p} 
  return an @i{implementation-defined}, @i{generalized boolean} value.

@item @t{*}  
For the input operations
        @b{clear-input}
        @b{listen},
        @b{peek-char},
        @b{read-byte},
        @b{read-char-no-hang},
        @b{read-char},
        @b{read-line},
    and @b{unread-char},
  the consequences are undefined if the indicated operation is performed.
  However, an @i{implementation} is permitted 
  to define such a behavior as an @i{implementation-dependent} extension.
@end table

For any output operations not having their return values explicitly specified above
or elsewhere in this document, it is defined that
the @i{values} returned by such an operation are 
the @i{values} resulting from performing the operation 
on the last of its @i{component streams};
the @i{values} resulting from performing the operation
on all preceding @i{streams} are discarded.                    
If there are no @i{component streams}, 
the value is @i{implementation-dependent}.

@subsubheading  See Also::

@ref{broadcast-stream-streams}
,
@ref{make-broadcast-stream}

@node concatenated-stream, echo-stream, broadcast-stream, Streams Dictionary
@subsection concatenated-stream                                          [System Class]

@subsubheading  Class Precedence List::

@b{concatenated-stream},
@b{stream},
@b{t}

@subsubheading  Description::

A @i{concatenated stream} is an @i{input} @i{stream} which 
is a @i{composite stream} of zero or more other @i{input} @i{streams}, 
such that the sequence of data which can be read from the
@i{concatenated stream} is the same as the concatenation of the 
sequences of data which could be read from each of the 
constituent @i{streams}.

Input from a @i{concatenated stream} is taken from the first
of the associated @i{input streams} until it reaches @i{end of file}_1; 
then that @i{stream} is discarded, and subsequent input is taken
from the next @i{input stream}, and so on.
An @i{end of file} on the associated @i{input streams} is always managed
invisibly by the @i{concatenated stream}---the only time a client of
a @i{concatenated stream} sees an @i{end of file} is when an attempt is
made to obtain data from the @i{concatenated stream} but it has no
remaining @i{input streams} from which to obtain such data.

@subsubheading  See Also::

@ref{concatenated-stream-streams}
,
@ref{make-concatenated-stream}

@node echo-stream, file-stream, concatenated-stream, Streams Dictionary
@subsection echo-stream                                                  [System Class]

@subsubheading  Class Precedence List::

@b{echo-stream},
@b{stream},
@b{t}

@subsubheading  Description::

An @i{echo stream} is a @i{bidirectional} @i{stream}
that gets  its input  from an associated @i{input}  @i{stream}
and  sends its output to   an associated @i{output} @i{stream}.

All input taken from the @i{input} @i{stream} 
is echoed to the @i{output} @i{stream}.
Whether the input is echoed immediately after it is encountered,
or after it has been read from the @i{input stream}
is @i{implementation-dependent}.

@subsubheading  See Also::

@ref{echo-stream-input-stream; echo-stream-output-stream}
,
@b{echo-stream-output-stream},
@ref{make-echo-stream}

@node file-stream, string-stream, echo-stream, Streams Dictionary
@subsection file-stream                                                  [System Class]

@subsubheading  Class Precedence List::

@b{file-stream},
@b{stream},
@b{t}

@subsubheading  Description::

An @i{object} of @i{type} @b{file-stream} is a @i{stream} the direct
source or sink of which is a @i{file}.  Such a @i{stream} is
created explicitly by @b{open} and @b{with-open-file}, and
implicitly by @i{functions} such as @b{load} that process @i{files}.

@subsubheading  See Also::

@ref{load}
,
@ref{open}
,
@ref{with-open-file}

@node string-stream, synonym-stream, file-stream, Streams Dictionary
@subsection string-stream                                                [System Class]

@subsubheading  Class Precedence List::

@b{string-stream},
@b{stream},
@b{t}

@subsubheading  Description::

A @i{string stream} is a @i{stream} 
which reads input from or writes output to an associated @i{string}.

The @i{stream element type} of a @i{string stream} is always
a @i{subtype} of @i{type} @b{character}.

@subsubheading  See Also::

@ref{make-string-input-stream}
,
@ref{make-string-output-stream}
,
@ref{with-input-from-string}
,
@ref{with-output-to-string}

@node synonym-stream, two-way-stream, string-stream, Streams Dictionary
@subsection synonym-stream                                               [System Class]

@subsubheading  Class Precedence List::

@b{synonym-stream},
@b{stream},
@b{t}

@subsubheading  Description::

A @i{stream} that is an alias for another @i{stream},
which is the @i{value} of a @i{dynamic variable}
whose @i{name} is the @i{synonym stream symbol} of the @i{synonym stream}.

Any operations on a @i{synonym stream} will be performed 
on the @i{stream} that is then the @i{value} of the
@i{dynamic variable} named by the @i{synonym stream symbol}.
If the @i{value} of the @i{variable} should change,
or if the @i{variable} should be @i{bound},
then the @i{stream} will operate on the new @i{value} of the @i{variable}.

@subsubheading  See Also::

@ref{make-synonym-stream}
,
@ref{synonym-stream-symbol}

@node two-way-stream, input-stream-p, synonym-stream, Streams Dictionary
@subsection two-way-stream                                               [System Class]

@subsubheading  Class Precedence List::

@b{two-way-stream},
@b{stream},
@b{t}

@subsubheading  Description::

A @i{bidirectional} @i{composite stream} that 
     receives its input  from an associated @i{input}  @i{stream} 
 and sends    its output to   an associated @i{output} @i{stream}.

@subsubheading  See Also::

@ref{make-two-way-stream}
,
@ref{two-way-stream-input-stream; two-way-stream-output-stream}
,
@b{two-way-stream-output-stream}

@node input-stream-p, interactive-stream-p, two-way-stream, Streams Dictionary
@subsection input-stream-p, output-stream-p                                  [Function]

@code{input-stream-p}  @i{stream} @result{}  @i{generalized-boolean}

@code{output-stream-p}  @i{stream} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values::

@i{stream}---a @i{stream}.

@i{generalized-boolean}---a @i{generalized boolean}.

@subsubheading  Description::

@b{input-stream-p} returns @i{true} if @i{stream} is an @i{input} @i{stream};
otherwise, returns @i{false}.

@b{output-stream-p} returns @i{true} if @i{stream} is an @i{output} @i{stream};
otherwise, returns @i{false}.

@subsubheading  Examples::

@example
 (input-stream-p *standard-input*) @result{}  @i{true}
 (input-stream-p *terminal-io*) @result{}  @i{true}
 (input-stream-p (make-string-output-stream)) @result{}  @i{false}

 (output-stream-p *standard-output*) @result{}  @i{true}
 (output-stream-p *terminal-io*) @result{}  @i{true}
 (output-stream-p (make-string-input-stream "jr")) @result{}  @i{false}
@end example

@subsubheading  Exceptional Situations::

Should signal an error of @i{type} @b{type-error}
			      if @i{stream} is not a @i{stream}.

@node interactive-stream-p, open-stream-p, input-stream-p, Streams Dictionary
@subsection interactive-stream-p                                             [Function]

@code{interactive-stream-p}  @i{stream} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values::

@i{stream}---a @i{stream}.

@i{generalized-boolean}---a @i{generalized boolean}.

@subsubheading  Description::

Returns @i{true} if @i{stream} is an @i{interactive stream};
otherwise, returns @i{false}.

@subsubheading  Examples::

@example
 (when (> measured limit)
   (let ((error (round (* (- measured limit) 100)
                       limit)))
     (unless (if (interactive-stream-p *query-io*)
                 (yes-or-no-p "The frammis is out of tolerance by ~D
                               Is it safe to proceed? " error)
                 (< error 15))  ;15
       (error "The frammis is out of tolerance by ~D
@end example

@subsubheading  Exceptional Situations::

Should signal an error of @i{type} @b{type-error}
			      if @i{stream} is not a @i{stream}.

@subsubheading  See Also::

@ref{Stream Concepts}

@node open-stream-p, stream-element-type, interactive-stream-p, Streams Dictionary
@subsection open-stream-p                                                    [Function]

@code{open-stream-p}  @i{stream} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values::

@i{stream}---a @i{stream}.

@i{generalized-boolean}---a @i{generalized boolean}.

@subsubheading  Description::

Returns @i{true} if @i{stream} is an @i{open} @i{stream};
otherwise, returns @i{false}.

@i{Streams} are open until they have been explicitly closed with @b{close},
or until they are implicitly closed due to exit from a
  @b{with-output-to-string}, 
  @b{with-open-file},
  @b{with-input-from-string},  or 
  @b{with-open-stream} @i{form}.

@subsubheading  Examples::

@example
 (open-stream-p *standard-input*) @result{}  @i{true}
@end example

@subsubheading  Affected By::

@b{close}.

@subsubheading  Exceptional Situations::

Should signal an error of @i{type} @b{type-error}
			      if @i{stream} is not a @i{stream}.

@node stream-element-type, streamp, open-stream-p, Streams Dictionary
@subsection stream-element-type                                              [Function]

@code{stream-element-type}  @i{stream} @result{}  @i{typespec}

@subsubheading  Arguments and Values::

@i{stream}---a @i{stream}.

@i{typespec}---a @i{type specifier}.

@subsubheading  Description::

@b{stream-element-type} returns a @i{type specifier} that
indicates the @i{types} of @i{objects} that may be read from 
or written to @i{stream}.

@i{Streams} created by @b{open} have an @i{element type}
restricted to @b{integer} or a @i{subtype} of @i{type} @b{character}.

@subsubheading  Examples::

@example
;; Note that the stream must accomodate at least the specified type,
;; but might accomodate other types.  Further note that even if it does
;; accomodate exactly the specified type, the type might be specified in
;; any of several ways.
 (with-open-file (s "test" :element-type '(integer 0 1)
                           :if-exists :error
                           :direction :output)
   (stream-element-type s))
@result{}  INTEGER
@i{OR}@result{} (UNSIGNED-BYTE 16)
@i{OR}@result{} (UNSIGNED-BYTE 8)
@i{OR}@result{} BIT
@i{OR}@result{} (UNSIGNED-BYTE 1)
@i{OR}@result{} (INTEGER 0 1)
@i{OR}@result{} (INTEGER 0 (2))
@end example

@subsubheading  Exceptional Situations::

Should signal an error of @i{type} @b{type-error}
			      if @i{stream} is not a @i{stream}.

@node streamp, read-byte, stream-element-type, Streams Dictionary
@subsection streamp                                                          [Function]

@code{streamp}  @i{object} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values::

@i{object}---an @i{object}.

@i{generalized-boolean}---a @i{generalized boolean}.

@subsubheading  Description::

Returns @i{true} if @i{object} is of @i{type} @b{stream};
otherwise, returns @i{false}.

@b{streamp} is unaffected by whether @i{object},
if it is a @i{stream}, is @i{open} or closed.

@subsubheading  Examples::

@example
 (streamp *terminal-io*) @result{}  @i{true}
 (streamp 1) @result{}  @i{false}
@end example

@subsubheading  Notes::

@example
 (streamp @i{object}) @equiv{} (typep @i{object} 'stream)
@end example

@node read-byte, write-byte, streamp, Streams Dictionary
@subsection read-byte                                                        [Function]

@code{read-byte}  @i{stream {&optional} eof-error-p eof-value} @result{}  @i{byte}

@subsubheading  Arguments and Values::

@i{stream}---a @i{binary} @i{input} @i{stream}.

@i{eof-error-p}---a @i{generalized boolean}.
 The default is @i{true}.

@i{eof-value}---an @i{object}.
 The default is @b{nil}.

@i{byte}---an @i{integer},
 or the @i{eof-value}.

@subsubheading  Description::

@b{read-byte} reads and returns one byte from @i{stream}.

If an @i{end of file}_2 occurs and @i{eof-error-p} is @i{false}, 
the @i{eof-value} is returned.  

@subsubheading  Examples::
@example
 (with-open-file (s "temp-bytes" 
                     :direction :output
                     :element-type 'unsigned-byte)
    (write-byte 101 s)) @result{}  101
 (with-open-file (s "temp-bytes" :element-type 'unsigned-byte)
    (format t "~S ~S" (read-byte s) (read-byte s nil 'eof)))
@t{ |> } 101 EOF
@result{}  NIL
@end example

@subsubheading  Side Effects::

Modifies @i{stream}.

@subsubheading  Exceptional Situations::

Should signal an error of @i{type} @b{type-error}
			      if @i{stream} is not a @i{stream}.

Should signal an error of @i{type} @b{error} 
if @i{stream} is not  a @i{binary} @i{input} @i{stream}.

If there are no @i{bytes} remaining in the @i{stream} 
and @i{eof-error-p} is @i{true}, an error of @i{type} @b{end-of-file} is signaled.

@subsubheading  See Also::

@ref{read-char}
,

@ref{read-sequence}
,

@ref{write-byte}

@node write-byte, peek-char, read-byte, Streams Dictionary
@subsection write-byte                                                       [Function]

@code{write-byte}  @i{byte stream} @result{}  @i{byte}

@subsubheading  Arguments and Values::

@i{byte}---an @i{integer} of the @i{stream element type}
		  of @i{stream}.

@i{stream}---a @i{binary} @i{output} @i{stream}.

@subsubheading  Description::

@b{write-byte} writes one byte, @i{byte}, to @i{stream}.

@subsubheading  Examples::

@example
 (with-open-file (s "temp-bytes" 
                    :direction :output
                    :element-type 'unsigned-byte)
    (write-byte 101 s)) @result{}  101
@end example

@subsubheading  Side Effects::

@i{stream} is modified.

@subsubheading  Affected By::

The @i{element type} of the @i{stream}.

@subsubheading  Exceptional Situations::

Should signal an error of @i{type} @b{type-error}
			      if @i{stream} is not a @i{stream}.
Should signal an error of @i{type} @b{error} 
if @i{stream} is not  a @i{binary} @i{output} @i{stream}.

Might signal an error of @i{type} @b{type-error} if @i{byte} is not
an @i{integer} of the @i{stream element type} of @i{stream}.

@subsubheading  See Also::

@ref{read-byte}
,
@ref{write-char}
,

@ref{write-sequence}

@node peek-char, read-char, write-byte, Streams Dictionary
@subsection peek-char                                                        [Function]

@code{peek-char}  @i{{&optional} peek-type input-stream eof-error-p
			       eof-value recursive-p} @result{}  @i{char}

@subsubheading  Arguments and Values::

@i{peek-type}---a @i{character} or @b{t} or @b{nil}.

@i{input-stream}---@i{input} @i{stream designator}.
  The default is @i{standard input}.

@i{eof-error-p}---a @i{generalized boolean}.
 The default is @i{true}.

@i{eof-value}---an @i{object}.
 The default is @b{nil}.

@i{recursive-p}---a @i{generalized boolean}.
 The default is @i{false}.

@i{char}---a @i{character} or the @i{eof-value}.

@subsubheading  Description::

@b{peek-char} obtains the next character in @i{input-stream}
without actually reading it, thus leaving the character
to be read at a later time.  It can
also be used to skip over and discard intervening
characters in the @i{input-stream} 
until a particular character is found.

If @i{peek-type} is not supplied or @b{nil},
@b{peek-char} returns the next character to be read from 
@i{input-stream}, without actually removing it from 
@i{input-stream}.
The next time input is done from @i{input-stream}, the character will still
be there.  
If @i{peek-type} is @b{t},
then @b{peek-char} skips over @i{whitespace}_2 @i{characters},
but not comments,
and then performs the peeking operation on the next
character.
The last character examined, the one that starts an @i{object},
is not removed from @i{input-stream}.
If @i{peek-type} is a @i{character},
then @b{peek-char} skips
over input characters until a character that
is @b{char=} to that @i{character} is found;          
that character is left in @i{input-stream}.

If an @i{end of file}_2 occurs and @i{eof-error-p} is @i{false},
@i{eof-value} is returned.  

{ }{If @i{recursive-p} is @i{true},
this call is expected to be embedded in a higher-level call to @b{read} 
or a similar @i{function} used by the @i{Lisp reader}.}

When @i{input-stream} is an @i{echo stream},
characters that are only peeked at are not echoed. In the
case that @i{peek-type} is not @b{nil},
the characters that are passed by @b{peek-char} 
are treated as if by @b{read-char},
and so are echoed unless they have been marked otherwise by @b{unread-char}.

@subsubheading  Examples::
@example
 (with-input-from-string (input-stream "    1 2 3 4 5")
    (format t "~S ~S ~S" 
            (peek-char t input-stream)
            (peek-char #\4 input-stream)
            (peek-char nil input-stream)))
@t{ |> } #\1 #\4 #\4
@result{}  NIL
@end example

@subsubheading  Affected By::

@b{*readtable*},
@b{*standard-input*},
@b{*terminal-io*}.

@subsubheading  Exceptional Situations::

If @i{eof-error-p} is @i{true} and an @i{end of file}_2 occurs
an error of @i{type} @b{end-of-file} is signaled.

If     @i{peek-type} is a @i{character},
       an @i{end of file}_2 occurs,
   and @i{eof-error-p} is @i{true},
an error of @i{type} @b{end-of-file} is signaled.

If @i{recursive-p} is @i{true}
and an @i{end of file}_2 occurs,
an error of @i{type} @b{end-of-file} is signaled.

@node read-char, read-char-no-hang, peek-char, Streams Dictionary
@subsection read-char                                                        [Function]

@code{read-char}  @i{{&optional} input-stream eof-error-p eof-value recursive-p} @result{}  @i{char}

@subsubheading  Arguments and Values::

@i{input-stream}---an @i{input} @i{stream designator}.
 The default is @i{standard input}.

@i{eof-error-p}---a @i{generalized boolean}.
 The default is @i{true}.

@i{eof-value}---an @i{object}.
 The default is @b{nil}.

@i{recursive-p}---a @i{generalized boolean}.
 The default is @i{false}.

@i{char}---a @i{character} or the @i{eof-value}.

@subsubheading  Description::

@b{read-char} returns the next @i{character} from @i{input-stream}.

When @i{input-stream} is an @i{echo stream},
the character is echoed on @i{input-stream} the first time the character is 
seen.
  Characters that are not echoed by @b{read-char} 
are those that were
  put there by @b{unread-char} 
and hence are assumed to have been echoed
  already by a previous call to @b{read-char}.

{ }{If @i{recursive-p} is @i{true},
this call is expected to be embedded in a higher-level call to @b{read} 
or a similar @i{function} used by the @i{Lisp reader}.}

If an @i{end of file}_2 occurs and @i{eof-error-p} is @i{false}, 
@i{eof-value} is returned.  

@subsubheading  Examples::
@example
 (with-input-from-string (is "0123")
    (do ((c (read-char is) (read-char is nil 'the-end)))
        ((not (characterp c)))
     (format t "~S " c)))
@t{ |> } #\0 #\1 #\2 #\3
@result{}  NIL
@end example

@subsubheading  Affected By::

@b{*standard-input*},
@b{*terminal-io*}.

@subsubheading  Exceptional Situations::

If an @i{end of file}_2 occurs before a character can be read, and 
@i{eof-error-p} is @i{true}, 
an error of @i{type} @b{end-of-file} is signaled.

@subsubheading  See Also::

@ref{read-byte}
,

@ref{read-sequence}
,

@ref{write-char}
,
@ref{read; read-preserving-whitespace}

@subsubheading  Notes::
The corresponding output function is @b{write-char}.

@node read-char-no-hang, terpri, read-char, Streams Dictionary
@subsection read-char-no-hang                                                [Function]

@code{read-char-no-hang}  @i{{&optional} input-stream eof-error-p
			       eof-value recursive-p} @result{}  @i{char}

@subsubheading  Arguments and Values::

@i{input-stream} -- an @i{input} @i{stream designator}.
 The default is @i{standard input}.

@i{eof-error-p}---a @i{generalized boolean}.
 The default is @i{true}.

@i{eof-value}---an @i{object}.
 The default is @b{nil}.

@i{recursive-p}---a @i{generalized boolean}.
 The default is @i{false}.

@i{char}---a @i{character} or @b{nil} or the @i{eof-value}.

@subsubheading  Description::

@b{read-char-no-hang} returns a character
from @i{input-stream} if such a character is available.  If no character
is available, @b{read-char-no-hang} returns @b{nil}.

{ }{If @i{recursive-p} is @i{true},
this call is expected to be embedded in a higher-level call to @b{read} 
or a similar @i{function} used by the @i{Lisp reader}.}

If an @i{end of file}_2 occurs and @i{eof-error-p} is @i{false}, 
@i{eof-value} is returned.  

@subsubheading  Examples::

@example
;; This code assumes an implementation in which a newline is not
;; required to terminate input from the console.
 (defun test-it ()
   (unread-char (read-char))
   (list (read-char-no-hang) 
         (read-char-no-hang) 
         (read-char-no-hang)))
@result{}  TEST-IT
;; Implementation A, where a Newline is not required to terminate
;; interactive input on the console.
 (test-it)
@t{ |> } @b{|>>}@t{a}@b{<<|}
@result{}  (#\a NIL NIL)
;; Implementation B, where a Newline is required to terminate
;; interactive input on the console, and where that Newline remains
;; on the input stream.
 (test-it)
@t{ |> } @b{|>>}@t{a{@i{[<--}~]}}@b{<<|}
@result{}  (#\a #\Newline NIL)
@end example

@subsubheading  Affected By::

@b{*standard-input*},
@b{*terminal-io*}.

@subsubheading  Exceptional Situations::

If an @i{end of file}_2 occurs
when @i{eof-error-p} is @i{true},
an error of @i{type} @b{end-of-file} is signaled .

@subsubheading  See Also::

@ref{listen}

@subsubheading  Notes::

@b{read-char-no-hang} is exactly like @b{read-char}, except
that if it would be necessary to wait in order to get a character (as
from a keyboard), @b{nil} is immediately returned without waiting.  

@node terpri, unread-char, read-char-no-hang, Streams Dictionary
@subsection terpri, fresh-line                                               [Function]

@code{terpri}  @i{{&optional} output-stream} @result{}  @i{@b{nil}}

@code{fresh-line}  @i{{&optional} output-stream} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values::

@i{output-stream} -- an @i{output} @i{stream designator}.
 The default is @i{standard output}.

@i{generalized-boolean}---a @i{generalized boolean}.

@subsubheading  Description::

@b{terpri} outputs a @i{newline} to @i{output-stream}.

@b{fresh-line} is similar to @b{terpri} but outputs a @i{newline}
only if the @i{output-stream} is not already at the start of a line.
If for some reason this cannot be determined, then a @i{newline} is output anyway.
@b{fresh-line} returns @i{true} if it outputs a @i{newline};
otherwise it returns @i{false}.

@subsubheading  Examples::

@example
 (with-output-to-string (s)
    (write-string "some text" s)
    (terpri s)
    (terpri s)
    (write-string "more text" s))
@result{}  "some text

more text"
 (with-output-to-string (s)
    (write-string "some text" s)
    (fresh-line s)
    (fresh-line s)
    (write-string "more text" s))
@result{}  "some text
more text"
@end example

@subsubheading  Side Effects::

The @i{output-stream} is modified.

@subsubheading  Affected By::

@b{*standard-output*},
@b{*terminal-io*}.

@subsubheading  Exceptional Situations::

None.

[Reviewer Note by Barmar: What if stream is closed?]

@subsubheading  Notes::

@b{terpri} is identical in effect to

@example
 (write-char #\Newline output-stream)
@end example

@node unread-char, write-char, terpri, Streams Dictionary
@subsection unread-char                                                      [Function]

@code{unread-char}  @i{character {&optional} input-stream} @result{}  @i{@b{nil}}

@subsubheading  Arguments and Values::

@i{character}---a @i{character};
  must be the last @i{character} that was read from @i{input-stream}.

@i{input-stream}---an @i{input} @i{stream designator}.
 The default is @i{standard input}.

@subsubheading  Description::

@b{unread-char} places @i{character} back onto the front of
@i{input-stream} so that it will again be the next character
in @i{input-stream}.

When @i{input-stream} is an @i{echo stream},
no attempt is made to undo any echoing of the character that might already
have been done on @i{input-stream}. However, characters placed on 
@i{input-stream} by @b{unread-char} are marked in such a way 
as to inhibit later re-echo by @b{read-char}.

It is an error to invoke @b{unread-char} 
twice consecutively on the same @i{stream}
without an intervening call to @b{read-char} 
(or some other input operation which implicitly reads characters)
on that @i{stream}.

Invoking @b{peek-char} or @b{read-char} commits all previous characters.
The consequences of invoking @b{unread-char}
on any character preceding that which is returned by 
@b{peek-char} (including those passed over by 
@b{peek-char} that has a @i{non-nil} @i{peek-type})
are unspecified.
In particular, the consequences of 
invoking @b{unread-char} after @b{peek-char}
are unspecified.

@subsubheading  Examples::

@example
 (with-input-from-string (is "0123")
    (dotimes (i 6)
      (let ((c (read-char is)))
        (if (evenp i) (format t "~&~S ~S~
@t{ |> } 0 #\0
@t{ |> } 2 #\1
@t{ |> } 4 #\2
@result{}  NIL
@end example

@subsubheading  Affected By::

@b{*standard-input*},
@b{*terminal-io*}.

@subsubheading  See Also::

@ref{peek-char}
,
@ref{read-char}
,
@ref{Stream Concepts}

@subsubheading  Notes::

@b{unread-char} is intended to be an efficient mechanism for allowing
the @i{Lisp reader} and other parsers to perform one-character lookahead
in @i{input-stream}.

@node write-char, read-line, unread-char, Streams Dictionary
@subsection write-char                                                       [Function]

@code{write-char}  @i{character {&optional} output-stream} @result{}  @i{character}

@subsubheading  Arguments and Values::

@i{character}---a @i{character}.

@i{output-stream} -- an @i{output} @i{stream designator}.
 The default is @i{standard output}.

@subsubheading  Description::

@b{write-char} outputs @i{character} to @i{output-stream}.

@subsubheading  Examples::
@example
 (write-char #\a)
@t{ |> } a
@result{}  #\a
 (with-output-to-string (s) 
   (write-char #\a s)
   (write-char #\Space s)
   (write-char #\b s))
@result{}  "a b"
@end example

@subsubheading  Side Effects::

The @i{output-stream} is modified.

@subsubheading  Affected By::

@b{*standard-output*},
@b{*terminal-io*}.

@subsubheading  See Also::

@ref{read-char}
,
@ref{write-byte}
,

@ref{write-sequence}

@node read-line, write-string, write-char, Streams Dictionary
@subsection read-line                                                        [Function]

@code{read-line}  @i{{&optional} input-stream eof-error-p eof-value recursive-p}@*
   @result{}  @i{line, missing-newline-p}

@subsubheading  Arguments and Values::

@i{input-stream}---an @i{input} @i{stream designator}.
 The default is @i{standard input}.

@i{eof-error-p}---a @i{generalized boolean}.
 The default is @i{true}.

@i{eof-value}---an @i{object}.
 The default is @b{nil}.

@i{recursive-p}---a @i{generalized boolean}.
 The default is @i{false}.

@i{line}---a @i{string} or the @i{eof-value}.

@i{missing-newline-p}---a @i{generalized boolean}.

@subsubheading  Description::

Reads from @i{input-stream} a line of text
that is terminated by a @i{newline} or @i{end of file}.

{ }{If @i{recursive-p} is @i{true},
this call is expected to be embedded in a higher-level call to @b{read} 
or a similar @i{function} used by the @i{Lisp reader}.}

The @i{primary value}, @i{line}, is the line that is read,
represented as a @i{string} (without the trailing @i{newline}, if any).
If  @i{eof-error-p} is @i{false} 
and the @i{end of file} for @i{input-stream} is reached
     before any @i{characters} are read,
@i{eof-value} is returned as the @i{line}.

The @i{secondary value}, @i{missing-newline-p}, 
is a @i{generalized boolean} that is
    @i{false} if the @i{line} was terminated by a @i{newline},
 or @i{true}  if the @i{line} was terminated by 
		   the @i{end of file} for @i{input-stream}
		   (or if the @i{line} is the @i{eof-value}).

@subsubheading  Examples::

@example
 (setq a "line 1
 line2")
@result{}  "line 1
 line2"
 (read-line (setq input-stream (make-string-input-stream a)))
@result{}  "line 1", @i{false}
 (read-line input-stream)
@result{}  "line2", @i{true}
 (read-line input-stream nil nil)
@result{}  NIL, @i{true}
@end example

@subsubheading  Affected By::

@b{*standard-input*},
@b{*terminal-io*}.

@subsubheading  Exceptional Situations::

If an @i{end of file}_2 occurs before any characters are read in the line,
an error is signaled if @i{eof-error-p} is @i{true}.  

@subsubheading  See Also::

@ref{read; read-preserving-whitespace}

@subsubheading  Notes::

The corresponding output function is @b{write-line}.

@node write-string, read-sequence, read-line, Streams Dictionary
@subsection write-string, write-line                                         [Function]

@code{write-string}  @i{string {&optional} output-stream {&key} start end} @result{}  @i{string}

@code{write-line}  @i{string {&optional} output-stream {&key} start end} @result{}  @i{string}

@subsubheading  Arguments and Values::

@i{string}---a @i{string}.

@i{output-stream} -- an @i{output} @i{stream designator}.
 The default is @i{standard output}.

@i{start}, @i{end}---@i{bounding index designators} of @i{string}.
 The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.

@subsubheading  Description::

@b{write-string} writes the @i{characters} of 
the subsequence of @i{string} @i{bounded} by @i{start} and @i{end}
to @i{output-stream}.
@b{write-line} does the same thing, 
but then outputs a newline afterwards.  

@subsubheading  Examples::

@example
 (prog1 (write-string "books" nil :end 4) (write-string "worms"))
@t{ |> } bookworms
@result{}  "books"
 (progn (write-char #\*)
        (write-line "test12" *standard-output* :end 5) 
        (write-line "*test2")
        (write-char #\*)
        nil)
@t{ |> } *test1
@t{ |> } *test2
@t{ |> } *
@result{}  NIL
@end example

@subsubheading  Affected By::

@b{*standard-output*},
@b{*terminal-io*}.

@subsubheading  See Also::

@ref{read-line}
, 
@ref{write-char}

@subsubheading  Notes::

@b{write-line} and @b{write-string} return @i{string},
not the substring @i{bounded} by @i{start} and @i{end}.

@example
 (write-string string)
@equiv{} (dotimes (i (length string)
      (write-char (char string i)))

 (write-line string)
@equiv{} (prog1 (write-string string) (terpri))
@end example

@node read-sequence, write-sequence, write-string, Streams Dictionary
@subsection read-sequence                                                    [Function]

@code{read-sequence}  @i{sequence stream {&key} start end} @result{}  @i{position}

@i{sequence}---a @i{sequence}.

@i{stream}---an @i{input} @i{stream}.

@i{start}, @i{end}---@i{bounding index designators} of
 @i{sequence}.  The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.

@i{position}---an @i{integer} greater than or equal to zero, and
 less than or equal to the @i{length} of the @i{sequence}.

@subsubheading  Description::

Destructively modifies @i{sequence} by replacing the @i{elements}
of @i{sequence} @i{bounded} by @i{start} and @i{end} with
@i{elements} read from @i{stream}.

@i{Sequence} is destructively modified by copying successive
@i{elements} into it from @i{stream}.  If the @i{end of file} for
@i{stream} is reached before copying all @i{elements} of the
subsequence, then the extra @i{elements} near the end of @i{sequence}
are not updated.

@i{Position} is the index of the first @i{element} of @i{sequence}
that was not updated, which might be less than @i{end} because the
@i{end of file} was reached.

@subsubheading  Examples::

@example
 (defvar *data* (make-array 15 :initial-element nil))
 (values (read-sequence *data* (make-string-input-stream "test string")) *data*)
 @result{}  11, #(#\t #\e #\s #\t #\Space #\s #\t #\r #\i #\n #\g NIL NIL NIL NIL)
@end example

@subsubheading  Side Effects::

Modifies @i{stream} and @i{sequence}.

@subsubheading  Exceptional Situations::

Should be prepared to signal an error of @i{type} @b{type-error}
			 if @i{sequence} is not a @i{proper sequence}.
Should signal an error of @i{type} @b{type-error}
			      if @i{start} is not a non-negative @i{integer}.
Should signal an error of @i{type} @b{type-error}
			      if @i{end} is not a non-negative @i{integer} or @b{nil}.

Might signal an error of @i{type} @b{type-error} if an @i{element} read from
the @i{stream} is not a member of the @i{element type} of the
@i{sequence}.

@subsubheading  See Also::

@ref{Compiler Terminology},
@ref{write-sequence}
,
@ref{read-line}

@subsubheading  Notes::

@b{read-sequence} is identical in effect to iterating over the indicated
subsequence and reading one @i{element} at a time from @i{stream} and
storing it into @i{sequence}, but may be more efficient than the
equivalent loop.  An efficient implementation is more likely to exist
for the case where the @i{sequence} is a @i{vector} with the same
@i{element type} as the @i{stream}.

@node write-sequence, file-length, read-sequence, Streams Dictionary
@subsection write-sequence                                                   [Function]

@code{write-sequence}  @i{sequence stream {&key} start end} @result{}  @i{sequence}

@i{sequence}---a @i{sequence}.

@i{stream}---an @i{output} @i{stream}.

@i{start}, @i{end}---@i{bounding index designators} of
 @i{sequence}.  The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.

@subsubheading  Description::

@b{write-sequence} writes the @i{elements} of the subsequence
of @i{sequence} @i{bounded} by @i{start} and @i{end} to
@i{stream}.

@subsubheading  Examples::

@example
 (write-sequence "bookworms" *standard-output* :end 4)
 @t{ |> } book
 @result{}  "bookworms"
@end example

@subsubheading  Side Effects::

Modifies @i{stream}.

@subsubheading  Exceptional Situations::

Should be prepared to signal an error of @i{type} @b{type-error}
			 if @i{sequence} is not a @i{proper sequence}.
Should signal an error of @i{type} @b{type-error}
			      if @i{start} is not a non-negative @i{integer}.
Should signal an error of @i{type} @b{type-error}
			      if @i{end} is not a non-negative @i{integer} or @b{nil}.

Might signal an error of @i{type} @b{type-error} if an @i{element} of the
@i{bounded} @i{sequence} is not a member of the
@i{stream element type} of the @i{stream}.

@subsubheading  See Also::

@ref{Compiler Terminology},
@ref{read-sequence}
,
@ref{write-string; write-line}
,
@b{write-line}

@subsubheading  Notes::

@b{write-sequence} is identical in effect to iterating over the indicated
subsequence and writing one @i{element} at a time to @i{stream}, but
may be more efficient than the equivalent loop.  An efficient implementation
is more likely to exist for the case where the @i{sequence} is a
@i{vector} with the same @i{element type} as the @i{stream}.

@node file-length, file-position, write-sequence, Streams Dictionary
@subsection file-length                                                      [Function]

@code{file-length}  @i{stream} @result{}  @i{length}

@subsubheading  Arguments and Values::

@i{stream}---a @i{stream associated with a file}.

@i{length}---a non-negative @i{integer} or @b{nil}.

@subsubheading  Description::

@b{file-length} returns the length of @i{stream},  
or @b{nil} if the length cannot be determined.

For a binary file, the length is measured in units of
the @i{element type} of the @i{stream}.

@subsubheading  Examples::

@example
 (with-open-file (s "decimal-digits.text" 
                    :direction :output :if-exists :error)
   (princ "0123456789" s)
   (truename s))
@result{}  #P"A:>Joe>decimal-digits.text.1"
 (with-open-file (s "decimal-digits.text")
   (file-length s))
@result{}  10
@end example

@subsubheading  Exceptional Situations::

Should signal an error of @i{type} @b{type-error}
			      if @i{stream} is not a @i{stream associated with a file}.

@subsubheading  See Also::

@ref{open}

@node file-position, file-string-length, file-length, Streams Dictionary
@subsection file-position                                                    [Function]

@code{file-position}  @i{stream} @result{}  @i{position}

@code{file-position}  @i{stream position-spec} @result{}  @i{success-p}

@subsubheading  Arguments and Values::

@i{stream}---a @i{stream}.

@i{position-spec}---a @i{file position designator}.

@i{position}---a @i{file position} or @b{nil}.

@i{success-p}---a @i{generalized boolean}.

@subsubheading  Description::

Returns or changes the current position within a @i{stream}.

When @i{position-spec} is not supplied,
@b{file-position} returns the current @i{file position} in the @i{stream},
or @b{nil} if this cannot be determined.

When @i{position-spec} is supplied,
the @i{file position} in @i{stream} is set to that @i{file position} (if possible).
@b{file-position} returns @i{true} 
if the repositioning is performed successfully,
or @i{false} if it is not.

An @i{integer} returned by @b{file-position} of one argument 
should be acceptable as @i{position-spec} for use with the same file.

For a character file,
performing a single @b{read-char} or @b{write-char} operation
may cause the file position to be increased by more than 1 because of
character-set translations (such as translating between the @r{Common Lisp}
@t{#\Newline} character and an external ASCII
carriage-return/line-feed sequence) and other aspects of the
implementation.  For a binary file, every @b{read-byte} 
or @b{write-byte}
operation increases the file position by 1.

@subsubheading  Examples::

@example
 (defun tester ()
   (let ((noticed '()) file-written)
     (flet ((notice (x) (push x noticed) x))
       (with-open-file (s "test.bin" 
                          :element-type '(unsigned-byte 8)
                          :direction :output
                          :if-exists :error)
          (notice (file-position s)) ;1
          (write-byte 5 s) 
          (write-byte 6 s)
          (let ((p (file-position s)))
            (notice p) ;2
            (notice (when p (file-position s (1- p))))) ;3
          (write-byte 7 s)
          (notice (file-position s)) ;4
          (setq file-written (truename s)))
        (with-open-file (s file-written
                           :element-type '(unsigned-byte 8)
                           :direction :input)
          (notice (file-position s)) ;5
          (let ((length (file-length s)))
            (notice length) ;6
            (when length
              (dotimes (i length)
                (notice (read-byte s)))))) ;7,...
        (nreverse noticed))))
@result{}  tester
 (tester)
@result{}  (0 2 T 2 0 2 5 7)
@i{OR}@result{} (0 2 NIL 3 0 3 5 6 7)
@i{OR}@result{} (NIL NIL NIL NIL NIL NIL)
@end example

@subsubheading  Side Effects::

When the @i{position-spec} argument is supplied,
the @i{file position} in the @i{stream} might be moved.

@subsubheading  Affected By::

The value returned by @b{file-position} increases monotonically
as input or output operations are performed.  

@subsubheading  Exceptional Situations::

If @i{position-spec} is supplied, but is too large or otherwise inappropriate, 
an error is signaled.

@subsubheading  See Also::

@ref{file-length}
,
@ref{file-string-length}
,
@ref{open}

@subsubheading  Notes::

Implementations that have character files represented
as a sequence of records of bounded size might choose to encode the
file position as, for example,
<<@i{record-number}>>*<<@i{max-record-size}>>+<<@i{character-within-record}>>.
This is a valid encoding because it increases monotonically as
each character is read or written, though not necessarily by 1 at
each step.  An @i{integer} might then be considered ``inappropriate''
as @i{position-spec} to @b{file-position} if, when decoded into
record number and character number, it turned out that the
supplied record was too short for the specified character number.

@node file-string-length, open, file-position, Streams Dictionary
@subsection file-string-length                                               [Function]

@code{file-string-length}  @i{stream object} @result{}  @i{length}

@subsubheading  Arguments and Values::

@i{stream}---an @i{output} @i{character} @i{file stream}.

@i{object}---a @i{string} or a @i{character}.

@i{length}---a non-negative @i{integer}, or @b{nil}.

@subsubheading  Description::

@b{file-string-length} returns the difference between what 
@t{(file-position @i{stream})} would be after writing 
@i{object} and its current value, or @b{nil} if this cannot be determined.  

The returned value corresponds to the current state of @i{stream}
at the time of the call and might not be 
the same if it is called again
when the state of the @i{stream} has changed.

@node open, stream-external-format, file-string-length, Streams Dictionary
@subsection open                                                             [Function]

@code{open}  @i{filespec {&key} direction element-type
				               if-exists if-does-not-exist
						     external-format}@*
   @result{}  @i{stream}

@subsubheading  Arguments and Values::

@i{filespec}---a @i{pathname designator}.

@i{direction}---one of @t{:input}, @t{:output}, @t{:io}, or @t{:probe}.
 The default is @t{:input}.

@i{element-type}---a @i{type specifier} 
		       for @i{recognizable subtype} of @b{character};
		    or a @i{type specifier} 
		       for a @i{finite} @i{recognizable subtype} of @i{integer};
		    or one of the @i{symbols} 
                          @b{signed-byte},
                          @b{unsigned-byte},
		       or @t{:default}.
 The default is @b{character}.

@i{if-exists}---one of @t{:error}, @t{:new-version}, @t{:rename},
		  @t{:rename-and-delete}, @t{:overwrite}, @t{:append},
		  @t{:supersede}, or @b{nil}.
 The default is @t{:new-version} if the version component of @i{filespec} is @t{:newest},
          or @t{:error} otherwise.

@i{if-does-not-exist}---one of @t{:error}, @t{:create}, or @b{nil}.
 The default is @t{:error} if @i{direction} is @t{:input} 
		      or @i{if-exists} is @t{:overwrite} or @t{:append};
	  @t{:create} if @i{direction} is @t{:output} or @t{:io},
		      and @i{if-exists} is neither @t{:overwrite} nor @t{:append};
       or @b{nil} when @i{direction} is @t{:probe}.

@i{external-format}---an @i{external file format designator}.
  The default is @t{:default}.

@i{stream}---a @i{file stream} or @b{nil}.

@subsubheading  Description::

@b{open} creates, opens, and returns a @i{file stream} 
that is connected to the file specified by @i{filespec}.
@i{Filespec} is the name of the file to be opened.  
If the @i{filespec} @i{designator} is a @i{stream},
that @i{stream} is not closed first or otherwise affected.

The keyword arguments to @b{open} specify the characteristics 
of the @i{file stream} that is returned, and how to handle errors.

If @i{direction} is @t{:input}
or @t{:probe},
or if @i{if-exists} is not @t{:new-version}
and the version component of the @i{filespec} is @t{:newest},
then the file opened is that file already existing in the file system
that has a version greater than that of any other file in the file system
whose other pathname components are the same as those of @i{filespec}.

An implementation is required to recognize all of 
the @b{open} keyword options 
and to do something reasonable in the context of the host operating
system.  
For example, if a file system does not support distinct file
versions and does not distinguish the notions of deletion and expunging,
@t{:new-version} might be treated the same as
@t{:rename} or @t{:supersede}, and @t{:rename-and-delete} might
be treated the same as @t{:supersede}.

@table @asis

@item @t{:direction}  
These are the possible values for @i{direction}, 
and how they affect the nature of the @i{stream} that is created:

@table @asis

@item @t{:input}  
Causes the creation of an @i{input} @i{file stream}.

@item @t{:output}  
Causes the creation of an @i{output} @i{file stream}.

@item @t{:io}  
Causes the creation of a @i{bidirectional} @i{file stream}.

@item @t{:probe}  
Causes the creation of a ``no-directional'' @i{file stream}; 
in effect, the @i{file stream} is created 
and then closed prior to being returned by @b{open}.

@end table

@item @t{:element-type}  
The @i{element-type} specifies the unit of transaction for the @i{file stream}.
If it is @t{:default},
the unit is determined by @i{file system},
possibly based on the @i{file}.

@item @t{:if-exists}  
@i{if-exists} specifies the action to be taken if @i{direction} is
@t{:output} or @t{:io} and a file of the name @i{filespec} 
already exists.
If @i{direction} is @t{:input}, not supplied, or @t{:probe}, 
@i{if-exists} is ignored.
These are the results of @b{open} as modified by @i{if-exists}:

@table @asis

@item @t{:error}  
An error of @i{type} @b{file-error} is signaled.

@item @t{:new-version}  
A new file is created with a larger version number.

@item @t{:rename}  
The existing file is renamed to some other name and then a new file is created.

@item @t{:rename-and-delete}  
The existing file is renamed to some other name,
then it is deleted but not expunged, and then a new file is created.

@item @t{:overwrite}  
Output operations on the @i{stream} destructively modify the existing file.
If @i{direction} is @t{:io} the file is opened in a bidirectional mode
that allows both reading and writing.  The file pointer is initially 
positioned at the beginning of the file; however, the file is not truncated
back to length zero when it is opened.

@item @t{:append}  
Output operations on the @i{stream} destructively modify the existing file.
The file pointer is initially positioned at the end of the file.

If @i{direction} is @t{:io},
the file is opened in a bidirectional mode that allows both reading and writing.

@item @t{:supersede}  
The existing file is superseded;
that is, a new file with the same name as the old one is created.
If possible, the implementation should not destroy the old file until the new
@i{stream} is closed.

@item @b{nil}  
No file or @i{stream} is created;
instead, @b{nil} is returned to indicate failure.

@end table

@item @t{:if-does-not-exist}  
@i{if-does-not-exist}
specifies the action to be taken if
a file of name @i{filespec} does not already exist.
These are the results of @b{open} as modified by @i{if-does-not-exist}:

@table @asis

@item @t{:error}  
An error of @i{type} @b{file-error} is signaled.

@item @t{:create}  
An empty file is created.
Processing continues  as if the file 
had already existed but no processing as 
directed by @i{if-exists} is performed.

@item @b{nil}  
No file or @i{stream} is created;
instead, @b{nil} is returned to indicate failure.

@end table

@item @t{:external-format}  
This option selects an @i{external file format} for the @i{file}:
The only @i{standardized} value for this option is @t{:default},
although @i{implementations} are permitted to define additional 
@i{external file formats} and @i{implementation-dependent} values 
returned by @b{stream-external-format} can also be used by @i{conforming programs}.

The @i{external-format} is meaningful for
any kind of @i{file stream} whose @i{element type}
is a @i{subtype} of @i{character}.
This option is ignored for @i{streams} for which it is not meaningful;
however, @i{implementations} may define other @i{element types} 
for which it is meaningful.
The consequences are unspecified if a @i{character} is written 
that cannot be represented by the given @i{external file format}.

@end table

When a file is opened, a @i{file stream} is constructed to serve
as the file system's ambassador to the @r{Lisp} environment;
operations on the @i{file stream} are reflected by operations on the file
in the file system.  

A file can be deleted, renamed, or destructively modified by @b{open}.

For information about opening relative pathnames,
see @ref{Merging Pathnames}.

@subsubheading  Examples::

@example
 (open @i{filespec} :direction :probe)  @result{}  #<Closed Probe File Stream...>
 (setq q (merge-pathnames (user-homedir-pathname) "test"))
@result{}  #<PATHNAME :HOST NIL :DEVICE @i{device-name} :DIRECTORY @i{directory-name}
    :NAME "test" :TYPE NIL :VERSION :NEWEST>
 (open @i{filespec} :if-does-not-exist :create) @result{}  #<Input File Stream...>
 (setq s (open @i{filespec} :direction :probe)) @result{}  #<Closed Probe File Stream...>
 (truename s) @result{}  #<PATHNAME :HOST NIL :DEVICE @i{device-name} :DIRECTORY
    @i{directory-name} :NAME @i{filespec} :TYPE @i{extension} :VERSION 1>
 (open s :direction :output :if-exists nil) @result{}  NIL 
@end example

@subsubheading  Affected By::

The nature and state of the host computer's @i{file system}.

@subsubheading  Exceptional Situations::                        

If @i{if-exists} is @t{:error}, (subject to the
constraints on the meaning of @i{if-exists} listed above),
an error of @i{type} @b{file-error} is signaled.                        

If @i{if-does-not-exist} is @t{:error} (subject to the
constraints on the meaning of @i{if-does-not-exist} listed above),
an error of @i{type} @b{file-error} is signaled.

If it is impossible for an implementation to handle some option
in a manner close to what is specified here,
an error of @i{type} @b{error} might be signaled.

An error of @i{type} @b{file-error} is signaled if
@t{(wild-pathname-p @i{filespec})} returns true.

An error of @i{type} @b{error} is signaled if the @i{external-format} 
is not understood by the @i{implementation}.

The various @i{file systems} in existence today have widely differing capabilities,
and some aspects of the @i{file system} are beyond the scope of this specification
to define.  A given @i{implementation} might not be able to support all of these options 
in exactly the manner stated.  An @i{implementation} is required to recognize all of 
these option keywords and to try to do something ``reasonable'' in the context of the 
host @i{file system}.  Where necessary to accomodate the @i{file system},
an @i{implementation} deviate slightly from the semantics specified here without 
being disqualified for consideration as a @i{conforming implementation}.
If it is utterly impossible for an @i{implementation} to handle some option
in a manner similar to what is specified here, it may simply signal an error.

With regard to the @t{:element-type} option, if a @i{type} is
requested that is not supported by the @i{file system}, a substitution of types 
such as that which goes on in @i{upgrading} is permissible.  As a minimum 
requirement, it should be the case that opening an @i{output} @i{stream}
to a @i{file} in a given @i{element type} and later opening 
an @i{input} @i{stream} to the same @i{file} in the same @i{element type}
should work compatibly.

@subsubheading  See Also::

@ref{with-open-file}
,
@ref{close}
,
@b{pathname},
@b{logical-pathname},

@ref{Merging Pathnames},

@ref{Pathnames as Filenames}

@subsubheading  Notes::

@b{open} does not automatically close the file when an abnormal
exit occurs.

When @i{element-type} is a @i{subtype} of @b{character},
@b{read-char} and/or @b{write-char} can be
used on the resulting @i{file stream}. 

When @i{element-type} is a @i{subtype} of @i{integer},
@b{read-byte} and/or @b{write-byte} can be used on the resulting @i{file stream}.

When @i{element-type} is @t{:default},
the @i{type} can be determined by using @b{stream-element-type}.

@node stream-external-format, with-open-file, open, Streams Dictionary
@subsection stream-external-format                                           [Function]

@code{stream-external-format}  @i{stream} @result{}  @i{format}

@subsubheading  Arguments and Values::

@i{stream}---a @i{file stream}.

@i{format}---an @i{external file format}.

@subsubheading  Description::

Returns an @i{external file format designator} for the @i{stream}.

@subsubheading  Examples::

@example
 (with-open-file (stream "test" :direction :output)
   (stream-external-format stream))
@result{}  :DEFAULT
@i{OR}@result{} :ISO8859/1-1987
@i{OR}@result{} (:ASCII :SAIL)
@i{OR}@result{} ACME::PROPRIETARY-FILE-FORMAT-17
@i{OR}@result{} #<FILE-FORMAT :ISO646-1983 2343673>
@end example

@subsubheading  See Also::

the @t{:external-format} @i{argument} to the @i{function} 
@ref{open}
 and
the 
@ref{with-open-file}
 @i{macro}.

@subsubheading  Notes::

The @i{format} returned is not necessarily meaningful 
to other @i{implementations}.

@node with-open-file, close, stream-external-format, Streams Dictionary
@subsection with-open-file                                                      [macro]

@subsubheading  Syntax::

@code{with-open-file}  @i{@r{(}stream filespec @{@i{options}@}{*}@r{)}
		   @{@i{declaration}@}{*}
		   @{@i{form}@}{*}}@*
   @result{}  @i{results}

@subsubheading  Arguments and Values::

@i{stream} -- a variable.

@i{filespec}---a @i{pathname designator}.

@i{options} -- @i{forms}; evaluated.

@i{declaration}---a @b{declare} @i{expression}; not evaluated.

@i{forms}---an @i{implicit progn}.

@i{results}---the @i{values} returned by the @i{forms}.

@subsubheading  Description::

@b{with-open-file} uses @b{open} to create a @i{file stream}

to @i{file} named by @i{filespec}. 
@i{Filespec} is the name of the file to be opened.
@i{Options} are used as keyword arguments to @b{open}.

The @i{stream} @i{object} to which the @i{stream} @i{variable} 
is @i{bound} has @i{dynamic extent};
its @i{extent} ends when the @i{form} is exited.

@b{with-open-file} evaluates the @i{forms} as an @i{implicit progn} 
with @i{stream} bound to 

the value returned by @b{open}.

When control leaves the body, either normally or abnormally (such as by
use of @b{throw}), the file is automatically closed.  If a new
output file is being written, and control leaves abnormally, the file is
aborted and the file system is left, so far as possible, as if the file
had never been opened.  

It is possible by the use of @t{:if-exists nil} 
or @t{:if-does-not-exist nil} for
@i{stream} to be bound to @b{nil}.

Users of @t{:if-does-not-exist nil} should check for a valid @i{stream}.

The consequences are undefined if an attempt is made to @i{assign} the 
@i{stream} @i{variable}.  The compiler may choose to issue a
warning if such an attempt is detected.

@subsubheading  Examples::

@example
 (setq p (merge-pathnames "test"))
@result{}  #<PATHNAME :HOST NIL :DEVICE @i{device-name} :DIRECTORY @i{directory-name}
    :NAME "test" :TYPE NIL :VERSION :NEWEST>
 (with-open-file (s p :direction :output :if-exists :supersede)
    (format s "Here are a couple~
 (with-open-file (s p)
    (do ((l (read-line s) (read-line s nil 'eof)))
        ((eq l 'eof) "Reached end of file.")
     (format t "~&*** ~A~
@t{ |> } *** Here are a couple
@t{ |> } *** of test data lines
@result{}  "Reached end of file."
@end example

@example
;; Normally one would not do this intentionally because it is
;; not perspicuous, but beware when using :IF-DOES-NOT-EXIST NIL
;; that this doesn't happen to you accidentally...
 (with-open-file (foo "no-such-file" :if-does-not-exist nil)
   (read foo))
@t{ |> } @b{|>>}@t{hello?}@b{<<|}
@result{}  HELLO? ;This value was read from the terminal, not a file!

;; Here's another bug to avoid...
 (with-open-file (foo "no-such-file" :direction :output :if-does-not-exist nil)
   (format foo "Hello"))
@result{}  "Hello" ;FORMAT got an argument of NIL!
@end example

@subsubheading  Side Effects::

Creates a @i{stream} to the @i{file} named by @i{filename} (upon entry),
and closes the @i{stream} (upon exit).
In some @i{implementations},
the @i{file} might be locked in some way while it is open.
If the @i{stream} is an @i{output} @i{stream},
a @i{file} might be created.

@subsubheading  Affected By::

The host computer's file system.

@subsubheading  Exceptional Situations::

See the @i{function} @b{open}.

@subsubheading  See Also::

@ref{open}
,
@ref{close}
,
@b{pathname},
@b{logical-pathname},

@ref{Pathnames as Filenames}

@node close, with-open-stream, with-open-file, Streams Dictionary
@subsection close                                                            [Function]

@code{close}  @i{stream {&key} abort} @result{}  @i{result}

@subsubheading  Arguments and Values::

@i{stream}---a @i{stream} (either @i{open} or @i{closed}).

@i{abort}---a @i{generalized boolean}.
 The default is @i{false}.

@i{result}---@b{t} if the @i{stream} was @i{open} at the time it was
		     received as an @i{argument},
		 or @i{implementation-dependent} otherwise.

@subsubheading  Description::

@b{close} closes @i{stream}. 
Closing a @i{stream} means
that it may no longer be used in input or output operations.
The act of @i{closing} a @i{file stream}
ends the association between the @i{stream} and its associated @i{file}; 
the transaction with the @i{file system} is terminated,
and input/output may no longer be performed on the @i{stream}. 

If @i{abort} is @i{true}, an attempt is made to clean up any side
effects of having created @i{stream}.
If @i{stream} performs output to a file
that was created when the @i{stream} was created, the
file is deleted and any previously existing file is not superseded.

It is permissible to close an already closed @i{stream},
but in that case the @i{result} is @i{implementation-dependent}.

After @i{stream} is closed, it is still possible to perform 
the following query operations upon it:

@b{streamp}, @b{pathname}, @b{truename}, 
@b{merge-pathnames}, @b{pathname-host}, @b{pathname-device},
@b{pathname-directory},@b{pathname-name}, 
@b{pathname-type}, @b{pathname-version}, @b{namestring}, 
@b{file-namestring}, @b{directory-namestring}, 
@b{host-namestring}, @b{enough-namestring}, @b{open},
@b{probe-file}, and @b{directory}. 

The effect of @b{close} on a @i{constructed stream} is 
 to close the argument @i{stream} only. 
There is no effect on the @i{constituents} of @i{composite streams}.

For a @i{stream} created with @b{make-string-output-stream},
the result of @b{get-output-stream-string} is unspecified after @b{close}.

@subsubheading  Examples::

@example
 (setq s (make-broadcast-stream)) @result{}  #<BROADCAST-STREAM>
 (close s) @result{}  T
 (output-stream-p s) @result{}  @i{true}
@end example

@subsubheading  Side Effects::

The @i{stream} is @i{closed} (if necessary).
If @i{abort} is @i{true} and the @i{stream} is
an @i{output} @i{file stream}, its associated @i{file}
might be deleted.

@subsubheading  See Also::

@ref{open}

@node with-open-stream, listen, close, Streams Dictionary
@subsection with-open-stream                                                    [Macro]

@code{with-open-stream}  @i{@r{(}var stream@r{)}
		   @{@i{declaration}@}{*} 
		   @{@i{form}@}{*}}@*
   @result{}  @i{@{@i{result}@}{*}}

@subsubheading  Arguments and Values::

@i{var}---a @i{variable} @i{name}.

@i{stream}---a @i{form}; evaluated to produce a @i{stream}.

@i{declaration}---a @b{declare} @i{expression}; not evaluated.

@i{forms}---an @i{implicit progn}.

@i{results}---the @i{values} returned by the @i{forms}.

@subsubheading  Description::

@b{with-open-stream} performs a series of operations on 
@i{stream}, returns a value, and then closes the @i{stream}.

@i{Var} is bound to the value of @i{stream},
and then @i{forms} are executed
as an @i{implicit progn}. 
@i{stream}
is automatically closed on exit from @b{with-open-stream},
no matter whether the exit is normal or abnormal.

The @i{stream} has @i{dynamic extent};
its @i{extent} ends when the @i{form} is exited.

The consequences are undefined if an attempt is made to @i{assign} the 
the @i{variable} @i{var} with the @i{forms}.

@subsubheading  Examples::

@example
 (with-open-stream (s (make-string-input-stream "1 2 3 4"))
    (+ (read s) (read s) (read s))) @result{}  6
@end example

@subsubheading  Side Effects::

The @i{stream} is closed (upon exit).

@subsubheading  See Also::

@ref{close}

@node listen, clear-input, with-open-stream, Streams Dictionary
@subsection listen                                                           [Function]

@code{listen}  @i{{&optional} input-stream} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values::

@i{input-stream}---an @i{input} @i{stream designator}.
 The default is @i{standard input}.

@i{generalized-boolean}---a @i{generalized boolean}.

@subsubheading  Description::

Returns @i{true} if 
there is a character immediately available from @i{input-stream};
otherwise, returns @i{false}.
On a non-interactive @i{input-stream},
@b{listen} returns @i{true} except when at @i{end of file}_1.
If an @i{end of file} is encountered, @b{listen} returns @i{false}.
@b{listen} is intended to be used 
when @i{input-stream} obtains characters
from an interactive device such as a keyboard.  

@subsubheading  Examples::

@example
 (progn (unread-char (read-char)) (list (listen) (read-char)))
@t{ |> } @b{|>>}@t{1}@b{<<|}
@result{}  (T #\1)
 (progn (clear-input) (listen))
@result{}  NIL ;Unless you're a very fast typist!
@end example

@subsubheading  Affected By::

@b{*standard-input*}

@subsubheading  See Also::

@ref{interactive-stream-p}
,
@ref{read-char-no-hang}

@node clear-input, finish-output, listen, Streams Dictionary
@subsection clear-input                                                      [Function]

@code{clear-input}  @i{{&optional} input-stream} @result{}  @i{@b{nil}}

@subsubheading  Arguments and Values::

@i{input-stream}---an @i{input} @i{stream designator}.
  The default is @i{standard input}.

@subsubheading  Description::

Clears any available input from @i{input-stream}.

If @b{clear-input} does not make sense for @i{input-stream}, 
then @b{clear-input} does nothing. 

@subsubheading  Examples::
@example
;; The exact I/O behavior of this example might vary from implementation
;; to implementation depending on the kind of interactive buffering that
;; occurs.  (The call to SLEEP here is intended to help even out the 
;; differences in implementations which do not do line-at-a-time buffering.)

(defun read-sleepily (&optional (clear-p nil) (zzz 0))
  (list (progn (print '>) (read))
        ;; Note that input typed within the first ZZZ seconds 
        ;; will be discarded.
        (progn (print '>) 
               (if zzz (sleep zzz))
               (print '>>)
               (if clear-p (clear-input))
               (read))))

(read-sleepily)
@t{ |> } > @b{|>>}@t{10}@b{<<|}
@t{ |> } >
@t{ |> } >> @b{|>>}@t{20}@b{<<|}
@result{}  (10 20)

(read-sleepily t)
@t{ |> } > @b{|>>}@t{10}@b{<<|}
@t{ |> } >
@t{ |> } >> @b{|>>}@t{20}@b{<<|}
@result{}  (10 20)

(read-sleepily t 10)
@t{ |> } > @b{|>>}@t{10}@b{<<|}
@t{ |> } > @b{|>>}@t{20}@b{<<|}  ; Some implementations won't echo typeahead here.
@t{ |> } >> @b{|>>}@t{30}@b{<<|}
@result{}  (10 30)
@end example

@subsubheading  Side Effects::

The @i{input-stream} is modified.

@subsubheading  Affected By::

@b{*standard-input*}

@subsubheading  Exceptional Situations::

Should signal an error of @i{type} @b{type-error}
			      if @i{input-stream} is not a @i{stream designator}.

@subsubheading  See Also::

@b{clear-output}

@node finish-output, y-or-n-p, clear-input, Streams Dictionary
@subsection finish-output, force-output, clear-output                        [Function]

@code{finish-output}  @i{{&optional} output-stream} @result{}  @i{@b{nil}}

@code{force-output}  @i{{&optional} output-stream} @result{}  @i{@b{nil}}

@code{clear-output}  @i{{&optional} output-stream} @result{}  @i{@b{nil}}

@subsubheading  Arguments and Values::

@i{output-stream}---an @i{output} @i{stream designator}.
 The default is @i{standard output}.

@subsubheading  Description::

@b{finish-output}, @b{force-output}, and @b{clear-output}
exercise control over the internal handling of buffered stream output.  

@b{finish-output} attempts to ensure that any buffered output
sent to @i{output-stream} has reached its destination, and then returns.

@b{force-output} initiates the emptying of any
internal buffers but does not wait for completion
or acknowledgment to return.

@b{clear-output} attempts to abort any
outstanding output operation in progress in order
to allow as little output as possible
to continue to the destination.  

If any of these operations does not make sense for @i{output-stream}, 
then it does nothing. 
The precise actions of these @i{functions} are @i{implementation-dependent}.

@subsubheading  Examples::
@example
;; Implementation A
 (progn (princ "am i seen?") (clear-output))
@result{}  NIL

;; Implementation B
 (progn (princ "am i seen?") (clear-output))
@t{ |> } am i seen?
@result{}  NIL
@end example

@subsubheading  Affected By::

@b{*standard-output*}

@subsubheading  Exceptional Situations::

Should signal an error of @i{type} @b{type-error}
			      if @i{output-stream} is not a @i{stream designator}.

@subsubheading  See Also::

@ref{clear-input}

@node y-or-n-p, make-synonym-stream, finish-output, Streams Dictionary
@subsection y-or-n-p, yes-or-no-p                                            [Function]

@code{y-or-n-p}  @i{{&optional} control {&rest} arguments} @result{}  @i{generalized-boolean}

@code{yes-or-no-p}  @i{{&optional} control {&rest} arguments} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values::

@i{control}---a @i{format control}.

@i{arguments}---@i{format arguments} for @i{control}.

@i{generalized-boolean}---a @i{generalized boolean}.

@subsubheading  Description::

These functions ask a question and parse a response from the user.
They return @i{true} if the answer is affirmative,
or @i{false} if the answer is negative.

@b{y-or-n-p} is for asking the user a question whose answer is either
``yes'' or ``no.''  
It is intended that the reply require
the user to answer a yes-or-no question with a single
character.
@b{yes-or-no-p} is also for asking the user a question
whose answer is either ``Yes'' or ``No.''  
It is intended that the reply require
the user to take more action than just a single keystroke, such as typing
the full word @t{yes} or @t{no} followed by a newline.

@b{y-or-n-p} types out a message (if supplied), reads an answer
in some @i{implementation-dependent} manner (intended to be short and simple,
such as reading a single character such as @t{Y} or @t{N}).
@b{yes-or-no-p} types out a message (if supplied), 
attracts the user's attention (for example, by ringing
the terminal's bell),
and reads an answer
in some @i{implementation-dependent} manner (intended to be multiple characters,
such as @t{YES} or @t{NO}).

If @i{format-control} is supplied and not @b{nil},
then a @b{fresh-line} operation is performed; then
a message is printed as if @i{format-control} and @i{arguments}
were given to @b{format}.
In any case, @b{yes-or-no-p} and @b{y-or-n-p} will provide 
a prompt such as ``@t{(Y or N)}'' or ``@t{(Yes or No)}'' if appropriate.

All input and output are performed using @i{query I/O}.

@subsubheading  Examples::
@example
 (y-or-n-p "(t or nil) given by")
@t{ |> } (t or nil) given by (Y or N) @b{|>>}@t{Y}@b{<<|}
@result{}  @i{true}
 (yes-or-no-p "a ~S message" 'frightening) 
@t{ |> } a FRIGHTENING message (Yes or No) @b{|>>}@t{no}@b{<<|}
@result{}  @i{false}
 (y-or-n-p "Produce listing file?") 
@t{ |> } Produce listing file?
@t{ |> } Please respond with Y or N. @b{|>>}@t{n}@b{<<|}
@result{}  @i{false}
@end example

@subsubheading  Side Effects::

Output to and input from @i{query I/O} will occur.

@subsubheading  Affected By::

@b{*query-io*}.

@subsubheading  See Also::

@ref{format}

@subsubheading  Notes::

@b{yes-or-no-p} and @b{yes-or-no-p} do not add question marks
to the end of the prompt string, so any desired question mark or other
punctuation should be explicitly included in the text query.

@node make-synonym-stream, synonym-stream-symbol, y-or-n-p, Streams Dictionary
@subsection make-synonym-stream                                              [Function]

@code{make-synonym-stream}  @i{symbol} @result{}  @i{synonym-stream}

@subsubheading  Arguments and Values::

@i{symbol}---a @i{symbol} that names a @i{dynamic variable}.

@i{synonym-stream}---a @i{synonym stream}.

@subsubheading  Description::

Returns a @i{synonym stream} whose @i{synonym stream symbol} is @i{symbol}.

@subsubheading  Examples::

@example
 (setq a-stream (make-string-input-stream "a-stream")
        b-stream (make-string-input-stream "b-stream"))
@result{}  #<String Input Stream> 
 (setq s-stream (make-synonym-stream 'c-stream))
@result{}  #<SYNONYM-STREAM for C-STREAM> 
 (setq c-stream a-stream)
@result{}  #<String Input Stream> 
 (read s-stream) @result{}  A-STREAM
 (setq c-stream b-stream)
@result{}  #<String Input Stream> 
 (read s-stream) @result{}  B-STREAM
@end example

@subsubheading  Exceptional Situations::

Should signal @b{type-error} if its argument is not a @i{symbol}.

@subsubheading  See Also::

@ref{Stream Concepts}

@node synonym-stream-symbol, broadcast-stream-streams, make-synonym-stream, Streams Dictionary
@subsection synonym-stream-symbol                                            [Function]

@code{synonym-stream-symbol}  @i{synonym-stream} @result{}  @i{symbol}

@subsubheading  Arguments and Values::

@i{synonym-stream}---a @i{synonym stream}.

@i{symbol}---a @i{symbol}.

@subsubheading  Description::

Returns the @i{symbol} whose @b{symbol-value} the @i{synonym-stream} is using.  

@subsubheading  See Also::

@ref{make-synonym-stream}

@node broadcast-stream-streams, make-broadcast-stream, synonym-stream-symbol, Streams Dictionary
@subsection broadcast-stream-streams                                         [Function]

@code{broadcast-stream-streams}  @i{broadcast-stream} @result{}  @i{streams}

@subsubheading  Arguments and Values::

@i{broadcast-stream}---a @i{broadcast stream}.

@i{streams}---a @i{list} of @i{streams}.

@subsubheading  Description::

Returns a @i{list} of output @i{streams} that constitute
all the @i{streams} to which the @i{broadcast-stream} is broadcasting.  

@node make-broadcast-stream, make-two-way-stream, broadcast-stream-streams, Streams Dictionary
@subsection make-broadcast-stream                                            [Function]

@code{make-broadcast-stream}  @i{{&rest} streams} @result{}  @i{broadcast-stream}

@subsubheading  Arguments and Values::

@i{stream}---an @i{output} @i{stream}.

@i{broadcast-stream}---a @i{broadcast stream}.

@subsubheading  Description::

Returns a @i{broadcast stream}.

@subsubheading  Examples::

@example
 (setq a-stream (make-string-output-stream)
        b-stream (make-string-output-stream)) @result{}  #<String Output Stream>
 (format (make-broadcast-stream a-stream b-stream)
          "this will go to both streams") @result{}  NIL
 (get-output-stream-string a-stream) @result{}  "this will go to both streams"
 (get-output-stream-string b-stream) @result{}  "this will go to both streams"
@end example

@subsubheading  Exceptional Situations::

Should signal an error of @i{type} @b{type-error}
			      if any @i{stream} is not an @i{output} @i{stream}.

@subsubheading  See Also::

@ref{broadcast-stream-streams}

@node make-two-way-stream, two-way-stream-input-stream, make-broadcast-stream, Streams Dictionary
@subsection make-two-way-stream                                              [Function]

@code{make-two-way-stream}  @i{input-stream output-stream} @result{}  @i{two-way-stream}

@subsubheading  Arguments and Values::

@i{input-stream}---a @i{stream}.

@i{output-stream}---a @i{stream}.

@i{two-way-stream}---a @i{two-way stream}.

@subsubheading  Description::

Returns a @i{two-way stream} 
that gets  its input  from @i{input-stream}
and  sends its output to   @i{output-stream}.

@subsubheading  Examples::

@example
 (with-output-to-string (out)
    (with-input-from-string (in "input...")
      (let ((two (make-two-way-stream in out)))
        (format two "output...")
        (setq what-is-read (read two))))) @result{}  "output..."
 what-is-read @result{}  INPUT... 
@end example

@subsubheading  Exceptional Situations::

Should signal an error of @i{type} @b{type-error}
			      if @i{input-stream} is not an @i{input} @i{stream}.
Should signal an error of @i{type} @b{type-error}
			      if @i{output-stream} is not an @i{output} @i{stream}.

@node two-way-stream-input-stream, echo-stream-input-stream, make-two-way-stream, Streams Dictionary
@subsection two-way-stream-input-stream, two-way-stream-output-stream
@flushright
@i{[Function]}
@end flushright

@code{two-way-stream-input-stream}  @i{two-way-stream} @result{}  @i{input-stream}

@code{two-way-stream-output-stream}  @i{two-way-stream} @result{}  @i{output-stream}

@subsubheading  Arguments and Values::

@i{two-way-stream}---a @i{two-way stream}.

@i{input-stream}---an @i{input} @i{stream}.

@i{output-stream}---an @i{output} @i{stream}.

@subsubheading  Description::

@b{two-way-stream-input-stream} returns the @i{stream}
from which @i{two-way-stream} receives input.

@b{two-way-stream-output-stream} returns the @i{stream} 
to which @i{two-way-stream} sends output.

@node echo-stream-input-stream, make-echo-stream, two-way-stream-input-stream, Streams Dictionary
@subsection echo-stream-input-stream, echo-stream-output-stream              [Function]

@code{echo-stream-input-stream}  @i{echo-stream} @result{}  @i{input-stream}

@code{echo-stream-output-stream}  @i{echo-stream} @result{}  @i{output-stream}

@subsubheading  Arguments and Values::

@i{echo-stream}---an @i{echo stream}.

@i{input-stream}---an @i{input} @i{stream}.

@b{output-stream}---an @i{output} @i{stream}.

@subsubheading  Description::

@b{echo-stream-input-stream} returns the @i{input} @i{stream} 
from which @i{echo-stream} receives input.

@b{echo-stream-output-stream} returns the @i{output} @i{stream}
to which @i{echo-stream} sends output.

@node make-echo-stream, concatenated-stream-streams, echo-stream-input-stream, Streams Dictionary
@subsection make-echo-stream                                                 [Function]

@code{make-echo-stream}  @i{input-stream output-stream} @result{}  @i{echo-stream}

@subsubheading  Arguments and Values::

@i{input-stream}---an @i{input} @i{stream}.

@i{output-stream}---an @i{output} @i{stream}.

@i{echo-stream}---an @i{echo stream}.

@subsubheading  Description::

Creates and returns an @i{echo stream} 
that takes input  from @i{input-stream}
and  sends output to   @i{output-stream}.

@subsubheading  Examples::
@example
 (let ((out (make-string-output-stream)))
    (with-open-stream 
        (s (make-echo-stream
            (make-string-input-stream "this-is-read-and-echoed")
            out))
      (read s)
      (format s " * this-is-direct-output")
      (get-output-stream-string out)))
@result{}  "this-is-read-and-echoed * this-is-direct-output"
@end example

@subsubheading  See Also::

@ref{echo-stream-input-stream; echo-stream-output-stream}
,
@b{echo-stream-output-stream},
@ref{make-two-way-stream}

@node concatenated-stream-streams, make-concatenated-stream, make-echo-stream, Streams Dictionary
@subsection concatenated-stream-streams                                      [Function]

@code{concatenated-stream-streams}  @i{concatenated-stream} @result{}  @i{streams}

@subsubheading  Arguments and Values::

@i{concatenated-stream} -- a @i{concatenated stream}.

@i{streams}---a @i{list} of @i{input} @i{streams}.

@subsubheading  Description::

Returns a @i{list} of @i{input} @i{streams} that constitute the
ordered set of @i{streams} the @i{concatenated-stream} still 
has to read from, starting with the current one it is reading from.
The list may be @i{empty} if no more @i{streams} remain to be read.

The consequences are undefined if the @i{list structure} of the @i{streams}
is ever modified.

@node make-concatenated-stream, get-output-stream-string, concatenated-stream-streams, Streams Dictionary
@subsection make-concatenated-stream                                         [Function]

@code{make-concatenated-stream}  @i{{&rest} input-streams} @result{}  @i{concatenated-stream}

@subsubheading  Arguments and Values::

@i{input-stream}---an @i{input} @i{stream}.

@i{concatenated-stream}---a @i{concatenated stream}.

@subsubheading  Description::

Returns a @i{concatenated stream} that has the indicated @i{input-streams}
initially associated with it.

@subsubheading  Examples::
@example
 (read (make-concatenated-stream
         (make-string-input-stream "1")
         (make-string-input-stream "2"))) @result{}  12
@end example

@subsubheading  Exceptional Situations::

Should signal @b{type-error} if any argument is not an @i{input} @i{stream}.

@subsubheading  See Also::

@ref{concatenated-stream-streams}

@node get-output-stream-string, make-string-input-stream, make-concatenated-stream, Streams Dictionary
@subsection get-output-stream-string                                         [Function]

@code{get-output-stream-string}  @i{string-output-stream} @result{}  @i{string}

@subsubheading  Arguments and Values::

@i{string-output-stream}---a @i{stream}.

@i{string}---a @i{string}.

@subsubheading  Description::

Returns a @i{string} containing, in order, all the @i{characters} 
that have been output to @i{string-output-stream}.
This operation clears any @i{characters} on @i{string-output-stream},
so the @i{string} contains only those @i{characters} which have been output
   since the last call to @b{get-output-stream-string}
or since the creation of the @i{string-output-stream},
whichever occurred most recently.

@subsubheading  Examples::
@example
 (setq a-stream (make-string-output-stream)
        a-string "abcdefghijklm") @result{}  "abcdefghijklm"
 (write-string a-string a-stream) @result{}  "abcdefghijklm"
 (get-output-stream-string a-stream) @result{}  "abcdefghijklm"
 (get-output-stream-string a-stream) @result{}  ""
@end example

@subsubheading  Side Effects::

The @i{string-output-stream} is cleared.

@subsubheading  Exceptional Situations::

The consequences are undefined if @i{stream-output-string} is @i{closed}.

The consequences are undefined if @i{string-output-stream} is a @i{stream} that
was not produced by @b{make-string-output-stream}.

The consequences are undefined if @i{string-output-stream} was 
created implicitly by @b{with-output-to-string} or @b{format}.

@subsubheading  See Also::

@ref{make-string-output-stream}

@node make-string-input-stream, make-string-output-stream, get-output-stream-string, Streams Dictionary
@subsection make-string-input-stream                                         [Function]

@code{make-string-input-stream}  @i{string {&optional} start end} @result{}  @i{string-stream}

@subsubheading  Arguments and Values::

@i{string}---a @i{string}.

@i{start}, @i{end}---@i{bounding index designators} of @i{string}.
 The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.

@i{string-stream}---an @i{input} @i{string stream}.

@subsubheading  Description::

Returns an @i{input} @i{string stream}.  
This @i{stream} will supply, in order, the @i{characters} in the substring
of @i{string} @i{bounded} by @i{start} and @i{end}.
After the last @i{character} has been supplied, 
the @i{string stream} will then be at @i{end of file}.

@subsubheading  Examples::

@example
 (let ((string-stream (make-string-input-stream "1 one ")))
   (list (read string-stream nil nil)
         (read string-stream nil nil)
         (read string-stream nil nil)))
@result{}  (1 ONE NIL)

 (read (make-string-input-stream "prefixtargetsuffix" 6 12)) @result{}  TARGET
@end example

@subsubheading  See Also::

@ref{with-input-from-string}

@node make-string-output-stream, with-input-from-string, make-string-input-stream, Streams Dictionary
@subsection make-string-output-stream                                        [Function]

@code{make-string-output-stream}  @i{{&key} element-type} @result{}  @i{string-stream}

@subsubheading  Arguments and Values::

@i{element-type}---a @i{type specifier}.
  The default is @b{character}.

@i{string-stream}---an @i{output} @i{string stream}.

@subsubheading  Description::

Returns

an @i{output} @i{string stream} that accepts @i{characters}
and makes available (via @b{get-output-stream-string})
a @i{string} that contains the @i{characters} that were actually output.

The @i{element-type} names the @i{type} of the @i{elements}
of the @i{string}; a @i{string} is constructed of the most specialized
@i{type} that can accommodate @i{elements} of that @i{element-type}.

@subsubheading  Examples::

@example
 (let ((s (make-string-output-stream)))
   (write-string "testing... " s)
   (prin1 1234 s)
   (get-output-stream-string s))
@result{}  "testing... 1234"
@end example

None..

@subsubheading  See Also::

@ref{get-output-stream-string}
, 
@ref{with-output-to-string}

@node with-input-from-string, with-output-to-string, make-string-output-stream, Streams Dictionary
@subsection with-input-from-string                                              [Macro]

@code{with-input-from-string}  @i{@r{(}var string {&key} index start end@r{)}
			  @{@i{declaration}@}{*}
			  @{@i{form}@}{*}}@*
   @result{}  @i{@{@i{result}@}{*}}

@subsubheading  Arguments and Values::

@i{var}---a @i{variable} @i{name}.

@i{string}---a @i{form}; evaluated to produce a @i{string}.

@i{index}---a @i{place}.

@i{start}, @i{end}---@i{bounding index designators} of @i{string}.
 The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.

@i{declaration}---a @b{declare} @i{expression}; not evaluated.

@i{forms}---an @i{implicit progn}.

@i{result}---the @i{values} returned by the @i{forms}.

@subsubheading  Description::

Creates an

@i{input} @i{string stream}, 

provides an opportunity to perform operations on the @i{stream} 
 (returning zero or more @i{values}),
and then closes the @i{string stream}.

@i{String} is evaluated first, and @i{var} is bound to
a character @i{input} @i{string stream} that supplies 
@i{characters} from the subsequence of the resulting @i{string} @i{bounded} by
@i{start} and @i{end}. 
The body is executed as an @i{implicit progn}.

The @i{input} @i{string stream} is automatically closed on exit from
@b{with-input-from-string}, no matter whether the exit is normal or abnormal.

The @i{input} @i{string stream} to which the @i{variable} @i{var}
is @i{bound} has @i{dynamic extent};
its @i{extent} ends when the @i{form} is exited.

The @i{index} is a pointer within the @i{string} to be advanced.
If @b{with-input-from-string}
is exited normally, then @i{index} will have
as its @i{value}
the index into the @i{string} indicating the first character not read
which is @t{(length @i{string})} if all characters were used.
The place specified by @i{index}
is not updated as reading progresses, but only at the
end of the operation. 

@i{start} and @i{index} may both specify the same variable, 
which is a pointer within the @i{string} to be advanced,
perhaps repeatedly by some containing loop.

The consequences are undefined if an attempt is made to @i{assign} 
the @i{variable} @i{var}.

@subsubheading  Examples::
@example
 (with-input-from-string (s "XXX1 2 3 4xxx"
                             :index ind
                             :start 3 :end 10)
    (+ (read s) (read s) (read s))) @result{}  6
 ind @result{}  9
 (with-input-from-string (s "Animal Crackers" :index j :start 6)
   (read s)) @result{}  CRACKERS
@end example

The variable @t{j} is set to @t{15}.

@subsubheading  Side Effects::

The @i{value} of the @i{place} named by @i{index}, if any, is modified.

@subsubheading  See Also::

@ref{make-string-input-stream}
,

@ref{Traversal Rules and Side Effects}

@node with-output-to-string, *debug-io*, with-input-from-string, Streams Dictionary
@subsection with-output-to-string                                               [Macro]

@code{with-output-to-string}  @i{@r{(}var {&optional} string-form {&key} element-type@r{)}
 			  @{@i{declaration}@}{*}
 			  @{@i{form}@}{*}}@*
   @result{}  @i{@{@i{result}@}{*}}

@subsubheading  Arguments and Values::

@i{var}---a @i{variable} @i{name}.

@i{string-form}---a @i{form} or @b{nil};
		      if @i{non-nil}, evaluated to produce @i{string}.

@i{string}---a @i{string} that has a @i{fill pointer}.

@i{element-type}---a @i{type specifier}; evaluated.

  The default is @b{character}.

@i{declaration}---a @b{declare} @i{expression}; not evaluated.

@i{forms}---an @i{implicit progn}.

@i{results}---If a @i{string-form} is not supplied or @b{nil},
		  a @i{string}; otherwise, 
		  the @i{values} returned by the @i{forms}.

@subsubheading  Description::

@b{with-output-to-string} creates a

character @i{output} @i{stream}, performs a series of operations
that may send results to this @i{stream}, and then closes the @i{stream}. 

The @i{element-type} names the @i{type} of the elements
of the @i{stream}; a @i{stream} is constructed of the most specialized
@i{type} that can accommodate elements of the given @i{type}.  

The body is executed as an @i{implicit progn} with @i{var}
bound to an @i{output} @i{string stream}.  
All output to that @i{string stream} is saved in a @i{string}.  

If @i{string} is supplied, @i{element-type} is ignored, 
and the output is incrementally appended to @i{string} as
if by use of @b{vector-push-extend}.

The @i{output} @i{stream} 
is automatically closed on exit from @b{with-output-from-string},
no matter whether the exit is normal or abnormal.

The @i{output} @i{string stream} to which the @i{variable} @i{var}
is @i{bound} has @i{dynamic extent};
its @i{extent} ends when the @i{form} is exited.

If no @i{string} is provided, then @b{with-output-from-string} 

produces a @i{stream} that accepts characters and returns a @i{string} 
of the indicated @i{element-type}.

If @i{string} is provided,
@b{with-output-to-string} returns the results of evaluating the last @i{form}.

The consequences are undefined if an attempt is made to @i{assign}
the @i{variable} @i{var}.

@subsubheading  Examples::
@example
 (setq fstr (make-array '(0) :element-type 'base-char
                             :fill-pointer 0 :adjustable t)) @result{}  ""
 (with-output-to-string (s fstr)
    (format s "here's some output")
    (input-stream-p s)) @result{}  @i{false}
 fstr @result{}  "here's some output"
@end example

@subsubheading  Side Effects::

The @i{string} is modified.

@subsubheading  Exceptional Situations::

The consequences are undefined if destructive modifications are performed
directly on the @i{string} during the @i{dynamic extent} of the call.

@subsubheading  See Also::

@ref{make-string-output-stream}
,
@b{vector-push-extend},

@ref{Traversal Rules and Side Effects}

@node *debug-io*, *terminal-io*, with-output-to-string, Streams Dictionary
@subsection *debug-io*, *error-output*, *query-io*,
@subheading *standard-input*, *standard-output*,
@subheading *trace-output*
@flushright
@i{[Variable]}
@end flushright

@subsubheading  Value Type::

For @b{*standard-input*}:
 an @i{input} @i{stream}

For @b{*error-output*}, @b{*standard-output*}, and @b{*trace-output*}:
 an @i{output} @i{stream}.

For @b{*debug-io*}, @b{*query-io*}:
 a @i{bidirectional} @i{stream}.

@subsubheading  Initial Value::

@i{implementation-dependent}, but
it must be an @i{open} @i{stream} 
that is not a  @i{generalized synonym stream}
to an @i{I/O customization variables}
but that might be a @i{generalized synonym stream} to 
the value of some @i{I/O customization variable}.
The initial value might also be a @i{generalized synonym stream} 
to either the @i{symbol} @b{*terminal-io*} or to the @i{stream} 
that is its @i{value}.

@subsubheading  Description::

These @i{variables} are collectively called the
@i{standardized} @i{I/O customization variables}.
They can be @i{bound} or @i{assigned} in order to 
change the default destinations for input and/or output 
used by various @i{standardized} @i{operators} and facilities.

The @i{value} of @b{*debug-io*}, called @i{debug I/O},
is a @i{stream} to be used for interactive debugging purposes.  

The @i{value} of @b{*error-output*}, called @i{error output},
is a @i{stream} to which warnings and non-interactive error messages should be sent.

The @i{value} of @b{*query-io*}, called @i{query I/O},
is a @i{bidirectional} @i{stream} 
to be used when asking questions of the user.  The question should be output 
to this @i{stream}, and the answer read from it.

The @i{value} of @b{*standard-input*}, called @i{standard input},
is a @i{stream} that is used by many @i{operators} 
as a default source of input when no specific @i{input} @i{stream}
is explicitly supplied.

The @i{value} of @b{*standard-output*}, called @i{standard output},
is a @i{stream} that is used by many @i{operators} 
as a default destination for output when no specific @i{output} @i{stream}
is explicitly supplied.

The @i{value} of @b{*trace-output*}, called @i{trace output},
is the @i{stream} on which traced functions (see @b{trace})
and the @b{time} @i{macro} print their output.

@subsubheading  Examples::

@example
 (with-output-to-string (*error-output*)
   (warn "this string is sent to *error-output*"))
 @result{}  "Warning: this string is sent to *error-output*
" ;The exact format of this string is @i{implementation-dependent}.

 (with-input-from-string (*standard-input* "1001")
    (+ 990 (read))) @result{}  1991                       

 (progn (setq out (with-output-to-string (*standard-output*)
                     (print "print and format t send things to")
                     (format t "*standard-output* now going to a string")))
        :done)
@result{}  :DONE
 out
@result{}  "
\"print and format t send things to\" *standard-output* now going to a string"

 (defun fact (n) (if (< n 2) 1 (* n (fact (- n 1)))))
@result{}  FACT
 (trace fact)
@result{}  (FACT)
;; Of course, the format of traced output is implementation-dependent.
 (with-output-to-string (*trace-output*)
   (fact 3)) 
@result{}  "
1 Enter FACT 3
| 2 Enter FACT 2
|   3 Enter FACT 1
|   3 Exit FACT 1
| 2 Exit FACT 2
1 Exit FACT 6"
@end example

@subsubheading  See Also::

@b{*terminal-io*},
@b{synonym-stream},
@ref{Time}
,
@ref{trace; untrace}
,
{@ref{Conditions}},
{@ref{Reader}},
{@ref{Printer}}

@subsubheading  Notes::

The intent of the constraints on the initial @i{value} 
of the @i{I/O customization variables} is to ensure that it
is always safe to @i{bind} or @i{assign} such a @i{variable} to 
the @i{value} of another @i{I/O customization variable}, without
unduly restricting @i{implementation} flexibility.

It is common for an @i{implementation} to make
the initial @i{values} of @b{*debug-io*} and @b{*query-io*} 
be the @i{same} @i{stream}, 
and to make
the initial @i{values} of @b{*error-output*} and @b{*standard-output*} 
be the @i{same} @i{stream}.

The functions @b{y-or-n-p} and @b{yes-or-no-p} use @i{query I/O}
for their input and output.

In the normal @i{Lisp read-eval-print loop},
input is read from @i{standard input}.
Many input functions, including @b{read} and @b{read-char},
take a @i{stream} argument that defaults to @i{standard input}.

In the normal @i{Lisp read-eval-print loop}, output is sent to @i{standard output}.
Many output functions, including @b{print} and @b{write-char}, 
take a @i{stream} argument that defaults to @i{standard output}.

A program that wants, for example, to divert output to a file should do so by 
@i{binding} @b{*standard-output*}; that way error messages sent to
@b{*error-output*} can still get to the user by going through
@b{*terminal-io*} (if @b{*error-output*} is bound to @b{*terminal-io*}),
which is usually what is desired.

@node *terminal-io*, stream-error, *debug-io*, Streams Dictionary
@subsection *terminal-io*                                                    [Variable]

@subsubheading  Value Type::

a @i{bidirectional} @i{stream}.

@subsubheading  Initial Value::

@i{implementation-dependent}, but
it must be an @i{open} @i{stream} 
that is not a  @i{generalized synonym stream}
to an @i{I/O customization variables}
but that might be a @i{generalized synonym stream} to 
the @i{value} of some @i{I/O customization variable}.

@subsubheading  Description::

The @i{value} of @b{*terminal-io*}, called  @i{terminal I/O}, is ordinarily 
a @i{bidirectional} @i{stream} that connects to the user's console.
Typically, writing to this @i{stream} 
would cause the output to appear
on a display screen, for example, and reading from the @i{stream} would
accept input from a keyboard.  It is intended
that standard input functions such as @b{read} and @b{read-char},
when used with this @i{stream}, cause echoing of the input
into the output side of the @i{stream}. The means by which this is
accomplished are @i{implementation-dependent}.

The effect of changing the @i{value} of @b{*terminal-io*},
either by @i{binding} or @i{assignment},
is @i{implementation-defined}.

@subsubheading  Examples::

@example
 (progn (prin1 'foo) (prin1 'bar *terminal-io*))
@t{ |> } FOOBAR
@result{}  BAR
 (with-output-to-string (*standard-output*)
   (prin1 'foo) 
   (prin1 'bar *terminal-io*))
@t{ |> } BAR
@result{}  "FOO"
@end example

@subsubheading  See Also::

@b{*debug-io*},
@b{*error-output*},
@b{*query-io*},
@b{*standard-input*},
@b{*standard-output*},
@b{*trace-output*}

@node stream-error, stream-error-stream, *terminal-io*, Streams Dictionary
@subsection stream-error                                               [Condition Type]

@subsubheading  Class Precedence List::
@b{stream-error},
@b{error},
@b{serious-condition},
@b{condition},
@b{t}

@subsubheading  Description::

The @i{type} @b{stream-error}
consists of error conditions that are related to receiving input from
or sending output to a @i{stream}.  
The ``offending stream'' is initialized by
the @t{:stream} initialization argument to @b{make-condition}, 
and is @i{accessed} by the @i{function} @b{stream-error-stream}.

@subsubheading  See Also::

@ref{stream-error-stream}

@node stream-error-stream, end-of-file, stream-error, Streams Dictionary
@subsection stream-error-stream                                              [Function]

@code{stream-error-stream}  @i{condition} @result{}  @i{stream}

@subsubheading  Arguments and Values::

@i{condition}---a @i{condition} of @i{type} @b{stream-error}.

@i{stream}---a @i{stream}.

@subsubheading  Description::

Returns the offending @i{stream} of a @i{condition} of @i{type} @b{stream-error}.

@subsubheading  Examples::
@example
 (with-input-from-string (s "(FOO")
   (handler-case (read s)
     (end-of-file (c)
       (format nil "~&End of file on ~S." (stream-error-stream c)))))
"End of file on #<String Stream>."
@end example

@subsubheading  See Also::

@b{stream-error},
@ref{Conditions}

@node end-of-file,  , stream-error-stream, Streams Dictionary
@subsection end-of-file                                                [Condition Type]

@subsubheading  Class Precedence List::
@b{end-of-file},
@b{stream-error},
@b{error},
@b{serious-condition},
@b{condition},
@b{t}

@subsubheading  Description::

The @i{type} @b{end-of-file} consists of
error conditions related to read operations that are done on
@i{streams} that have no more data.

@subsubheading  See Also::

@ref{stream-error-stream}

@c end of including dict-streams

@c %**end of chapter