File: chap-7.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 (5987 lines) | stat: -rw-r--r-- 229,127 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
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987


@node Objects, Structures, Iteration, Top
@chapter Objects

@menu
* Object Creation and Initialization::	
* Changing the Class of an Instance::  
* Reinitializing an Instance::	
* Meta-Objects::		
* Slots::			
* Generic Functions and Methods::  
* Objects Dictionary::		
@end menu

@node Object Creation and Initialization, Changing the Class of an Instance, Objects, Objects
@section Object Creation and Initialization

@c including concept-objects

The @i{generic function} @b{make-instance} creates and returns a new
@i{instance} of a @i{class}.  The first argument is a @i{class} or
the @i{name} of a @i{class}, and the remaining arguments form an 
@i{initialization argument list}
@IGindex{initialization argument list}
.

The initialization of a new @i{instance} consists of several distinct
steps, including the following: combining the explicitly supplied initialization
arguments with default values for the unsupplied initialization arguments, 
checking the validity of the initialization arguments, allocating storage 
for the @i{instance}, filling @i{slots} with
values, and executing user-supplied @i{methods} that perform additional
initialization.  Each step of @b{make-instance} is implemented by a
@i{generic function} to provide a mechanism for customizing that step.  
In addition, @b{make-instance} is itself a @i{generic function} 
and thus also can be customized.

The object system specifies system-supplied primary @i{methods} for each step 
and thus specifies a well-defined standard behavior for the entire
initialization process.  The standard behavior provides four simple
mechanisms for controlling initialization:

@table @asis

@item @t{*}  
Declaring a @i{symbol} to be an initialization argument 
for a @i{slot}.  An initialization argument is declared by using the
@t{:initarg} slot option to @b{defclass}.  This provides a mechanism
for supplying a value for a @i{slot} in a call to @b{make-instance}.

@item @t{*}  
Supplying a default value form for an initialization argument.
Default value forms for initialization arguments are defined by using the
@t{:default-initargs} class option to @b{defclass}.  If an 
initialization argument is not explicitly provided
as an argument to @b{make-instance}, the default value form is
evaluated in the lexical environment of the @b{defclass} form that
defined it, and the resulting value is used as the value of the
initialization argument.

@item @t{*}  
Supplying a default initial value form for a @i{slot}.  
A default initial value form for a @i{slot} is defined by using the 
@t{:initform} slot option to @b{defclass}.  If no initialization
argument associated with that @i{slot} is given as an argument to 
@b{make-instance} or is defaulted by @t{:default-initargs}, this
default initial value form is evaluated in the lexical environment of
the @b{defclass} form that defined it, and the resulting value is
stored in the @i{slot}.  The @t{:initform} form for a
@i{local slot} may be used when creating an @i{instance}, when 
updating an @i{instance} to conform to a redefined @i{class}, 
or when updating an @i{instance} to conform to the definition of a
different @i{class}. The @t{:initform} form for a
@i{shared slot} may be used when defining or re-defining the @i{class}.

@item @t{*}  
Defining @i{methods} for @b{initialize-instance} and
@b{shared-initialize}.  The slot-filling behavior described above is
implemented by a system-supplied primary @i{method} for
@b{initialize-instance} which invokes @b{shared-initialize}. The
@i{generic function} @b{shared-initialize} implements the parts of
initialization shared by these four situations: when making an @i{instance}, 
when re-initializing an @i{instance}, when updating an @i{instance}
to conform to a redefined @i{class}, and when updating an @i{instance} 
to conform to the definition of a different @i{class}. The system-supplied
primary @i{method} for @b{shared-initialize} directly implements the
slot-filling behavior described above, and @b{initialize-instance}
simply invokes @b{shared-initialize}.

@end table

@menu
* Initialization Arguments::	
* Declaring the Validity of Initialization Arguments::	
* Defaulting of Initialization Arguments::  
* Rules for Initialization Arguments::	
* Shared-Initialize::		
* Initialize-Instance::		
* Definitions of Make-Instance and Initialize-Instance::  
@end menu

@node Initialization Arguments, Declaring the Validity of Initialization Arguments, Object Creation and Initialization, Object Creation and Initialization
@subsection Initialization Arguments

An initialization argument controls @i{object} creation and
initialization.  It is often convenient to use keyword @i{symbols}
to name initialization arguments, but the @i{name} of an
initialization argument can be any @i{symbol}, including @b{nil}.  An
initialization argument can be used in two ways: to fill a @i{slot}
with a value or to provide an argument for an initialization
@i{method}.  A single initialization argument can be used for both
purposes.

An @i{initialization argument list} is a
@i{property list} of
initialization argument names and values.
Its structure is identical
to a @i{property list} and also 
to the portion of an argument list
processed for @b{&key} parameters.
As in those lists,
if an initialization
argument name appears more than once in an initialization argument list,
the leftmost occurrence supplies the value and the remaining occurrences
are ignored.  The arguments to @b{make-instance} (after the first
argument) form an @i{initialization argument list}.

An initialization argument can be associated with a @i{slot}.  If
the initialization argument has a value in the @i{initialization
argument list}, the value is stored into the @i{slot} of the newly
created @i{object}, overriding any @t{:initform} form associated
with the @i{slot}.  A single initialization argument can initialize
more than one @i{slot}.  An initialization argument that initializes
a @i{shared slot} stores its value into the @i{shared slot},
replacing any previous value.

An initialization argument can be associated with a @i{method}.  When
an @i{object} is created and a particular initialization argument is
supplied, the @i{generic functions} @b{initialize-instance},
@b{shared-initialize}, and @b{allocate-instance} are called
with that initialization argument's name and value as a keyword argument
pair.  If a value for the initialization argument is not supplied in the
@i{initialization argument list}, the @i{method}'s 
@i{lambda list} supplies a default value.

Initialization arguments are used in four situations: when making an
@i{instance}, when re-initializing an @i{instance}, when updating
an @i{instance} to conform to a redefined @i{class}, and when
updating an @i{instance} to conform to the definition of a different
@i{class}.

Because initialization arguments are used to control the creation and
initialization of an @i{instance} of some particular @i{class},
we say that an initialization argument is
``an initialization argument for'' that @i{class}.

@node Declaring the Validity of Initialization Arguments, Defaulting of Initialization Arguments, Initialization Arguments, Object Creation and Initialization
@subsection Declaring the Validity of Initialization Arguments

Initialization arguments are checked for validity in each of the four
situations that use them.  An initialization argument may be valid in
one situation and not another. For example, the system-supplied     
primary @i{method} for @b{make-instance} defined for 
the @i{class} @b{standard-class} checks the validity of its initialization arguments
and signals an error if an initialization argument is supplied that is
not declared as valid in that situation.

There are two means for declaring initialization arguments valid.

@table @asis

@item @t{*}  
Initialization arguments that fill @i{slots} are declared as valid
by the @t{:initarg} slot option to @b{defclass}.  The
@t{:initarg} slot option is inherited from @i{superclasses}.  Thus
the set of valid initialization arguments that fill @i{slots} for a
@i{class} is the union of the initialization arguments that fill
@i{slots} declared as valid by that @i{class} and its
@i{superclasses}.  Initialization arguments that fill @i{slots}
are valid in all four contexts.

@item @t{*}  
Initialization arguments that supply arguments to @i{methods} are
declared as valid by defining those @i{methods}.  The keyword name of
each keyword parameter specified in the @i{method}'s 
@i{lambda list} becomes an initialization argument for all @i{classes} 
for which the @i{method} is applicable.

The presence of {&allow-other-keys} in the
@i{lambda list} of an applicable method disables validity checking of 
initialization arguments.

Thus @i{method} inheritance
controls the set of valid initialization arguments that supply arguments
to @i{methods}.  The @i{generic functions} for which @i{method}
definitions serve to declare initialization arguments valid are as
follows:
@table @asis

@item --  
Making an @i{instance} of a @i{class}:
@b{allocate-instance}, @b{initialize-instance}, and
@b{shared-initialize}.  Initialization arguments declared as valid
by these @i{methods} are valid when making 
an @i{instance} of a @i{class}.

@item --  
Re-initializing an @i{instance}:
@b{reinitialize-instance} and @b{shared-initialize}.
Initialization arguments declared as valid by these @i{methods} are
valid when re-initializing an @i{instance}.

@item --  
Updating an @i{instance} to conform to a redefined @i{class}:
@b{update-instance-for-redefined-class} and @b{shared-initialize}.
Initialization arguments declared as valid by these @i{methods} are
valid when updating an @i{instance} to conform to a redefined @i{class}.

@item --  
Updating an @i{instance} to conform to the definition of a
different @i{class}:
@b{update-instance-for-different-class} and @b{shared-initialize}.
Initialization arguments declared as valid by these @i{methods} are
valid when updating an @i{instance} to conform to the definition
of a different @i{class}.

@end table

@end table

The set of valid initialization arguments for a @i{class} is the set of
valid initialization arguments that either fill @i{slots} or supply
arguments to @i{methods}, along with the predefined initialization
argument @t{:allow-other-keys}.  The default value for 
@t{:allow-other-keys} is @b{nil}.

Validity checking of initialization arguments is disabled if the value of
the initialization argument @t{:allow-other-keys} is @i{true}.

@node Defaulting of Initialization Arguments, Rules for Initialization Arguments, Declaring the Validity of Initialization Arguments, Object Creation and Initialization
@subsection Defaulting of Initialization Arguments

A default value @i{form} can be supplied for an initialization
argument by using the @t{:default-initargs} @i{class} option.  If an
initialization argument is declared valid by some particular @i{class},
its default  value form might be specified by a different @i{class}. 
In this case @t{:default-initargs} is used to supply a default value
for an inherited initialization argument.

The @t{:default-initargs} option is used only to provide default
values for initialization arguments; it does not declare a @i{symbol} 
as a valid initialization argument name.  Furthermore, 
the @t{:default-initargs} option is used only to provide default values for
initialization arguments when making an @i{instance}.

The argument to the @t{:default-initargs} class 
option is a list of
alternating initialization argument names and @i{forms}.  
Each @i{form} is the
default  value form for the corresponding initialization
argument.  The default  value @i{form} of an initialization
argument is used and evaluated only if that initialization argument
does not appear in the arguments to @b{make-instance} and is not
defaulted by a more specific @i{class}.  The default  value @i{form} is
evaluated in the lexical environment of the @b{defclass} form that
supplied it; the resulting value is used as the initialization
argument's value.

The initialization arguments supplied to @b{make-instance} are combined
with defaulted initialization arguments to produce a 
@i{defaulted initialization argument list}. A 
@i{defaulted initialization argument list}
is a list of alternating initialization argument names and
values in which unsupplied initialization arguments are defaulted and in
which the explicitly supplied initialization arguments appear earlier in
the list than the defaulted initialization arguments.  Defaulted
initialization arguments are ordered according to the order in the 
@i{class precedence list} of the @i{classes} that supplied the default values.

There is a distinction between the purposes of the 
@t{:default-initargs} and the @t{:initform} options with respect to the
initialization of @i{slots}.  The @t{:default-initargs} 
class option
provides a mechanism for the user to give a default  value @i{form}
for an initialization argument without knowing whether the
initialization argument initializes a @i{slot} 
or is passed to a @i{method}.
If that initialization argument is not explicitly supplied in a call
to @b{make-instance}, the default  value @i{form} is used, just
as if it had been supplied in the call.  In contrast, the 
@t{:initform} slot option provides a mechanism for the user to give a
default initial value form for a @i{slot}.  An @t{:initform} form is
used to initialize a @i{slot} only if no initialization argument
associated with that @i{slot} is given as an argument to 
@b{make-instance} or is defaulted by @t{:default-initargs}.

@ITindex{order of evaluation}

@ITindex{evaluation order}

The order of evaluation of default value @i{forms} for initialization
arguments and the order of evaluation of @t{:initform} forms are
undefined.  If the order of evaluation is important, 
@b{initialize-instance} or @b{shared-initialize} @i{methods} 
should be used
instead.

@node Rules for Initialization Arguments, Shared-Initialize, Defaulting of Initialization Arguments, Object Creation and Initialization
@subsection Rules for Initialization Arguments

The @t{:initarg} slot option may be specified more than
once for a given @i{slot}.

The following rules specify when initialization arguments may be
multiply defined:

@table @asis

@item @t{*}  
A given initialization argument can be used to
initialize more than one @i{slot} if the same initialization argument name
appears in more than one @t{:initarg} slot option.

@item @t{*}  
A given initialization argument name can appear 
in the @i{lambda list} of more than one initialization @i{method}.

@item @t{*}  
A given initialization argument name can
appear both in an @t{:initarg} slot option and 
in the @i{lambda list}
of an initialization @i{method}.

@end table

[Reviewer Note by The next three paragraphs could be replaced by ``If two or more
initialization arguments that initialize the same slot appear in the
@i{defaulted initialization argument list}, the leftmost of these supplies
the value, even if they have different names.''  And the rest would follow
from the rules above.]

If two or more initialization arguments that initialize the same
@i{slot} are given in the arguments to @b{make-instance}, the
leftmost of these initialization arguments in the @i{initialization
argument list} supplies the value, even if the initialization arguments
have different names.

If two or more different initialization arguments that initialize the
same @i{slot} have default values and none is given explicitly in the
arguments to @b{make-instance}, the initialization argument that
appears in a @t{:default-initargs} class option in the most specific
of the @i{classes} supplies the value. If a single
@t{:default-initargs} class option specifies two or more initialization
arguments that initialize the same @i{slot} and none is given
explicitly in the arguments to @b{make-instance}, the leftmost in
the @t{:default-initargs} class option supplies the value, and the
values of the remaining default value @i{forms} are ignored.

Initialization arguments given explicitly in the arguments to
@b{make-instance} appear to the left of defaulted initialization
arguments. Suppose that the classes C_1 and C_2 supply the
values of defaulted initialization arguments for different @i{slots},
and suppose that C_1 is more specific than C_2; then the
defaulted initialization argument whose value is supplied by C_1
is to the left of the defaulted initialization argument whose value is
supplied by C_2 in the @i{defaulted initialization argument
list}.  If a single @t{:default-initargs} class option supplies the
values of initialization arguments for two different @i{slots}, the
initialization argument whose value is specified farther to the left in
the @t{:default-initargs} class option appears farther to the left in
the @i{defaulted initialization argument list}.

[Reviewer Note by Barmar: End of claim made three paragraphs back.]

If a @i{slot} has both an @t{:initform} form and an 
@t{:initarg} slot option, and the initialization argument is defaulted
using @t{:default-initargs} or is supplied to @b{make-instance},
the captured @t{:initform} form is neither used nor evaluated.

The following is an example of the above rules:

@example
 (defclass q () ((x :initarg a)))
 (defclass r (q) ((x :initarg b))
   (:default-initargs a 1 b 2))
@end example

@center 
@example
@group
@noindent
@w{ {}                           Defaulted                    {}                 }
@w{ Form                         Initialization Argument List Contents of Slot X }
@w{ _____________________________________________________________________________}
@w{ @t{(make-instance 'r)}           @t{(a 1 b 2)}                    @t{1}                  }
@w{ @t{(make-instance 'r 'a 3)}      @t{(a 3 b 2)}                    @t{3}                  }
@w{ @t{(make-instance 'r 'b 4)}      @t{(b 4 a 1)}                    @t{4}                  }
@w{ @t{(make-instance 'r 'a 1 'a 2)} @t{(a 1 a 2 b 2)}                @t{1}                  }
@end group

@end example

@node Shared-Initialize, Initialize-Instance, Rules for Initialization Arguments, Object Creation and Initialization
@subsection Shared-Initialize

The @i{generic function} @b{shared-initialize} is used to fill the 
@i{slots}
of an @i{instance} 
using initialization arguments and @t{:initform}
forms when an @i{instance} is created, when an 
@i{instance} is re-initialized,
when an @i{instance} 
is updated to conform to a redefined @i{class}, and when
an @i{instance} is updated to conform to a different @i{class}.
It uses
standard @i{method} combination. It takes the following arguments: the
@i{instance} to be initialized, a 
specification of a set of @i{names} of @i{slots}
@i{accessible} in that @i{instance}, and any number of initialization
arguments.  The arguments after the first two must form an
@i{initialization argument list}.

The second argument to @b{shared-initialize} may be one of the following:

@table @asis

@item @t{*}  
It can be a (possibly empty) @i{list} of @i{slot} names,
which specifies the set of those @i{slot} names. 

@item @t{*}  
It can be the symbol @b{t}, which specifies the set of all of the @i{slots}.

@end table

There is a system-supplied primary @i{method} for @b{shared-initialize}
whose first @i{parameter specializer} is the @i{class} @b{standard-object}.
This @i{method} behaves as follows on each @i{slot}, 
whether shared or local:

@table @asis

@item @t{*}  
If an initialization argument in the 
@i{initialization argument list} specifies a value for that @i{slot}, 
that value is stored
into the @i{slot}, even if a value has already been stored in the @i{slot}
before the @i{method} is run.  
The affected @i{slots} are independent of which
@i{slots} are indicated by the second argument to @b{shared-initialize}.

@item @t{*}  
Any @i{slots} 
indicated by the second argument that are still
unbound at this point are initialized according to their 
@t{:initform} forms.  For any such @i{slot} 
that has an @t{:initform} form,
that @i{form} is evaluated in the 
lexical environment of its defining 
@b{defclass} form and the result is stored into the @i{slot}.  
For example,
if a @i{before method} stores a value in the 
@i{slot}, the @t{:initform} form will not be used to supply a value 
for the @i{slot}.  If
the second argument specifies a @i{name} that does not correspond to any
@i{slots} @i{accessible} 
in the @i{instance}, the results are unspecified.

@item @t{*}  
The rules mentioned in @ref{Rules for Initialization Arguments} are obeyed.

@end table

The generic function @b{shared-initialize} is called by the
system-supplied primary @i{methods} 
for @b{reinitialize-instance},
@b{update-instance-for-different-class}, 
@b{update-instance-for-redefined-class}, and 
@b{initialize-instance}.  Thus, @i{methods} can be written for 
@b{shared-initialize} to specify actions that should be taken in all of
these contexts.

@node Initialize-Instance, Definitions of Make-Instance and Initialize-Instance, Shared-Initialize, Object Creation and Initialization
@subsection Initialize-Instance

The @i{generic function} @b{initialize-instance} is called by 
@b{make-instance} to initialize a newly created @i{instance}.
It uses @i{standard method combination}.  @i{Methods} for 
@b{initialize-instance} can be defined in order to perform any
initialization that cannot be achieved 
simply by supplying initial values for @i{slots}.

During initialization, @b{initialize-instance} is invoked
after the following actions have been taken:

@table @asis

@item @t{*}  
The @i{defaulted initialization argument list} 
has been computed by combining the supplied @i{initialization argument list} 
with any default initialization arguments for the @i{class}.

@item @t{*}  
The validity of the @i{defaulted initialization argument list}
has been checked.  If any of the initialization arguments has not
been declared as valid, an error is signaled. 

@item @t{*}  
A new @i{instance} whose @i{slots} 
are unbound has been created.

@end table

The generic function @b{initialize-instance} is called with the
new @i{instance} and the defaulted initialization arguments.  There is
a system-supplied primary @i{method} for @b{initialize-instance}
whose @i{parameter specializer} is the @i{class} @b{standard-object}.  This
@i{method} calls the generic function 
@b{shared-initialize} to fill in
the @i{slots} according to the initialization arguments and the 
@t{:initform} forms for the @i{slots}; the generic function 
@b{shared-initialize} is called with the following arguments: the @i{instance},
@b{t}, and the defaulted initialization arguments.

Note that @b{initialize-instance} provides the 
@i{defaulted initialization argument list} in its call to @b{shared-initialize},
so the first step performed by the system-supplied primary @i{method} for
@b{shared-initialize} takes into account both the initialization
arguments provided in the call to @b{make-instance} and the
@i{defaulted initialization argument list}.

@i{Methods} for @b{initialize-instance} can be defined to specify
actions to be taken when an @i{instance} is initialized.  
If only @i{after methods} for @b{initialize-instance} are defined, they will be
run after the system-supplied primary @i{method} for initialization and
therefore will not interfere with the default behavior of 
@b{initialize-instance}.

The object system provides two @i{functions} that are useful in the bodies of 
@b{initialize-instance} methods.  The @i{function} @b{slot-boundp}
returns a @i{generic boolean} value that indicates whether a specified @i{slot} has a
value; this provides a mechanism for writing @i{after methods} for
@b{initialize-instance} that initialize @i{slots} only if they have
not already been initialized.  The @i{function} @b{slot-makunbound}
causes the @i{slot} to have no value.

@node Definitions of Make-Instance and Initialize-Instance,  , Initialize-Instance, Object Creation and Initialization
@subsection Definitions of Make-Instance and Initialize-Instance

The generic function @b{make-instance} behaves as if it were defined as
follows, except that certain optimizations are permitted:

@example
 (defmethod make-instance ((class standard-class) &rest initargs)
   ...
   (let ((instance (apply #'allocate-instance class initargs)))
     (apply #'initialize-instance instance initargs)
     instance))

 (defmethod make-instance ((class-name symbol) &rest initargs)
   (apply #'make-instance (find-class class-name) initargs))
@end example

The elided code in the definition of @b{make-instance} 
augments the @t{initargs} with any @i{defaulted initialization arguments} and
checks the
resulting
initialization arguments to determine whether an initialization
argument was supplied that neither filled a @i{slot} nor supplied an argument
to an applicable @i{method}. 

The generic function @b{initialize-instance} behaves as if it were
defined as follows, except that certain optimizations are permitted:

@example
 (defmethod initialize-instance ((instance standard-object) &rest initargs)
   (apply #'shared-initialize instance t initargs)))
@end example

These procedures can be customized.

Customizing at the Programmer Interface level includes using the 
@t{:initform}, @t{:initarg}, and @t{:default-initargs} options to
@b{defclass}, as well as defining @i{methods}
for @b{make-instance}, 
@b{allocate-instance},
and @b{initialize-instance}.  It is also possible to define
@i{methods} for @b{shared-initialize}, which would be invoked by the
generic functions @b{reinitialize-instance}, 
@b{update-instance-for-redefined-class}, 
@b{update-instance-for-different-class}, and 
@b{initialize-instance}.  
The meta-object level supports additional
customization.

Implementations are permitted to make certain optimizations to 
@b{initialize-instance} and @b{shared-initialize}.  
The description of @b{shared-initialize} in Chapter~7 mentions the
possible optimizations.

@c end of including concept-objects

@node Changing the Class of an Instance, Reinitializing an Instance, Object Creation and Initialization, Objects
@section Changing the Class of an Instance

@c including concept-change-class

The @i{function} @b{change-class} can be used to change the @i{class} 
of an @i{instance} from its current class, C_@{{from}@},
to a different class, C_@{{to}@}; it changes the
structure of the @i{instance} to conform to the definition of the class
C_@{{to}@}.

Note that changing the @i{class} of an @i{instance} may cause
@i{slots} to be added or deleted.  Changing the @i{class} of an
@i{instance} does not change its identity as defined by the
@b{eq} function.

When @b{change-class} is invoked on an @i{instance}, a two-step
updating process takes place.  The first step modifies the structure of
the @i{instance} by adding new @i{local slots} and discarding 
@i{local slots} that are not specified in the new version of the @i{instance}.
The second step initializes the newly added @i{local slots} and performs 
any other user-defined actions. These two steps are further described in the 
two following sections.

@menu
* Modifying the Structure of the Instance::  
* Initializing Newly Added Local Slots (Changing the Class of an Instance)::  
* Customizing the Change of Class of an Instance::  
@end menu

@node Modifying the Structure of the Instance, Initializing Newly Added Local Slots (Changing the Class of an Instance), Changing the Class of an Instance, Changing the Class of an Instance
@subsection Modifying the Structure of the Instance

In order to make the @i{instance} conform to the class C_@{{to}@}, @i{local slots} specified by the class C_@{{to}@} that are not specified by the class C_@{{from}@} are added, and @i{local slots} not specified by
the class C_@{{to}@} that are specified by the
class C_@{{from}@} are discarded.

The values of @i{local slots} specified by both the class C_@{{to}@} and the class C_@{{from}@} are retained. If such a @i{local slot} was unbound, it remains
unbound.

The values of @i{slots} specified as shared in the class C_@{{from}@} and as local in the class C_@{{to}@} are retained.

This first step of the update does not affect the values of any 
@i{shared slots}.

@node Initializing Newly Added Local Slots (Changing the Class of an Instance), Customizing the Change of Class of an Instance, Modifying the Structure of the Instance, Changing the Class of an Instance
@subsection Initializing Newly Added Local Slots

The second step of the update initializes the newly added @i{slots} and
performs any other user-defined actions.  This step is implemented by
the generic function @b{update-instance-for-different-class}.  The
generic function @b{update-instance-for-different-class} is invoked
by @b{change-class} after the first step of the update has been
completed.

The generic function @b{update-instance-for-different-class} is
invoked on arguments computed by @b{change-class}.
The first argument passed is a copy of the @i{instance} being updated 
and is an @i{instance} of the class C_@{{from}@}; 
this copy has @i{dynamic extent} within the generic function @b{change-class}.  
The second argument is the @i{instance} as updated so far by @b{change-class}
and is an @i{instance} of the class C_@{{to}@}.
The remaining arguments are an @i{initialization argument list}.

There is a system-supplied primary @i{method} for 
@b{update-instance-for-different-class} that has two parameter
specializers, each of which is the @i{class} @b{standard-object}.  First
this @i{method} checks the validity of initialization arguments and
signals an error if an initialization argument is supplied that is not
declared as valid.  (For more information, see @ref{Declaring the Validity of Initialization Arguments}.)
Then it calls the
generic function @b{shared-initialize} with the following arguments:
the
new
@i{instance}, a list of @i{names} of the newly added 
@i{slots}, and the
initialization arguments it received.

@node Customizing the Change of Class of an Instance,  , Initializing Newly Added Local Slots (Changing the Class of an Instance), Changing the Class of an Instance
@subsection Customizing the Change of Class of an Instance

@i{Methods} for @b{update-instance-for-different-class} may be defined
to specify actions to be taken when an @i{instance} is updated.  If only
@i{after methods} for @b{update-instance-for-different-class} are
defined, they will be run after the system-supplied primary @i{method} for
initialization and will not interfere with the default behavior of
@b{update-instance-for-different-class}.

@i{Methods} 
for @b{shared-initialize} may be defined to customize @i{class}
redefinition.  For more information, see @ref{Shared-Initialize}.

@c end of including concept-change-class

@node Reinitializing an Instance, Meta-Objects, Changing the Class of an Instance, Objects
@section Reinitializing an Instance

@c including concept-reinit

The generic function @b{reinitialize-instance} may be used to change
the values of @i{slots} according to initialization arguments.

The process of reinitialization changes the values of some @i{slots} and
performs any user-defined actions.  It does not modify the structure
of an @i{instance} to add or delete @i{slots}, 
and it does not use any @t{:initform} forms to initialize @i{slots}.

The generic function @b{reinitialize-instance} may be called
directly.  It takes one required argument, the @i{instance}.  It also
takes any number of initialization arguments to be used by @i{methods} for
@b{reinitialize-instance} or for @b{shared-initialize}. The
arguments after the required @i{instance} must form an 
@i{initialization argument list}.

There is a system-supplied primary @i{method} for 
@b{reinitialize-instance} whose @i{parameter specializer} is 
the @i{class} @b{standard-object}.  First this @i{method} checks the validity of
initialization arguments and signals an error if an initialization
argument is supplied that is not declared as valid. 
(For more information, see @ref{Declaring the Validity of Initialization Arguments}.)
Then it calls the generic function 
@b{shared-initialize} with the following arguments: the @i{instance},
@b{nil}, and the initialization arguments it received.

@menu
* Customizing Reinitialization::  
@end menu

@node Customizing Reinitialization,  , Reinitializing an Instance, Reinitializing an Instance
@subsection Customizing Reinitialization

@i{Methods} for @b{reinitialize-instance} may be defined to specify
actions to be taken when an @i{instance} is updated.  If only
@i{after methods} for @b{reinitialize-instance} are defined, 
they will be run after the system-supplied primary @i{method} for 
initialization and therefore will not interfere with the default behavior of 
@b{reinitialize-instance}.

@i{Methods} for @b{shared-initialize} may be defined to customize 
@i{class} redefinition.  For more information, see @ref{Shared-Initialize}.

@c end of including concept-reinit

@node Meta-Objects, Slots, Reinitializing an Instance, Objects
@section Meta-Objects

@c including concept-meta-objects

The implementation of the object system manipulates @i{classes}, @i{methods},
and @i{generic functions}.  The object system contains a set of 
@i{generic functions} defined by @i{methods} on @i{classes}; 
the behavior of those @i{generic functions} defines the behavior of
the object system.  The @i{instances} of the @i{classes} on which those
@i{methods} are defined are called meta-objects.  

@menu
* Standard Meta-objects::	
@end menu

@node Standard Meta-objects,  , Meta-Objects, Meta-Objects
@subsection Standard Meta-objects

The object system supplies a set of meta-objects, called standard meta-objects.
These include the @i{class} @b{standard-object} and
@i{instances} of the classes @b{standard-method}, 
@b{standard-generic-function}, and @b{method-combination}.

@table @asis

[Editorial Note by KMP: This is said redundantly in the definition of STANDARD-METHOD.]
@item @t{*}  
The @i{class} @b{standard-method} is the default @i{class} of 
@i{methods} defined by the 
 @b{defmethod} and
 @b{defgeneric} @i{forms}.

@item @t{*}  
The @i{class} @b{standard-generic-function} is the default @i{class} of 
@i{generic functions} defined by the forms
  @b{defmethod},
  @b{defgeneric},

 and
  @b{defclass}.

@item @t{*}  
The @i{class} named @b{standard-object} 
is an @i{instance} of the @i{class} @b{standard-class} 
and is a @i{superclass} of every @i{class} that is an
@i{instance} of @b{standard-class} except itself and 
@b{structure-class}.

@item @t{*}  
Every @i{method} combination object is 
an @i{instance} of a @i{subclass} of @i{class} @b{method-combination}.

@end table

@c end of including concept-meta-objects

@node Slots, Generic Functions and Methods, Meta-Objects, Objects
@section Slots

@c including concept-slots

@menu
* Introduction to Slots::	
* Accessing Slots::		
* Inheritance of Slots and Slot Options::  
@end menu

@node Introduction to Slots, Accessing Slots, Slots, Slots
@subsection Introduction to Slots

An @i{object} of @i{metaclass} @b{standard-class} has zero or more named
@i{slots}.  The @i{slots} of an @i{object} are determined 
by the @i{class} of the @i{object}.  Each @i{slot} can hold
one value.

[Reviewer Note by Barmar: All symbols are valid variable names.  Perhaps this means
                  to preclude the use of named constants?  We have a terminology
		  problem to solve.]
The @i{name} of a @i{slot} is a @i{symbol} that is syntactically
valid for use as a variable name.

When a @i{slot} does not have a value, the @i{slot} is said to be 
@i{unbound}.  When an unbound @i{slot} is read,

[Reviewer Note by Barmar: from an object whose metaclass is standard-class?]
the @i{generic function} @b{slot-unbound} is invoked. The 
system-supplied primary @i{method} 
for @b{slot-unbound} 
on @i{class} @b{t} signals an error.

If @b{slot-unbound} returns, its @i{primary value} 
is used that time as the @i{value} of the @i{slot}.

The default initial value form for a @i{slot} is defined by
the @t{:initform} slot option.  When the @t{:initform} form is used to
supply a value, it is evaluated in the lexical environment in which
the @b{defclass} form was evaluated. The @t{:initform} along with
the lexical environment in which the @b{defclass} form was evaluated
is called a @i{captured initialization form}. 
For more details, see @ref{Object Creation and Initialization}.

A @i{local slot} is defined to be a @i{slot} that is
@i{accessible}
to exactly one @i{instance}, 
namely the one in which the @i{slot} is allocated.  
A @i{shared slot} is defined to be a @i{slot} that is visible to more than one
@i{instance} of a given @i{class} and its @i{subclasses}.

A @i{class} is said to define a @i{slot} with a given @i{name} when
the @b{defclass} form for that @i{class} contains a @i{slot specifier} with
that @i{name}.  Defining a @i{local slot} does not immediately create 
a @i{slot}; it causes a @i{slot} to be created each time 
an @i{instance} of the @i{class} is created.
Defining a @i{shared slot} immediately creates a @i{slot}.

The @t{:allocation} slot option to @b{defclass} controls the kind
of @i{slot} that is defined.  If the value of the @t{:allocation} slot
option is @t{:instance}, a @i{local slot} is created.  If the value of
@t{:allocation} is @t{:class}, a @i{shared slot} is created.

A @i{slot} is said to be @i{accessible} in an @i{instance} 
of a @i{class} if
the @i{slot} is defined by the @i{class} 
of the @i{instance} or is inherited from
a @i{superclass} of that @i{class}.  
At most one @i{slot} of a given @i{name} can be
@i{accessible} in an @i{instance}.  
A @i{shared slot} defined by a @i{class} is
@i{accessible} in all @i{instances} 
of that @i{class}.  
A detailed explanation of the inheritance of @i{slots} is given in 
@ref{Inheritance of Slots and Slot Options}.

@node Accessing Slots, Inheritance of Slots and Slot Options, Introduction to Slots, Slots
@subsection Accessing Slots

@i{Slots} can be @i{accessed} in two ways: by use of the primitive function
@b{slot-value} and by use of @i{generic functions} generated by
the @b{defclass} form.

The @i{function} @b{slot-value} can be used with any of the @i{slot}
names specified in the @b{defclass} form to @i{access} a specific
@i{slot} @i{accessible} in an @i{instance} of the given @i{class}.

The macro @b{defclass} provides syntax for generating @i{methods} to
read and write @i{slots}.  If a reader @i{method} is requested, 
a @i{method} is automatically generated for reading the value of the
@i{slot}, but no @i{method} for storing a value into it is generated.
If a writer @i{method} is requested, a @i{method} is automatically 
generated for storing a value into the @i{slot}, but no @i{method} 
for reading its value is generated.  If an accessor @i{method} is 
requested, a @i{method} for reading the value of the @i{slot} and a
@i{method} for storing a value into the @i{slot} are automatically
generated.  Reader and writer @i{methods} are implemented using
@b{slot-value}.

When a reader or writer @i{method} is specified for a @i{slot}, the
name of the @i{generic function} to which the generated @i{method}
belongs is directly specified.  If the @i{name} specified for the writer
@i{method} is the symbol @t{name}, the @i{name} of the
@i{generic function} for writing the @i{slot} is the symbol
@t{name}, and the @i{generic function} takes two arguments: the new
value and the @i{instance}, in that order.  If the @i{name} specified
for the accessor @i{method} is the symbol @t{name}, the @i{name} of
the @i{generic function} for reading the @i{slot} is the symbol 
@t{name}, and the @i{name} of the @i{generic function} for writing 
the @i{slot} is the list @t{(setf name)}.

A @i{generic function} created or modified by supplying @t{:reader},
@t{:writer}, or @t{:accessor} @i{slot} options can be treated exactly
as an ordinary @i{generic function}.

Note that @b{slot-value} can be used to read or write the value of a
@i{slot} whether or not reader or writer @i{methods} exist for that
@i{slot}.  When @b{slot-value} is used, no reader or writer
@i{methods} are invoked.

The macro @b{with-slots} can be used to establish a 
@i{lexical environment} in which specified @i{slots} are lexically
available as if they were variables.  The macro @b{with-slots} 
invokes the @i{function} @b{slot-value} to @i{access} the specified @i{slots}.

The macro @b{with-accessors} can be used to establish a lexical
environment in which specified @i{slots} are lexically available through
their accessors as if they were variables.  The macro @b{with-accessors}
invokes the appropriate accessors to @i{access} the specified @i{slots}. 

@node Inheritance of Slots and Slot Options,  , Accessing Slots, Slots
@subsection Inheritance of Slots and Slot Options

The set of the @i{names} of all @i{slots} @i{accessible} 
in an @i{instance} of a @i{class} C is the union of 
the sets of @i{names} of @i{slots} defined by C and its
@i{superclasses}. The structure of an @i{instance} is
the set of @i{names} of @i{local slots} in that @i{instance}.

In the simplest case, only one @i{class} among C and its @i{superclasses}
defines a @i{slot} with a given @i{slot} name.  
If a @i{slot} is defined by a @i{superclass} of C, 
the @i{slot} is said to be inherited.  The characteristics 
of the @i{slot} are determined by the @i{slot specifier}
of the defining @i{class}.
Consider the defining @i{class} for
a slot S.  If the value of the @t{:allocation} 
slot
option is @t{:instance}, then S is a @i{local slot} and each 
@i{instance}
of C has its own @i{slot} named S that stores its own value.  If the
value of the @t{:allocation} slot 
option is @t{:class}, then S
is a @i{shared slot}, the @i{class} 
that defined S stores the value, and all
@i{instances} of C can @i{access} that single @i{slot}.  
If the @t{:allocation} slot option is omitted, @t{:instance} is used.

In general, more than one @i{class} among C and its 
@i{superclasses} can
define a @i{slot} with a given @i{name}.  
In such cases, only one @i{slot} with
the given name is @i{accessible} in an @i{instance} 
of C, and
the characteristics of that @i{slot} are 
a combination of the several @i{slot}
specifiers, computed as follows:

@table @asis

@item @t{*}  
All the @i{slot specifiers} for a given @i{slot} name
are ordered from most specific to least specific, according to the order in C's
@i{class precedence list} of the @i{classes} that define them. All references
to the specificity of @i{slot specifiers} immediately below refers to this
ordering.

@item @t{*}  
The allocation of a @i{slot} is controlled by the most 
specific @i{slot specifier}.  If the most specific @i{slot specifier} 
does not contain an @t{:allocation} slot option, @t{:instance} is used.
Less specific @i{slot specifiers} do not affect the allocation.

@item @t{*}  
The default initial value form for a @i{slot} 
is the value of the @t{:initform} slot option in the most specific
@i{slot specifier} that contains one.  If no @i{slot specifier}
contains an @t{:initform} slot option, the @i{slot} 
has no default initial value form.

@item @t{*}  
The contents of a @i{slot} will always be of type 
@t{(and T_1 ... T_n)} where T_1 ... T_n are
the values of the @t{:type} slot options contained in all of the
@i{slot specifiers}.  If no @i{slot specifier} contains the
@t{:type} slot option, the contents of the @i{slot} will always be 
of @i{type} @b{t}. The consequences of attempting to store in a @i{slot}
a value that does not satisfy the @i{type} of the @i{slot} are undefined.

@item @t{*}  
The set of initialization arguments that initialize a 
given @i{slot} is the union of the initialization arguments declared in
the @t{:initarg} slot options in all the @i{slot specifiers}.

@item @t{*}  
The @i{documentation string} for a @i{slot} is the value of
the @t{:documentation} slot option in the most specific @i{slot}
specifier that contains one.  If no @i{slot specifier} contains a
@t{:documentation} slot option, the @i{slot} has no @i{documentation string}.

@end table

A consequence of the allocation rule is that a @i{shared slot} can be
@i{shadowed}.  For example, if a class C_1 defines 
a @i{slot} named S
whose value for the @t{:allocation} slot option is @t{:class},
that @i{slot} is @i{accessible} 
in @i{instances} of C_1 and all of its
@i{subclasses}.  However, if C_2 is a @i{subclass} 
of C_1 and also
defines a @i{slot} named S, C_1's 
@i{slot} is not shared
by @i{instances} of C_2 and its @i{subclasses}. When a class
C_1 defines a @i{shared slot}, any subclass C_2 of C_1 will share this single @i{slot} 
unless the @b{defclass} form for
C_2 specifies a @i{slot} of the same 
@i{name} or there is a @i{superclass}
of C_2 that precedes C_1 in the @i{class precedence list} of
C_2 that defines a @i{slot} of the same name.

A consequence of the type rule is that the value of a @i{slot}
satisfies the type constraint of each @i{slot specifier} that
contributes to that @i{slot}.  Because the result of attempting to
store in a @i{slot} a value that does not satisfy the type
constraint for the @i{slot} is undefined, the value in a @i{slot}
might fail to satisfy its type constraint.

The @t{:reader}, @t{:writer}, and @t{:accessor} slot options
create @i{methods} rather than define the characteristics of a @i{slot}.
Reader and writer @i{methods} are inherited in the sense described in
@ref{Inheritance of Methods}.

@i{Methods} that @i{access} @i{slots} use only the name of the
@i{slot} and the @i{type} of the @i{slot}'s value.  Suppose
a @i{superclass} provides a @i{method} that expects to @i{access} a
@i{shared slot} of a given @i{name}, and a @i{subclass} defines
a @i{local slot} with the same @i{name}.  If the @i{method} provided 
by the @i{superclass} is used on an @i{instance} of the @i{subclass}, 
the @i{method} @i{accesses} the @i{local slot}.

@c end of including concept-slots

@node Generic Functions and Methods, Objects Dictionary, Slots, Objects
@section Generic Functions and Methods

@c including concept-gfs-and-methods

@menu
* Introduction to Generic Functions::  
* Introduction to Methods::	
* Agreement on Parameter Specializers and Qualifiers::	
* Congruent Lambda-lists for all Methods of a Generic Function::  
* Keyword Arguments in Generic Functions and Methods::	
* Method Selection and Combination::  
* Inheritance of Methods::	
@end menu

@node Introduction to Generic Functions, Introduction to Methods, Generic Functions and Methods, Generic Functions and Methods
@subsection Introduction to Generic Functions

A @i{generic function}
@IGindex{generic function}
 is a function whose behavior depends on
the @i{classes} or identities of the @i{arguments} supplied to it.
A @i{generic function} @i{object} 
is associated with 
     a set of @i{methods},
     a @i{lambda list},
     a @i{method combination}_2, 
 and other information.

Like an @i{ordinary function}, a @i{generic function} takes @i{arguments},
performs a series of operations, and perhaps returns useful @i{values}.
An @i{ordinary function} has a single body of @i{code} that is always @i{executed}
when the @i{function} is called.  A @i{generic function} has a set of bodies
of @i{code} of which a subset is selected for @i{execution}. The selected
bodies of @i{code} and the manner of their combination are determined by
the @i{classes} or identities of one or more of the @i{arguments} to the
@i{generic function} and by its @i{method combination}.

@i{Ordinary functions} and @i{generic functions} are called with identical syntax.

@i{Generic functions} are true @i{functions} that can be passed as @i{arguments}
and used as the first @i{argument} to @b{funcall} and @b{apply}.

A @i{binding} of a @i{function name} to a @i{generic function}
can be @i{established} in one of several ways.  It can be
@i{established} in the @i{global environment} by 
 @b{ensure-generic-function},
 @b{defmethod} (implicitly, due to @b{ensure-generic-function})
or
 @b{defgeneric} (also implicitly, due to @b{ensure-generic-function}).

No @i{standardized} mechanism is provided for @i{establishing} a
@i{binding} of a @i{function name} to a @i{generic function}
in the @i{lexical environment}.

When a @b{defgeneric} form is evaluated, one of three actions
is taken (due to @b{ensure-generic-function}):

@table @asis

@item @t{*}  
If a generic function of the given name already exists,
the existing generic function object is modified.  Methods specified
by the current @b{defgeneric} form are added, and any methods in the
existing generic function that were defined by a previous @b{defgeneric}
form are removed.  Methods added by the current @b{defgeneric} 
form might replace methods defined by @b{defmethod}, 
@b{defclass}, @b{define-condition}, or @b{defstruct}.  
No other methods in the generic function are affected
or replaced.

@item @t{*}  
If the given name names 
    an @i{ordinary function}, 
    a  @i{macro},
 or a @i{special operator}, 
an error is signaled.

@item @t{*}  
Otherwise a generic function is created with the
methods specified by the method definitions in the @b{defgeneric}
form.

@end table

Some @i{operators} permit specification of the options of a
@i{generic function}, such as 
the @i{type} of @i{method combination} it uses 
or its @i{argument precedence order}.
These @i{operators} will be referred to as
``operators that specify generic function options.''

The only @i{standardized} @i{operator} in this category is @b{defgeneric}.

Some @i{operators} define @i{methods} for a @i{generic function}.
These @i{operators} will be referred to as
@i{method-defining operators}
@IGindex{method-defining operator}
;
their associated @i{forms} are called @i{method-defining forms}.
The @i{standardized} @i{method-defining operators} are listed in Figure 7--2.

@group
@noindent
@w{  defgeneric        defmethod  defclass  }
@w{  define-condition  defstruct            }

@noindent
@w{  Figure 7--2: Standardized Method-Defining Operators}

@end group

Note that of the @i{standardized} @i{method-defining operators}
only @b{defgeneric}
can specify @i{generic function} options.
@b{defgeneric} and any @i{implementation-defined} @i{operators}
that can specify @i{generic function} options
are also referred to as ``operators that specify generic function options.''

@node Introduction to Methods, Agreement on Parameter Specializers and Qualifiers, Introduction to Generic Functions, Generic Functions and Methods
@subsection Introduction to Methods

@i{Methods} define the class-specific or identity-specific behavior
and operations of a @i{generic function}. 

A @i{method} @i{object} 
is associated with 
     @i{code} that implements the method's behavior,
     a sequence of @i{parameter specializers} 
       that specify when the given @i{method} is applicable,
     a @i{lambda list},
 and a sequence of @i{qualifiers} that are used by the method combination
       facility to distinguish among @i{methods}.

A method object is not a function and cannot be invoked as a function. 
Various mechanisms in the object system take a method object and invoke its method
function, as is the case when a generic function is invoked.  When this
occurs it is said that the method is invoked or called.

A method-defining form contains the @i{code} that is to be run when the
arguments to the generic function cause the method that it defines to
be invoked.  When a method-defining form is evaluated, a method object
is created and one of four actions is taken:

@table @asis

@item @t{*}  
If a @i{generic function} of the given name already exists
and if a @i{method object} already exists that agrees with the new one on
@i{parameter specializers} and @i{qualifiers}, the new @i{method object} replaces
the old one.  For a definition of one method agreeing with another on
@i{parameter specializers} and @i{qualifiers}, 
see @ref{Agreement on Parameter Specializers and Qualifiers}.

@item @t{*}  
If a @i{generic function} of the given name already exists
and if there is no @i{method object} that agrees with the new one on
@i{parameter specializers} and @i{qualifiers}, the existing @i{generic function}
@i{object} is modified to contain the new @i{method} @i{object}.

@item @t{*}  
If the given @i{name} names an @i{ordinary function}, a @i{macro},
or a @i{special operator}, an error is signaled.

@item @t{*}  
Otherwise a @i{generic function} is created with the @i{method}
specified by the @i{method-defining form}.

@end table

If the @i{lambda list} of a new @i{method} is not
@i{congruent} with the @i{lambda list} of the @i{generic function},
an error is signaled.  If a @i{method-defining operator} that cannot specify
@i{generic function} options creates a new @i{generic function}, 
a @i{lambda list} for that @i{generic function} is derived from the
@i{lambda list} of the @i{method} in the @i{method-defining form} in such a way
as to be @i{congruent} with it.  For a discussion of @i{congruence}
@IGindex{congruence}
,
see @ref{Congruent Lambda-lists for all Methods of a Generic Function}.

Each method has a @i{specialized lambda list}, which determines
when that method can be applied.  A @i{specialized lambda list} is like
an @i{ordinary lambda list} except that a specialized parameter
may occur instead of the name of a required parameter.  A specialized parameter
is a list @t{(@i{variable-name} @i{parameter-specializer-name})},
where @i{parameter-specializer-name} is one of the following:

@table @asis

@item a @i{symbol}  
denotes a @i{parameter specializer} which is the @i{class} 
named by that @i{symbol}.

@item a @i{class}  
denotes a @i{parameter specializer} which is the @i{class} itself.

@item @t{(eql @i{form})}  
denotes a @i{parameter specializer} which satisfies the @i{type specifier}
@t{(eql @i{object})}, where @i{object} is the 
result of evaluating @i{form}.  The form @i{form} is evaluated in 
the lexical environment in which the method-defining form is evaluated.
Note that @i{form} is evaluated only once, at the time the method is
defined, not each time the generic function is called.
@end table

@i{Parameter specializer names} are used in macros intended as the
user-level interface (@b{defmethod}), while @i{parameter specializers}
are used in the functional interface.

Only required parameters may be specialized, and there must be a
@i{parameter specializer} for each required parameter.  For notational
simplicity, if some required parameter in a @i{specialized lambda list} in
a method-defining form is simply a variable name, its 
@i{parameter specializer} defaults to the @i{class} @b{t}.

Given a generic function and a set of arguments, an applicable
method is a method for that generic function whose parameter
specializers are satisfied by their corresponding arguments.  The
following definition specifies what it means for a method to be
applicable and for an argument to satisfy a @i{parameter specializer}.

Let < A_1, ..., A_n> be the required
arguments to a generic function in order. Let < P_1,
..., P_n> be the @i{parameter specializers} corresponding to
the required parameters of the method M in order.  The method M is
applicable when each A_i is of the @i{type} specified by 
the @i{type specifier} P_i.
Because every valid @i{parameter specializer} is 
also a valid @i{type specifier}, the @i{function} @b{typep} can be used during method
selection to determine whether an argument satisfies a @i{parameter specializer}.  

A method all of whose @i{parameter specializers} are 
the @i{class} @b{t} is called a @i{default method}
@IGindex{default method}
; it is always applicable but
may be shadowed by a more specific method.

Methods can have @i{qualifiers}, which give the method combination
procedure a way to distinguish among methods.  A method that has one
or more @i{qualifiers} is called a @i{qualified method}.
A method with no @i{qualifiers} is called an @i{unqualified method}. 
A @i{qualifier} is any @i{non-list}.
The @i{qualifiers} defined by the @i{standardized} method combination types 
are @i{symbols}.

In this specification, the terms ``@i{primary method}'' and 
``@i{auxiliary method}'' are used to partition @i{methods}
within a method combination type according to their intended use.  
In standard method combination, @i{primary methods} are 
@i{unqualified methods} 
and @i{auxiliary methods} are methods with a single @i{qualifier} 
that is one of @t{:around}, @t{:before}, or @t{:after}.
@i{Methods} with these @i{qualifiers} are called @i{around methods},
@i{before methods}, and @i{after methods}, respectively.
When a method combination type is defined using the short form of
@b{define-method-combination}, @i{primary methods} are 
methods qualified with the name of the type of method combination, 
and auxiliary methods have the @i{qualifier} @t{:around}.
Thus the terms ``@i{primary method}'' and ``@i{auxiliary method}''
have only a relative definition within a given method combination type.

@node Agreement on Parameter Specializers and Qualifiers, Congruent Lambda-lists for all Methods of a Generic Function, Introduction to Methods, Generic Functions and Methods
@subsection Agreement on Parameter Specializers and Qualifiers

Two @i{methods} are said to agree with each other on @i{parameter specializers}
and @i{qualifiers} if the following conditions hold:

@table @asis

@item 1.  
Both methods have the same number of required parameters.
Suppose the @i{parameter specializers} of the two methods are
P_@{1,1@}... P_@{1,n@} and P_@{2,1@}... P_@{2,n@}.

@item 2.  
For each 1<= i<= n, P_@{1,i@} agrees with P_@{2,i@}.
The @i{parameter specializer} P_@{1,i@} agrees with P_@{2,i@} if
P_@{1,i@} and P_@{2,i@} are the same class or if 
P_@{1,i@}=@t{(@b{eql} @i{object}_1)},
P_@{2,i@}=@t{(@b{eql} @i{object}_2)}, and
@t{(@b{eql} @i{object}_1 @i{object}_2)}.
Otherwise P_@{1,i@} and P_@{2,i@} do not agree.

@item 3.  
The two @i{lists} of @i{qualifiers} are the @i{same} 
under @b{equal}.

@end table

@node Congruent Lambda-lists for all Methods of a Generic Function, Keyword Arguments in Generic Functions and Methods, Agreement on Parameter Specializers and Qualifiers, Generic Functions and Methods
@subsection Congruent Lambda-lists for all Methods of a Generic Function

These rules define the congruence of a set of @i{lambda lists}, including the
@i{lambda list} of each method for a given generic function and the
@i{lambda list} specified for the generic function itself, if given.

@table @asis

@item 1.  
Each @i{lambda list} must have the same number of required
parameters.

@item 2.  
Each @i{lambda list} must have the same number of optional
parameters.  Each method can supply its own default for an optional
parameter.

@item 3.  
If any @i{lambda list} mentions @b{&rest} or @b{&key}, each
@i{lambda list} must mention one or both of them.

@item 4.  
If the @i{generic function} @i{lambda list}
mentions @b{&key}, each
method must accept all of the keyword names mentioned after @b{&key},
either by accepting them explicitly, by specifying @b{&allow-other-keys},
or by specifying @b{&rest} but not @b{&key}.
Each method can accept additional keyword arguments of its own.  The
checking of the validity of keyword names is done in the generic
function, not in each method.
A method is invoked as if the keyword
argument pair whose name is @t{:allow-other-keys} and whose value
is @i{true} were supplied, though no such argument pair will be passed.

@item 5.  
The use of @b{&allow-other-keys} need not be consistent
across @i{lambda lists}.  If @b{&allow-other-keys} is mentioned in 
the @i{lambda list} of any applicable @i{method} or of the @i{generic function},
any keyword arguments may be mentioned in the call to the @i{generic function}.

@item 6.  
The use of @b{&aux} need not be consistent across methods.

If a @i{method-defining operator} that cannot specify @i{generic function} options
creates a @i{generic function}, and if the @i{lambda list} for the method
mentions keyword arguments, the @i{lambda list} of the generic function
will mention @b{&key} (but no keyword arguments).

@end table

@node Keyword Arguments in Generic Functions and Methods, Method Selection and Combination, Congruent Lambda-lists for all Methods of a Generic Function, Generic Functions and Methods
@subsection Keyword Arguments in Generic Functions and Methods

When a generic function or any of its methods mentions 
@b{&key} in a @i{lambda list}, the specific set of keyword
arguments accepted by the generic function varies according to the
applicable methods.  The set of keyword arguments accepted by the
generic function for a particular call is the union of the keyword
arguments accepted by all applicable methods and the keyword arguments
mentioned after @b{&key} in the generic function definition,
if any.  A method that has @b{&rest} but not @b{&key} does not affect the
set of acceptable keyword arguments.  If
the @i{lambda list} of any applicable method or of the generic
function definition contains @b{&allow-other-keys}, all
keyword arguments are accepted by the generic function.

The @i{lambda list} congruence rules require that each method
accept all of the keyword arguments mentioned after @b{&key} in the
generic function definition, by accepting them explicitly, by
specifying @b{&allow-other-keys}, or by specifying @b{&rest} but
not @b{&key}.  Each method can accept additional keyword arguments
of its own, in addition to the keyword arguments mentioned in the
generic function definition.

If a @i{generic function} is passed a keyword argument that no applicable
method accepts, an error should be signaled; see @ref{Error Checking in Function Calls}.

@menu
* Examples of Keyword Arguments in Generic Functions and Methods::  
@end menu

@node Examples of Keyword Arguments in Generic Functions and Methods,  , Keyword Arguments in Generic Functions and Methods, Keyword Arguments in Generic Functions and Methods
@subsubsection Examples of Keyword Arguments in Generic Functions and Methods

For example, suppose there are two methods defined for @t{width}
as follows:

@example
 (defmethod width ((c character-class) &key font) ...)

 (defmethod width ((p picture-class) &key pixel-size) ...)
@end example

@noindent
Assume that there are no other methods and no generic
function definition for @t{width}. The evaluation of the
following form should signal an error because 
the keyword argument @t{:pixel-size} is not accepted by the applicable method.

@example
 (width (make-instance `character-class :char #\Q) 
        :font 'baskerville :pixel-size 10)
@end example

The evaluation of the following form should signal an error.

@example
 (width (make-instance `picture-class :glyph (glyph #\Q)) 
        :font 'baskerville :pixel-size 10)
@end example

The evaluation of the following form will not signal an error
if the class named @t{character-picture-class} is a subclass of
both @t{picture-class} and @t{character-class}.

@example
 (width (make-instance `character-picture-class :char #\Q)
        :font 'baskerville :pixel-size 10)
@end example

@node Method Selection and Combination, Inheritance of Methods, Keyword Arguments in Generic Functions and Methods, Generic Functions and Methods
@subsection Method Selection and Combination

When a @i{generic function} is called with particular arguments, it must
determine the code to execute.  This code is called the 
@i{effective method}
@IGindex{effective method}
 for those @i{arguments}.
The @i{effective method} is a 
combination of the @i{applicable methods} in the @i{generic function}
that @i{calls} some or all of the @i{methods}.

If a @i{generic function} is called and no @i{methods} are 
@i{applicable}, the @i{generic function} @b{no-applicable-method}
is invoked, with the @i{results} from that call being used as the
@i{results} of the call to the original @i{generic function}.  Calling
@b{no-applicable-method} takes precedence over checking for acceptable
keyword arguments; see @ref{Keyword Arguments in Generic Functions and Methods}.

When the @i{effective method} has been determined,
it is invoked with the same @i{arguments} as were passed to the @i{generic function}.  
Whatever @i{values} it returns are returned as the @i{values}
of the @i{generic function}.

@menu
* Determining the Effective Method::  
* Selecting the Applicable Methods::  
* Sorting the Applicable Methods by Precedence Order::	
* Applying method combination to the sorted list of applicable methods::  
* Standard Method Combination::	 
* Declarative Method Combination::  
* Built-in Method Combination Types::  
@end menu

@node Determining the Effective Method, Selecting the Applicable Methods, Method Selection and Combination, Method Selection and Combination
@subsubsection Determining the Effective Method

The effective method is determined by the following three-step procedure:

@table @asis

@item 1.  
{Select the applicable methods.}

@item 2.  
{Sort the applicable methods by precedence order, putting
the most specific method first.}

@item 3.  
{Apply method combination to the sorted list of
applicable methods, producing the effective method.}

@end table

@node Selecting the Applicable Methods, Sorting the Applicable Methods by Precedence Order, Determining the Effective Method, Method Selection and Combination
@subsubsection Selecting the Applicable Methods

This step is described in @ref{Introduction to Methods}.

@node Sorting the Applicable Methods by Precedence Order, Applying method combination to the sorted list of applicable methods, Selecting the Applicable Methods, Method Selection and Combination
@subsubsection Sorting the Applicable Methods by Precedence Order

To compare the precedence of two methods, their @i{parameter specializers}
are examined in order.  The default examination order is from left to
right, but an alternative order may be specified by the 
@t{:argument-precedence-order} option to @b{defgeneric} or to any of
the other operators that specify generic function options.

The corresponding @i{parameter specializers} from each method are
compared.  When a pair of @i{parameter specializers} agree, the next
pair are compared for agreement.  If all corresponding parameter
specializers agree, the two methods must have different
@i{qualifiers}; in this case, either method can be selected to precede the
other.  For information about agreement, see @ref{Agreement on Parameter Specializers and Qualifiers}.

If some corresponding @i{parameter specializers} do not agree, the first
pair of @i{parameter specializers} that do not agree determines the
precedence.  If both @i{parameter specializers} are classes, the more
specific of the two methods is the method whose @i{parameter specializer}
appears earlier in the @i{class precedence list} of the corresponding
argument.  Because of the way in which the set of applicable methods
is chosen, the @i{parameter specializers} are guaranteed to be present in
the class precedence list of the class of the argument.

If just one of a pair of corresponding @i{parameter specializers} is @t{(eql @i{object})},
the @i{method} with that @i{parameter specializer} precedes the
other @i{method}.  If both @i{parameter specializers} are @b{eql}
@i{expressions}, the
specializers must agree (otherwise the two @i{methods} would
not both have been applicable to this argument).

The resulting list of @i{applicable methods} has the most specific
@i{method} first and the least specific @i{method} last.    

@node Applying method combination to the sorted list of applicable methods, Standard Method Combination, Sorting the Applicable Methods by Precedence Order, Method Selection and Combination
@subsubsection Applying method combination to the sorted list of applicable methods

In the simple case---if standard method combination is used and all
applicable methods are primary methods---the 
effective method is the most specific method.
That method can call the next most specific
method by using the @i{function} @b{call-next-method}.  The method that
@b{call-next-method} will call is referred to as the 
@i{next method}
@IGindex{next method}
.  The predicate @b{next-method-p} tests whether a next
method exists.  If @b{call-next-method} is called and there is no
next most specific method, the generic function @b{no-next-method}
is invoked.

In general, the effective method is some combination of the applicable
methods.  It is described by a @i{form} that contains calls to some or
all of the applicable methods, returns the value or values that will
be returned as the value or values of the generic function, and
optionally makes some of the methods accessible by means of 
@b{call-next-method}.

The role of each method in the effective method is determined by its
@i{qualifiers} and the specificity of the method.  A @i{qualifier}
serves to mark a method, and the meaning of a @i{qualifier} is
determined by the way that these marks are used by this step
of the procedure.  If an applicable method has an unrecognized
@i{qualifier}, this step signals an error and does not include that method
in the effective method.

When standard method combination is used together with qualified methods, 
the effective method is produced as described in @ref{Standard Method Combination}.

Another type of method combination can be specified by using the
@t{:method-combination} option of @b{defgeneric} or
of any of the other operators that specify generic function options.  In
this way this step of the procedure can be customized.

New types of method combination can be defined by using 
the @b{define-method-combination} @i{macro}. 

@node Standard Method Combination, Declarative Method Combination, Applying method combination to the sorted list of applicable methods, Method Selection and Combination
@subsubsection Standard Method Combination

@IRindex{standard}

Standard method combination is supported by the @i{class} @b{standard-generic-function}.
It is used if no other type of method
combination is specified or if the built-in method combination type
@b{standard} is specified. 

Primary methods define the main action of the effective method,  
while auxiliary methods modify that action in one of three ways.
A primary method has no method @i{qualifiers}.

An auxiliary method is a method whose 
@i{qualifier} is @t{:before}, @t{:after}, or @t{:around}.
Standard method combination
allows no more than one @i{qualifier} per method; if a method definition
specifies more than one @i{qualifier} per method, an error is signaled.

@table @asis

@item @t{*}  
A @i{before method} has the keyword @t{:before} as its only @i{qualifier}.
A @i{before method} specifies @i{code} that is to be run before any 
@i{primary methods}.

@item @t{*}  
An @i{after method} has the keyword @t{:after} as its only @i{qualifier}.
An @i{after method} specifies @i{code} that is to be run after
@i{primary methods}.

@item @t{*}  
An @i{around method} has the keyword @t{:around} as its only @i{qualifier}.
An @i{around method} specifies @i{code} that is to be run instead of other
@i{applicable methods},
but which might contain explicit @i{code}
which calls some of those @i{shadowed} @i{methods}
(via @b{call-next-method}).

@end table

The semantics of standard method combination is as follows:

@table @asis

@item @t{*}  
If there are any @i{around methods}, the most specific
@i{around method} is called.  It supplies the value or values of the
generic function.

@item @t{*}  
Inside the body of an @i{around method}, 
@b{call-next-method} can be used to call the @i{next method}.  When the next
method returns, the @i{around method} can execute more code,
perhaps based on the returned value or values.
The @i{generic function} @b{no-next-method} is invoked if @b{call-next-method} is used and
there is no @i{applicable method} to call.  The @i{function} @b{next-method-p}
may be used to determine whether a @i{next method} exists.

@item @t{*}  
If an @i{around method} invokes @b{call-next-method},
the next most specific @i{around method}
is called, if one is applicable.  If there are no @i{around methods} 
or if @b{call-next-method} is called by the least
specific @i{around method}, the other methods are called as
follows:
@table @asis

@item --  
All the @i{before methods} are called, in
most-specific-first order.  Their values are ignored.
An error is signaled if @b{call-next-method} is used in a
@i{before method}.

@item --  
The most specific primary method is called.  Inside the
body of a primary method, @b{call-next-method} may be used to call
the next most specific primary method.  When that method returns, the
previous primary method can execute more code, perhaps based on the
returned value or values.  The generic function @b{no-next-method}
is invoked if @b{call-next-method} is used and there are no more
applicable primary methods.  The @i{function} @b{next-method-p} may be
used to determine whether a @i{next method} exists.  If @b{call-next-method}
is not used, only the most specific @i{primary method} is called.

@item --  
All the @i{after methods} are called in
most-specific-last order.  Their values are ignored.
An error is signaled if @b{call-next-method} is used in an
@i{after method}.
@end table

@item @t{*}  
If no @i{around methods} were invoked, the most
specific primary method supplies the value or values returned by the
generic function.  The value or values returned by the invocation of
@b{call-next-method} in the least specific @i{around method} are
those returned by the most specific primary method.

@end table

In standard method combination, if there is an applicable method
but no applicable primary method, an error is signaled.

The @i{before methods} are run in most-specific-first order while
the @i{after methods} are run in least-specific-first order.  The
design rationale for this difference can be illustrated with an
example.  Suppose class C_1 modifies the behavior of its
superclass, C_2, by adding @i{before methods} and @i{after methods}.
Whether the behavior of the class C_2 is defined
directly by methods on C_2 or is inherited from its superclasses
does not affect the relative order of invocation of methods on
instances of the class C_1.  Class C_1's 
@i{before method} runs before all of class C_2's methods.  
Class C_1's @i{after method} runs after all of class C_2's methods.

By contrast, all @i{around methods} run before any other methods
run.  Thus a less specific @i{around method} runs before a more
specific primary method.

If only primary methods are used and if @b{call-next-method} is not
used, only the most specific method is invoked; that is, more specific
methods shadow more general ones. 

@node Declarative Method Combination, Built-in Method Combination Types, Standard Method Combination, Method Selection and Combination
@subsubsection Declarative Method Combination

The macro @b{define-method-combination} defines new forms of method
combination.  It provides a mechanism for customizing the production
of the effective method. The default procedure for producing an
effective method is described in @ref{Determining the Effective Method}.
There are two forms of
@b{define-method-combination}.  The short form is a simple facility while
the long form is more powerful and more verbose.  The long form
resembles @b{defmacro} in that the body is an expression that
computes a Lisp form; it provides mechanisms for implementing
arbitrary control structures within method combination and for
arbitrary processing of method @i{qualifiers}.  

@node Built-in Method Combination Types,  , Declarative Method Combination, Method Selection and Combination
@subsubsection Built-in Method Combination Types

The object system provides a set of built-in method combination types.  To
specify that a generic function is to use one of these method
combination types, the name of the method combination type is given as
the argument to the @t{:method-combination} option to 
@b{defgeneric} or to the @t{:method-combination} option to any of the
other operators that specify generic function options.

The names of the built-in  method combination types are listed in Figure 7--3.

@IRindex{+}

@IRindex{and}

@IRindex{append}

@IRindex{list}

@IRindex{max}

@IRindex{min}

@IRindex{nconc}

@IRindex{or}

@IRindex{progn}

@IRindex{standard}

@group
@noindent
@w{  +    append  max  nconc  progn     }
@w{  and  list    min  or     standard  }

@noindent
@w{  Figure 7--3: Built-in Method Combination Types}

@end group

The semantics of the @b{standard} built-in method combination type is
described in @ref{Standard Method Combination}.  The other
built-in method combination types are called simple built-in method
combination types.

The simple built-in method combination types act as though they were
defined by the short form of @b{define-method-combination}.  
They recognize two roles for @i{methods}:

@table @asis

@item @t{*}  
An @i{around method} has the keyword symbol 
@t{:around} as its sole @i{qualifier}.  The meaning of 
@t{:around} @i{methods} is the same as in standard method combination.
Use of the functions @b{call-next-method} and @b{next-method-p}
is supported in @i{around methods}.

@item @t{*}  
A primary method has the name of the method combination
type as its sole @i{qualifier}.  For example, the built-in method
combination type @t{and} recognizes methods whose sole @i{qualifier} is
@t{and}; these are primary methods. Use of the functions 
@b{call-next-method} and @b{next-method-p} is not supported 
in @i{primary methods}.

@end table

The semantics of the simple built-in method combination types is as
follows:

@table @asis

@item @t{*}  
If there are any @i{around methods}, the most specific @i{around method}
is called.   It supplies the value or values of the @i{generic function}. 

@item @t{*}  
Inside the body of an @i{around method}, the function
@b{call-next-method} can be used to call the @i{next method}.
The @i{generic function} @b{no-next-method} is invoked if 
@b{call-next-method} is used and there is no applicable method to call.
The @i{function} @b{next-method-p} may be used to determine whether a
@i{next method} exists. When the @i{next method} returns, 
the @i{around method} can execute more code,
perhaps based on the returned value or values.

@item @t{*}  
If an @i{around method} invokes @b{call-next-method},
the next most specific @i{around method} is
called, if one is applicable.  If there are no @i{around methods}
or if @b{call-next-method} is called by the least specific
@i{around method}, a Lisp form derived from the name of the built-in
method combination type and from the list of applicable primary
methods is evaluated to produce the value of the generic function.
Suppose the name of the method combination type is @i{operator}
and the call to the generic function is of the form

@center (@i{generic-function} a_1... a_n)

@item @t{}  
Let M_1,...,M_k be the applicable primary methods
in order; then the derived Lisp form is

@center (@i{operator} < M_1
 a_1... a_n>...<
M_k a_1... a_n>)

@item @t{}  
If the expression < M_i  a_1... a_n> is
evaluated, the method M_i will be applied to the arguments
a_1... a_n.  
For example,
if @i{operator} is @t{or},
the expression < M_i  a_1... a_n> is
evaluated only if < M_j  a_1... a_n>,
1<= j<i, returned @t{nil}.

@item @t{}  
The default order for the primary methods is 
@t{:most-specific-first}.  However, the order can be reversed by supplying
@t{:most-specific-last} as the second argument to the @t{:method-combination} option.
@end table

The simple built-in method combination types require exactly one
@i{qualifier} per method.  An error is signaled if there are applicable
methods with no @i{qualifiers} or with @i{qualifiers} that are not supported
by the method combination type. An error is signaled if there are
applicable @i{around methods} and no applicable primary
methods.

@node Inheritance of Methods,  , Method Selection and Combination, Generic Functions and Methods
@subsection Inheritance of Methods

A subclass inherits methods in the sense that any method applicable to
all instances of a class is also applicable to all instances of any
subclass of that class.

The inheritance of methods acts the same way regardless of 
which of the @i{method-defining operators} created the methods.

The inheritance of methods is described in detail in 
@ref{Method Selection and Combination}.

@c end of including concept-gfs-and-methods

@node Objects Dictionary,  , Generic Functions and Methods, Objects
@section Objects Dictionary

@c including dict-objects

@menu
* function-keywords::		
* ensure-generic-function::	
* allocate-instance::		
* reinitialize-instance::	
* shared-initialize::		
* update-instance-for-different-class::	 
* update-instance-for-redefined-class::	 
* change-class::		
* slot-boundp::			
* slot-exists-p::		
* slot-makunbound::		
* slot-missing::		
* slot-unbound::		
* slot-value::			
* method-qualifiers::		
* no-applicable-method::	
* no-next-method::		
* remove-method::		
* make-instance::		
* make-instances-obsolete::	
* make-load-form::		
* make-load-form-saving-slots::	 
* with-accessors::		
* with-slots::			
* defclass::			
* defgeneric::			
* defmethod::			
* find-class::			
* next-method-p::		
* call-method::			
* call-next-method::		
* compute-applicable-methods::	
* define-method-combination::	
* find-method::			
* add-method::			
* initialize-instance::		
* class-name::			
* (setf class-name)::		
* class-of::			
* unbound-slot::		
* unbound-slot-instance::	
@end menu

@node function-keywords, ensure-generic-function, Objects Dictionary, Objects Dictionary
@subsection function-keywords                               [Standard Generic Function]

@subsubheading  Syntax::

@code{function-keywords}  @i{method} @result{}  @i{keys, allow-other-keys-p}

@subsubheading  Method Signatures::

@code{function-keywords}  @i{@r{(}@i{method} @b{standard-method}@r{)}}

@subsubheading  Arguments and Values::

@i{method}---a @i{method}.

@i{keys}---a @i{list}.

@i{allow-other-keys-p}---a @i{generalized boolean}.

@subsubheading  Description::

Returns the keyword parameter specifiers for a @i{method}.

Two values are returned: 
 a @i{list} of the explicitly named keywords 
 and a @i{generalized boolean} that states whether @b{&allow-other-keys}
  had been specified in the @i{method} definition.

@subsubheading  Examples::

@example
 (defmethod gf1 ((a integer) &optional (b 2)
                 &key (c 3) ((:dee d) 4) e ((eff f)))
   (list a b c d e f))
@result{}  #<STANDARD-METHOD GF1 (INTEGER) 36324653>
 (find-method #'gf1 '() (list (find-class 'integer))) 
@result{}  #<STANDARD-METHOD GF1 (INTEGER) 36324653>
 (function-keywords *)
@result{}  (:C :DEE :E EFF), @i{false}
 (defmethod gf2 ((a integer))
   (list a b c d e f))
@result{}  #<STANDARD-METHOD GF2 (INTEGER) 42701775>
 (function-keywords (find-method #'gf1 '() (list (find-class 'integer))))
@result{}  (), @i{false}
 (defmethod gf3 ((a integer) &key b c d &allow-other-keys)
   (list a b c d e f))
 (function-keywords *)
@result{}  (:B :C :D), @i{true}
@end example

@subsubheading  Affected By::

@b{defmethod}

@subsubheading  See Also::

@ref{defmethod}

@node ensure-generic-function, allocate-instance, function-keywords, Objects Dictionary
@subsection ensure-generic-function                                          [Function]

@code{ensure-generic-function}  @i{function-name {&key}
			 argument-precedence-order declare
                               documentation environment
                               generic-function-class lambda-list
                               method-class method-combination}@*
   @result{}  @i{generic-function}

@subsubheading  Arguments and Values::

@i{function-name}---a @i{function name}.

The keyword arguments correspond to the @i{option} arguments of
@b{defgeneric}, except that the @t{:method-class} and
@t{:generic-function-class} arguments can be @i{class} @i{object}s
as well as names.

@t{Method-combination} -- method combination object.

@t{Environment} -- the same as the @b{&environment} argument
to macro expansion functions and is used to distinguish between compile-time
and run-time environments.

[Editorial Note by KMP: What about documentation. Missing from this arguments enumeration,
  and confusing in description below.]

@i{generic-function}---a @i{generic function} @i{object}.

@subsubheading  Description::

The @i{function} @b{ensure-generic-function} is used to define 
a globally named @i{generic function} with no @i{methods} 
or to specify or modify options and declarations that pertain to 
a globally named @i{generic function} as a whole.

If @i{function-name} is not @i{fbound} in the @i{global environment},
a new
@i{generic function} is created.  
If 

@t{(fdefinition @i{function-name})} 

is an @i{ordinary function}, 
a @i{macro}, 
or a @i{special operator},
an error is signaled.

If @i{function-name} 
is a @i{list}, it must be of the
form @t{(setf @i{symbol})}.
If @i{function-name} specifies a @i{generic function} that has a
different value for any of the following arguments,
the @i{generic function} is modified to have the new value: 
@t{:argument-precedence-order}, @t{:declare}, @t{:documentation},
@t{:method-combination}.

If @i{function-name} specifies a @i{generic function} that has a
different value for the @t{:lambda-list} argument, and the new value
is congruent with the @i{lambda lists} of all existing 
@i{methods} or there
are no @i{methods}, the value is changed; otherwise an error is signaled.

If @i{function-name} specifies a @i{generic function} that has a
different value for the @t{:generic-function-class} argument and if
the new generic function class is compatible with the old,
@b{change-class} is called to change the @i{class} of the 
@i{generic function};
otherwise an error is signaled.

If @i{function-name} specifies a @i{generic function} that has a
different value for the @t{:method-class} argument, the value is
changed, but any existing @i{methods} are not changed.

@subsubheading  Affected By::

Existing function binding of @i{function-name}.

@subsubheading  Exceptional Situations::

If 

@t{(fdefinition @i{function-name})}

is an @i{ordinary function}, a @i{macro}, or a @i{special operator}, 
an error of @i{type} @b{error} is signaled.

If @i{function-name} specifies a 
@i{generic function} that has a
different value for the @t{:lambda-list} argument, and the new value
is not congruent with the @i{lambda list} of any existing 
@i{method},
an error of @i{type} @b{error} is signaled.

If @i{function-name} specifies a 
@i{generic function} that has a
different value for the @t{:generic-function-class} argument and if
the new generic function class not is compatible with the old,
an error of @i{type} @b{error} is signaled.

@subsubheading  See Also::

@ref{defgeneric}

@node allocate-instance, reinitialize-instance, ensure-generic-function, Objects Dictionary
@subsection allocate-instance                               [Standard Generic Function]

@subsubheading  Syntax::

@code{allocate-instance}  @i{class {&rest} initargs {&key} {&allow-other-keys}} @result{}  @i{new-instance}

@subsubheading  Method Signatures::

@code{allocate-instance}  @i{@r{(}@i{class} @b{standard-class}@r{)} {&rest} initargs}

@code{allocate-instance}  @i{@r{(}@i{class} @b{structure-class}@r{)} {&rest} initargs}

@subsubheading  Arguments and Values::

@i{class}---a @i{class}.

@i{initargs}---a @i{list} of @i{keyword/value pairs} 
		   (initialization argument @i{names} and @i{values}).

@i{new-instance}---an @i{object} whose @i{class} is @i{class}.

@subsubheading  Description::

The generic function @b{allocate-instance} creates and returns
a new instance of the @i{class}, without initializing it.
When the @i{class} is a @i{standard class}, this means that
the @i{slots} are @i{unbound}; when the @i{class} is a
@i{structure class}, this means the @i{slots}' @i{values}
are unspecified.

The caller of @b{allocate-instance} is expected to have
already checked the initialization arguments.

The @i{generic function} @b{allocate-instance} is called by
@b{make-instance}, as described in
@ref{Object Creation and Initialization}.

@subsubheading  See Also::

@ref{defclass}
, 
@ref{make-instance}
, 
@ref{class-of}
,
@ref{Object Creation and Initialization}

@subsubheading  Notes::

The consequences of adding @i{methods} to @b{allocate-instance} is unspecified.
This capability might be added by the @i{Metaobject Protocol}.

@node reinitialize-instance, shared-initialize, allocate-instance, Objects Dictionary
@subsection reinitialize-instance                           [Standard Generic Function]

@subsubheading  Syntax::

@code{reinitialize-instance}  @i{instance {&rest} initargs {&key} {&allow-other-keys}} @result{}  @i{instance}

@subsubheading  Method Signatures::

@code{reinitialize-instance}  @i{@r{(}@i{instance} @b{standard-object}@r{)} {&rest} initargs}

@subsubheading  Arguments and Values::

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

@i{initargs}---an @i{initialization argument list}.

@subsubheading  Description::

The @i{generic function} @b{reinitialize-instance} can be used to change
the values of @i{local slots} of an @i{instance} according to 
@i{initargs}.
This @i{generic function} can be called by users.

The system-supplied primary @i{method} for @b{reinitialize-instance}
checks the validity of @i{initargs} and signals an error if
an @i{initarg} is supplied that is not declared as valid.
The @i{method} then calls the generic function @b{shared-initialize}
with the following arguments:  the @i{instance}, 
@b{nil} (which means no @i{slots}
should be initialized according to their initforms), and the
@i{initargs} it received.

@subsubheading  Side Effects::

The @i{generic function} @b{reinitialize-instance} changes the values of @i{local slots}.

@subsubheading  Exceptional Situations::

The system-supplied primary @i{method} for @b{reinitialize-instance}
signals an error if an @i{initarg} is supplied that is not declared as valid.

@subsubheading  See Also::

@ref{Initialize-Instance}
,
@ref{Shared-Initialize}
,
@ref{update-instance-for-redefined-class}
,
@ref{update-instance-for-different-class}
,
@ref{slot-boundp}
,
@ref{slot-makunbound}
,
@ref{Reinitializing an Instance},
@ref{Rules for Initialization Arguments},
@ref{Declaring the Validity of Initialization Arguments}

@subsubheading  Notes::

@i{Initargs} are declared as valid by using the
@t{:initarg} option to @b{defclass}, or by defining 
@i{methods} for @b{reinitialize-instance}
or @b{shared-initialize}.  The keyword name
of each keyword parameter specifier in the @i{lambda list} of any 
@i{method}
defined on @b{reinitialize-instance} or @b{shared-initialize} is
declared as a valid initialization argument name for all 
@i{classes} for
which that @i{method} is applicable.

@node shared-initialize, update-instance-for-different-class, reinitialize-instance, Objects Dictionary
@subsection shared-initialize                               [Standard Generic Function]

@subsubheading  Syntax::

@code{shared-initialize}  @i{instance slot-names {&rest} initargs {&key} {&allow-other-keys}} @result{}  @i{instance}

@subsubheading  Method Signatures::

@code{shared-initialize}  @i{@r{(}@i{instance} @b{standard-object}@r{)} slot-names {&rest} initargs}

@subsubheading  Arguments and Values::

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

@i{slot-names}---a @i{list} or @b{t}.

@i{initargs}---a @i{list} of @i{keyword/value pairs}
		   (of initialization argument @i{names} and @i{values}).

@subsubheading  Description::

The generic function @b{shared-initialize} is used to fill the 
@i{slots}                        
of an @i{instance} 
using @i{initargs} and @t{:initform}
forms.  It is called when an instance is created, when an instance is
re-initialized, when an instance is updated to conform to a redefined
@i{class}, and when an instance is updated to conform to a different
@i{class}. The generic function @b{shared-initialize} is called by the
system-supplied primary @i{method} for @b{initialize-instance},
@b{reinitialize-instance}, @b{update-instance-for-redefined-class}, and
@b{update-instance-for-different-class}.

The generic function @b{shared-initialize} takes the following
arguments: the @i{instance} to be initialized, a specification of a set of
@i{slot-names} @i{accessible} in that @i{instance}, 
and any number of @i{initargs}.
The arguments after the first two must form an 
@i{initialization argument list}.  The system-supplied primary @i{method} on 
@b{shared-initialize} initializes the @i{slots} with values according to the
@i{initargs} and supplied @t{:initform} forms.  @i{Slot-names}
indicates which @i{slots} should be initialized according
to their @t{:initform} forms if no @i{initargs} are
provided for those @i{slots}. 

The system-supplied primary @i{method} behaves as follows, 
regardless of whether the @i{slots} are local or shared: 

@table @asis

@item @t{*}  
If an @i{initarg} in the @i{initialization argument list} 
 specifies a value for that @i{slot}, that
 value is stored into the @i{slot}, even if a value has
 already been stored in the @i{slot} before the @i{method} is run.

@item @t{*}  
Any @i{slots} indicated by @i{slot-names} that are still unbound
 at this point are initialized according to their @t{:initform} forms.
 For any such @i{slot} that has an @t{:initform} form,
 that @i{form} is evaluated in the lexical environment of its defining 
 @b{defclass} @i{form} and the result is stored into the @i{slot}.
 For example, if a @i{before method} stores a value in the @i{slot}, 
 the @t{:initform} form will not be used to supply a value for the @i{slot}.

@item @t{*}  
The rules mentioned in @ref{Rules for Initialization Arguments} are obeyed.

@end table

The @i{slots-names} argument specifies the @i{slots} that are to be
initialized according to their @t{:initform} forms if no
initialization arguments apply.  It can be a @i{list} of slot @i{names}, 
which specifies the set of those slot @i{names}; or it can be the @i{symbol} @b{t}, 
which specifies the set of all of the @i{slots}.

@subsubheading  See Also::

@ref{Initialize-Instance}
,
@ref{reinitialize-instance}
,
@ref{update-instance-for-redefined-class}
,
@ref{update-instance-for-different-class}
,
@ref{slot-boundp}
,
@ref{slot-makunbound}
,
@ref{Object Creation and Initialization},
@ref{Rules for Initialization Arguments},
@ref{Declaring the Validity of Initialization Arguments}

@subsubheading  Notes::

@i{Initargs} are declared as valid by using the @t{:initarg}
option to @b{defclass}, or by defining 
@i{methods} for @b{shared-initialize}. 
The keyword name of each keyword parameter
specifier in the @i{lambda list} of any @i{method} defined on 
@b{shared-initialize} is declared as a valid @i{initarg}
name for all @i{classes} for which that @i{method} is applicable.

Implementations are permitted to optimize @t{:initform} forms that 
neither produce nor depend on side effects, by evaluating these @i{forms}
and storing them into slots before running any 
@b{initialize-instance} methods, rather than by handling them in the
primary @b{initialize-instance} method.  (This optimization might
be implemented by having the @b{allocate-instance} method copy a
prototype instance.)

Implementations are permitted to optimize default initial value forms
for @i{initargs} associated with slots by not actually
creating the complete initialization argument 
@i{list} when the only @i{method}
that would receive the complete @i{list} is the 
@i{method} on @b{standard-object}.
In this case default initial value forms can be 
treated like @t{:initform} forms.  This optimization has no visible
effects other than a performance improvement.

@node update-instance-for-different-class, update-instance-for-redefined-class, shared-initialize, Objects Dictionary
@subsection update-instance-for-different-class             [Standard Generic Function]

@subsubheading  Syntax::

@code{update-instance-for-different-class}  @i{previous current 
		   {&rest} initargs
		   {&key} {&allow-other-keys}} @result{}  @i{@i{implementation-dependent}}

@subsubheading  Method Signatures::

@code{update-instance-for-different-class}  @i{@r{(}@i{previous} @b{standard-object}@r{)}
	        @r{(}@i{current} @b{standard-object}@r{)}
	        {&rest} initargs}

@subsubheading  Arguments and Values::

@i{previous}---a copy of the original @i{instance}.

@i{current}---the original @i{instance} (altered).

@i{initargs}---an @i{initialization argument list}.

@subsubheading  Description::

The generic function @b{update-instance-for-different-class} is not
intended to be called by programmers.  Programmers may write
@i{methods} for it.  The @i{function} @b{update-instance-for-different-class}
is called only by the @i{function} @b{change-class}.

The system-supplied primary @i{method} on 
@b{update-instance-for-different-class} checks the validity of
@i{initargs} and signals an error if an @i{initarg}
is supplied that is not declared as valid.  This @i{method} then
initializes @i{slots} with values according to the @i{initargs},
and initializes the newly added @i{slots} with values according
to their @t{:initform} forms.  It does this by calling the generic
function @b{shared-initialize} with the following arguments: the 
instance (@i{current}),
a list of @i{names} of the newly added @i{slots}, and the @i{initargs}
it received.  Newly added @i{slots} are those @i{local slots} for which
no @i{slot} of the same name exists in the @i{previous} class.

@i{Methods} for @b{update-instance-for-different-class} can be defined to
specify actions to be taken when an @i{instance} is updated.  If only 
@i{after methods} for @b{update-instance-for-different-class} are
defined, they will be run after the system-supplied primary @i{method} for
initialization and therefore will not interfere with the default
behavior of @b{update-instance-for-different-class}.

@i{Methods} on @b{update-instance-for-different-class} can be defined to
initialize @i{slots} differently from @b{change-class}.  The default
behavior of @b{change-class} is described in 
@ref{Changing the Class of an Instance}.

The arguments to @b{update-instance-for-different-class} are
computed by @b{change-class}.  When @b{change-class} is invoked on
an @i{instance}, a copy of that @i{instance} is made; @b{change-class} then
destructively alters the original @i{instance}. The first argument to
@b{update-instance-for-different-class}, @i{previous}, is that
copy; it holds the old @i{slot} values temporarily.  This argument has
dynamic extent within @b{change-class}; if it is referenced in any
way once @b{update-instance-for-different-class} returns, the
results are undefined.  The second argument to
@b{update-instance-for-different-class}, @i{current}, is the altered
original @i{instance}.
The intended use of @i{previous} is to extract old @i{slot} values by using
@b{slot-value} or @b{with-slots} or by invoking 
a reader generic function, or to run other @i{methods} that were applicable to 
@i{instances} of
the original @i{class}.

@subsubheading  Examples::

See the example for the @i{function} @b{change-class}.

@subsubheading  Exceptional Situations::
The system-supplied primary @i{method} on
@b{update-instance-for-different-class} signals an error if an
initialization argument is supplied that is not declared as valid.

@subsubheading  See Also::

@ref{change-class}
,
@ref{Shared-Initialize}
,
@ref{Changing the Class of an Instance},
@ref{Rules for Initialization Arguments},
@ref{Declaring the Validity of Initialization Arguments}

@subsubheading  Notes::

@i{Initargs} are declared as valid by using the @t{:initarg}
option to @b{defclass}, or by defining @i{methods}
for @b{update-instance-for-different-class} or @b{shared-initialize}.
The keyword name of each keyword parameter specifier in the @i{lambda list} of
any @i{method} defined on @b{update-instance-for-different-class}
or @b{shared-initialize} is declared as a valid @i{initarg} name
for all @i{classes} for which that @i{method} is applicable.

The value returned by @b{update-instance-for-different-class} is
ignored by @b{change-class}.

@node update-instance-for-redefined-class, change-class, update-instance-for-different-class, Objects Dictionary
@subsection update-instance-for-redefined-class             [Standard Generic Function]

@subsubheading  Syntax::

@code{update-instance-for-redefined-class}  @i{instance
                                added-slots discarded-slots
                                property-list
                                {&rest} initargs {&key} {&allow-other-keys}}@*
   @result{}  @i{@{@i{result}@}{*}}

@subsubheading  Method Signatures::

@code{update-instance-for-redefined-class}  @i{@r{(}@i{instance} @b{standard-object}@r{)}
		added-slots discarded-slots
		property-list
		{&rest} initargs}

@subsubheading  Arguments and Values::

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

@i{added-slots}---a @i{list}.

@i{discarded-slots}---a @i{list}.

@i{property-list}---a @i{list}.

@i{initargs}---an @i{initialization argument list}.

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

@subsubheading  Description::

The @i{generic function} @b{update-instance-for-redefined-class} 
is not intended to be called by programmers. Programmers may write
@i{methods} for it.  The @i{generic function} 
@b{update-instance-for-redefined-class} is called by the mechanism
activated by @b{make-instances-obsolete}.

The system-supplied primary @i{method} on 
@b{update-instance-for-redefined-class} checks the validity of
@i{initargs} and signals an error if an @i{initarg}
is supplied that is not declared as valid.  This @i{method} then
initializes @i{slots} with values according to the @i{initargs},
and initializes the newly @i{added-slots} with values according
to their @t{:initform} forms.  It does this by calling the generic
function @b{shared-initialize} with the following arguments: 
the @i{instance},
a list of names of the newly @i{added-slots} to @i{instance},
and the @i{initargs}
it received.  Newly @i{added-slots} are those @i{local slots} for which
no @i{slot} of the same name exists in the old version of the @i{class}.

When @b{make-instances-obsolete} is invoked or when a @i{class} has been
redefined and an @i{instance} is being updated, a @i{property-list} is created
that captures the slot names and values of all the @i{discarded-slots} with
values in the original @i{instance}.  The structure of the 
@i{instance} is
transformed so that it conforms to the current class definition.  The
arguments to @b{update-instance-for-redefined-class} are this
transformed @i{instance}, a list of @i{added-slots} to the
@i{instance}, a list @i{discarded-slots} from the
@i{instance}, and the @i{property-list} 
containing the slot names and values for
@i{slots} that were discarded and had values.  Included in this list of
discarded @i{slots} are @i{slots} that were local in the old @i{class} and are
shared in the new @i{class}.

The value returned by @b{update-instance-for-redefined-class} is ignored.

@subsubheading  Examples::

@example

 (defclass position () ())

 (defclass x-y-position (position)
     ((x :initform 0 :accessor position-x)
      (y :initform 0 :accessor position-y)))

;;; It turns out polar coordinates are used more than Cartesian 
;;; coordinates, so the representation is altered and some new
;;; accessor methods are added.

 (defmethod update-instance-for-redefined-class :before
    ((pos x-y-position) added deleted plist &key)
   ;; Transform the x-y coordinates to polar coordinates
   ;; and store into the new slots.
   (let ((x (getf plist 'x))
         (y (getf plist 'y)))
     (setf (position-rho pos) (sqrt (+ (* x x) (* y y)))
           (position-theta pos) (atan y x))))

 (defclass x-y-position (position)
     ((rho :initform 0 :accessor position-rho)
      (theta :initform 0 :accessor position-theta)))

;;; All instances of the old x-y-position class will be updated
;;; automatically.

;;; The new representation is given the look and feel of the old one.

 (defmethod position-x ((pos x-y-position))  
    (with-slots (rho theta) pos (* rho (cos theta))))

 (defmethod (setf position-x) (new-x (pos x-y-position))
    (with-slots (rho theta) pos
      (let ((y (position-y pos)))
        (setq rho (sqrt (+ (* new-x new-x) (* y y)))
              theta (atan y new-x))
        new-x)))

 (defmethod position-y ((pos x-y-position))
    (with-slots (rho theta) pos (* rho (sin theta))))

 (defmethod (setf position-y) (new-y (pos x-y-position))
    (with-slots (rho theta) pos
      (let ((x (position-x pos)))
        (setq rho (sqrt (+ (* x x) (* new-y new-y)))
              theta (atan new-y x))
        new-y)))

@end example

@subsubheading  Exceptional Situations::
The system-supplied primary @i{method} on 
@b{update-instance-for-redefined-class} signals an error if an
@i{initarg} is supplied that is not declared as valid.

@subsubheading  See Also::

@ref{make-instances-obsolete}
,
@ref{Shared-Initialize}
,
@ref{Redefining Classes},
@ref{Rules for Initialization Arguments},
@ref{Declaring the Validity of Initialization Arguments}

@subsubheading  Notes::

@i{Initargs} are declared as valid by using the @t{:initarg}
option to @b{defclass}, or by defining @i{methods} for
@b{update-instance-for-redefined-class} or @b{shared-initialize}.
The keyword name of each keyword parameter specifier in the @i{lambda list} of
any @i{method} defined on 
@b{update-instance-for-redefined-class} or 
@b{shared-initialize} is declared as a valid @i{initarg} name
for all @i{classes} for which that @i{method} is applicable.

@node change-class, slot-boundp, update-instance-for-redefined-class, Objects Dictionary
@subsection change-class                                    [Standard Generic Function]

@subsubheading  Syntax::

@code{change-class}  @i{instance new-class {&key} {&allow-other-keys}} @result{}  @i{instance}

@subsubheading  Method Signatures::

@code{change-class}  @i{@r{(}@i{instance} @b{standard-object}@r{)}
			 @r{(}@i{new-class} @b{standard-class}@r{)}
			 {&rest} initargs}

@code{change-class}  @i{@r{(}@i{instance} @b{t}@r{)}
		         @r{(}@i{new-class} @b{symbol}@r{)}
			 {&rest} initargs}

@subsubheading  Arguments and Values::

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

@i{new-class}---a @i{class designator}.

@i{initargs}---an @i{initialization argument list}.

@subsubheading  Description::

The @i{generic function} @b{change-class} changes the 
@i{class} of an @i{instance} to @i{new-class}.  
It destructively modifies and returns the @i{instance}.

If in the old @i{class} there is any @i{slot} of the 
same name as a local @i{slot} in the @i{new-class}, 
the value of that @i{slot} is retained.  This means that if 
the @i{slot} has a value, the value returned by @b{slot-value}
after @b{change-class} is invoked is @b{eql} to the
value returned by @b{slot-value} before @b{change-class} is
invoked.  Similarly, if the @i{slot} was unbound, it remains
unbound.  The other @i{slots} are initialized as described in 
@ref{Changing the Class of an Instance}.

After completing all other actions, @b{change-class} invokes
@b{update-instance-for-different-class}.  The
generic function @b{update-instance-for-different-class} can be used
to assign values to slots in the transformed instance.

See @ref{Initializing Newly Added Local Slots}.

If the second of the above @i{methods} is selected, 
that @i{method} invokes @b{change-class} 
on @i{instance}, @t{(find-class @i{new-class})},
and the @i{initargs}.

@subsubheading  Examples::

@example

 (defclass position () ())

 (defclass x-y-position (position)
     ((x :initform 0 :initarg :x)
      (y :initform 0 :initarg :y)))

 (defclass rho-theta-position (position)
     ((rho :initform 0)
      (theta :initform 0)))

 (defmethod update-instance-for-different-class :before ((old x-y-position) 
                                                         (new rho-theta-position)
                                                         &key)
   ;; Copy the position information from old to new to make new
   ;; be a rho-theta-position at the same position as old.
   (let ((x (slot-value old 'x))
         (y (slot-value old 'y)))
     (setf (slot-value new 'rho) (sqrt (+ (* x x) (* y y)))
           (slot-value new 'theta) (atan y x))))

;;; At this point an instance of the class x-y-position can be
;;; changed to be an instance of the class rho-theta-position using
;;; change-class:

 (setq p1 (make-instance 'x-y-position :x 2 :y 0))

 (change-class p1 'rho-theta-position)

;;; The result is that the instance bound to p1 is now an instance of
;;; the class rho-theta-position.   The update-instance-for-different-class
;;; method performed the initialization of the rho and theta slots based
;;; on the value of the x and y slots, which were maintained by
;;; the old instance.

@end example

@subsubheading  See Also::

@ref{update-instance-for-different-class}
,
@ref{Changing the Class of an Instance}

@subsubheading  Notes::

The generic function @b{change-class} has several semantic
difficulties.  First, it performs a destructive operation that can be
invoked within a @i{method} on an @i{instance} that was used to select that
@i{method}. 
When multiple @i{methods} are involved because @i{methods} are being
combined, the @i{methods} currently executing or about to be executed may
no longer be applicable.  Second, some implementations might use
compiler optimizations of slot @i{access}, and when the @i{class} of an
@i{instance} is changed the assumptions the compiler made might be
violated.  This implies that a programmer must not use
@b{change-class} inside a @i{method} if any 
@i{methods} for that @i{generic function}
@i{access} any @i{slots}, or the results are undefined.

@node slot-boundp, slot-exists-p, change-class, Objects Dictionary
@subsection slot-boundp                                                      [Function]

@code{slot-boundp}  @i{instance slot-name} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values::

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

@i{slot-name}---a @i{symbol} naming a @i{slot} of @i{instance}.

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

@subsubheading  Description::

Returns @i{true} if the @i{slot} named @i{slot-name} in @i{instance} is bound;
otherwise, returns @i{false}.

@subsubheading  Exceptional Situations::

If no @i{slot} of the @i{name} @i{slot-name} exists in the 
@i{instance}, @b{slot-missing} is called as follows:

@example
 (slot-missing (class-of @i{instance})
               @i{instance}
               @i{slot-name}
               'slot-boundp)
@end example

(If @b{slot-missing} is invoked and returns a value,
a @i{boolean equivalent} to its @i{primary value} 
is returned by @b{slot-boundp}.)

The specific behavior depends on @i{instance}'s @i{metaclass}.
An error is never signaled if @i{instance} has @i{metaclass} @b{standard-class}.
An error is always signaled if @i{instance} has @i{metaclass} @b{built-in-class}.
The consequences are undefined if @i{instance} has any other @i{metaclass}--an error
might or might not be signaled in this situation.  Note in particular that the behavior
for @i{conditions} and @i{structures} is not specified.

@subsubheading  See Also::

@ref{slot-makunbound}
,
@ref{slot-missing}

@subsubheading  Notes::

The @i{function} @b{slot-boundp} allows for writing 
@i{after methods} on @b{initialize-instance} in order to initialize only
those @i{slots} that have not already been bound.

  Although no @i{implementation} is required to do so,
  implementors are strongly encouraged to implement the @i{function} @b{slot-boundp} using 
  the @i{function} @t{slot-boundp-using-class} described in the @i{Metaobject Protocol}.

@node slot-exists-p, slot-makunbound, slot-boundp, Objects Dictionary
@subsection slot-exists-p                                                    [Function]

@code{slot-exists-p}  @i{object slot-name} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values::

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

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

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

@subsubheading  Description::

Returns @i{true} if the @i{object} has
a @i{slot} named @i{slot-name}.

@subsubheading  Affected By::

@b{defclass},
@b{defstruct}

@subsubheading  See Also::

@ref{defclass}
,
@ref{slot-missing}

@subsubheading  Notes::

  Although no @i{implementation} is required to do so,
  implementors are strongly encouraged to implement the @i{function} @b{slot-exists-p} using 
  the @i{function} @t{slot-exists-p-using-class} described in the @i{Metaobject Protocol}.

@node slot-makunbound, slot-missing, slot-exists-p, Objects Dictionary
@subsection slot-makunbound                                                  [Function]

@code{slot-makunbound}  @i{instance slot-name} @result{}  @i{instance}

@subsubheading  Arguments and Values::

@i{instance} -- instance.

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

@subsubheading  Description::

The @i{function} @b{slot-makunbound} restores a @i{slot} 
of the name @i{slot-name} in an @i{instance} to
the unbound state.

@subsubheading  Exceptional Situations::

If no @i{slot} of the name @i{slot-name} exists in the 
@i{instance}, @b{slot-missing} is called as follows:

@example
(slot-missing (class-of @i{instance})
              @i{instance}
              @i{slot-name}
              'slot-makunbound)
@end example

(Any values returned by @b{slot-missing} in this case are
ignored by @b{slot-makunbound}.)

The specific behavior depends on @i{instance}'s @i{metaclass}.
An error is never signaled if @i{instance} has @i{metaclass} @b{standard-class}.
An error is always signaled if @i{instance} has @i{metaclass} @b{built-in-class}.
The consequences are undefined if @i{instance} has any other @i{metaclass}--an error
might or might not be signaled in this situation.  Note in particular that the behavior
for @i{conditions} and @i{structures} is not specified.

@subsubheading  See Also::

@ref{slot-boundp}
,
@ref{slot-missing}

@subsubheading  Notes::

  Although no @i{implementation} is required to do so,
  implementors are strongly encouraged to implement the @i{function} @b{slot-makunbound} using 
  the @i{function} @t{slot-makunbound-using-class} described in the @i{Metaobject Protocol}.

@node slot-missing, slot-unbound, slot-makunbound, Objects Dictionary
@subsection slot-missing                                    [Standard Generic Function]

@subsubheading  Syntax::

@code{slot-missing}  @i{class object slot-name operation {&optional} new-value} @result{}  @i{@{@i{result}@}{*}}

@subsubheading  Method Signatures::

@code{slot-missing}  @i{@r{(}@i{class} @b{t}@r{)}
				   object slot-name
			     operation {&optional} new-value}

@subsubheading  Arguments and Values::

@i{class}---the @i{class} of @i{object}.

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

@i{slot-name}---a @i{symbol} (the @i{name} of a would-be @i{slot}).

@i{operation}---one of the @i{symbols}
		    @b{setf},
		    @b{slot-boundp},
		    @b{slot-makunbound},
		 or @b{slot-value}.

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

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

@subsubheading  Description::

The generic function @b{slot-missing} is invoked when an attempt is
made to @i{access} a @i{slot} in an @i{object} whose 
@i{metaclass} is @b{standard-class}
and the @i{slot} of the name @i{slot-name}
is not a @i{name} of a
@i{slot} in that @i{class}. 
The default @i{method} signals an error.

The generic function @b{slot-missing} is not intended to be called by
programmers.  Programmers may write @i{methods} for it.

The generic function @b{slot-missing} may be called during
evaluation of @b{slot-value}, @t{(setf slot-value)}, 
@b{slot-boundp}, and @b{slot-makunbound}.  For each
of these operations the corresponding @i{symbol} 
for the @i{operation}
argument is @b{slot-value}, @b{setf}, @b{slot-boundp},
and @b{slot-makunbound} respectively.

The optional @i{new-value} argument to @b{slot-missing} is used
when the operation is attempting to set the value of the @i{slot}.

If @b{slot-missing} returns, its values will be treated as follows:

@table @asis

@item @t{*}  
If the @i{operation} is @b{setf} or @b{slot-makunbound},
any @i{values} will be ignored by the caller.

@item @t{*}  
If the @i{operation} is @b{slot-value},
only the @i{primary value} will be used by the caller,
and all other values will be ignored.

@item @t{*}  
If the @i{operation} is @b{slot-boundp},
any @i{boolean equivalent} of the @i{primary value}
of the @i{method} might be is used,
and all other values will be ignored.
@end table

@subsubheading  Exceptional Situations::

The default @i{method} on @b{slot-missing} 
signals an error of @i{type} @b{error}.

@subsubheading  See Also::

@ref{defclass}
,
@ref{slot-exists-p}
,
@ref{slot-value}

@subsubheading  Notes::

The set of arguments (including the @i{class} of the instance) facilitates
defining methods on the metaclass for @b{slot-missing}.

@node slot-unbound, slot-value, slot-missing, Objects Dictionary
@subsection slot-unbound                                    [Standard Generic Function]

@subsubheading  Syntax::

@code{slot-unbound}  @i{class instance slot-name} @result{}  @i{@{@i{result}@}{*}}

@subsubheading  Method Signatures::

@code{slot-unbound}  @i{@r{(}@i{class} @b{t}@r{)}
		       instance slot-name}

@subsubheading  Arguments and Values::

@i{class}---the @i{class} of the @i{instance}.

@i{instance}---the @i{instance} in which an attempt
		   was made to @i{read} the @i{unbound} @i{slot}.

@i{slot-name}---the @i{name} of the @i{unbound} @i{slot}.

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

@subsubheading  Description::

The generic function @b{slot-unbound} is called when an
unbound @i{slot} is read in
an @i{instance} whose metaclass is @b{standard-class}.
The default @i{method} signals an error 

of @i{type} @b{unbound-slot}.
The name slot of the 
@b{unbound-slot} @i{condition} is initialized
  to the name of the offending variable, and the instance slot
  of the @b{unbound-slot} @i{condition} is initialized to the offending instance.

The generic function @b{slot-unbound} is not intended to be called
by programmers.  Programmers may write @i{methods} for it.
The @i{function} @b{slot-unbound} is called only 
indirectly by @b{slot-value}.

If @b{slot-unbound} returns, 
only the @i{primary value} will be used by the caller,
and all other values will be ignored.

@subsubheading  Exceptional Situations::

The default @i{method} on @b{slot-unbound}
signals an error of @i{type} @b{unbound-slot}.

@subsubheading  See Also::

@ref{slot-makunbound}

@subsubheading  Notes::

An unbound @i{slot} may occur if no @t{:initform} form was
specified for the @i{slot} and the @i{slot} value has not been set,
or if @b{slot-makunbound} has been called on the @i{slot}.

@node slot-value, method-qualifiers, slot-unbound, Objects Dictionary
@subsection slot-value                                                       [Function]

@code{slot-value}  @i{object slot-name} @result{}  @i{value}

@subsubheading  Arguments and Values::

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

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

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

@subsubheading  Description::

The @i{function} @b{slot-value} returns the @i{value} of the @i{slot}
named @i{slot-name} in the @i{object}.
If there is no @i{slot} named @i{slot-name}, @b{slot-missing} is called.
If the @i{slot} is unbound, @b{slot-unbound} is called.

The macro @b{setf} can be used with @b{slot-value} 
to change the value of a @i{slot}. 

@subsubheading  Examples::

@example
 (defclass foo () 
   ((a :accessor foo-a :initarg :a :initform 1)
    (b :accessor foo-b :initarg :b)
    (c :accessor foo-c :initform 3)))
@result{}  #<STANDARD-CLASS FOO 244020371>
 (setq foo1 (make-instance 'foo :a 'one :b 'two))
@result{}  #<FOO 36325624>
 (slot-value foo1 'a) @result{}  ONE
 (slot-value foo1 'b) @result{}  TWO
 (slot-value foo1 'c) @result{}  3
 (setf (slot-value foo1 'a) 'uno) @result{}  UNO
 (slot-value foo1 'a) @result{}  UNO
 (defmethod foo-method ((x foo))
   (slot-value x 'a))
@result{}  #<STANDARD-METHOD FOO-METHOD (FOO) 42720573>
 (foo-method foo1) @result{}  UNO
@end example

@subsubheading  Exceptional Situations::

If an attempt is made to read a @i{slot} and no @i{slot} of
the name @i{slot-name} exists in the @i{object}, 
@b{slot-missing} is called as follows:

@example
 (slot-missing (class-of @i{instance})
               @i{instance}
               @i{slot-name}
               'slot-value)
@end example

(If @b{slot-missing} is invoked, its @i{primary value} 
 is returned by @b{slot-value}.)

If an attempt is made to write a @i{slot} and no @i{slot} of
the name @i{slot-name} exists in the @i{object},
@b{slot-missing} is called as follows:

@example
 (slot-missing (class-of @i{instance})
               @i{instance}
               @i{slot-name}
               'setf
               @i{new-value})
@end example

(If @b{slot-missing} returns in this case, any @i{values} are ignored.)

The specific behavior depends on @i{object}'s @i{metaclass}.
An error is never signaled if @i{object} has @i{metaclass} @b{standard-class}.
An error is always signaled if @i{object} has @i{metaclass} @b{built-in-class}.
The consequences are 
unspecified
if @i{object} has any other @i{metaclass}--an error
might or might not be signaled in this situation.  Note in particular that the behavior
for @i{conditions} and @i{structures} is not specified.

@subsubheading  See Also::

@ref{slot-missing}
,
@ref{slot-unbound}
,
@ref{with-slots}

@subsubheading  Notes::

  Although no @i{implementation} is required to do so,
  implementors are strongly encouraged to implement the @i{function} @b{slot-value} using 
  the @i{function} @t{slot-value-using-class} described in the @i{Metaobject Protocol}.

Implementations may optimize @b{slot-value} by compiling it inline.

@node method-qualifiers, no-applicable-method, slot-value, Objects Dictionary
@subsection method-qualifiers                               [Standard Generic Function]

@subsubheading  Syntax::

@code{method-qualifiers}  @i{method} @result{}  @i{qualifiers}

@subsubheading  Method Signatures::

@code{method-qualifiers}  @i{@r{(}@i{method} @b{standard-method}@r{)}}

@subsubheading  Arguments and Values::

@i{method}---a @i{method}.

@i{qualifiers}---a @i{proper list}.

@subsubheading  Description::

Returns a @i{list} of the @i{qualifiers} of the @i{method}.

@subsubheading  Examples::

@example
 (defmethod some-gf :before ((a integer)) a)
@result{}  #<STANDARD-METHOD SOME-GF (:BEFORE) (INTEGER) 42736540>
 (method-qualifiers *) @result{}  (:BEFORE)
@end example

@subsubheading  See Also:: 

@ref{define-method-combination}

@node no-applicable-method, no-next-method, method-qualifiers, Objects Dictionary
@subsection no-applicable-method                            [Standard Generic Function]

@subsubheading  Syntax::

@code{no-applicable-method}  @i{generic-function {&rest} function-arguments} @result{}  @i{@{@i{result}@}{*}}

@subsubheading  Method Signatures::

@code{no-applicable-method}  @i{@r{(}@i{generic-function} @b{t}@r{)}
				     {&rest} function-arguments}

@subsubheading  Arguments and Values::

@i{generic-function}---a @i{generic function} 
			   on which no @i{applicable method} was found.  

@i{function-arguments}---@i{arguments} to the @i{generic-function}.

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

@subsubheading  Description::

The generic function @b{no-applicable-method} is called when a
@i{generic function} 
is invoked
and no @i{method} on that @i{generic function} is applicable.
The @i{default method} signals an error.

The generic function @b{no-applicable-method} is not intended
to be called by programmers.  Programmers may write @i{methods} for it.

@subsubheading  Exceptional Situations::

The default @i{method} signals an error of @i{type} @b{error}.

@subsubheading  See Also::

@node no-next-method, remove-method, no-applicable-method, Objects Dictionary
@subsection no-next-method                                  [Standard Generic Function]

@subsubheading  Syntax::

@code{no-next-method}  @i{generic-function method {&rest} args} @result{}  @i{@{@i{result}@}{*}}

@subsubheading  Method Signatures::

@code{no-next-method}  @i{@r{(}@i{generic-function} @b{standard-generic-function}@r{)}
			       @r{(}@i{method} @b{standard-method}@r{)}
			       {&rest} args}

@subsubheading  Arguments and Values::

@i{generic-function} -- @i{generic function} to which @i{method} belongs.

@i{method} -- @i{method} that contained the call to
		  @b{call-next-method} for which there is no next @i{method}.

@i{args} -- arguments to @b{call-next-method}.

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

@subsubheading  Description::

The @i{generic function} @b{no-next-method} is called by @b{call-next-method} 
when there is no @i{next method}.

The @i{generic function} @b{no-next-method} is not intended to be called by programmers.
Programmers may write @i{methods} for it.

@subsubheading  Exceptional Situations::

The system-supplied @i{method} on @b{no-next-method} 
signals an error of @i{type} @b{error}. 
[Editorial Note by KMP: perhaps control-error??]

@subsubheading  See Also::

@ref{call-next-method}

@node remove-method, make-instance, no-next-method, Objects Dictionary
@subsection remove-method                                   [Standard Generic Function]

@subsubheading  Syntax::

@code{remove-method}  @i{generic-function method} @result{}  @i{generic-function}

@subsubheading  Method Signatures::

@code{remove-method}  @i{@r{(}@i{generic-function} @b{standard-generic-function}@r{)}
			      method}

@subsubheading  Arguments and Values::

@i{generic-function}---a @i{generic function}.

@i{method}---a @i{method}.

@subsubheading  Description::

The @i{generic function} @b{remove-method} removes a @i{method} from @i{generic-function}
by modifying the @i{generic-function} (if necessary).

@b{remove-method} must not signal an error if the @i{method} 
is not one of the @i{methods} on the @i{generic-function}.

@subsubheading  See Also::

@ref{find-method}

@node make-instance, make-instances-obsolete, remove-method, Objects Dictionary
@subsection make-instance                                   [Standard Generic Function]

@subsubheading  Syntax::

@code{make-instance}  @i{class {&rest} initargs {&key} {&allow-other-keys}} @result{}  @i{instance}

@subsubheading  Method Signatures::

@code{make-instance}  @i{@r{(}@i{class} @b{standard-class}@r{)} {&rest} initargs}

@code{make-instance}  @i{@r{(}@i{class} @b{symbol}@r{)} {&rest} initargs}

@subsubheading  Arguments and Values::

@i{class}---a @i{class},
	     or a @i{symbol} that names a @i{class}.

@i{initargs}---an @i{initialization argument list}.

@i{instance}---a @i{fresh} @i{instance} of @i{class} @i{class}.

@subsubheading  Description::

The @i{generic function} @b{make-instance} 
creates and returns a new @i{instance} of the given @i{class}.

If the second of the above @i{methods} is selected, 
that @i{method} invokes @b{make-instance} on the arguments
@t{(find-class @i{class})} and @i{initargs}.

The initialization arguments are checked within @b{make-instance}.

The @i{generic function} @b{make-instance} 
may be used as described in @ref{Object Creation and Initialization}.

@subsubheading  Exceptional Situations::

If any of the initialization arguments has not
been declared as valid, an error of @i{type} @b{error} is signaled.

@subsubheading  See Also::

@ref{defclass}
,
@ref{class-of}
,
@ref{allocate-instance}
,
@ref{Initialize-Instance}
,
@ref{Object Creation and Initialization}

@node make-instances-obsolete, make-load-form, make-instance, Objects Dictionary
@subsection make-instances-obsolete                         [Standard Generic Function]

@subsubheading  Syntax::

@code{make-instances-obsolete}  @i{class} @result{}  @i{class}

@subsubheading  Method Signatures::

@code{make-instances-obsolete}  @i{@r{(}@i{class} @b{standard-class}@r{)}}

@code{make-instances-obsolete}  @i{@r{(}@i{class} @b{symbol}@r{)}}

@subsubheading  Arguments and Values::

@i{class}---a @i{class designator}.

@subsubheading  Description::

The @i{function} @b{make-instances-obsolete} has the effect of
initiating the process of updating the instances of the
@i{class}. During updating, the generic function
@b{update-instance-for-redefined-class} will be invoked.

The generic function @b{make-instances-obsolete} is invoked
automatically by the system when @b{defclass} has been used to
redefine an existing standard class and the set of local 
@i{slots} @i{accessible} in an
instance is changed or the order of @i{slots} in storage is changed.  It
can also be explicitly invoked by the user.

If the second of the above @i{methods} is selected, that 
@i{method} invokes
@b{make-instances-obsolete} on @t{(find-class @i{class})}.

@subsubheading  Examples::

@subsubheading  See Also::

@ref{update-instance-for-redefined-class}
,
@ref{Redefining Classes}

@node make-load-form, make-load-form-saving-slots, make-instances-obsolete, Objects Dictionary
@subsection make-load-form                                  [Standard Generic Function]

@subsubheading  Syntax::

@code{make-load-form}  @i{object {&optional} environment} @result{}  @i{creation-form@r{[}, initialization-form@r{]}}

@subsubheading  Method Signatures::

@code{make-load-form}  @i{@r{(}@i{object} @b{standard-object}@r{)}  {&optional} environment}

@code{make-load-form}  @i{@r{(}@i{object} @b{structure-object}@r{)} {&optional} environment}

@code{make-load-form}  @i{@r{(}@i{object} @b{condition}@r{)}        {&optional} environment}

@code{make-load-form}  @i{@r{(}@i{object} @b{class}@r{)}            {&optional} environment}

@subsubheading  Arguments and Values::

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

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

@i{creation-form}---a @i{form}.

@i{initialization-form}---a @i{form}.

@subsubheading  Description::

The @i{generic function} @b{make-load-form} creates and returns 
one or two @i{forms},
     a @i{creation-form}
 and an @i{initialization-form},
that enable @b{load} to construct an @i{object}
equivalent to @i{object}.
@i{Environment} is an @i{environment object} 
corresponding to the @i{lexical environment} 
in which the @i{forms} will be processed.

The @i{file compiler} calls @b{make-load-form} to process certain
@i{classes} of @i{literal objects}; see @ref{Additional Constraints on Externalizable Objects}.

@i{Conforming programs} may call @b{make-load-form} directly,
providing @i{object} is a @i{generalized instance} of
@b{standard-object}, @b{structure-object}, 
or @b{condition}.

The creation form is a @i{form} that, when evaluated at
@b{load} time, should return an @i{object} that 
is equivalent to @i{object}.  The exact meaning of
equivalent depends on the @i{type} of @i{object} 
and is up to the programmer who defines a @i{method} for
@b{make-load-form};
see @ref{Literal Objects in Compiled Files}.

The initialization form is a @i{form} that, when evaluated at @b{load} time, 
should perform further initialization of the @i{object}.  
The value returned by the initialization form is ignored.
If @b{make-load-form}
returns only one value, 
the initialization form is @b{nil}, which has no effect.
If @i{object} appears as a constant in the initialization form,
at @b{load} time it will be replaced by the equivalent @i{object} 
constructed by the creation form;
this is how the further initialization gains access to the @i{object}.

Both the @i{creation-form} and the @i{initialization-form} may contain references
to any @i{externalizable object}.
However, there must not be any circular dependencies in creation forms.
An example of a circular dependency is when the creation form for the
object @t{X} contains a reference to the object @t{Y},
and the creation form for the object @t{Y} contains a reference to the object @t{X}.  
Initialization forms are not subject to any restriction against circular dependencies, 
which is the reason that initialization forms exist; 
see the example of circular data structures below.

The creation form for an @i{object} is always @i{evaluated} before the
initialization form for that @i{object}.  When either the creation form or
the initialization form references other @i{objects} that have not been
referenced earlier in the @i{file} being @i{compiled}, the @i{compiler} ensures
that all of the referenced @i{objects} have been created before @i{evaluating}
the referencing @i{form}.  When the referenced @i{object} is of a @i{type} which
the @i{file compiler} processes using @b{make-load-form},
this involves @i{evaluating}
the creation form returned for it.  (This is the reason for the
prohibition against circular references among creation forms).

Each initialization form is @i{evaluated} as soon as possible after its
associated creation form, as determined by data flow.  If the
initialization form for an @i{object} does not reference any other @i{objects}
not referenced earlier in the @i{file} and processed by 
the @i{file compiler}
using
@b{make-load-form}, the initialization form is evaluated immediately after
the creation form.  If a creation or initialization form F does contain
references to such @i{objects}, the creation forms for those other objects
are evaluated before F, and the initialization forms for those other
@i{objects} are also evaluated before F whenever they do not depend on the
@i{object} created or initialized by F.  Where these rules do not uniquely
determine an order of @i{evaluation} between two creation/initialization
forms, the order of @i{evaluation} is unspecified.

  While these creation and initialization forms are being evaluated, the
  @i{objects} are possibly in an uninitialized state, 
analogous to the state
  of an @i{object} 
between the time it has been created by @b{allocate-instance}
  and it has been processed fully by 
@b{initialize-instance}.  Programmers
  writing @i{methods} for 
@b{make-load-form} must take care in manipulating
  @i{objects} not to depend on 
@i{slots} that have not yet been initialized.

  It is @i{implementation-dependent}
whether @b{load} calls @b{eval} on the 
@i{forms} or does some
  other operation that has an equivalent effect.  For example, the
  @i{forms} might be translated into different but equivalent 
@i{forms} and
  then evaluated, they might be compiled and the resulting functions
  called by @b{load}, 
or they might be interpreted by a special-purpose
function different from @b{eval}.  
All that is required is that the
  effect be equivalent to evaluating the @i{forms}.

The @i{method} @i{specialized} on @b{class} returns a creation
@i{form} using the @i{name} of the @i{class} if the @i{class} has
a @i{proper name} in @i{environment}, signaling an error of @i{type} @b{error}
if it does not have a @i{proper name}.  @i{Evaluation} of the creation
@i{form} uses the @i{name} to find the @i{class} with that
@i{name}, as if by @i{calling} @b{find-class}.  If a @i{class}
with that @i{name} has not been defined, then a @i{class} may be
computed in an @i{implementation-defined} manner.  If a @i{class}
cannot be returned as the result of @i{evaluating} the creation
@i{form}, then an error of @i{type} @b{error} is signaled.

Both @i{conforming implementations} and @i{conforming programs} may
further @i{specialize} @b{make-load-form}.

@subsubheading  Examples::

@example
 (defclass obj ()
    ((x :initarg :x :reader obj-x)
     (y :initarg :y :reader obj-y)
     (dist :accessor obj-dist)))
@result{}  #<STANDARD-CLASS OBJ 250020030>
 (defmethod shared-initialize :after ((self obj) slot-names &rest keys)
   (declare (ignore slot-names keys))
   (unless (slot-boundp self 'dist)
     (setf (obj-dist self)
           (sqrt (+ (expt (obj-x self) 2) (expt (obj-y self) 2))))))
@result{}  #<STANDARD-METHOD SHARED-INITIALIZE (:AFTER) (OBJ T) 26266714>
 (defmethod make-load-form ((self obj) &optional environment)
   (declare (ignore environment))
   ;; Note that this definition only works because X and Y do not
   ;; contain information which refers back to the object itself.
   ;; For a more general solution to this problem, see revised example below.
   `(make-instance ',(class-of self)
                   :x ',(obj-x self) :y ',(obj-y self)))
@result{}  #<STANDARD-METHOD MAKE-LOAD-FORM (OBJ) 26267532>
 (setq obj1 (make-instance 'obj :x 3.0 :y 4.0)) @result{}  #<OBJ 26274136>
 (obj-dist obj1) @result{}  5.0
 (make-load-form obj1) @result{}  (MAKE-INSTANCE 'OBJ :X '3.0 :Y '4.0)
@end example

In the above example, an equivalent @i{instance} of @t{obj} is
reconstructed by using the values of two of its @i{slots}.  
The value of the third @i{slot} is derived from those two values.

Another way to write the @b{make-load-form} @i{method}
in that example is to use @b{make-load-form-saving-slots}.
The code it generates might yield a slightly different result 
from the @b{make-load-form} @i{method} shown above,
but the operational effect will be the same.  For example:

@example
 ;; Redefine method defined above.
 (defmethod make-load-form ((self obj) &optional environment)
    (make-load-form-saving-slots self
                                 :slot-names '(x y)
                                 :environment environment))
@result{}  #<STANDARD-METHOD MAKE-LOAD-FORM (OBJ) 42755655>
 ;; Try MAKE-LOAD-FORM on object created above.
 (make-load-form obj1)
@result{}  (ALLOCATE-INSTANCE '#<STANDARD-CLASS OBJ 250020030>),
    (PROGN
      (SETF (SLOT-VALUE '#<OBJ 26274136> 'X) '3.0)
      (SETF (SLOT-VALUE '#<OBJ 26274136> 'Y) '4.0)
      (INITIALIZE-INSTANCE '#<OBJ 26274136>))
@end example

In the following example, @i{instances} of @t{my-frob} are ``interned'' 
in some way.  An equivalent @i{instance} is reconstructed by using the 
value of the name slot as a key for searching existing @i{objects}.
In this case the programmer has chosen to create a new @i{object} 
if no existing @i{object} is found; alternatively an error could 
have been signaled in that case.

@example
 (defclass my-frob ()
    ((name :initarg :name :reader my-name)))
 (defmethod make-load-form ((self my-frob) &optional environment)
   (declare (ignore environment))
   `(find-my-frob ',(my-name self) :if-does-not-exist :create))
@end example

In the following example, the data structure to be dumped is circular, 
because each parent has a list of its children and each child has a reference
back to its parent.  If @b{make-load-form} is called on one   
@i{object} in such a structure,  the creation form creates an equivalent 
@i{object} and fills in the children slot, which forces creation of equivalent
@i{objects} for all of its children, grandchildren, etc.  At this point
none of the parent @i{slots} have been filled in.  
The initialization form fills in the parent @i{slot}, which forces creation 
of an equivalent @i{object} for the parent if it was not already created.
Thus the entire tree is recreated at @b{load} time.  
At compile time, @b{make-load-form} is called once for each @i{object} 
in the tree.  
All of the creation forms are evaluated,
in @i{implementation-dependent} order,
and then all of the initialization forms are evaluated, 
also in @i{implementation-dependent} order.

@example
 (defclass tree-with-parent () ((parent :accessor tree-parent)
                                (children :initarg :children)))
 (defmethod make-load-form ((x tree-with-parent) &optional environment)
   (declare (ignore environment))
   (values
     ;; creation form
     `(make-instance ',(class-of x) :children ',(slot-value x 'children))
     ;; initialization form
     `(setf (tree-parent ',x) ',(slot-value x 'parent))))
@end example

In the following example, the data structure to be dumped has no special
properties and an equivalent structure can be reconstructed
simply by reconstructing the @i{slots}' contents.

@example
 (defstruct my-struct a b c)
 (defmethod make-load-form ((s my-struct) &optional environment)
    (make-load-form-saving-slots s :environment environment))
@end example

@subsubheading  Exceptional Situations::

The @i{methods} @i{specialized} on 
     @b{standard-object},
     @b{structure-object},
 and @b{condition}
all signal an error of @i{type} @b{error}.

It is @i{implementation-dependent} whether @i{calling}
@b{make-load-form} on a @i{generalized instance} of a
@i{system class} signals an error or returns creation and
initialization @i{forms}.

@subsubheading  See Also::

@ref{compile-file}
, 
@ref{make-load-form-saving-slots}
,
@ref{Additional Constraints on Externalizable Objects}
@ref{Evaluation},
@ref{Compilation}

@subsubheading  Notes::

The @i{file compiler}
calls @b{make-load-form} in specific circumstances
detailed in @ref{Additional Constraints on Externalizable Objects}.

Some @i{implementations} may provide facilities for defining new
@i{subclasses} of @i{classes} which are specified as
@i{system classes}.  (Some likely candidates include
@b{generic-function}, @b{method}, and @b{stream}).  Such
@i{implementations} should document how the @i{file compiler} processes
@i{instances} of such @i{classes} when encountered as
@i{literal objects}, and should document any relevant @i{methods}
for @b{make-load-form}.

@node make-load-form-saving-slots, with-accessors, make-load-form, Objects Dictionary
@subsection make-load-form-saving-slots                                      [Function]

@code{make-load-form-saving-slots}  @i{object {&key} slot-names environment}@*
   @result{}  @i{creation-form, initialization-form}

@subsubheading  Arguments and Values::

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

@i{slot-names}---a @i{list}.

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

@i{creation-form}---a @i{form}.

@i{initialization-form}---a @i{form}.

@subsubheading  Description::

Returns @i{forms} that, when @i{evaluated}, will construct an
@i{object} equivalent to @i{object}, without @i{executing}
@i{initialization forms}.  The @i{slots} in the new @i{object}
that correspond to initialized @i{slots} in @i{object} are
initialized using the values from @i{object}.  Uninitialized @i{slots}
in @i{object} are not initialized in the new @i{object}.
@b{make-load-form-saving-slots} works for any @i{instance} of
@b{standard-object} or @b{structure-object}.

@i{Slot-names} is a @i{list} of the names of the 
@i{slots} to preserve. If @i{slot-names} is not
supplied, its value is all of the @i{local slots}.  

@b{make-load-form-saving-slots} returns two values,
thus it can deal with circular structures.
Whether the result is useful in an application depends on
whether the @i{object}'s @i{type} and slot contents
fully capture the application's idea of the @i{object}'s state.

@i{Environment} is the environment in which the forms will be processed.

@subsubheading  See Also::

@ref{make-load-form}
,
@ref{make-instance}
,
@ref{setf; psetf}
,
@ref{slot-value}
,
@ref{slot-makunbound}

@subsubheading  Notes::

@b{make-load-form-saving-slots} can be useful in user-written
@b{make-load-form} methods.

When the @i{object} is an @i{instance} of @b{standard-object},
@b{make-load-form-saving-slots} could return a creation form that
@i{calls} @b{allocate-instance} and an initialization form that
contains @i{calls} to @b{setf} of @b{slot-value} and
@b{slot-makunbound}, though other @i{functions} of similar effect
might actually be used.

@node with-accessors, with-slots, make-load-form-saving-slots, Objects Dictionary
@subsection with-accessors                                                      [Macro]

@code{with-accessors}  @i{{@r{(}@{@i{slot-entry}@}{*}@r{)}} 
		   instance-form
 		   @{@i{declaration}@}{*} @{@i{form}@}{*}}@*
   @result{}  @i{@{@i{result}@}{*}}

@w{@i{slot-entry} ::=@r{(}variable-name accessor-name@r{)}}

@subsubheading  Arguments and Values::

@i{variable-name}---a @i{variable name}; not evaluated.

@i{accessor-name}---a @i{function name}; not evaluated.

@i{instance-form}---a @i{form}; 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::

Creates a lexical environment in which
the slots specified by
@i{slot-entry} are lexically available through their accessors as if
they were variables.  The macro @b{with-accessors} invokes the
appropriate accessors to @i{access} the @i{slots} specified
by @i{slot-entry}.  Both @b{setf}
and @b{setq} can be used to set the value of the @i{slot}.

@subsubheading  Examples::

@example
 (defclass thing ()
           ((x :initarg :x :accessor thing-x)
            (y :initarg :y :accessor thing-y)))
@result{}  #<STANDARD-CLASS THING 250020173>
 (defmethod (setf thing-x) :before (new-x (thing thing))
   (format t "~&Changing X from ~D to ~D in ~S.~
           (thing-x thing) new-x thing))
 (setq thing1 (make-instance 'thing :x 1 :y 2)) @result{}  #<THING 43135676>
 (setq thing2 (make-instance 'thing :x 7 :y 8)) @result{}  #<THING 43147374>
 (with-accessors ((x1 thing-x) (y1 thing-y))
                 thing1
   (with-accessors ((x2 thing-x) (y2 thing-y))
                   thing2
     (list (list x1 (thing-x thing1) y1 (thing-y thing1)
                 x2 (thing-x thing2) y2 (thing-y thing2))
           (setq x1 (+ y1 x2))
           (list x1 (thing-x thing1) y1 (thing-y thing1)
                 x2 (thing-x thing2) y2 (thing-y thing2))
           (setf (thing-x thing2) (list x1))
           (list x1 (thing-x thing1) y1 (thing-y thing1)
                 x2 (thing-x thing2) y2 (thing-y thing2)))))
@t{ |> } Changing X from 1 to 9 in #<THING 43135676>.
@t{ |> } Changing X from 7 to (9) in #<THING 43147374>.
@result{}  ((1 1 2 2 7 7 8 8)
     9
     (9 9 2 2 7 7 8 8) 
     (9)
     (9 9 2 2 (9) (9) 8 8))
@end example

@subsubheading  Affected By::

@b{defclass}

@subsubheading  Exceptional Situations::

The consequences are undefined if any @i{accessor-name} is not the name
of an accessor for the @i{instance}.

@subsubheading  See Also::

@ref{with-slots}
,
@ref{symbol-macrolet}

@subsubheading  Notes::

A @b{with-accessors} expression of the form:

@center 
@example

@w{@t{(with-accessors} ({slot-entry}_1 ...{slot-entry}_n) @i{instance-form} {form}_1 ...{form}_k)}@*
@end example

@noindent
expands into the equivalent of

@center 
@example

@w{@t{(}@t{let ((}in @i{instance-form}@t{))}}@*
@w{ @t{(symbol-macrolet (}{Q}_1... {Q}_n@t{)} {form}_1 ...{form}_k@t{))}}@*
@end example

@noindent
where {Q}_i is 

@center {
@example
@t{(}{variable-name}_i () 
@t{({accessor-name}_i in))}
@end example
}

@node with-slots, defclass, with-accessors, Objects Dictionary
@subsection with-slots                                                          [Macro]

@code{with-slots}  @i{@r{(}@{@i{slot-entry}@}{*}@r{)}
		          instance-form 
                          @{@i{declaration}@}{*} @{@i{form}@}{*}}@*
   @result{}  @i{@{@i{result}@}{*}}

@w{@i{slot-entry} ::=slot-name | @r{(}variable-name slot-name@r{)}}

@subsubheading  Arguments and Values::

@i{slot-name}---a @i{slot} @i{name}; not evaluated.

@i{variable-name}---a @i{variable name}; not evaluated.

@i{instance-form}---a @i{form}; evaluted to produce @i{instance}.

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

@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::

The macro @b{with-slots} @i{establishes} a
@i{lexical environment}
for referring to the @i{slots} in the @i{instance} 
named by the given @i{slot-names} 
as though they were @i{variables}.  Within such a context
the value of the @i{slot} can be specified by using its slot name, as if
it were a lexically bound variable.  Both @b{setf} and @b{setq}
can be used to set the value of the @i{slot}.

The macro @b{with-slots} translates an appearance of the slot 
name as a @i{variable} into a call to @b{slot-value}.

@subsubheading  Examples::

@example
 (defclass thing ()
           ((x :initarg :x :accessor thing-x)
            (y :initarg :y :accessor thing-y)))
@result{}  #<STANDARD-CLASS THING 250020173>
 (defmethod (setf thing-x) :before (new-x (thing thing))
   (format t "~&Changing X from ~D to ~D in ~S.~
           (thing-x thing) new-x thing))
 (setq thing (make-instance 'thing :x 0 :y 1)) @result{}  #<THING 62310540>
 (with-slots (x y) thing (incf x) (incf y)) @result{}  2
 (values (thing-x thing) (thing-y thing)) @result{}  1, 2
 (setq thing1 (make-instance 'thing :x 1 :y 2)) @result{}  #<THING 43135676>
 (setq thing2 (make-instance 'thing :x 7 :y 8)) @result{}  #<THING 43147374>
 (with-slots ((x1 x) (y1 y))
             thing1
   (with-slots ((x2 x) (y2 y))
               thing2
     (list (list x1 (thing-x thing1) y1 (thing-y thing1)
                 x2 (thing-x thing2) y2 (thing-y thing2))
           (setq x1 (+ y1 x2))
           (list x1 (thing-x thing1) y1 (thing-y thing1)
                 x2 (thing-x thing2) y2 (thing-y thing2))
           (setf (thing-x thing2) (list x1))
           (list x1 (thing-x thing1) y1 (thing-y thing1)
                 x2 (thing-x thing2) y2 (thing-y thing2)))))
@t{ |> } Changing X from 7 to (9) in #<THING 43147374>.
@result{}  ((1 1 2 2 7 7 8 8)
     9
     (9 9 2 2 7 7 8 8) 
     (9)
     (9 9 2 2 (9) (9) 8 8))
@end example

@subsubheading  Affected By::

@b{defclass}

@subsubheading  Exceptional Situations::

The consequences are undefined if any @i{slot-name} is not the name
of a @i{slot} in the @i{instance}.

@subsubheading  See Also::

@ref{with-accessors}
,
@ref{slot-value}
,
@ref{symbol-macrolet}

@subsubheading  Notes::

A @b{with-slots} expression of the form:

@center 
@example

@w{@t{(with-slots} ({slot-entry}_1 ...{slot-entry}_n) @i{instance-form} {form}_1 ...{form}_k)}@*
@end example

@noindent
expands into the equivalent of

@center 
@example

@w{@t{(}@t{let ((}in @i{instance-form}@t{))}}@*
@w{ @t{(symbol-macrolet (}{Q}_1... {Q}_n@t{)} {form}_1 ...{form}_k@t{))}}@*
@end example

@noindent
where {Q}_i is 

@center 
@example
@t{(}{slot-entry}_i () 
@t{(slot-value }in '{slot-entry}_i@t{))}
@end example

@noindent
if {slot-entry}_i is a @i{symbol}
and is

@center {
@example
@t{(}{variable-name}_i () 
@t{(slot-value }in '{slot-name}_i@t{))}
@end example
}

@noindent
if {slot-entry}_i
is of the form 

@center 
@example
@t{(}{variable-name}_i 
{slot-name}_i@t{)}
@end example

@node defclass, defgeneric, with-slots, Objects Dictionary
@subsection defclass                                                            [Macro]

@code{defclass}  @i{@i{class-name} @r{(}@{@i{superclass-name}@}{*}@r{)}
@r{(}@{{@i{slot-specifier}}@}{*}@r{)}
 [[!@i{class-option}]]}@*
   @result{}  @i{new-class}

@w{ slot-specifier::=@i{slot-name} | (@i{slot-name} [[!@i{slot-option}]])}@*

@w{ @i{slot-name}::= @i{symbol}}@*

@w{ slot-option::=@{{:reader} @i{reader-function-name}@}{*} |}@*
@w{                         @{{:writer} @i{writer-function-name}@}{*} |}@*
@w{                         @{{:accessor} @i{reader-function-name}@}{*} |}@*
@w{                         @{{:allocation} @i{allocation-type}@} |}@*
@w{                         @{{:initarg} @i{initarg-name}@}{*} |}@*
@w{                         @{{:initform} @i{form}@} |}@*
@w{                         @{{:type} @i{type-specifier}@} |}@*
@w{                         @{{:documentation} @i{string}@}}@*

@w{ @i{function-name}::= @{@i{symbol} | @t{(setf @i{symbol})}@}}@*

@w{ class-option::=(@t{:default-initargs} @t{.} @i{initarg-list}) |}@*
@w{                          (@t{:documentation} @i{string}) |}@*
@w{                          (@t{:metaclass} @i{class-name})}@*

@subsubheading  Arguments and Values::

@i{Class-name}---a @i{non-nil} @i{symbol}.

@i{Superclass-name}--a @i{non-nil} @i{symbol}.

@i{Slot-name}--a @i{symbol}.
  The @i{slot-name} argument is 
  a @i{symbol} that is syntactically valid for use as a variable name.

@i{Reader-function-name}---a @i{non-nil} @i{symbol}.
 @t{:reader} can be supplied more than once for a given @i{slot}.

@i{Writer-function-name}---a @i{generic function} name.
 @t{:writer} can be supplied more than once for a given @i{slot}.

@i{Reader-function-name}---a @i{non-nil} @i{symbol}.
 @t{:accessor} can be supplied more than once for a given @i{slot}.

@i{Allocation-type}---(member @t{:instance} @t{:class}).
 @t{:allocation} can be supplied once at most for a given @i{slot}.

@i{Initarg-name}---a @i{symbol}.
 @t{:initarg} can be supplied more than once for a given @i{slot}.  

@i{Form}---a @i{form}. 
 @t{:init-form} can be supplied once at most for a given @i{slot}.  

@i{Type-specifier}---a @i{type specifier}.
 @t{:type} can be supplied once at most for a given @i{slot}. 

@i{Class-option}--- refers to the @i{class} as a whole or to all class @i{slots}.

@i{Initarg-list}---a @i{list} of alternating initialization argument
		        @i{names} and default initial value @i{forms}.
 @t{:default-initargs} can be supplied at most once.

@i{Class-name}---a @i{non-nil} @i{symbol}.
 @t{:metaclass} can be supplied once at most.

@i{new-class}---the new @i{class} @i{object}.

@subsubheading  Description::

The macro @b{defclass} defines a new named @i{class}.  It returns
the new @i{class} @i{object} as its result.

The syntax of @b{defclass} provides options for specifying
initialization arguments for @i{slots}, for specifying default
initialization values for @i{slots}, and for requesting that 
@i{methods} on specified @i{generic functions} be automatically 
generated for reading and writing the values of @i{slots}.  
No reader or writer functions are defined by default; 
their generation must be explicitly requested.  However,
@i{slots} can always be @i{accessed} using @b{slot-value}.

Defining a new @i{class} also causes a @i{type} of the same name to be
defined.  The predicate @t{(typep @i{object} @i{class-name})} returns
true if the @i{class} of the given @i{object} is 
the @i{class} named by @i{class-name} itself or
a subclass of the class @i{class-name}.  A @i{class} @i{object} 
can be used as a @i{type specifier}.  
Thus @t{(typep @i{object} @i{class})} returns @i{true}
if the @i{class} of the @i{object} is 
@i{class} itself or a subclass of @i{class}.   

The @i{class-name} argument specifies the @i{proper name} 
of the new @i{class}.  
If a @i{class} with the same @i{proper name} already exists 
 and that @i{class} is an @i{instance} of @b{standard-class}, 
 and if the @b{defclass} form for the definition of the new @i{class}
      specifies a @i{class} of @i{class} @b{standard-class},
the existing @i{class} is redefined,
and instances of it (and its @i{subclasses}) are updated 
 to the new definition at the time that they are next @i{accessed}.
For details, see @ref{Redefining Classes}.

Each @i{superclass-name} argument 
specifies a direct @i{superclass} of the new @i{class}.  
If the @i{superclass} list is empty, then the @i{superclass}
defaults depending on the @i{metaclass}, 
with @b{standard-object} being the
default for @b{standard-class}.

The new @i{class} will
inherit @i{slots} and @i{methods} 
from each of its direct @i{superclasses}, from
their direct @i{superclasses}, and so on.  
For a discussion of how @i{slots} and @i{methods} are inherited,
see @ref{Inheritance}.

The following slot options are available:

@table @asis

@item @t{*}  
The @t{:reader} slot option specifies that an @i{unqualified method} is
to be defined on the @i{generic function} named @i{reader-function-name}
to read the value of the given @i{slot}.

@item @t{*}  
The @t{:writer} slot option specifies that an @i{unqualified method} is
to be defined on the @i{generic function} named @i{writer-function-name}
to write the value of the @i{slot}.

@item @t{*}  
The @t{:accessor} slot option specifies that an @i{unqualified method}
is to be defined on the generic function named @i{reader-function-name}
to read the value of the given @i{slot}
and that an @i{unqualified method} is to be defined on the 
@i{generic function} named @t{(setf @i{reader-function-name})} to be
used with @b{setf} to modify the value of the @i{slot}.

@item @t{*}  
The @t{:allocation} slot option is used to specify where storage is
to be allocated for the given @i{slot}.  Storage for a 
@i{slot} can be located
in each instance or in the @i{class} @i{object} itself.
The value of the @i{allocation-type} argument can be 
either the keyword @t{:instance}
or the keyword @t{:class}.    If the @t{:allocation}
slot option is not specified, the effect is the same as specifying
@t{:allocation :instance}.
@table @asis

@item --  
If @i{allocation-type} is @t{:instance}, a @i{local slot} of
the name @i{slot-name} is allocated in each instance of the 
@i{class}.

@item --  
If @i{allocation-type} is @t{:class}, a shared 
@i{slot} of the given                                      
name is allocated in the @i{class} @i{object} created by this @b{defclass}
form.  The value of the @i{slot} is shared by all 
@i{instances} of the @i{class}.
If a class C_1 defines such a @i{shared slot}, any 
subclass C_2 of
C_1 will share this single @i{slot} unless the @b{defclass} form
for C_2 specifies a @i{slot} of the same @i{name} or there is a
superclass of C_2 that precedes C_1 in the class precedence
list of C_2 and that defines a @i{slot} of the same @i{name}.
@end table

@item @t{*}  
The @t{:initform} slot option is used to provide a default
initial value form to be used in the initialization of the @i{slot}.  This
@i{form} is evaluated every time it is used to initialize the 
@i{slot}.  The
lexical environment in which this @i{form} is evaluated is the lexical
environment in which the @b{defclass} form was evaluated.
Note that the lexical environment refers both to variables and to
functions.  For @i{local slots}, the dynamic environment is the dynamic
environment in which @b{make-instance} is called; for shared
@i{slots}, the dynamic environment is the dynamic environment in which the
@b{defclass} form was evaluated.  
See @ref{Object Creation and Initialization}.

No implementation is permitted to extend the syntax of @b{defclass}
to allow @t{(@i{slot-name} @i{form})} as an abbreviation for 
@t{(@i{slot-name} :initform @i{form})}.

[Reviewer Note by Barmar: Can you extend this to mean something else?]

@item @t{*}  
The @t{:initarg} slot option declares an initialization
argument named @i{initarg-name} and specifies that this
initialization argument initializes the given @i{slot}.  If the
initialization argument has a value in the call to
@b{initialize-instance}, the value will be stored into the given @i{slot},
and the slot's @t{:initform} slot option, if any, is not
evaluated.  If none of the initialization arguments specified for a
given @i{slot} has a value, the @i{slot} is initialized according to the
@t{:initform} slot option, if specified.  

@item @t{*}  
The @t{:type} slot option specifies that the contents of the
@i{slot} will always be of the specified data type.  It effectively
declares the result type of the reader generic function when applied
to an @i{object} of this @i{class}.  The consequences of attempting to store in a
@i{slot} a value that does not satisfy the type of the @i{slot} are undefined.
The @t{:type} slot option is further discussed in 
@ref{Inheritance of Slots and Slot Options}.

@item @t{*}  
The @t{:documentation} slot option provides a @i{documentation string}
for the @i{slot}.  @t{:documentation} can be supplied once at most 
for a given @i{slot}. 
[Reviewer Note by Barmar: How is this retrieved?]
@end table

Each class option is an option that refers to the @i{class} as a whole.
The following class options are available:

@table @asis

@item @t{*}  
The @t{:default-initargs} class option is followed by a list of
alternating initialization argument @i{names} and default initial value
forms.  If any of these initialization arguments does not appear in
the initialization argument list supplied to @b{make-instance}, the
corresponding default initial value form is evaluated, and the
initialization argument @i{name} and the @i{form}'s value are added to the end
of the initialization argument list before the instance is created;
see @ref{Object Creation and Initialization}.
The default initial value form is evaluated each time it is used.  The lexical
environment in which this @i{form} is evaluated is the lexical environment
in which the @b{defclass} form was evaluated.  The dynamic
environment is the dynamic environment in which @b{make-instance}
was called.  If an initialization argument @i{name} appears more than once
in a @t{:default-initargs} class option, an error is signaled.

@item @t{*}  

The @t{:documentation} class option causes a @i{documentation string} 
to be attached with the @i{class} @i{object},
and attached with kind @b{type} to the @i{class-name}.
@t{:documentation} can be supplied once at most.

@item @t{*}  
The @t{:metaclass} class option is used to specify that
instances of the @i{class} being defined are to have a different metaclass
than the default provided by the system (the @i{class} @b{standard-class}).

@end table

Note the following rules of @b{defclass} for @i{standard classes}:

@table @asis

@item @t{*}  
It is not required that the @i{superclasses} of a @i{class} be defined before
the @b{defclass} form for that @i{class} is evaluated.

@item @t{*}  
All the @i{superclasses} of a @i{class} must be defined before 
an @i{instance} of the @i{class} can be made.

@item @t{*}  
A @i{class} must be defined before it can be used as a parameter
specializer in a @b{defmethod} form.

@end table

The object system can be extended to cover situations where these rules are not
obeyed.

Some slot options are inherited by a @i{class} from its 
@i{superclasses}, and
some can be shadowed or altered by providing a local slot description.
No class options except @t{:default-initargs} are inherited.  For a
detailed description of how @i{slots} and slot options are inherited, 
see @ref{Inheritance of Slots and Slot Options}.

The options to @b{defclass} can be extended.  It is required that
all implementations signal an error if they observe a class option or
a slot option that is not implemented locally.

It is valid to specify more than one reader, writer, accessor, or
initialization argument for a @i{slot}.  No other slot option can
appear
more than once in a single slot description, or an error is
signaled.

If no reader, writer, or accessor is specified for a @i{slot}, 
the @i{slot} can only be @i{accessed} by the @i{function} @b{slot-value}.

If a @b{defclass} @i{form} appears as a @i{top level form},
the @i{compiler} must make the @i{class} @i{name} be recognized as a
valid @i{type} @i{name} in subsequent declarations (as for @b{deftype})
and be recognized as a valid @i{class} @i{name} for @b{defmethod}
@i{parameter specializers} and for use as the @t{:metaclass} option of a
subsequent @b{defclass}.  The @i{compiler} must make 
the @i{class} definition 
available to be returned by @b{find-class} when its @i{environment}
@i{argument} is a value received as the @i{environment parameter} of a @i{macro}.

@subsubheading  Exceptional Situations::

If there are any duplicate slot names, 
an error of @i{type} @b{program-error} is signaled.

If an initialization argument @i{name} appears more than once in 
@t{:default-initargs} class option, 
an error of @i{type} @b{program-error} is signaled.

If any of the following slot options appears more than once in a
single slot description, an error of @i{type} @b{program-error}
is signaled: @t{:allocation},
@t{:initform}, @t{:type}, @t{:documentation}.

It is required that all implementations signal 
an error of @i{type} @b{program-error} if they observe a class option 
or a slot option that is not implemented locally.

@subsubheading  See Also::

@ref{documentation; (setf documentation)}
,
@ref{Initialize-Instance}
,
@ref{make-instance}
,
@ref{slot-value}
,
@ref{Classes},
@ref{Inheritance},
@ref{Redefining Classes},
@ref{Determining the Class Precedence List},
@ref{Object Creation and Initialization}

@node defgeneric, defmethod, defclass, Objects Dictionary
@subsection defgeneric                                                          [Macro]

@code{defgeneric}  @i{function-name gf-lambda-list
	  		  [[!@i{option} | @{!@i{method-description}@}{*}]]}@*
   @result{}  @i{new-generic}

@w{@i{option} ::=@r{(}@t{:argument-precedence-order} @{@i{parameter-name}@}^+@r{)} |}
@w{           @r{(}@b{declare} @{@i{gf-declaration}@}^+@r{)} |}
@w{           @r{(}@t{:documentation} @i{gf-documentation}@r{)} |}
@w{           @r{(}@t{:method-combination} @i{method-combination} @{@i{method-combination-argument}@}{*}@r{)} |}
@w{           @r{(}@t{:generic-function-class} @i{generic-function-class}@r{)} |}
@w{           @r{(}@t{:method-class} @i{method-class}@r{)}}

@w{@i{method-description} ::=@r{(}@t{:method} @{@i{method-qualifier}@}{*} @i{specialized-lambda-list} {[[@{@i{declaration}@}{*} | @i{documentation}]]} @{@i{form}@}{*}@r{)}}

@subsubheading  Arguments and Values::

@i{function-name}---a @i{function name}.

@i{generic-function-class}---a @i{non-nil} @i{symbol} naming a @i{class}.

@i{gf-declaration}---an @b{optimize} @i{declaration specifier};
  other @i{declaration specifiers} are not permitted.

@i{gf-documentation}---a @i{string}; not evaluated.

@i{gf-lambda-list}---a @i{generic function lambda list}.

@i{method-class}---a @i{non-nil} @i{symbol} naming a @i{class}.

@i{method-combination-argument}---an @i{object.}

@i{method-combination-name}---a @i{symbol} 
				  naming a @i{method combination} @i{type}.

@i{method-qualifiers},
@i{specialized-lambda-list},
@i{declarations},
@i{documentation},
@i{forms}---as per @b{defmethod}.

@i{new-generic}---the @i{generic function} @i{object}.

@i{parameter-name}---a @i{symbol} that names a @i{required parameter} 
			 in the @i{lambda-list}.
  (If the @t{:argument-precedence-order} option is specified,
   each @i{required parameter} in the @i{lambda-list}
   must be used exactly once as a @i{parameter-name}.)

@subsubheading  Description::

The macro @b{defgeneric} is used to define a @i{generic function}
or to specify options and declarations that pertain 
to a @i{generic function} as a whole.

If @i{function-name} is a 
@i{list} it must be of the form @t{(setf @i{symbol})}.
If @t{(fboundp @i{function-name})} is @i{false}, a new
@i{generic function} is created.  

If @t{(fdefinition @i{function-name})} is a @i{generic function}, that 

@i{generic function}
is modified.  If @i{function-name} names 
an @i{ordinary function},
a @i{macro}, or a @i{special operator}, 
an error is signaled.

The effect of the @b{defgeneric} macro is as if the following three
steps were performed: first, 
@i{methods} defined by previous @b{defgeneric} @i{forms} are removed; 

[Reviewer Note by Barmar: Shouldn't this (second) be first?]
second, @b{ensure-generic-function}
is called; and finally, @i{methods} specified by the current
@b{defgeneric} @i{form} are added to the @i{generic function}. 

Each @i{method-description} defines a @i{method} on the @i{generic function}.
The @i{lambda list} of each @i{method} must be congruent with the 
@i{lambda list}
specified by the @i{gf-lambda-list} option.  
If no @i{method} descriptions are specified and a @i{generic function} of the same
name does not already exist, a @i{generic function} with no 
@i{methods} is created.

The @i{gf-lambda-list} argument of @b{defgeneric} specifies the shape of
@i{lambda lists} for the @i{methods} on this @i{generic function}.
All @i{methods} on the resulting 
@i{generic function} must have
@i{lambda lists} that are congruent with this shape.  If a @b{defgeneric}
form is evaluated and some 
@i{methods} for that @i{generic function}
have @i{lambda lists} that are not congruent with that given in
the @b{defgeneric} form, an error is signaled.  For further details
on method congruence, see @ref{Congruent Lambda-lists for all Methods of a Generic Function}.

The @i{generic function} passes to the 
@i{method} all the argument values passed to
it, and only those; default values are not supported.
Note that optional and keyword arguments in method definitions, however,
can have default initial value forms and can use supplied-p parameters. 

The following options are provided.  

Except as otherwise noted, 

a given option may occur only once.

@table @asis

@item @t{*}  
The @t{:argument-precedence-order} option is used to specify the
order in which the required arguments in a call to the @i{generic function}
are tested for specificity when selecting a particular
@i{method}. Each required argument, as specified in the @i{gf-lambda-list}
argument, must be included exactly once as a @i{parameter-name}
so that the full and unambiguous precedence order is
supplied.  If this condition is not met, an error is signaled.

[Reviewer Note by Barmar: What is the default order?]

@item @t{*}  
The @b{declare} option is used to specify declarations that pertain
to the @i{generic function}.

An @b{optimize} @i{declaration specifier} is allowed.
It specifies whether method selection should be optimized for 
speed or space, but it has no effect on @i{methods}.
To control how a @i{method} is optimized, an @b{optimize}
declaration must be placed directly in the @b{defmethod} @i{form}
or method description.  The optimization qualities @b{speed} and
@b{space} are the only qualities this standard requires, but an
implementation can extend the object system to recognize other qualities.  
A simple implementation that has only one method selection technique 
and ignores @b{optimize} @i{declaration specifiers} is valid.

The @b{special}, @b{ftype}, @b{function}, @b{inline},
@b{notinline}, and @b{declaration} declarations are not permitted.
Individual implementations can extend the @b{declare} option to
support additional declarations.

[Editorial Note by KMP: Does ``additional'' mean including special, ftype, etc.?  
Or only other things that are not mentioned here?]
If an implementation notices a @i{declaration specifier} that it does
not support and that has not been proclaimed as a non-standard 
@i{declaration identifier} name in a @b{declaration} @i{proclamation}, 
it should issue a warning. 
[Editorial Note by KMP: The wording of this previous sentence,
particularly the word ``and'' suggests to me that you can `proclaim declaration'
of an unsupported declaration (e.g., ftype) in order to suppress the warning.
That seems wrong.  Perhaps it instead means to say ``does not support or 
is both undefined and not proclaimed declaration.'']

The @b{declare} option may be specified more than once.
The effect is the same as if the lists of @i{declaration specifiers} 
had been appended together into a single list and specified as a 
single @b{declare} option.

@item @t{*}  
The @t{:documentation} argument is a @i{documentation string}
to be attached to the @i{generic function} @i{object}, 
and to be attached with kind @b{function} to the @i{function-name}.

@item @t{*}  
The @t{:generic-function-class} option may be used to specify that
the @i{generic function} is to have a different @i{class} than
the default provided by the system (the @i{class} @b{standard-generic-function}).
The @i{class-name} argument is the name of a @i{class} that can be the
@i{class} of a @i{generic function}.  If @i{function-name} specifies
an existing @i{generic function} that has a different value for the
@t{:generic-function-class} argument and the new generic function 
@i{class} is compatible with the old, @b{change-class} is called 
to change the @i{class} of the @i{generic function}; 
otherwise an error is signaled.

@item @t{*}  
The @t{:method-class} option is used to specify that all @i{methods} on
this @i{generic function} are to have a different @i{class} from the 
default provided by the system (the @i{class} @b{standard-method}).
The @i{class-name} argument is the name of a @i{class} that is capable 
of being the @i{class} of a @i{method}.

[Reviewer Note by Barmar: Is @b{change-class} called on existing methods?]

@item @t{*}  
The @t{:method-combination} option is followed by a symbol that
names a type of method combination.  The arguments (if any) that
follow that symbol depend on the type of method combination.  Note
that the standard method combination type does not support any
arguments.  However, all types of method combination defined by the
short form of @b{define-method-combination} accept an optional
argument named @i{order}, defaulting to @t{:most-specific-first},
where a value of @t{:most-specific-last} reverses
the order of the primary @i{methods} without affecting the order of the
auxiliary @i{methods}.

@end table

The @i{method-description} arguments define @i{methods} that will
be associated with the @i{generic function}.  The @i{method-qualifier}
and @i{specialized-lambda-list} arguments in a method description
are the same as for @b{defmethod}.

The @i{form} arguments specify the method body.  The body of the
@i{method} is enclosed in an @i{implicit block}.
If @i{function-name} is a @i{symbol}, this block bears the same name as
the @i{generic function}.  If @i{function-name} is a 
@i{list} of the
form @t{(setf @i{symbol})}, the name of the block is @i{symbol}.  

Implementations can extend @b{defgeneric} to include other options.
It is required that an implementation signal an error if
it observes an option that is not implemented locally.

@b{defgeneric} is not required to perform any compile-time side effects.
In particular, the @i{methods} are not installed for invocation during 
compilation.  An @i{implementation} may choose to store information about
the @i{generic function} for the purposes of compile-time error-checking
(such as checking the number of arguments on calls, or noting that a definition
 for the function name has been seen).

@subsubheading  Examples::

@subsubheading  Exceptional Situations::

If @i{function-name} names an @i{ordinary function}, a @i{macro},
or a @i{special operator}, an error of @i{type} @b{program-error} is signaled.

Each required argument, as specified in the @i{gf-lambda-list}
argument, must be included exactly once as a @i{parameter-name},
or an error of @i{type} @b{program-error} is signaled.

The @i{lambda list} of each @i{method} specified by a 
@i{method-description} must be congruent with the @i{lambda list} specified
by the @i{gf-lambda-list} option, or
an error of @i{type} @b{error} is signaled.

If a @b{defgeneric} form is evaluated and some @i{methods} for
that @i{generic function} have @i{lambda lists} that are not congruent with
that given in the @b{defgeneric} form, 
an error of @i{type} @b{error} is signaled.

A given @i{option} may occur only once,
or an error of @i{type} @b{program-error} is signaled.

[Reviewer Note by Barmar: This says that an error is signaled if you specify the same generic
    function class as it already has!]
If @i{function-name} specifies an existing @i{generic function} 
that has a different value for the @t{:generic-function-class} 
argument and the new generic function @i{class} is compatible with the
old, @b{change-class} is called to change the @i{class} of 
the @i{generic function}; otherwise an error of @i{type} @b{error} is signaled.

Implementations can extend @b{defgeneric} to include other options.
It is required that an implementation 
signal an error of @i{type} @b{program-error} if
it observes an option that is not implemented locally.

@subsubheading  See Also::

@ref{defmethod}
,
@ref{documentation; (setf documentation)}
,
@ref{ensure-generic-function}
,

@b{generic-function},

@ref{Congruent Lambda-lists for all Methods of a Generic Function}

@node defmethod, find-class, defgeneric, Objects Dictionary
@subsection defmethod                                                           [Macro]

@code{defmethod}  @i{@i{function-name}
				      @{{@i{method-qualifier}}@}{*}
				      @i{specialized-lambda-list}
				{[[@{@i{declaration}@}{*} | @i{documentation}]]} @{@i{form}@}{*}}@*
   @result{}  @i{new-method}

@i{function-name}::= @{@i{symbol} 
| @t{(setf @i{symbol})}@}

@i{method-qualifier}::= @i{non-list}

@w{ @i{specialized-lambda-list}::= (@{@i{var} | @r{(}{@i{var} @i{parameter-specializer-name}}@r{)}@}{*}}@*
@w{                             @t{[}{&optional} @{@i{var} | @r{(}var @t{[}@i{initform} {@r{[}@i{supplied-p-parameter}@r{]}} @t{]}@r{)}@}{*}@t{]}}@*
@w{                             @t{[}@t{&rest} @i{var}@t{]}}@*
@w{                             @t{{[}}{{&key}{}}@{@i{var} | @r{(}@{@i{var} | @r{(}@i{keyword}@i{var}@r{)}@} @t{[}@i{initform} @r{[}@i{supplied-p-parameter}@r{]} @t{]}@r{)}@}{*}}@*
@w{                                          @r{[}@b{&allow-other-keys}@r{]} @t{{]}}}@*
@w{                             @t{[}@t{&aux} @{@i{var} | @r{(}@i{var} @r{[}@i{initform}@r{]} @r{)}@}{*}@t{]} @r{)}}@*

@w{ @i{parameter-specializer-name}::= @i{symbol} | @r{(}@t{eql} @i{eql-specializer-form}@r{)}}@*

@subsubheading  Arguments and Values::

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

@i{documentation}---a @i{string}; not evaluated.

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

@i{eql-specializer-form}---a @i{form}.

@i{Form}---a @i{form}.

@i{Initform}---a @i{form}.

@i{Supplied-p-parameter}---variable name. 

@i{new-method}---the new @i{method} @i{object}.

@subsubheading  Description::

The macro @b{defmethod} defines a @i{method} on a 
@i{generic function}.  

If @t{(fboundp @i{function-name})} is @b{nil}, a 
@i{generic function} is created with default values for 
the argument precedence order
(each argument is more specific than the arguments to its right
in the argument list),
for the generic function class (the @i{class} @b{standard-generic-function}),
for the method class (the @i{class} @b{standard-method}),
and for the method combination type (the standard method combination type).
The @i{lambda list} of the @i{generic function} is
congruent with the @i{lambda list} of the 
@i{method} being defined; if the
@b{defmethod} form mentions keyword arguments, the @i{lambda list} of
the @i{generic function} 
will mention @t{&key} (but no keyword
arguments).  If @i{function-name} names 
an @i{ordinary function},
a @i{macro}, or a @i{special operator}, 
an error is signaled.

If a @i{generic function} is currently named by @i{function-name},
the @i{lambda list} of the
@i{method} must be congruent with the @i{lambda list} of the 
@i{generic function}.
If this condition does not hold, an error is signaled.  
For a definition of congruence in this context, see @ref{Congruent Lambda-lists for all Methods of a Generic Function}.

Each @i{method-qualifier} argument is an @i{object} that is used by
method combination to identify the given @i{method}.  
The method combination type might further
restrict what a method @i{qualifier} can be.
The standard method combination type allows for @i{unqualified methods} and
@i{methods} whose sole
@i{qualifier} is one of the keywords @t{:before}, @t{:after}, or @t{:around}.

The @i{specialized-lambda-list} argument is like an ordinary
@i{lambda list} except that the @i{names} of required parameters can
be replaced by specialized parameters.  A specialized parameter is a
list of the form 
@t{(@i{var} @i{parameter-specializer-name})}.
Only required parameters can be
specialized.  If @i{parameter-specializer-name} is a @i{symbol} it names a
@i{class}; if it is a @i{list},
it is of the form @t{(eql @i{eql-specializer-form})}.  The parameter
specializer name @t{(eql @i{eql-specializer-form})} indicates
that the corresponding argument must be @b{eql} to the @i{object} that
is the value of @i{eql-specializer-form} for the @i{method} to be applicable.  
The @i{eql-specializer-form} is evaluated at the time
that the expansion of the @b{defmethod} macro is evaluated.  
If no @i{parameter specializer name} is specified for a given
required parameter, the @i{parameter specializer} defaults to 
the @i{class} @b{t}.
For further discussion, see @ref{Introduction to Methods}.

The @i{form} arguments specify the method body.
The body of the @i{method} is enclosed in an @i{implicit block}.  If
@i{function-name} is a @i{symbol}, 
this block bears the same @i{name} as the @i{generic function}.  
If @i{function-name} is a @i{list} of the form 
@t{(setf @i{symbol})}, the @i{name} of the block is @i{symbol}.  

The @i{class} of the @i{method} @i{object} that is created is that given by the 
method class option of the @i{generic function} 
on which the @i{method} is defined.

If the @i{generic function} already has a @i{method} that agrees with the
@i{method} being defined on @i{parameter specializers} and @i{qualifiers},
@b{defmethod} replaces the existing @i{method} with the one now being
defined.
For a definition of agreement in this context.
see @ref{Agreement on Parameter Specializers and Qualifiers}.

The @i{parameter specializers} are derived from 
the @i{parameter specializer names} as described in
@ref{Introduction to Methods}.

The expansion of the @b{defmethod} macro ``refers to'' each
specialized parameter (see the description of @b{ignore} 
within the description of @b{declare}).
This includes parameters that
have an explicit @i{parameter specializer name} of @b{t}.  This means
that a compiler warning does not occur if the body of the @i{method} does
not refer to a specialized parameter, while a warning might occur
if the body of the @i{method} does not refer to an unspecialized parameter.
For this reason, a parameter that specializes on @b{t} is not quite synonymous
with an unspecialized parameter in this context.

Declarations at the head of the method body that apply to the 
method's @i{lambda variables} are treated as @i{bound declarations}
whose @i{scope} is the same as the corresponding @i{bindings}.

Declarations at the head of the method body that apply to the 
functional bindings of @b{call-next-method} or @b{next-method-p}
apply to references to those functions within the method body @i{forms}.
Any outer @i{bindings} of the @i{function names} @b{call-next-method} and
@b{next-method-p}, and declarations associated with such @i{bindings}
are @i{shadowed}_2 within the method body @i{forms}.

The @i{scope} of @i{free declarations} at the head of the method body 
is the entire method body, 
which includes any implicit local function definitions
  but excludes @i{initialization forms} for the @i{lambda variables}.

@b{defmethod} is not required to perform any compile-time side effects.
In particular, the @i{methods} are not installed for invocation during 
compilation.  An @i{implementation} may choose to store information about
the @i{generic function} for the purposes of compile-time error-checking
(such as checking the number of arguments on calls, or noting that a definition
 for the function name has been seen).

@i{Documentation} is attached as a @i{documentation string}
to the @i{method} @i{object}.

@subsubheading  Affected By::

The definition of the referenced @i{generic function}.

@subsubheading  Exceptional Situations::

If @i{function-name} names an @i{ordinary function},
a @i{macro}, or a @i{special operator}, 
an error of @i{type} @b{error} is signaled.

If a @i{generic function} is currently named by @i{function-name},
the @i{lambda list} of the
@i{method} must be congruent with the @i{lambda list} of the 
@i{generic function}, or
an error of @i{type} @b{error} is signaled.

@subsubheading  See Also::

@ref{defgeneric}
, 
@ref{documentation; (setf documentation)}
,
@ref{Introduction to Methods},
@ref{Congruent Lambda-lists for all Methods of a Generic Function},
@ref{Agreement on Parameter Specializers and Qualifiers},
@ref{Syntactic Interaction of Documentation Strings and Declarations}

@node find-class, next-method-p, defmethod, Objects Dictionary
@subsection find-class                                                       [Accessor]

@code{find-class}  @i{symbol {&optional} errorp environment} @result{}  @i{class}

(setf (@code{         find-class} @i{symbol {&optional} errorp environment}) new-class)@*

@subsubheading  Arguments and Values::

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

@i{errorp}---a @i{generalized boolean}.
 The default is @i{true}.

@i{environment} -- same as the @b{&environment} argument to
  macro expansion functions and is used to distinguish between 
  compile-time and run-time environments.

  The @b{&environment} argument has 
  @i{dynamic extent}; the consequences are undefined if 
  the @b{&environment} argument is 
  referred to outside the @i{dynamic extent} 
  of the macro expansion function.

@i{class}---a @i{class} @i{object}, or @b{nil}.

@subsubheading  Description::

Returns the @i{class} @i{object} named by the @i{symbol}
in the @i{environment}.  If there is no such @i{class},
@b{nil} is returned if @i{errorp} is @i{false}; otherwise,
if @i{errorp} is @i{true}, an error is signaled.

The @i{class} associated with a particular @i{symbol} can be changed by using
@b{setf} with @b{find-class};

or, if the new @i{class} given to @b{setf} is @b{nil},
the @i{class} association is removed 
(but the @i{class} @i{object} itself is not affected).

The results are undefined if the user attempts to change

or remove

the @i{class} associated with a 
@i{symbol} that is defined as a @i{type specifier} in this standard.
See @ref{Integrating Types and Classes}.

When using @b{setf} of @b{find-class}, any @i{errorp} argument is @i{evaluated}
for effect, but any @i{values} it returns are ignored; the @i{errorp}
@i{parameter} is permitted primarily so that the @i{environment} @i{parameter}
can be used.

The @i{environment} might be used to distinguish between a compile-time and a
run-time environment.

@subsubheading  Exceptional Situations::

If there is no such @i{class} and @i{errorp} is @i{true},
@b{find-class} signals an error of @i{type} @b{error}.

@subsubheading  See Also::

@ref{defmacro}
,
@ref{Integrating Types and Classes}

@node next-method-p, call-method, find-class, Objects Dictionary
@subsection next-method-p                                              [Local Function]

@subsubheading  Syntax::

@code{next-method-p}  @i{<@i{no @i{arguments}}>} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values::

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

@subsubheading  Description::

The locally defined function @b{next-method-p} can be used 

within the body @i{forms} (but not the @i{lambda list})

defined by a @i{method-defining form} to determine
whether a next @i{method} exists.

The @i{function} @b{next-method-p} has @i{lexical scope} and @i{indefinite extent}.

Whether or not @b{next-method-p} is @i{fbound} in the
@i{global environment} is @i{implementation-dependent};
however, the restrictions on redefinition and @i{shadowing} of
@b{next-method-p} are the same as for @i{symbols} in the @t{COMMON-LISP} @i{package}
which are @i{fbound} in the @i{global environment}.
The consequences of attempting to use @b{next-method-p} outside
of a @i{method-defining form} are undefined.

@subsubheading  See Also::

@ref{call-next-method}
,
@ref{defmethod}
,
@ref{call-method; make-method}

@node call-method, call-next-method, next-method-p, Objects Dictionary
@subsection call-method, make-method                                      [Local Macro]

@subsubheading  Syntax::

@code{call-method}  @i{method {&optional} next-method-list} @result{}  @i{@{@i{result}@}{*}}

@code{make-method}  @i{form} @result{}  @i{method-object}

@subsubheading  Arguments and Values::

@i{method}---a @i{method} @i{object},
	      or a @i{list} (see below); not evaluated.

@i{method-object}---a @i{method} @i{object}.

@i{next-method-list}---a @i{list} of @i{method} @i{objects}; not evaluated.

@i{results}---the @i{values} returned by the @i{method} invocation.

@subsubheading  Description::

The macro @b{call-method} is used in method combination.  It hides
the @i{implementation-dependent} details of how 
@i{methods} are called. The
macro @b{call-method} has @i{lexical scope} and 
can only be used within
an @i{effective method} @i{form}.

[Editorial Note by KMP: This next paragraph still needs some work.]

Whether or not @b{call-method} is @i{fbound} in the
@i{global environment} is @i{implementation-dependent};
however, the restrictions on redefinition and @i{shadowing} of
@b{call-method} are the same as for @i{symbols} in the @t{COMMON-LISP} @i{package}
which are @i{fbound} in the @i{global environment}.
The consequences of attempting to use @b{call-method} outside
of an @i{effective method} @i{form} are undefined.

The macro @b{call-method} invokes the specified @i{method},
supplying it with arguments and with definitions for
@b{call-next-method} and for @b{next-method-p}.
If the invocation of @b{call-method} is lexically inside
of a @b{make-method}, the arguments are those that
were supplied to that method.  Otherwise the arguments are
those that were supplied to the generic function.
The definitions
of @b{call-next-method} and @b{next-method-p} rely on
the specified @i{next-method-list}.

If @i{method} is a @i{list}, the first element of the @i{list}
must be the symbol @b{make-method} and the second element must be
a @i{form}.  Such a @i{list} specifies a @i{method} @i{object}
whose @i{method} function has a body that is the given @i{form}.

@i{Next-method-list} can contain @i{method} @i{objects} or @i{lists},
the first element of which must be the symbol @b{make-method} and the
second element of which must be a @i{form}.

Those are the only two places where @b{make-method} can be used.
The @i{form} used with @b{make-method} is evaluated in
the @i{null lexical environment} augmented with a local macro definition
for @b{call-method} and with bindings named by
symbols not @i{accessible} from the @t{COMMON-LISP-USER} @i{package}.

The @b{call-next-method} function available to @i{method} 
will call the first @i{method} in @i{next-method-list}.
The @b{call-next-method} function
available in that @i{method}, in turn, will call the second
@i{method} in @i{next-method-list}, and so on, until
the list of next @i{methods} is exhausted.

If @i{next-method-list} is not supplied, the
@b{call-next-method} function available to
@i{method} signals an error of @i{type} @b{control-error}
and the @b{next-method-p} function
available to @i{method} returns {@b{nil}}.

@subsubheading  Examples::

@subsubheading  See Also:: 

@ref{call-next-method}
,
@ref{define-method-combination}
,
@ref{next-method-p}

@node call-next-method, compute-applicable-methods, call-method, Objects Dictionary
@subsection call-next-method                                           [Local Function]

@subsubheading  Syntax::

@code{call-next-method}  @i{{&rest} args} @result{}  @i{@{@i{result}@}{*}}

@subsubheading  Arguments and Values::

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

@i{results}---the @i{values} returned by the @i{method} it calls.

@subsubheading  Description::

The @i{function} @b{call-next-method} can be used 

within the body @i{forms} (but not the @i{lambda list})

of a @i{method} defined by a @i{method-defining form} to call the 
@i{next method}.

If there is no next @i{method}, the generic function 
@b{no-next-method} is called.

The type of method combination used determines which @i{methods}
can invoke @b{call-next-method}.  The standard 
@i{method combination} type allows @b{call-next-method} 
to be used within primary @i{methods} and @i{around methods}.
For generic functions using a type of method combination defined by
the short form of @b{define-method-combination},
@b{call-next-method} can be used in @i{around methods} only.

When @b{call-next-method} is called with no arguments, it passes the
current @i{method}'s original arguments to the next @i{method}.  Neither
argument defaulting, nor using @b{setq}, nor rebinding variables
with the same @i{names} as parameters of the @i{method} affects the values
@b{call-next-method} passes to the @i{method} it calls.

When @b{call-next-method} is called with arguments, the 
@i{next method} is called with those arguments.

If @b{call-next-method} is called with arguments but omits
optional arguments, the @i{next method} called defaults those arguments.

The @i{function} @b{call-next-method} returns any @i{values} that are
returned by the @i{next method}.

The @i{function} @b{call-next-method} has @i{lexical scope} and 
@i{indefinite extent} and can only be used within the body of a
@i{method} defined by a @i{method-defining form}.

Whether or not @b{call-next-method} is @i{fbound} in the
@i{global environment} is @i{implementation-dependent};
however, the restrictions on redefinition and @i{shadowing} of
@b{call-next-method} are the same as for @i{symbols} in the @t{COMMON-LISP} @i{package}
which are @i{fbound} in the @i{global environment}.
The consequences of attempting to use @b{call-next-method} outside
of a @i{method-defining form} are undefined.

@subsubheading  Affected By::

@b{defmethod}, @b{call-method}, @b{define-method-combination}.

@subsubheading  Exceptional Situations::

When providing arguments to @b{call-next-method}, 
the following rule must be satisfied or an error of @i{type} @b{error} 
should be
signaled: 
the ordered set of @i{applicable methods} for a changed set of arguments
for @b{call-next-method} must be the same as the ordered set of
@i{applicable methods} for the original arguments to the
@i{generic function}.
Optimizations of the error checking are possible, but they must not change
the semantics of @b{call-next-method}.

@subsubheading  See Also::

@ref{define-method-combination}
,
@ref{defmethod}
,
@ref{next-method-p}
,
@ref{no-next-method}
,
@ref{call-method; make-method}
,
@ref{Method Selection and Combination},
@ref{Standard Method Combination},
@ref{Built-in Method Combination Types}

@node compute-applicable-methods, define-method-combination, call-next-method, Objects Dictionary
@subsection compute-applicable-methods                      [Standard Generic Function]

@subsubheading  Syntax::

@code{compute-applicable-methods}  @i{generic-function function-arguments} @result{}  @i{methods}

@subsubheading  Method Signatures::

@code{compute-applicable-methods}  @i{@r{(}@i{generic-function} @b{standard-generic-function}@r{)}}

@subsubheading  Arguments and Values::

@i{generic-function}---a @i{generic function}.

@i{function-arguments}---a @i{list} of arguments for the @i{generic-function}.

@i{methods}---a @i{list} of @i{method} @i{objects}.

@subsubheading  Description::

Given a @i{generic-function} and a set of 
@i{function-arguments}, the function
@b{compute-applicable-methods} returns the set of @i{methods}
that are applicable for those arguments
sorted according to precedence order.
See @ref{Method Selection and Combination}.

@subsubheading  Affected By::

@b{defmethod}

@subsubheading  See Also::

@ref{Method Selection and Combination}

@node define-method-combination, find-method, compute-applicable-methods, Objects Dictionary
@subsection define-method-combination                                           [Macro]

@code{define-method-combination}  @i{name [[!@i{short-form-option}]]}@*
   @result{}  @i{name}

@code{define-method-combination}  @i{name lambda-list
                                @r{(}@{@i{method-group-specifier}@}{*}@r{)}
                                @r{[}@r{(}@t{:arguments} . args-lambda-list@r{)}@r{]}
                                @r{[}@r{(}@t{:generic-function} 
                                                   generic-function-symbol@r{)}@r{]}
                                [[@{@i{declaration}@}{*} | @i{documentation}]]
                                @{@i{form}@}{*}}@*
   @result{}  @i{name}

@w{@i{short-form-option} ::=@t{:documentation} @i{documentation} | }
@w{                      @t{:identity-with-one-argument} @i{identity-with-one-argument} |}
@w{                      @t{:operator} @i{operator}}

@w{@i{method-group-specifier} ::=@r{(}name @{@{@i{qualifier-pattern}@}^+ | predicate@} [[!@i{long-form-option}]]@r{)}}

@w{@i{long-form-option} ::=@t{:description} @i{description} |}
@w{                     @t{:order} @i{order} |}
@w{                     @t{:required} @i{required-p}}

@subsubheading  Arguments and Values::

@i{args-lambda-list}---
a @i{define-method-combination arguments lambda list}.

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

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

@i{documentation}---a @i{string}; not evaluated.

@i{forms}---an @i{implicit progn} 
  that must compute and return the @i{form} that specifies how
  the @i{methods} are combined, that is, the @i{effective method}.

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

@i{identity-with-one-argument}---a @i{generalized boolean}.

@i{lambda-list}---@i{ordinary lambda list}.

@i{name}---a @i{symbol}. 
  Non-@i{keyword}, @i{non-nil} @i{symbols} are usually used.

@i{operator}---an @i{operator}.
  @i{Name} and @i{operator} are often the @i{same} @i{symbol}.
  This is the default, but it is not required.

@i{order}---@t{:most-specific-first} or @t{:most-specific-last}; evaluated.

@i{predicate}---a @i{symbol} that names a @i{function} of one argument
		    that returns a @i{generalized boolean}.

@i{qualifier-pattern}---a @i{list},
			 or the @i{symbol} @b{*}.

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

@subsubheading  Description::

The macro @b{define-method-combination} is used to define new types
of method combination.

There are two forms of @b{define-method-combination}.  The short
form is a simple facility for the cases that are expected
to be most commonly needed.  The long form is more powerful but more
verbose.  It resembles @b{defmacro} in that the body is an
expression, usually using backquote, that computes a @i{form}.  Thus
arbitrary control structures can be implemented.  The long form also
allows arbitrary processing of method @i{qualifiers}.

@table @asis

@item @b{Short Form}  
The short form syntax of @b{define-method-combination} is recognized
when the second @i{subform} is a @i{non-nil} symbol or is not present.
When the short form is used, @i{name} is defined as a type of
method combination that produces a Lisp form
@t{({@i{operator} @i{method-call} @i{method-call} ...})}.
The @i{operator} is a @i{symbol} that can be the @i{name} of a 
@i{function}, @i{macro}, or @i{special operator}.  
The @i{operator} can be supplied by a keyword option;
it defaults to @i{name}.

Keyword options for the short form are the following:

@table @asis

@item @t{*}  
The @t{:documentation} option is used to document the method-combination type;
see description of long form below.

@item @t{*}  
The @t{:identity-with-one-argument} option enables an optimization
when its value is @i{true} (the default is @i{false}).  If there is
exactly one applicable method and it is a primary method, that method
serves as the effective method and @i{operator} is not called.
This optimization avoids the need to create a new effective method and
avoids the overhead of a @i{function} call.  This option is designed to be
used with operators such as @b{progn}, @b{and}, @b{+}, and
@b{max}.

@item @t{*}  
The @t{:operator} option specifies the @i{name} of the operator.  The
@i{operator} argument is a @i{symbol} that can be the 
@i{name} of a @i{function},
@i{macro}, or 
@i{special form}.  

@end table

These types of method combination require exactly one @i{qualifier} per
method.  An error is signaled if there are applicable methods with no
@i{qualifiers} or with @i{qualifiers} that are not supported by 
the method combination type. 

A method combination procedure defined in this way recognizes two
roles for methods.  A method whose one @i{qualifier} is the symbol naming
this type of method combination is defined to be a primary method.  At
least one primary method must be applicable or an error is signaled.
A method with @t{:around} as its one @i{qualifier} is an auxiliary
method that behaves the same as an @i{around method} in standard
method combination.  The @i{function} @b{call-next-method} can only be
used in @i{around methods}; it cannot be used in primary methods
defined by the short form of the @b{define-method-combination} macro.

A method combination procedure defined in this way accepts an optional
argument named @i{order}, which defaults to 
@t{:most-specific-first}.  A value of @t{:most-specific-last} reverses
the order of the primary methods without affecting the order of the
auxiliary methods.

The short form automatically includes error checking and support for
@i{around methods}.

For a discussion of built-in method combination types, 
see @ref{Built-in Method Combination Types}.

@item @b{Long Form}  
The long form syntax of @b{define-method-combination} is recognized 
when the second @i{subform} is a list.  

The @i{lambda-list} 
receives any arguments provided after the @i{name} of the method
combination type in the @t{:method-combination} option to
@b{defgeneric}.

A list of method group specifiers follows.  Each specifier selects a subset
of the applicable methods to play a particular role, either by matching
their @i{qualifiers} against some patterns or by testing their @i{qualifiers} with
a @i{predicate}.   
These method group specifiers define all method @i{qualifiers}
that can be used with this type of method combination.

The @i{car} of each @i{method-group-specifier} is a @i{symbol}
which @i{names} a @i{variable}.
During the execution of
the @i{forms} in the body of @b{define-method-combination}, this
@i{variable} is bound to a list of the @i{methods} in the method group.  The
@i{methods} in this list occur in the order specified by the 
@t{:order} option.

If @i{qualifier-pattern} is a @i{symbol} it must be @b{*}.  
A method matches
a @i{qualifier-pattern} if the method's 
list of @i{qualifiers} is @b{equal}
to the @i{qualifier-pattern} (except that the symbol @b{*} in a 
@i{qualifier-pattern} matches anything).  Thus 
a @i{qualifier-pattern} can be one of the
following:
 the @i{empty list}, which matches @i{unqualified methods};
 the symbol @b{*}, which matches all methods;
 a true list, which matches methods with the same number of @i{qualifiers} 
   as the length of the list when each @i{qualifier} matches 
   the corresponding list element; or
 a dotted list that ends in the symbol @b{*} 
   (the @b{*} matches any number of additional @i{qualifiers}).

Each applicable method is tested against the @i{qualifier-patterns} and
@i{predicates} in left-to-right order.  
As soon as a @i{qualifier-pattern} matches
or a @i{predicate} returns true, the method becomes a member of the
corresponding method group and no further tests are made.  Thus if a method
could be a member of more than one method group, it joins only the first
such group.  If a method group has more than one 
@i{qualifier-pattern}, a
method need only satisfy one of the @i{qualifier-patterns} to be a member of
the group.

The @i{name} of a @i{predicate} function can appear instead of 
@i{qualifier-patterns} in a method group specifier.  
The @i{predicate} is called for
each method that has not been assigned to an earlier method group; it
is called with one argument, the method's @i{qualifier} @i{list}.
The @i{predicate} should return true if the method is to be a member of the
method group.  A @i{predicate} can be distinguished from a 
@i{qualifier-pattern}
because it is a @i{symbol} other than @b{nil} or @b{*}.

If there is an applicable method that does not fall into any method group,
the @i{function} @b{invalid-method-error} is called.

Method group specifiers can have keyword options following the
@i{qualifier} patterns or predicate.  Keyword options can be distinguished from
additional @i{qualifier} patterns because they are neither lists nor the symbol
@b{*}.  The keyword options are as follows:

@table @asis

@item @t{*}  
The @t{:description} option is used to provide a description of the
role of methods in the method group.  Programming environment tools
use
 @t{(apply #'format stream @i{format-control} (method-qualifiers @i{method}))}
to print this description, which
is expected to be concise.  This keyword
option allows the description of a method @i{qualifier} to be defined in
the same module that defines the meaning of the 
method @i{qualifier}.  In most cases, @i{format-control} will not contain any
@b{format} directives, but they are available for generality.  
If @t{:description} is not supplied, a default description is generated
based on the variable name and the @i{qualifier} patterns and on whether
this method group includes the @i{unqualified methods}.  

@item @t{*}  
The @t{:order} option specifies the order of methods.  The @i{order}
argument is a @i{form} that evaluates to 
@t{:most-specific-first} or @t{:most-specific-last}.  If it evaluates
to any other value, an error is signaled.  
If @t{:order} is not supplied, it defaults to 
@t{:most-specific-first}.

@item @t{*}  
The @t{:required} option specifies whether at least one method in
this method group is required.
If its value is @i{true} and the method group is empty 
(that is, no applicable methods match the @i{qualifier} patterns
or satisfy the predicate), 
an error is signaled.  
If @t{:required} is not supplied,
it defaults to @b{nil}.  

@end table

The use of method group specifiers provides a convenient syntax to
select methods, to divide them among the possible roles, and to perform the
necessary error checking.  It is possible to perform further filtering
of methods in the body @i{forms} by using normal list-processing operations
and the functions @b{method-qualifiers} and 
@b{invalid-method-error}.  It is permissible to use @b{setq} on the
variables named in the method group specifiers and to bind additional
variables.  It is also possible to bypass the method group specifier
mechanism and do everything in the body @i{forms}.  This is accomplished
by writing a single method group with @b{*} as its only 
@i{qualifier-pattern}; 
the variable is then bound to a @i{list} of all of the
@i{applicable methods}, in most-specific-first order.

The body @i{forms} compute and return the @i{form} that specifies
how the methods are combined, that is, the effective method.
The effective method is evaluated in
the @i{null lexical environment} augmented with a local macro definition
for @b{call-method} and with bindings named by
symbols not @i{accessible} from the @t{COMMON-LISP-USER} @i{package}.
Given a method object in one of the 
@i{lists} produced by the method group
specifiers and a @i{list} of next methods,
@b{call-method}
will invoke the method such that @b{call-next-method} has available
the next methods.

When an effective method has no effect other than to call a single
method, some implementations employ an optimization that uses the
single method directly as the effective method, thus avoiding the need
to create a new effective method.  This optimization is active when
the effective method form consists entirely of an invocation of
the @b{call-method} macro whose first @i{subform} is a method object and
whose second @i{subform} is @b{nil} or unsupplied.  Each
@b{define-method-combination} body is responsible for stripping off
redundant invocations of @b{progn}, @b{and},
@b{multiple-value-prog1}, and the like, if this optimization is desired.

The list @t{(:arguments . @i{lambda-list})} can appear before
any declarations or @i{documentation string}.  This form is useful when
the method combination type performs some specific behavior as part of
the combined method and that behavior needs access to the arguments to
the @i{generic function}.  Each parameter variable defined by 
@i{lambda-list} is bound to a @i{form} that can be inserted into the
effective method.  When this @i{form} is evaluated during execution of the
effective method, its value is the corresponding argument to the
@i{generic function}; the consequences of using such a @i{form} as
the @i{place} in a @b{setf} @i{form} are undefined.

Argument correspondence is computed by dividing the @t{:arguments} @i{lambda-list}
and the @i{generic function} @i{lambda-list} into three sections:
     the @i{required parameters},
     the @i{optional parameters},
 and the @i{keyword} and @i{rest parameters}.
The @i{arguments} supplied to the @i{generic function} for a particular @i{call}
are also divided into three sections;
     the required @i{arguments} section contains as many @i{arguments}
      as the @i{generic function} has @i{required parameters},
     the optional @i{arguments} section contains as many arguments
      as the @i{generic function} has @i{optional parameters},
     and the keyword/rest @i{arguments} section contains the remaining arguments.
Each @i{parameter} in the required and optional sections of the 
@t{:arguments} @i{lambda-list} accesses the argument at the same position
in the corresponding section of the @i{arguments}.
If the section of the @t{:arguments} @i{lambda-list} is shorter,
 extra @i{arguments} are ignored. 
If the section of the @t{:arguments} @i{lambda-list} is longer,
 excess @i{required parameters} are bound to forms that evaluate to @b{nil} 
 and excess @i{optional parameters} are @i{bound} to their initforms.
The @i{keyword parameters} and @i{rest parameters} in the @t{:arguments}
@i{lambda-list} access the keyword/rest section of the @i{arguments}.
If the @t{:arguments} @i{lambda-list} contains @b{&key}, it behaves as
if it also contained @b{&allow-other-keys}.

In addition, @b{&whole} @i{var} can be placed first in the @t{:arguments}
@i{lambda-list}.  It causes @i{var} to be @i{bound} to a @i{form}
that @i{evaluates} to a @i{list} of all of the @i{arguments} supplied
to the @i{generic function}.  This is different from @b{&rest} because it
accesses all of the arguments, not just the keyword/rest @i{arguments}.

Erroneous conditions detected by the body should be reported with
@b{method-combination-error} or @b{invalid-method-error}; these
@i{functions}
add any necessary contextual information to the error message and will
signal the appropriate error.

The body @i{forms} are evaluated inside of the @i{bindings} created by
the
@i{lambda list} and method group specifiers. 

[Reviewer Note by Barmar: Are they inside or outside the :ARGUMENTS bindings?]
Declarations at the head of
the body are positioned directly inside of @i{bindings} created by the
@i{lambda list} and outside of the @i{bindings} of the method group variables. 
Thus method group variables cannot be declared in this way.  @b{locally} may be used
around the body, however.

Within the body @i{forms}, @i{generic-function-symbol}
is bound to the @i{generic function} @i{object}.

@i{Documentation} is attached as a @i{documentation string} 
    to @i{name} (as kind @b{method-combination})
and to the @i{method combination} @i{object}.

Note that two methods with identical specializers, but with different
@i{qualifiers}, are not ordered by the algorithm described in Step 2 of
the method selection and combination process described in 
@ref{Method Selection and Combination}.  Normally the two methods play
different roles in the effective method because they have different
@i{qualifiers}, and no matter how they are ordered in the result of Step
2, the effective method is the same.  If the two methods play the same
role and their order matters, 

[Reviewer Note by Barmar: How does the system know when the order matters?]
an error is signaled.  This happens as
part of the @i{qualifier} pattern matching in
@b{define-method-combination}.

@end table

If a @b{define-method-combination} @i{form} appears as a
@i{top level form}, the @i{compiler} must make the
@i{method combination} @i{name} be recognized as a valid
@i{method combination} @i{name} in subsequent @b{defgeneric}
@i{forms}.  However, the @i{method combination} is executed
no earlier than when the @b{define-method-combination} @i{form}
is executed, and possibly as late as the time that @i{generic functions}
that use the @i{method combination} are executed.

@subsubheading  Examples::

Most examples of the long form of @b{define-method-combination} also
illustrate the use of the related @i{functions} that are provided as part
of the declarative method combination facility.

@example
;;; Examples of the short form of define-method-combination

 (define-method-combination and :identity-with-one-argument t) 

 (defmethod func and ((x class1) y) ...)

;;; The equivalent of this example in the long form is:

 (define-method-combination and 
         (&optional (order :most-specific-first))
         ((around (:around))
          (primary (and) :order order :required t))
   (let ((form (if (rest primary)
                   `(and ,@@(mapcar #'(lambda (method)
                                       `(call-method ,method))
                                   primary))
                   `(call-method ,(first primary)))))
     (if around
         `(call-method ,(first around)
                       (,@@(rest around)
                        (make-method ,form)))
         form)))

;;; Examples of the long form of define-method-combination

;The default method-combination technique
 (define-method-combination standard ()
         ((around (:around))
          (before (:before))
          (primary () :required t)
          (after (:after)))
   (flet ((call-methods (methods)
            (mapcar #'(lambda (method)
                        `(call-method ,method))
                    methods)))
     (let ((form (if (or before after (rest primary))
                     `(multiple-value-prog1
                        (progn ,@@(call-methods before)
                               (call-method ,(first primary)
                                            ,(rest primary)))
                        ,@@(call-methods (reverse after)))
                     `(call-method ,(first primary)))))
       (if around
           `(call-method ,(first around)
                         (,@@(rest around)
                          (make-method ,form)))
           form))))

;A simple way to try several methods until one returns non-nil
 (define-method-combination or ()
         ((methods (or)))
   `(or ,@@(mapcar #'(lambda (method)
                      `(call-method ,method))
                  methods)))

;A more complete version of the preceding
 (define-method-combination or 
         (&optional (order ':most-specific-first))
         ((around (:around))
          (primary (or)))
   ;; Process the order argument
   (case order
     (:most-specific-first)
     (:most-specific-last (setq primary (reverse primary)))
     (otherwise (method-combination-error "~S is an invalid order.~@@
     :most-specific-first and :most-specific-last are the possible values."
                                          order)))
   ;; Must have a primary method
   (unless primary
     (method-combination-error "A primary method is required."))
   ;; Construct the form that calls the primary methods
   (let ((form (if (rest primary)
                   `(or ,@@(mapcar #'(lambda (method)
                                      `(call-method ,method))
                                  primary))
                   `(call-method ,(first primary)))))
     ;; Wrap the around methods around that form
     (if around
         `(call-method ,(first around)
                       (,@@(rest around)
                        (make-method ,form)))
         form)))

;The same thing, using the :order and :required keyword options
 (define-method-combination or 
         (&optional (order ':most-specific-first))
         ((around (:around))
          (primary (or) :order order :required t))
   (let ((form (if (rest primary)
                   `(or ,@@(mapcar #'(lambda (method)
                                      `(call-method ,method))
                                  primary))
                   `(call-method ,(first primary)))))
     (if around
         `(call-method ,(first around)
                       (,@@(rest around)
                        (make-method ,form)))
         form)))

;This short-form call is behaviorally identical to the preceding
 (define-method-combination or :identity-with-one-argument t)

;Order methods by positive integer qualifiers
;:around methods are disallowed to keep the example small
 (define-method-combination example-method-combination ()
         ((methods positive-integer-qualifier-p))
   `(progn ,@@(mapcar #'(lambda (method)
                         `(call-method ,method))
                     (stable-sort methods #'<
                       :key #'(lambda (method)
                                (first (method-qualifiers method)))))))

 (defun positive-integer-qualifier-p (method-qualifiers)
   (and (= (length method-qualifiers) 1)
        (typep (first method-qualifiers) '(integer 0 *))))

;;; Example of the use of :arguments
 (define-method-combination progn-with-lock ()
         ((methods ()))
   (:arguments object)
   `(unwind-protect
        (progn (lock (object-lock ,object))
               ,@@(mapcar #'(lambda (method)
                             `(call-method ,method))
                         methods))
      (unlock (object-lock ,object))))

@end example

@subsubheading  Side Effects::

The @i{compiler} is not required to perform any compile-time side-effects.

@subsubheading  Exceptional Situations::

Method combination types defined with the short form require exactly
one @i{qualifier} per method.  
An error of @i{type} @b{error} is signaled if there are
applicable methods with no @i{qualifiers} or with @i{qualifiers} that are not
supported by the method combination type.
At least one primary method must be applicable or 
an error of @i{type} @b{error} is signaled.

If an applicable method does not fall into any method group, the
system signals an error of @i{type} @b{error}
indicating that the method is invalid for the kind of
method combination in use.

If the value of the @t{:required} option is @i{true}
and the method group is empty (that is, no applicable
methods match the @i{qualifier} patterns or satisfy the predicate), 
an error of @i{type} @b{error} is signaled.

If the @t{:order} option evaluates to a value other than 
@t{:most-specific-first} or @t{:most-specific-last}, 
an error of @i{type} @b{error} is signaled.

@subsubheading  See Also:: 

@ref{call-method; make-method}
,
@ref{call-next-method}
,
@ref{documentation; (setf documentation)}
,
@ref{method-qualifiers}
,
@ref{method-combination-error}
,
@ref{invalid-method-error}
,
@ref{defgeneric}
,
@ref{Method Selection and Combination},
@ref{Built-in Method Combination Types},
@ref{Syntactic Interaction of Documentation Strings and Declarations}

@subsubheading  Notes::

The @t{:method-combination} option of @b{defgeneric} is used to
specify that a @i{generic function} should use a particular method
combination type.  The first argument to the @t{:method-combination}
option is the @i{name} of a method combination type and the remaining
arguments are options for that type.

@node find-method, add-method, define-method-combination, Objects Dictionary
@subsection find-method                                     [Standard Generic Function]

@subsubheading  Syntax::

@code{find-method}  @i{generic-function method-qualifiers specializers {&optional} errorp}@*
   @result{}  @i{method}

@subsubheading  Method Signatures::

@code{find-method}  @i{@r{(}@i{generic-function} @b{standard-generic-function}@r{)}
		method-qualifiers specializers {&optional} errorp}

@subsubheading  Arguments and Values::

@i{generic-function}---a @i{generic function}.

@i{method-qualifiers}---a @i{list}.

@i{specializers}---a @i{list}.

@i{errorp}---a @i{generalized boolean}.
 The default is @i{true}.

@i{method}---a @i{method} @i{object}, or @b{nil}.

@subsubheading  Description::

The @i{generic function} @b{find-method} takes a @i{generic function} 
and returns the @i{method} @i{object} that agrees on @i{qualifiers} 
and @i{parameter specializers} with the @i{method-qualifiers} and 
@i{specializers} arguments of @b{find-method}.  
@i{Method-qualifiers}  contains the
method @i{qualifiers} for the @i{method}. 
The order of the method @i{qualifiers}
is significant.                                
For a definition of agreement in this context,
see @ref{Agreement on Parameter Specializers and Qualifiers}.

The @i{specializers} argument contains the parameter
specializers for the @i{method}. It must correspond in length to
the number of required arguments of the @i{generic function}, or
an error is signaled.  This means that to obtain the
default @i{method} on a given @i{generic-function},
a @i{list} whose elements are the @i{class} @b{t} must be given.

If there is no such @i{method} and @i{errorp} is @i{true},
@b{find-method} signals an error.
If there is no such @i{method} and @i{errorp} is @i{false},
@b{find-method} returns @b{nil}.

@subsubheading  Examples::

@example
 (defmethod some-operation ((a integer) (b float)) (list a b))
@result{}  #<STANDARD-METHOD SOME-OPERATION (INTEGER FLOAT) 26723357>
 (find-method #'some-operation '() (mapcar #'find-class '(integer float)))
@result{}  #<STANDARD-METHOD SOME-OPERATION (INTEGER FLOAT) 26723357>
 (find-method #'some-operation '() (mapcar #'find-class '(integer integer)))
@t{ |> } Error: No matching method
 (find-method #'some-operation '() (mapcar #'find-class '(integer integer)) nil)
@result{}  NIL
@end example

@subsubheading  Affected By::

@b{add-method},
@b{defclass},
@b{defgeneric},
@b{defmethod}

@subsubheading  Exceptional Situations::

If the @i{specializers} argument does not correspond in length to
the number of required arguments of the @i{generic-function}, an
an error of @i{type} @b{error} is signaled.  

If there is no such @i{method} and @i{errorp} is @i{true}, 
@b{find-method} signals an error of @i{type} @b{error}.

@subsubheading  See Also::

@ref{Agreement on Parameter Specializers and Qualifiers}

@node add-method, initialize-instance, find-method, Objects Dictionary
@subsection add-method                                      [Standard Generic Function]

@subsubheading  Syntax::

@code{add-method}  @i{generic-function method} @result{}  @i{generic-function}

@subsubheading  Method Signatures::

@code{add-method}  @i{@r{(}@i{generic-function} @b{standard-generic-function}@r{)}
			   @r{(}@i{method} @b{method}@r{)}}

@subsubheading  Arguments and Values::

@i{generic-function}---a @i{generic function} @i{object}.

@i{method}---a @i{method} @i{object}.

@subsubheading  Description::

The generic function @b{add-method} adds a @i{method}
to a @i{generic function}.

If @i{method} agrees with an existing @i{method} of @i{generic-function}
on @i{parameter specializers} and @i{qualifiers}, 
the existing @i{method} is replaced.

@subsubheading  Exceptional Situations::

The @i{lambda list} of the method function of @i{method} must be
congruent with the @i{lambda list} of @i{generic-function}, 
or an error of @i{type} @b{error} is signaled.

If @i{method} is a @i{method} @i{object} of
another @i{generic function}, an error of @i{type} @b{error} is signaled.

@subsubheading  See Also::

@ref{defmethod}
,
@ref{defgeneric}
,
@ref{find-method}
,
@ref{remove-method}
,
@ref{Agreement on Parameter Specializers and Qualifiers}

@node initialize-instance, class-name, add-method, Objects Dictionary
@subsection initialize-instance                             [Standard Generic Function]

@subsubheading  Syntax::

@code{initialize-instance}  @i{instance {&rest} initargs {&key} {&allow-other-keys}} @result{}  @i{instance}

@subsubheading  Method Signatures::

@code{initialize-instance}  @i{@r{(}@i{instance} @b{standard-object}@r{)} {&rest} initargs}

@subsubheading  Arguments and Values::

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

@i{initargs}---a @i{defaulted initialization argument list}.

@subsubheading  Description::

Called by @b{make-instance} to initialize a newly created @i{instance}.
The generic function is called with the new @i{instance} 
and the @i{defaulted initialization argument list}.

The system-supplied primary @i{method} on @b{initialize-instance}
initializes the @i{slots} of the @i{instance} with values according 
to the @i{initargs} and the @t{:initform} forms of the @i{slots}.
It does this by calling the generic function @b{shared-initialize}
with the following arguments: the @i{instance}, @b{t} (this indicates
that all @i{slots} for which no initialization arguments are provided
should be initialized according to their @t{:initform} forms), and
the @i{initargs}.

Programmers can define @i{methods} for @b{initialize-instance} to
specify actions to be taken when an instance is initialized.  If only
@i{after methods} are defined, they will be run after the
system-supplied primary @i{method} for initialization and therefore will
not interfere with the default behavior of @b{initialize-instance}.

@subsubheading  See Also::

@ref{Shared-Initialize}
,
@ref{make-instance}
,
@ref{slot-boundp}
,
@ref{slot-makunbound}
,
@ref{Object Creation and Initialization},
@ref{Rules for Initialization Arguments},
@ref{Declaring the Validity of Initialization Arguments}

@node class-name, (setf class-name), initialize-instance, Objects Dictionary
@subsection class-name                                      [Standard Generic Function]

@subsubheading  Syntax::

@code{class-name}  @i{class} @result{}  @i{name}

@subsubheading  Method Signatures::

@code{class-name}  @i{@r{(}@i{class} @b{class}@r{)}}

@subsubheading  Arguments and Values::

@i{class}---a @i{class} @i{object}.

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

@subsubheading  Description::

Returns the @i{name} of the given @i{class}.

@subsubheading  See Also::

@ref{find-class}
,
@ref{Classes}

@subsubheading  Notes::

If S is a @i{symbol} such that S =@t{(class-name C)}
and C =@t{(find-class S)}, then S is the proper name of C.
For further discussion, see @ref{Classes}.

The name of an anonymous @i{class} is @b{nil}.

@node (setf class-name), class-of, class-name, Objects Dictionary
@subsection (setf class-name)                               [Standard Generic Function]

@subsubheading  Syntax::

@code{(setf class-name)}  @i{new-value class} @result{}  @i{new-value}

@subsubheading  Method Signatures::

@code{(setf class-name)}  @i{new-value @r{(}@i{class} @b{class}@r{)}}

@subsubheading  Arguments and Values::

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

@i{class}---a @i{class}.

@subsubheading  Description::

The generic function @t{(setf class-name)} sets the name of 
a @i{class} object.

@subsubheading  See Also::

@ref{find-class}
,
@i{proper name},
@ref{Classes}

@node class-of, unbound-slot, (setf class-name), Objects Dictionary
@subsection class-of                                                         [Function]

@code{class-of}  @i{object} @result{}  @i{class}

@subsubheading  Arguments and Values::

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

@i{class}---a @i{class} @i{object}.

@subsubheading  Description::

Returns the @i{class} of which the @i{object} is 
a @i{direct instance}.

@subsubheading  Examples::

@example
 (class-of 'fred) @result{}  #<BUILT-IN-CLASS SYMBOL 610327300>
 (class-of 2/3) @result{}  #<BUILT-IN-CLASS RATIO 610326642>

 (defclass book () ()) @result{}  #<STANDARD-CLASS BOOK 33424745>
 (class-of (make-instance 'book)) @result{}  #<STANDARD-CLASS BOOK 33424745>

 (defclass novel (book) ()) @result{}  #<STANDARD-CLASS NOVEL 33424764>
 (class-of (make-instance 'novel)) @result{}  #<STANDARD-CLASS NOVEL 33424764>

 (defstruct kons kar kdr) @result{}  KONS
 (class-of (make-kons :kar 3 :kdr 4)) @result{}  #<STRUCTURE-CLASS KONS 250020317>
@end example

@subsubheading  See Also::

@ref{make-instance}
,
@ref{type-of}

@node unbound-slot, unbound-slot-instance, class-of, Objects Dictionary
@subsection unbound-slot                                               [Condition Type]

@subsubheading  Class Precedence List::
@b{unbound-slot},
@b{cell-error},
@b{error},
@b{serious-condition},
@b{condition},
@b{t}

@subsubheading  Description::

The @i{object} having the unbound slot is initialized by 
the @t{:instance} initialization argument to @b{make-condition},
and is @i{accessed} by the @i{function} @b{unbound-slot-instance}.

The name of the cell (see @b{cell-error}) is the name of the slot.

@subsubheading  See Also::

@ref{cell-error-name}
,
@b{unbound-slot-object},
@ref{Condition System Concepts}

@node unbound-slot-instance,  , unbound-slot, Objects Dictionary
@subsection unbound-slot-instance                                            [Function]

@code{unbound-slot-instance}  @i{condition} @result{}  @i{instance}

@subsubheading  Arguments and Values::

@i{condition}---a @i{condition} of @i{type} @b{unbound-slot}.

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

@subsubheading  Description::

Returns the instance which had the unbound slot in the @i{situation}
represented by the @i{condition}.          

@subsubheading  See Also::

@ref{cell-error-name}
,
@b{unbound-slot},
@ref{Condition System Concepts}

@c end of including dict-objects

@c %**end of chapter