File: ProgrammersManual.texinfo

package info (click to toggle)
lambdamoo-docs 1.8.2-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 596 kB
  • sloc: makefile: 22
file content (5832 lines) | stat: -rw-r--r-- 251,661 bytes parent folder | download | duplicates (5)
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
\input texinfo   @c -*-texinfo-*-

@comment %**start of header (This is for running Texinfo on a region.)
@set INDEX
@setfilename ProgrammersManual.info
@settitle LambdaMOO Programmer's Manual
@c Uncomment the following line for two-sided printing.
@c @setchapternewpage odd
@comment %**end of header (This is for running Texinfo on a region.)

@ifinfo
@format
@sp 5
		     *************************************
		     *** LambdaMOO Programmer's Manual ***
		     *************************************
				       
                         For LambdaMOO Version 1.8.0p6
                                  March 1997
				       
				by Pavel Curtis
				  aka Haakon
				  aka Lambda
@sp 4
Copyright @copyright{} 1991, 1992, 1993, 1995, 1996 by Pavel Curtis.
@end format

Permission is granted to make and distribute verbatim copies of this manual
provided the copyright notice and this permission notice are preserved on all
copies.

@ignore
Permission is granted to process this file through TeX and print the results,
provided the printed document carries copying permission notice identical to
this one except for the removal of this paragraph (this paragraph not being
relevant to the printed manual).

@end ignore
Permission is granted to copy and distribute modified versions of this manual
under the conditions for verbatim copying, provided that the entire resulting
derived work is distributed under the terms of a permission notice identical
to this one.

Permission is granted to copy and distribute translations of this manual into
another language, under the above conditions for modified versions, except
that this permission notice may be stated in a translation approved by the
author.
@format
@sp 5
@end format
@end ifinfo

@titlepage
@title LambdaMOO Programmer's Manual
@subtitle For LambdaMOO Version 1.8.0p6
@subtitle March 1997
@author by Pavel Curtis
@author aka Haakon
@author aka Lambda

@page
@vskip 0pt plus 1filll
Copyright @copyright{} 1991, 1992, 1993, 1995, 1996 by Pavel Curtis.

Copies of the electronic source for this document can be obtained using
anonymous FTP on the Internet.  At the site @code{ftp.research.att.com} the
files are @code{dist/eostrom/MOO/ProgrammersManual.*}; several different file
formats are provided, including HTML, Texinfo, plain text, and PostScript.

Permission is granted to make and distribute verbatim copies of this manual
provided the copyright notice and this permission notice are preserved on all
copies.

Permission is granted to copy and distribute modified versions of this manual
under the conditions for verbatim copying, provided that the entire resulting
derived work is distributed under the terms of a permission notice identical
to this one.

Permission is granted to copy and distribute translations of this manual into
another language, under the above conditions for modified versions, except
that this permission notice may be stated in a translation approved by the
author.
@end titlepage

@node Top, Introduction, (dir), (dir)
@comment  node-name,  next,  previous,  up
@ifset INFO
@format
		     *************************************
		     *** LambdaMOO Programmer's Manual ***
		     *************************************
				       
                         For LambdaMOO Version 1.8.0p6
                                  March 1997
				       
				by Pavel Curtis
				  aka Haakon
				  aka Lambda

          Copyright @copyright{} 1991, 1992, 1993, 1995, 1996 by Pavel Curtis.
@end format
@end ifset

@menu
* Introduction::             What is LambdaMOO?
* Database::                 The LambdaMOO Database
* Parsing::                  The Built-in Command Parser
* Language::                 The MOO Programming Language
* Server::                   Server Commands and Database Assumptions
* Function Index::           Index to All Built-In Functions
@end menu

@node Introduction, Database, Top, Top
@comment  node-name,  next,  previous,  up
@chapter Introduction

LambdaMOO is a network-accessible, multi-user, programmable, interactive
system well-suited to the construction of text-based adventure games,
conferencing systems, and other collaborative software.  Its most common use,
however, is as a multi-participant, low-bandwidth virtual reality, and it is
with this focus in mind that I describe it here.

Participants (usually referred to as @dfn{players}) connect to LambdaMOO using
Telnet or some other, more specialized, @dfn{client} program.  Upon
connection, they are usually presented with a @dfn{welcome message} explaining
how to either create a new @dfn{character} or connect to an existing one.
Characters are the embodiment of players in the virtual reality that is
LambdaMOO.

Having connected to a character, players then give one-line commands that are
parsed and interpreted by LambdaMOO as appropriate.  Such commands may cause
changes in the virtual reality, such as the location of a character, or may
simply report on the current state of that reality, such as the appearance of
some object.

The job of interpreting those commands is shared between the two major
components in the LambdaMOO system: the @dfn{server} and the @dfn{database}.
The server is a program, written in a standard programming language, that
manages the network connections, maintains queues of commands and other tasks
to be executed, controls all access to the database, and executes other
programs written in the MOO programming language.  The database contains
representations of all the objects in the virtual reality, including the MOO
programs that the server executes to give those objects their specific
behaviors.

Almost every command is parsed by the server into a call on a MOO procedure,
or @dfn{verb}, that actually does the work.  Thus, programming in the MOO
language is a central part of making non-trivial extensions to the database
and thus, the virtual reality.

In the next chapter, I describe the structure and contents of a LambdaMOO
database.  The following chapter gives a complete description of how the
server performs its primary duty: parsing the commands typed by players.
Next, I describe the complete syntax and semantics of the MOO programming
language.  Finally, I describe all of the database conventions assumed by the
server.

@quotation
@strong{Note:} This manual describes only those aspects of LambdaMOO that are
entirely independent of the contents of the database.  It does not describe,
for example, the commands or programming interfaces present in the LambdaCore
database.
@end quotation

@node Database, Parsing, Introduction, Top
@comment  node-name,  next,  previous,  up
@chapter The LambdaMOO Database

In this chapter, I begin by describing in detail the various kinds of data
that can appear in a LambdaMOO database and that, therefore, MOO programs can
manipulate.  In a few places, I refer to the @dfn{LambdaCore} database.  This
is one particular LambdaMOO database, created every so often by extracting the
``core'' of the current database for the original LambdaMOO.

@quotation
@strong{Note}: The original LambdaMOO resides on the host
@code{lambda.parc.xerox.com} (the numeric address for which is
@code{192.216.54.2}), on port 8888.  Feel free to drop by!  A copy of the most
recent release of the LambdaCore database can be obtained by anonymous FTP from
host @code{ftp.parc.xerox.com} in the directory @code{pub/MOO}.
@end quotation

@menu
* Values::                   MOO Value Types
* Objects::                  Objects in the MOO Database
@end menu

@node Values, Objects, Database, Database
@comment  node-name,  next,  previous,  up
@section MOO Value Types

There are only a few kinds of values that MOO programs can manipulate:

@itemize @bullet
@item
integers (in a specific, large range)
@item
real numbers (represented with floating-point numbers)
@item
strings (of characters)
@item
objects (in the virtual reality)
@item
errors (arising during program execution)
@item
lists (of all of the above, including lists)
@end itemize

MOO supports the integers from @minus{}2^31 (that is, negative two to the power
of 31) up to 2^31 @minus{} 1 (one less than two to the power of 31); that's
from @minus{}2147483648 to 2147483647, enough for most purposes.  In MOO
programs, integers are written just as you see them here, an optional minus
sign followed by a non-empty sequence of decimal digits.  In particular, you
may not put commas, periods, or spaces in the middle of large integers, as we
sometimes do in English and other natural languages (e.g., `2,147,483,647').

Real numbers in MOO are represented as they are in almost all other programming
languages, using so-called @dfn{floating-point} numbers.  These have certain
(large) limits on size and precision that make them useful for a wide range of
applications.  Floating-point numbers are written with an optional minus sign
followed by a non-empty sequence of digits punctuated at some point with a
decimal point (`.') and/or followed by a scientific-notation marker (the letter
`E' or `e' followed by an optional sign and one or more digits).  Here are some
examples of floating-point numbers:

@example
325.0   325.   3.25e2   0.325E3   325.E1   .0325e+4   32500e-2
@end example

@noindent
All of these examples mean the same number.  The third of these, as an example
of scientific notation, should be read ``3.25 times 10 to the power of 2''.

@quotation
@emph{Fine points:} The MOO represents floating-point numbers using the local
meaning of the C-language @code{double} type, which is almost always equivalent
to IEEE 754 double precision floating point.  If so, then the smallest positive
floating-point number is no larger than @code{2.2250738585072014e-308} and the
largest floating-point number is @code{1.7976931348623157e+308}.

IEEE infinities and NaN values are not allowed in MOO.  The error
@code{E_FLOAT} is raised whenever an infinity would otherwise be computed;
@code{E_INVARG} is raised whenever a NaN would otherwise arise.  The value
@code{0.0} is always returned on underflow.
@end quotation

Character @dfn{strings} are arbitrarily-long sequences of normal, ASCII
printing characters.  When written as values in a program, strings are
enclosed in double-quotes, like this:

@example
"This is a character string."
@end example

@noindent
To include a double-quote in the string, precede it with a backslash
(@samp{\}), like this:

@example
"His name was \"Leroy\", but nobody ever called him that."
@end example

@noindent
Finally, to include a backslash in a string, double it:

@example
"Some people use backslash ('\\') to mean set difference."
@end example

@noindent
MOO strings may not include special ASCII characters like carriage-return,
line-feed, bell, etc.  The only non-printing characters allowed are spaces and
tabs.

@quotation
@emph{Fine point:} There is a special kind of string used for representing the
arbitrary bytes used in general, binary input and output.  In a @dfn{binary
string}, any byte that isn't an ASCII printing character or the space character
is represented as the three-character substring "~XX", where XX is the
hexadecimal representation of the byte; the input character `~' is represented
by the three-character substring "~7E".  This special representation is used by
the functions @code{encode_binary()} and @code{decode_binary()} and by the
functions @code{notify()} and @code{read()} with network connections that are
in binary mode.  See the descriptions of the @code{set_connection_option()},
@code{encode_binary()}, and @code{decode_binary()} functions for more details.
@end quotation

@dfn{Objects} are the backbone of the MOO database and, as such, deserve a
great deal of discussion; the entire next section is devoted to them.  For now,
let it suffice to say that every object has a number, unique to that object.
In programs, we write a reference to a particular object by putting a hash mark
(@samp{#}) followed by the number, like this:

@example
#495
@end example

@noindent
Object numbers are always integers.

There are three special object numbers used for a variety of purposes:
@code{#-1}, @code{#-2}, and @code{#-3}, usually referred to in the
LambdaCore database as @code{$nothing}, @code{$ambiguous_match}, and
@code{$failed_match}, respectively.

@dfn{Errors} are, by far, the least frequently used values in MOO.  In the
normal case, when a program attempts an operation that is erroneous for some
reason (for example, trying to add a number to a character string), the server
stops running the program and prints out an error message.  However, it is
possible for a program to stipulate that such errors should not stop execution;
instead, the server should just let the value of the operation be an error
value.  The program can then test for such a result and take some appropriate
kind of recovery action.  In programs, error values are written as words
beginning with @samp{E_}.  The complete list of error values, along with their
associated messages, is as follows:

@example
E_NONE      @r{No error}
E_TYPE      @r{Type mismatch}
E_DIV       @r{Division by zero}
E_PERM      @r{Permission denied}
E_PROPNF    @r{Property not found}
E_VERBNF    @r{Verb not found}
E_VARNF     @r{Variable not found}
E_INVIND    @r{Invalid indirection}
E_RECMOVE   @r{Recursive move}
E_MAXREC    @r{Too many verb calls}
E_RANGE     @r{Range error}
E_ARGS      @r{Incorrect number of arguments}
E_NACC      @r{Move refused by destination}
E_INVARG    @r{Invalid argument}
E_QUOTA     @r{Resource limit exceeded}
E_FLOAT     @r{Floating-point arithmetic error}
@end example

The final kind of value in MOO programs is @dfn{lists}.  A list is a sequence
of arbitrary MOO values, possibly including other lists.  In programs,
lists are written in mathematical set notation with each of the elements
written out in order, separated by commas, the whole enclosed in curly
braces (@samp{@{} and @samp{@}}).  For example, a list of the names of
the days of the week is written like this:

@example
@{"Sunday", "Monday", "Tuesday", "Wednesday",
 "Thursday", "Friday", "Saturday"@}
@end example

@noindent
Note that it doesn't matter that we put a line-break in the middle of
the list.  This is true in general in MOO: anywhere that a space can go,
a line-break can go, with the same meaning.  The only exception is
inside character strings, where line-breaks are not allowed.

@node Objects,  , Values, Database
@comment  node-name,  next,  previous,  up
@section Objects in the MOO Database

Objects are, in a sense, the whole point of the MOO programming language.
They are used to represent objects in the virtual reality, like people, rooms,
exits, and other concrete things.  Because of this, MOO makes a bigger deal
out of creating objects than it does for other kinds of value, like integers.

Numbers always exist, in a sense; you have only to write them down in order to
operate on them.  With objects, it is different.  The object with number
@samp{#958} does not exist just because you write down its number.  An
explicit operation, the @samp{create()} function described later, is required
to bring an object into existence.  Symmetrically, once created, objects
continue to exist until they are explicitly destroyed by the @samp{recycle()}
function (also described later).

The identifying number associated with an object is unique to that
object.  It was assigned when the object was created and will never be
reused, even if the object is destroyed.  Thus, if we create an object
and it is assigned the number @samp{#1076}, the next object to be
created will be assigned @samp{#1077}, even if @samp{#1076} is destroyed
in the meantime.

Every object is made up of three kinds of pieces that together define its
behavior: @dfn{attributes}, @dfn{properties}, and @dfn{verbs}.

@menu
* Attributes::               Fundamental Object Attributes
* Properties::               Properties on Objects
* Verbs::                    Verbs on Objects
@end menu

@node Attributes, Properties, Objects, Objects
@comment  node-name,  next,  previous,  up
@subsection Fundamental Object Attributes

There are three fundamental @dfn{attributes} to every object:

@enumerate 1
@item
A flag (either true or false) specifying whether or not the object represents
a player,
@item
The object that is its @dfn{parent}, and
@item
A list of the objects that are its @dfn{children}; that is, those objects for
which this object is their parent.
@end enumerate

The act of creating a character sets the player attribute of an object and
only a wizard (using the function @code{set_player_flag()}) can change that
setting.  Only characters have the player bit set to 1.

The parent/child hierarchy is used for classifying objects into general classes
and then sharing behavior among all members of that class.  For example, the
LambdaCore database contains an object representing a sort of ``generic'' room.
All other rooms are @dfn{descendants} (i.e., children or children's children,
or @dots{}) of that one.  The generic room defines those pieces of behavior
that are common to all rooms; other rooms specialize that behavior for their
own purposes.  The notion of classes and specialization is the very essence of
what is meant by @dfn{object-oriented} programming.  Only the functions
@code{create()}, @code{recycle()}, @code{chparent()}, and @code{renumber()} can
change the parent and children attributes.

@node Properties, Verbs, Attributes, Objects
@comment  node-name,  next,  previous,  up
@subsection Properties on Objects

A @dfn{property} is a named ``slot'' in an object that can hold an arbitrary
MOO value.  Every object has eight built-in properties whose values are
constrained to be of particular types.  In addition, an object can have any
number of other properties, none of which have type constraints.  The built-in
properties are as follows:

@example
name         @r{a string, the usual name for this object}
owner        @r{an object, the player who controls access to it}
location     @r{an object, where the object is in virtual reality}
contents     @r{a list of objects, the inverse of @samp{location}}
programmer   @r{a bit, does the object have programmer rights?}
wizard       @r{a bit, does the object have wizard rights?}
r            @r{a bit, is the object publicly readable?}
w            @r{a bit, is the object publicly writable?}
f            @r{a bit, is the object fertile?}
@end example

The @samp{name} property is used to identify the object in various printed
messages.  It can only be set by a wizard or by the owner of the object.  For
player objects, the @samp{name} property can only be set by a wizard; this
allows the wizards, for example, to check that no two players have the same
name.

The @samp{owner} identifies the object that has owner rights to this object,
allowing them, for example, to change the @samp{name} property.  Only a wizard
can change the value of this property.

The @samp{location} and @samp{contents} properties describe a hierarchy of
object containment in the virtual reality.  Most objects are located
``inside'' some other object and that other object is the value of the
@samp{location} property.  The @samp{contents} property is a list of those
objects for which this object is their location.  In order to maintain the
consistency of these properties, only the @code{move()} function is able to
change them.

The @samp{wizard} and @samp{programmer} bits are only applicable to
characters, objects representing players.  They control permission to use
certain facilities in the server.  They may only be set by a wizard.

The @samp{r} bit controls whether or not players other than the owner of this
object can obtain a list of the properties or verbs in the object.
Symmetrically, the @samp{w} bit controls whether or not non-owners can add or
delete properties and/or verbs on this object.  The @samp{r} and @samp{w} bits
can only be set by a wizard or by the owner of the object.

The @samp{f} bit specifies whether or not this object is @dfn{fertile}, whether
or not players other than the owner of this object can create new objects with
this one as the parent.  It also controls whether or not non-owners can use the
@code{chparent()} built-in function to make this object the parent of an
existing object.  The @samp{f} bit can only be set by a wizard or by the owner
of the object.

All of the built-in properties on any object can, by default, be read by any
player.  It is possible, however, to override this behavior from within the
database, making any of these properties readable only by wizards.  See the
chapter on server assumptions about the database for details.

As mentioned above, it is possible, and very useful, for objects to have other
properties aside from the built-in ones.  These can come from two sources.

First, an object has a property corresponding to every property in its parent
object.  To use the jargon of object-oriented programming, this is a kind of
@dfn{inheritance}.  If some object has a property named @samp{foo}, then so
will all of its children and thus its children's children, and so on.

Second, an object may have a new property defined only on itself and its
descendants.  For example, an object representing a rock might have properties
indicating its weight, chemical composition, and/or pointiness, depending upon
the uses to which the rock was to be put in the virtual reality.

Every defined property (as opposed to those that are built-in) has an owner
and a set of permissions for non-owners.  The owner of the property can get
and set the property's value and can change the non-owner permissions.  Only a
wizard can change the owner of a property.

The initial owner of a property is the player who added it; this is usually,
but not always, the player who owns the object to which the property was
added.  This is because properties can only be added by the object owner or a
wizard, unless the object is publicly writable (i.e., its @samp{w} property is
1), which is rare.  Thus, the owner of an object may not necessarily be the
owner of every (or even any) property on that object.

The permissions on properties are drawn from this set: @samp{r} (read),
@samp{w} (write), and @samp{c} (change ownership in descendants).  Read
permission lets non-owners get the value of the property and, of course, write
permission lets them set that value.  The @samp{c} permission bit is a little
more complicated.

Recall that every object has all of the properties that its parent does and
perhaps some more.  Ordinarily, when a child object inherits a property from
its parent, the owner of the child becomes the owner of that property.  This
is because the @samp{c} permission bit is ``on'' by default.  If the @samp{c}
bit is not on, then the inherited property has the same owner in the child as
it does in the parent.

As an example of where this can be useful, the LambdaCore database ensures
that every player has a @samp{password} property containing the encrypted
version of the player's connection password.  For security reasons, we don't
want other players to be able to see even the encrypted version of the
password, so we turn off the @samp{r} permission bit.  To ensure that the
password is only set in a consistent way (i.e., to the encrypted version of a
player's password), we don't want to let anyone but a wizard change the
property.  Thus, in the parent object for all players, we made a wizard the
owner of the password property and set the permissions to the empty string,
@code{""}.  That is, non-owners cannot read or write the property and, because
the @samp{c} bit is not set, the wizard who owns the property on the parent
class also owns it on all of the descendants of that class.

Another, perhaps more down-to-earth example arose when a character named Ford
started building objects he called ``radios'' and another character, yduJ,
wanted to own one.  Ford kindly made the generic radio object fertile, allowing
yduJ to create a child object of it, her own radio.  Radios had a property
called @samp{channel} that identified something corresponding to the frequency
to which the radio was tuned.  Ford had written nice programs on radios (verbs,
discussed below) for turning the channel selector on the front of the radio,
which would make a corresponding change in the value of the @samp{channel}
property.  However, whenever anyone tried to turn the channel selector on
yduJ's radio, they got a permissions error.  The problem concerned the
ownership of the @samp{channel} property.

As I explain later, programs run with the permissions of their author.  So, in
this case, Ford's nice verb for setting the channel ran with his permissions.
But, since the @samp{channel} property in the generic radio had the @samp{c}
permission bit set, the @samp{channel} property on yduJ's radio was owned by
her.  Ford didn't have permission to change it!  The fix was simple.  Ford
changed the permissions on the @samp{channel} property of the generic radio to
be just @samp{r}, without the @samp{c} bit, and yduJ made a new radio.  This
time, when yduJ's radio inherited the @samp{channel} property, yduJ did not
inherit ownership of it; Ford remained the owner.  Now the radio worked
properly, because Ford's verb had permission to change the channel.

@node Verbs,  , Properties, Objects
@comment  node-name,  next,  previous,  up
@subsection Verbs on Objects

The final kind of piece making up an object is @dfn{verbs}.  A verb is a named
MOO program that is associated with a particular object.  Most verbs implement
commands that a player might type; for example, in the LambdaCore database,
there is a verb on all objects representing containers that implements
commands of the form `put @var{object} in @var{container}'.  It is also
possible for MOO programs to invoke the verbs defined on objects.  Some verbs,
in fact, are designed to be used only from inside MOO code; they do not
correspond to any particular player command at all.  Thus, verbs in MOO are
like the `procedures' or `methods' found in some other programming languages.

As with properties, every verb has an owner and a set of permission bits.  The
owner of a verb can change its program, its permission bits, and its argument
specifiers (discussed below).  Only a wizard can change the owner of a verb.
The owner of a verb also determines the permissions with which that verb runs;
that is, the program in a verb can do whatever operations the owner of that
verb is allowed to do and no others.  Thus, for example, a verb owned by a
wizard must be written very carefully, since wizards are allowed to do just
about anything.

The permission bits on verbs are drawn from this set: @samp{r} (read),
@samp{w} (write), @samp{x} (execute), and @samp{d} (debug).  Read permission
lets non-owners see the program for a verb and, symmetrically, write
permission lets them change that program.  The other two bits are not,
properly speaking, permission bits at all; they have a universal effect,
covering both the owner and non-owners.

The execute bit determines whether or not the verb can be invoked from within
a MOO program (as opposed to from the command line, like the @samp{put} verb
on containers).  If the @samp{x} bit is not set, the verb cannot be called
from inside a program.  The @samp{x} bit is usually set.

The setting of the debug bit determines what happens when the verb's program
does something erroneous, like subtracting a number from a character string.
If the @samp{d} bit is set, then the server @dfn{raises} an error value; such
raised errors can be @dfn{caught} by certain other pieces of MOO code.  If the
error is not caught, however, the server aborts execution of the command and,
by default, prints an error message on the terminal of the player whose command
is being executed.  (See the chapter on server assumptions about the database
for details on how uncaught errors are handled.)  If the @samp{d} bit is not
set, then no error is raised, no message is printed, and the command is not
aborted; instead the error value is returned as the result of the erroneous
operation.

@quotation
@strong{Note:} the @samp{d} bit exists only for historical reasons; it used to
be the only way for MOO code to catch and handle errors.  With the introduction
of the @code{try}-@code{except} statement and the error-catching expression,
the @samp{d} bit is no longer useful.  All new verbs should have the @samp{d}
bit set, using the newer facilities for error handling if desired.  Over time,
old verbs written assuming the @samp{d} bit would not be set should be changed
to use the new facilities instead.
@end quotation

In addition to an owner and some permission bits, every verb has three
`argument specifiers', one each for the direct object, the preposition, and
the indirect object.  The direct and indirect specifiers are each drawn from
this set: @samp{this}, @samp{any}, or @samp{none}.  The preposition specifier
is @samp{none}, @samp{any}, or one of the items in this list:

@example
with@r{/}using
at@r{/}to
in front of
in@r{/}inside@r{/}into
on top of@r{/}on@r{/}onto@r{/}upon
out of@r{/}from inside@r{/}from
over
through
under@r{/}underneath@r{/}beneath
behind
beside
for@r{/}about
is
as
off@r{/}off of
@end example

The argument specifiers are used in the process of parsing commands,
described in the next chapter.

@node Parsing, Language, Database, Top
@comment  node-name,  next,  previous,  up
@chapter The Built-in Command Parser

The MOO server is able to do a small amount of parsing on the commands
that a player enters.  In particular, it can break apart commands that
follow one of the following forms:

@example
@var{verb}
@var{verb} @var{direct-object}
@var{verb} @var{direct-object} @var{preposition} @var{indirect-object}
@end example

Real examples of these forms, meaningful in the LambdaCore database, are
as follows:

@example
look
take yellow bird
put yellow bird in cuckoo clock
@end example

Note that English articles (i.e., @samp{the}, @samp{a}, and @samp{an}) are not
generally used in MOO commands; the parser does not know that they are
not important parts of objects' names.

To have any of this make real sense, it is important to understand
precisely how the server decides what to do when a player types a
command.

First, the server checks whether or not the first non-blank character in the
command is one of the following:

@example
"        :        ;
@end example

@noindent
If so, that character is replaced by the corresponding command below, followed
by a space:

@example
say      emote    eval
@end example

@noindent
For example, the command

@example
"Hi, there.
@end example

@noindent
is treated exactly as if it were as follows:

@example
say Hi, there.
@end example

The server next breaks up the command into words.  In the simplest case,
the command is broken into words at every run of space characters; for example,
the command @samp{foo bar baz} would be broken into the words @samp{foo},
@samp{bar}, and @samp{baz}.  To force the server to include spaces in a
``word'', all or part of a word can be enclosed in double-quotes.  For example,
the command

@example
foo "bar mumble" baz" "fr"otz" bl"o"rt
@end example

@noindent
is broken into the words @samp{foo}, @samp{bar mumble}, @samp{baz frotz}, and
@samp{blort}.  Finally, to include a double-quote or a backslash in a word,
they can be preceded by a backslash, just like in MOO strings.

Having thus broken the string into words, the server next checks to see if the
first word names any of the six ``built-in'' commands: @samp{.program},
@samp{PREFIX}, @samp{OUTPUTPREFIX}, @samp{SUFFIX}, @samp{OUTPUTSUFFIX}, or the
connection's defined @dfn{flush} command, if any (@samp{.flush} by default).
The first one of these is only available to programmers, the next four are
intended for use by client programs, and the last can vary from database to
database or even connection to connection; all six are described in the final
chapter of this document, ``Server Commands and Database Assumptions''.  If the
first word isn't one of the above, then we get to the usual case: a normal MOO
command.

The server next gives code in the database a chance to handle the command.  If
the verb @code{$do_command()} exists, it is called with the words of the
command passed as its arguments and @code{argstr} set to the raw command typed
by the user.  If @code{$do_command()} does not exist, or if that verb-call
completes normally (i.e., without suspending or aborting) and returns a false
value, then the built-in command parser is invoked to handle the command as
described below.  Otherwise, it is assumed that the database code handled the
command completely and no further action is taken by the server for that
command.

If the built-in command parser is invoked, the server tries to parse the
command into a verb, direct object, preposition and indirect object.  The first
word is taken to be the verb.  The server then tries to find one of the
prepositional phrases listed at the end of the previous section, using the
match that occurs earliest in the command.  For example, in the very odd
command @samp{foo as bar to baz}, the server would take @samp{as} as the
preposition, not @samp{to}.

If the server succeeds in finding a preposition, it considers the words
between the verb and the preposition to be the direct object and those
after the preposition to be the indirect object.  In both cases, the
sequence of words is turned into a string by putting one space between
each pair of words.  Thus, in the odd command from the previous
paragraph, there are no words in the direct object (i.e., it is
considered to be the empty string, @code{""}) and the indirect object is
@code{"bar to baz"}.

If there was no preposition, then the direct object is taken to be all
of the words after the verb and the indirect object is the empty string.

The next step is to try to find MOO objects that are named by the direct
and indirect object strings.

First, if an object string is empty, then the corresponding object is the
special object @code{#-1} (aka @code{$nothing} in LambdaCore).  If an object
string has the form of an object number (i.e., a hash mark (@samp{#}) followed
by digits), and the object with that number exists, then that is the named
object.  If the object string is either @code{"me"} or @code{"here"}, then the
player object itself or its location is used, respectively.

Otherwise, the server considers all of the objects whose location is either
the player (i.e., the objects the player is ``holding'', so to speak) or the
room the player is in (i.e., the objects in the same room as the player); it
will try to match the object string against the various names for these
objects.

The matching done by the server uses the @samp{aliases} property of each of the
objects it considers.  The value of this property should be a list of strings,
the various alternatives for naming the object.  If it is not a list, or the
object does not have an @samp{aliases} property, then the empty list is used.
In any case, the value of the @samp{name} property is added to the list for the
purposes of matching.

The server checks to see if the object string in the command is either exactly
equal to or a prefix of any alias; if there are any exact matches, the prefix
matches are ignored.  If exactly one of the objects being considered has a
matching alias, that object is used.  If more than one has a match, then the
special object @code{#-2} (aka @code{$ambiguous_match} in LambdaCore) is used.
If there are no matches, then the special object @code{#-3} (aka
@code{$failed_match} in LambdaCore) is used.

So, now the server has identified a verb string, a preposition string,
and direct- and indirect-object strings and objects.  It then looks at
each of the verbs defined on each of the following four objects, in
order:

@enumerate 1
@item
the player who typed the command,
@item
the room the player is in,
@item
the direct object, if any, and
@item
the indirect object, if any.
@end enumerate

@noindent
For each of these verbs in turn, it tests if all of the the following
are true:

@itemize @bullet
@item
the verb string in the command matches one of the names for the
verb,
@item
the direct- and indirect-object values found by matching are allowed by
the corresponding argument specifiers for the verb, and
@item
the preposition string in the command is matched by the preposition
specifier for the verb.
@end itemize

@noindent
I'll explain each of these criteria in turn.

Every verb has one or more names; all of the names are kept in a single
string, separated by spaces.  In the simplest case, a verb-name is just
a word made up of any characters other than spaces and stars (i.e., ` '
and @samp{*}).  In this case, the verb-name matches only itself; that
is, the name must be matched exactly.

If the name contains a single star, however, then the name matches any prefix
of itself that is at least as long as the part before the star.  For example,
the verb-name @samp{foo*bar} matches any of the strings @samp{foo},
@samp{foob}, @samp{fooba}, or @samp{foobar}; note that the star itself is not
considered part of the name.

If the verb name @emph{ends} in a star, then it matches any string that begins
with the part before the star.  For example, the verb-name @samp{foo*} matches
any of the strings @samp{foo}, @samp{foobar}, @samp{food}, or @samp{foogleman},
among many others.  As a special case, if the verb-name is @samp{*} (i.e., a
single star all by itself), then it matches anything at all.

Recall that the argument specifiers for the direct and indirect objects are
drawn from the set @samp{none}, @samp{any}, and @samp{this}.  If the specifier
is @samp{none}, then the corresponding object value must be @code{#-1} (aka
@code{$nothing} in LambdaCore); that is, it must not have been specified.  If
the specifier is @samp{any}, then the corresponding object value may be
anything at all.  Finally, if the specifier is @samp{this}, then the
corresponding object value must be the same as the object on which we found
this verb; for example, if we are considering verbs on the player, then the
object value must be the player object.

Finally, recall that the argument specifier for the preposition is
either @samp{none}, @samp{any}, or one of several sets of prepositional
phrases, given above.  A specifier of @samp{none} matches only if there
was no preposition found in the command.  A specifier of @samp{any}
always matches, regardless of what preposition was found, if any.  If
the specifier is a set of prepositional phrases, then the one found must
be in that set for the specifier to match.

So, the server considers several objects in turn, checking each of their
verbs in turn, looking for the first one that meets all of the criteria
just explained.  If it finds one, then that is the verb whose program
will be executed for this command.  If not, then it looks for a verb
named @samp{huh} on the room that the player is in; if one is found,
then that verb will be called.  This feature is useful for implementing
room-specific command parsing or error recovery.  If the server can't
even find a @samp{huh} verb to run, it prints an error message like
@samp{I couldn't understand that.} and the command is considered complete.

At long last, we have a program to run in response to the command typed by the
player.  When the code for the program begins execution, the following
built-in variables will have the indicated values:

@example
player    @r{an object, the player who typed the command}
this      @r{an object, the object on which this verb was found}
caller    @r{an object, the same as @samp{player}}
verb      @r{a string, the first word of the command}
argstr    @r{a string, everything after the first word of the command}
args      @r{a list of strings, the words in @samp{argstr}}
dobjstr   @r{a string, the direct object string found during parsing}
dobj      @r{an object, the direct object value found during matching}
prepstr   @r{a string, the prepositional phrase found during parsing}
iobjstr   @r{a string, the indirect object string}
iobj      @r{an object, the indirect object value}
@end example

@noindent
The value returned by the program, if any, is ignored by the server.

@node Language, Server, Parsing, Top
@comment  node-name,  next,  previous,  up
@chapter The MOO Programming Language

MOO stands for ``MUD, Object Oriented.''  MUD, in turn, has been said to stand
for many different things, but I tend to think of it as ``Multi-User Dungeon''
in the spirit of those ancient precursors to MUDs, Adventure and Zork.

MOO, the programming language, is a relatively small and simple
object-oriented language designed to be easy to learn for most
non-programmers; most complex systems still require some significant
programming ability to accomplish, however.

Having given you enough context to allow you to understand exactly what MOO
code is doing, I now explain what MOO code looks like and what it means.  I
begin with the syntax and semantics of expressions, those pieces of code that
have values.  After that, I cover statements, the next level of structure up
from expressions.  Next, I discuss the concept of a task, the kind of running
process initiated by players entering commands, among other causes.  Finally,
I list all of the built-in functions available to MOO code and describe what
they do.

First, though, let me mention comments.  You can include bits of text in your
MOO program that are ignored by the server.  The idea is to allow you to put
in notes to yourself and others about what the code is doing.  To do this,
begin the text of the comment with the two characters @samp{/*} and end it
with the two characters @samp{*/}; this is just like comments in the C
programming language.  Note that the server will completely ignore that text;
it will @emph{not} be saved in the database.  Thus, such comments are only
useful in files of code that you maintain outside the database.

To include a more persistent comment in your code, try using a character
string literal as a statement.  For example, the sentence about peanut butter
in the following code is essentially ignored during execution but will be
maintained in the database:

@example
for x in (players())
  "Grendel eats peanut butter!";
  player:tell(x.name, " (", x, ")");
endfor
@end example

@menu
* Expressions::              MOO Language Expressions
* Statements::               MOO Language Statements
* Tasks::                    MOO Tasks
* Builtins::                 Built-in Functions
@end menu

@node Expressions, Statements, Language, Language
@comment  node-name,  next,  previous,  up
@section MOO Language Expressions

Expressions are those pieces of MOO code that generate values; for
example, the MOO code
@example
3 + 4
@end example
@noindent
is an expression that generates (or ``has'' or ``returns'') the value 7.
There are many kinds of expressions in MOO, all of them discussed below.

@menu
* Expression Errors::        Errors While Evaluating Expressions
* Literals::                 Writing Values Directly in Verbs
* Variables::                Naming Values Within a Verb
* Arithmetic::               Arithmetic Operators
* Comparisons::              Comparing Values
* Truth Values::             Values as True and False
* Indexing::                 Indexing into Lists and Strings
* More On Lists::            Other Operations on Lists
* Scattering::               Spreading List Elements Among Variables
* Property Values::          Getting and Setting the Values of Properties
* Calling::                  Calling Built-in Functions and Other Verbs
* Catch::                    Catching Errors in Expressions
* Precedence::               Parentheses and Operator Precedence
@end menu

@node Expression Errors, Literals, Expressions, Expressions
@comment  node-name,  next,  previous,  up
@subsection Errors While Evaluating Expressions

Most kinds of expressions can, under some circumstances, cause an error to be
generated.  For example, the expression @code{x / y} will generate the error
@code{E_DIV} if @code{y} is equal to zero.  When an expression generates an
error, the behavior of the server is controlled by setting of the @samp{d}
(debug) bit on the verb containing that expression.  If the @samp{d} bit is not
set, then the error is effectively squelched immediately upon generation; the
error value is simply returned as the value of the expression that generated
it.

@quotation
@strong{Note:} this error-squelching behavior is very error prone, since it
affects @emph{all} errors, including ones the programmer may not have
anticipated.  The @samp{d} bit exists only for historical reasons; it was once
the only way for MOO programmers to catch and handle errors.  The
error-catching expression and the @code{try}-@code{except} statement, both
described below, are far better ways of accomplishing the same thing.
@end quotation

If the @samp{d} bit is set, as it usually is, then the error is @dfn{raised}
and can be caught and handled either by code surrounding the expression in
question or by verbs higher up on the chain of calls leading to the current
verb.  If the error is not caught, then the server aborts the entire task and,
by default, prints a message to the current player.  See the descriptions of
the error-catching expression and the @code{try}-@code{except} statement for
the details of how errors can be caught, and the chapter on server assumptions
about the database for details on the handling of uncaught errors.

@node Literals, Variables, Expression Errors, Expressions
@comment  node-name,  next,  previous,  up
@subsection Writing Values Directly in Verbs

The simplest kind of expression is a literal MOO value, just as
described in the section on values at the beginning of this document.
For example, the following are all expressions:

@example
17
#893
"This is a character string."
E_TYPE
@{"This", "is", "a", "list", "of", "words"@}
@end example

In the case of lists, like the last example above, note that the list
expression contains other expressions, several character strings in this
case.  In general, those expressions can be of any kind at all, not
necessarily literal values.  For example,
@example
@{3 + 4, 3 - 4, 3 * 4@}
@end example
@noindent
is an expression whose value is the list @code{@{7, -1, 12@}}.

@node Variables, Arithmetic, Literals, Expressions
@comment  node-name,  next,  previous,  up
@subsection Naming Values Within a Verb

As discussed earlier, it is possible to store values in properties on
objects; the properties will keep those values forever, or until another
value is explicitly put there.  Quite often, though, it is useful to
have a place to put a value for just a little while.  MOO provides local
variables for this purpose.

Variables are named places to hold values; you can get and set the value
in a given variable as many times as you like.  Variables are temporary,
though; they only last while a particular verb is running; after it
finishes, all of the variables given values there cease to exist and the
values are forgotten.

Variables are also ``local'' to a particular verb; every verb has its own
set of them.  Thus, the variables set in one verb are not visible to the
code of other verbs.

The name for a variable is made up entirely of letters, digits, and the
underscore character (@samp{_}) and does not begin with a digit.  The
following are all valid variable names:

@example
foo
_foo
this2that
M68000
two_words
This_is_a_very_long_multiword_variable_name
@end example

Note that, along with almost everything else in MOO, the case of the
letters in variable names is insignificant.  For example, these are all
names for the same variable:

@example
fubar
Fubar
FUBAR
fUbAr
@end example

A variable name is itself an expression; its value is the value of the named
variable.  When a verb begins, almost no variables have values yet; if you try
to use the value of a variable that doesn't have one, the error value
@code{E_VARNF} is raised.  (MOO is unlike many other programming languages in
which one must `declare' each variable before using it; MOO has no such
declarations.)  The following variables always have values:

@example
INT         FLOAT        OBJ
STR         LIST         ERR
player      this         caller
verb        args         argstr
dobj        dobjstr      prepstr
iobj        iobjstr      NUM
@end example

The values of some of these variables always start out the same:

@table @code
@item INT
an integer, the type code for integers (see the description of the function
@code{typeof()}, below)
@item NUM
the same as @code{INT} (for historical reasons)
@item FLOAT
an integer, the type code for floating-point numbers
@item LIST
an integer, the type code for lists
@item STR
an integer, the type code for strings
@item OBJ
an integer, the type code for objects
@item ERR
an integer, the type code for error values
@end table

For others, the general meaning of the value is consistent, though the
value itself is different for different situations:

@table @code
@item player
an object, the player who typed the command that started the task that
involved running this piece of code.
@item this
an object, the object on which the currently-running verb was found.
@item caller
an object, the object on which the verb that called the
currently-running verb was found.  For the first verb called for a given
command, @samp{caller} has the same value as @samp{player}.
@item verb
a string, the name by which the currently-running verb was identified.
@item args
a list, the arguments given to this verb.  For the first verb called for
a given command, this is a list of strings, the words on the command
line.
@end table

The rest of the so-called ``built-in'' variables are only really
meaningful for the first verb called for a given command.  Their
semantics is given in the discussion of command parsing, above.

To change what value is stored in a variable, use an @dfn{assignment}
expression:

@example
@var{variable} = @var{expression}
@end example

For example, to change the variable named @samp{x} to have the value 17,
you would write @samp{x = 17} as an expression.  An assignment
expression does two things:

@itemize @bullet
@item
it changes the value of of the named variable, and
@item
it returns the new value of that variable.
@end itemize

@noindent
Thus, the expression

@example
13 + (x = 17)
@end example

@noindent
changes the value of @samp{x} to be 17 and returns 30.

@node Arithmetic, Comparisons, Variables, Expressions
@comment  node-name,  next,  previous,  up
@subsection Arithmetic Operators

All of the usual simple operations on numbers are available to MOO programs:

@example
+    -    *    /    %
@end example

These are, in order, addition, subtraction, multiplication, division, and
remainder.  In the following table, the expressions on the left have the
corresponding values on the right:

@example
5 + 2       @result{}   7
5 - 2       @result{}   3
5 * 2       @result{}   10
5 / 2       @result{}   2
5.0 / 2.0   @result{}   2.5
5 % 2       @result{}   1
5.0 % 2.0   @result{}   1.0
5 % -2      @result{}   1
-5 % 2      @result{}   -1
-5 % -2     @result{}   -1
-(5 + 2)    @result{}   -7
@end example

Note that integer division in MOO throws away the remainder and that the result
of the remainder operator (@samp{%}) has the same sign as the left-hand
operand.  Also, note that @samp{-} can be used without a left-hand operand to
negate a numeric expression.

@quotation
@emph{Fine point:} Integers and floating-point numbers cannot be mixed in any
particular use of these arithmetic operators; unlike some other programming
languages, MOO does not automatically coerce integers into floating-point
numbers.  You can use the @code{tofloat()} function to perform an explicit
conversion.
@end quotation

The @samp{+} operator can also be used to append two strings.  The expression

@example
"foo" + "bar"
@end example

@noindent
has the value

@example
"foobar"
@end example

Unless both operands to an arithmetic operator are numbers of the same kind
(or, for @samp{+}, both strings), the error value @code{E_TYPE} is raised.  If
the right-hand operand for the division or remainder operators (@samp{/} or
@samp{%}) is zero, the error value @code{E_DIV} is raised.

MOO also supports the exponentiation operation, also known as ``raising to a
power,'' using the @samp{^} operator:

@example
3 ^ 4       @result{}   81
3 ^ 4.5     @error{}   E_TYPE
3.5 ^ 4     @result{}   150.0625
3.5 ^ 4.5   @result{}   280.741230801382
@end example

@noindent
Note that if the first operand is an integer, then the second operand must also
be an integer.  If the first operand is a floating-point number, then the
second operand can be either kind of number.  Although it is legal to raise an
integer to a negative power, it is unlikely to be terribly useful.

@node Comparisons, Truth Values, Arithmetic, Expressions
@comment  node-name,  next,  previous,  up
@subsection Comparing Values

Any two values can be compared for equality using @samp{==} and
@samp{!=}.  The first of these returns 1 if the two values are equal and
0 otherwise; the second does the reverse:

@example
3 == 4                              @result{}  0
3 != 4                              @result{}  1
3 == 3.0                            @result{}  0
"foo" == "Foo"                      @result{}  1
#34 != #34                          @result{}  0
@{1, #34, "foo"@} == @{1, #34, "FoO"@}  @result{}  1
E_DIV == E_TYPE                     @result{}  0
3 != "foo"                          @result{}  1
@end example

@noindent
Note that integers and floating-point numbers are never equal to one another,
even in the `obvious' cases.  Also note that comparison of strings (and list
values containing strings) is case-insensitive; that is, it does not
distinguish between the upper- and lower-case version of letters.  To test two
values for case-sensitive equality, use the @samp{equal} function described
later.

@quotation
@strong{Warning}: It is easy (and very annoying) to confuse the
equality-testing operator (@samp{==}) with the assignment operator (@samp{=}),
leading to nasty, hard-to-find bugs.  Don't do this.
@end quotation

Numbers, object numbers, strings, and error values can also be compared
for ordering purposes using the following operators:

@example
<       <=      >=      >
@end example

@noindent
meaning ``less than,'' ``less than or equal,'' ``greater than or
equal,'' and ``greater than,'' respectively.  As with the equality
operators, these return 1 when their operands are in the appropriate
relation and 0 otherwise:

@example
3 < 4           @result{}  1
3 < 4.0         @error{}  E_TYPE
#34 >= #32      @result{}  1
"foo" <= "Boo"  @result{}  0
E_DIV > E_TYPE  @result{}  1
@end example

@noindent
Note that, as with the equality operators, strings are compared
case-insensitively.  To perform a case-sensitive string comparison, use the
@samp{strcmp} function described later.  Also note that the error values are
ordered as given in the table in the section on values.  If the operands to
these four comparison operators are of different types (even integers and
floating-point numbers are considered different types), or if they are lists,
then @code{E_TYPE} is raised.

@node Truth Values, Indexing, Comparisons, Expressions
@comment  node-name,  next,  previous,  up
@subsection Values as True and False

There is a notion in MOO of @dfn{true} and @dfn{false} values; every value
is one or the other.  The true values are as follows:

@itemize @bullet
@item
all integers other than zero,
@item
all floating-point numbers not equal to @code{0.0},
@item
all non-empty strings (i.e., other than @samp{""}), and
@item
all non-empty lists (i.e., other than @samp{@{@}}).
@end itemize

@noindent
All other values are false:

@itemize @bullet
@item
the integer zero,
@item
the floating-point numbers @code{0.0} and @code{-0.0},
@item
the empty string (@samp{""}),
@item
the empty list (@samp{@{@}}),
@item
all object numbers, and
@item
all error values.
@end itemize

There are four kinds of expressions and two kinds of statements that depend
upon this classification of MOO values.  In describing them, I sometimes refer
to the @dfn{truth value} of a MOO value; this is just @dfn{true} or
@dfn{false}, the category into which that MOO value is classified.

The conditional expression in MOO has the following form:

@example
@var{expression-1} ? @var{expression-2} | @var{expression-3}
@end example

First, @var{expression-1} is evaluated.  If it returns a true value, then
@var{expression-2} is evaluated and whatever it returns is returned as the
value of the conditional expression as a whole.  If @var{expression-1} returns
a false value, then @var{expression-3} is evaluated instead and its value is
used as that of the conditional expression.

@example
1 ? 2 | 3           @result{}  2
0 ? 2 | 3           @result{}  3
"foo" ? 17 | @{#34@}  @result{}  17
@end example

@noindent
Note that only one of @var{expression-2} and @var{expression-3} is evaluated,
never both.

To negate the truth value of a MOO value, use the @samp{!} operator:

@example
! @var{expression}
@end example

If the value of @var{expression} is true, @samp{!} returns 0; otherwise, it
returns 1:

@example
! "foo"     @result{}  0
! (3 >= 4)  @result{}  1
@end example

@noindent
The negation operator is usually read as ``not.''

It is frequently useful to test more than one condition to see if some or all
of them are true.  MOO provides two operators for this:

@example
@var{expression-1} && @var{expression-2}
@var{expression-1} || @var{expression-2}
@end example

@noindent
These operators are usually read as ``and'' and ``or,'' respectively.

The @samp{&&} operator first evaluates @var{expression-1}.  If it returns a
true value, then @var{expression-2} is evaluated and its value becomes the
value of the @samp{&&} expression as a whole; otherwise, the value of
@var{expression-1} is used as the value of the @samp{&&} expression.  Note
that @var{expression-2} is only evaluated if @var{expression-1} returns a true
value.  The @samp{&&} expression is equivalent to the conditional expression

@example
@var{expression-1} ? @var{expression-2} | @var{expression-1}
@end example

@noindent
except that @var{expression-1} is only evaluated once.

The @samp{||} operator works similarly, except that @var{expression-2} is
evaluated only if @var{expression-1} returns a false value.  It is equivalent
to the conditional expression

@example
@var{expression-1} ? @var{expression-1} | @var{expression-2}
@end example

@noindent
except that, as with @samp{&&}, @var{expression-1} is only evaluated once.

These two operators behave very much like ``and'' and ``or'' in English:

@example
1 && 1                  @result{}  1
0 && 1                  @result{}  0
0 && 0                  @result{}  0
1 || 1                  @result{}  1
0 || 1                  @result{}  1
0 || 0                  @result{}  0
17 <= 23  &&  23 <= 27  @result{}  1
@end example

@node Indexing, More On Lists, Truth Values, Expressions
@comment  node-name,  next,  previous,  up
@subsection Indexing into Lists and Strings

Both strings and lists can be seen as ordered sequences of MOO values.  In the
case of strings, each is a sequence of single-character strings; that is, one
can view the string @code{"bar"} as a sequence of the strings @code{"b"},
@code{"a"}, and @code{"r"}.  MOO allows you to refer to the elements of lists
and strings by number, by the @dfn{index} of that element in the list or
string.  The first element in a list or string has index 1, the second has
index 2, and so on.

@menu
* Extracting::               Extracting an Element from a List or String
* Replacing::                Replacing an Element of a List or String
* Subsequences::             Extracting a Subsequence of a List or String
* Subsequence Replacement::  Replacing a Subsequence of a List or String
@end menu

@node Extracting, Replacing, Indexing, Indexing
@comment  node-name,  next,  previous,  up
@subsubsection Extracting an Element from a List or String

The indexing expression in MOO extracts a specified element from a list or
string:

@example
@var{expression-1}[@var{expression-2}]
@end example

First, @var{expression-1} is evaluated; it must return a list or a string (the
@dfn{sequence}).  Then, @var{expression-2} is evaluated and must return an
integer (the @dfn{index}).  If either of the expressions returns some other type
of value, @code{E_TYPE} is returned.  The index must be between 1 and the
length of the sequence, inclusive; if it is not, then @code{E_RANGE} is raised.
The value of the indexing expression is the index'th element in the sequence.
Anywhere within @var{expression-2}, you can use the symbol @code{$} as an
expression returning the length of the value of @var{expression-1}.

@example
"fob"[2]                @result{}  "o"
"fob"[1]                @result{}  "f"
@{#12, #23, #34@}[$ - 1]  @result{}  #23
@end example

@noindent
Note that there are no legal indices for the empty string or list, since
there are no integers between 1 and 0 (the length of the empty string or
list).

@quotation
@emph{Fine point:} The @code{$} expression actually returns the length of the
value of the expression just before the nearest enclosing @code{[@dots{}]}
indexing or subranging brackets.  For example:
@example
"frob"[@{3, 2, 4@}[$]]     @result{}  "b"
@end example
@end quotation

@node Replacing, Subsequences, Extracting, Indexing
@comment  node-name,  next,  previous,  up
@subsubsection Replacing an Element of a List or String

It often happens that one wants to change just one particular slot of a list or
string, which is stored in a variable or a property.  This can be done
conveniently using an @dfn{indexed assignment} having one of the following
forms:

@example
@var{variable}[@var{index-expr}] = @var{result-expr}
@var{object-expr}.@var{name}[@var{index-expr}] = @var{result-expr}
@var{object-expr}.(@var{name-expr})[@var{index-expr}] = @var{result-expr}
$@var{name}[@var{index-expr}] = @var{result-expr}
@end example

@noindent
The first form writes into a variable, and the last three forms write into a
property.  The usual errors (@code{E_TYPE}, @code{E_INVIND}, @code{E_PROPNF}
and @code{E_PERM} for lack of read/write permission on the property) may be
raised, just as in reading and writing any object property; see the
discussion of object property expressions below for details.  Correspondingly,
if @var{variable} does not yet have a value (i.e., it has never been assigned
to), @code{E_VARNF} will be raised.

If @var{index-expr} is not an integer, or if the value of @var{variable} or the
property is not a list or string, @code{E_TYPE} is raised.  If
@var{result-expr} is a string, but not of length 1, @code{E_INVARG} is
raised.  Now suppose @var{index-expr} evaluates to an integer @var{k}.  If
@var{k} is outside the range of the list or string (i.e.  smaller than 1 or
greater than the length of the list or string), @code{E_RANGE} is raised.
Otherwise, the actual assignment takes place.  For lists, the variable or the
property is assigned a new list that is identical to the original one except at
the @var{k}-th position, where the new list contains the result of
@var{result-expr} instead.  For strings, the variable or the property is
assigned a new string that is identical to the original one, except the
@var{k}-th character is changed to be @var{result-expr}.

The assignment expression itself returns the value of @var{result-expr}.  For
the following examples, assume that @code{l} initially contains the list
@code{@{1, 2, 3@}} and that @code{s} initially contains the string "foobar":

@example
l[5] = 3          @error{}   E_RANGE
l["first"] = 4    @error{}   E_TYPE
s[3] = "baz"      @error{}   E_INVARG
l[2] = l[2] + 3   @result{}   5
l                 @result{}   @{1, 5, 3@}
l[2] = "foo"      @result{}   "foo"
l                 @result{}   @{1, "foo", 3@}
s[2] = "u"        @result{}   "u"
s                 @result{}   "fuobar"
s[$] = "z"        @result{}   "z"
s                 @result{}   "fuobaz"
@end example

@noindent
Note that the @code{$} expression may also be used in indexed assignments with
the same meaning as before.

@quotation
@emph{Fine point:} After an indexed assignment, the variable or property
contains a @emph{new} list or string, a copy of the original list in all but
the @var{k}-th place, where it contains a new value.  In programming-language
jargon, the original list is not mutated, and there is no aliasing.  (Indeed,
no MOO value is mutable and no aliasing ever occurs.)
@end quotation

In the list case, indexed assignment can be nested to many levels, to work on
nested lists.  Assume that @code{l} initially contains the list

@example
@{@{1, 2, 3@}, @{4, 5, 6@}, "foo"@}
@end example

@noindent
in the following examples:

@example
l[7] = 4             @error{}   E_RANGE
l[1][8] = 35         @error{}   E_RANGE
l[3][2] = 7          @error{}   E_TYPE
l[1][1][1] = 3       @error{}   E_TYPE
l[2][2] = -l[2][2]   @result{}   -5
l                    @result{}   @{@{1, 2, 3@}, @{4, -5, 6@}, "foo"@}
l[2] = "bar"         @result{}   "bar"
l                    @result{}   @{@{1, 2, 3@}, "bar", "foo"@}
l[2][$] = "z"        @result{}   "z"
l                    @result{}   @{@{1, 2, 3@}, "baz", "foo"@}
@end example

@noindent
The first two examples raise @code{E_RANGE} because 7 is out of the range of
@code{l} and 8 is out of the range of @code{l[1]}.  The next two examples
raise @code{E_TYPE} because @code{l[3]} and @code{l[1][1]} are not lists.

@node Subsequences, Subsequence Replacement, Replacing, Indexing
@comment  node-name,  next,  previous,  up
@subsubsection Extracting a Subsequence of a List or String

The range expression extracts a specified subsequence from a list or string:

@example
@var{expression-1}[@var{expression-2}..@var{expression-3}]
@end example

The three expressions are evaluated in order.  @var{Expression-1} must return a
list or string (the @dfn{sequence}) and the other two expressions must return
integers (the @dfn{low} and @dfn{high} indices, respectively); otherwise,
@code{E_TYPE} is raised.  The @code{$} expression can be used in either or both
of @var{expression-2} and @var{expression-3} just as before, meaning the length
of the value of @var{expression-1}.

If the low index is greater than the high index, then the empty string or list
is returned, depending on whether the sequence is a string or a list.
Otherwise, both indices must be between 1 and the length of the sequence;
@code{E_RANGE} is raised if they are not.  A new list or string is returned
that contains just the elements of the sequence with indices between the low
and high bounds.

@example
"foobar"[2..$]                       @result{}  "oobar"
"foobar"[3..3]                       @result{}  "o"
"foobar"[17..12]                     @result{}  ""
@{"one", "two", "three"@}[$ - 1..$]    @result{}  @{"two", "three"@}
@{"one", "two", "three"@}[3..3]        @result{}  @{"three"@}
@{"one", "two", "three"@}[17..12]      @result{}  @{@}
@end example

@node Subsequence Replacement,  , Subsequences, Indexing
@comment  node-name,  next,  previous,  up
@subsubsection Replacing a Subsequence of a List or String

  The subrange assigment replaces a specified subsequence of a list or string
with a supplied subsequence.  The allowed forms are:

@example
@var{variable}[@var{start-index-expr}..@var{end-index-expr}] = @var{result-expr}
@var{object-expr}.@var{name}[@var{start-index-expr}..@var{end-index-expr}] = @var{result-expr}
@var{object-expr}.(@var{name-expr})[@var{start-index-expr}..@var{end-index-expr}] = @var{result-expr}
$@var{name}[@var{start-index-expr}..@var{end-index-expr}] = @var{result-expr}
@end example

As with indexed assigments, the first form writes into a variable, and the last
three forms write into a property.  The same errors (@code{E_TYPE},
@code{E_INVIND}, @code{E_PROPNF} and @code{E_PERM} for lack of read/write
permission on the property) may be raised.  If @var{variable} does not yet have
a value (i.e., it has never been assigned to), @code{E_VARNF} will be raised.
As before, the @code{$} expression can be used in either @var{start-index-expr}
or @var{end-index-expr}, meaning the length of the original value of the
expression just before the @code{[@dots{}]} part.

If @var{start-index-expr} or @var{end-index-expr} is not an integer, if the value
of @var{variable} or the property is not a list or string, or @var{result-expr}
is not the same type as @var{variable} or the property, @code{E_TYPE} is
raised.  @code{E_RANGE} is raised if @var{end-index-expr} is less than zero
or if @var{start-index-expr} is greater than the length of the list or string
plus one.  Note: the length of @var{result-expr} does not need to be the same
as the length of the specified range.

In precise terms, the subrange assigment
@example
@var{v}[@var{start}..@var{end}] = @var{value}
@end example
is equivalent to
@example
@var{v} = @{@@@var{v}[1..@var{start} - 1], @@@var{value}, @@@var{v}[@var{end} + 1..$]@}
@end example
if @var{v} is a list and to
@example
@var{v} = @var{v}[1..@var{start} - 1] + @var{value} + @var{v}[@var{end} + 1..$]
@end example
if @var{v} is a string.

The assigment expression itself returns the value of @var{result-expr}.  For
the following examples, assume that @code{l} initially contains the list
@code{@{1, 2, 3@}} and that @code{s} initially contains the string "foobar":

@example
l[5..6] = @{7, 8@}       @error{}   E_RANGE
l[2..3] = 4            @error{}   E_TYPE
l[#2..3] = @{7@}         @error{}   E_TYPE
s[2..3] = @{6@}          @error{}   E_TYPE
l[2..3] = @{6, 7, 8, 9@} @result{}   @{6, 7, 8, 9@}
l                      @result{}   @{1, 6, 7, 8, 9@}
l[2..1] = @{10, "foo"@}  @result{}   @{10, "foo"@}
l                      @result{}   @{1, 10, "foo", 6, 7, 8, 9@}
l[3][2..$] = "u"       @result{}   "u"
l                      @result{}   @{1, 10, "fu", 6, 7, 8, 9@}
s[7..12] = "baz"       @result{}   "baz"
s                      @result{}   "foobarbaz"
s[1..3] = "fu"         @result{}   "fu"
s                      @result{}   "fubarbaz"
s[1..0] = "test"       @result{}   "test"
s                      @result{}   "testfubarbaz"
@end example

@node More On Lists, Scattering, Indexing, Expressions
@comment  node-name,  next,  previous,  up
@subsection Other Operations on Lists

As was mentioned earlier, lists can be constructed by writing a
comma-separated sequence of expressions inside curly braces:

@example
@{@var{expression-1}, @var{expression-2}, @dots{}, @var{expression-N}@}
@end example

@noindent
The resulting list has the value of @var{expression-1} as its first element,
that of @var{expression-2} as the second, etc.

@example
@{3 < 4, 3 <= 4, 3 >= 4, 3 > 4@}  @result{}  @{1, 1, 0, 0@}
@end example

Additionally, one may precede any of these expressions by the splicing
operator, @samp{@@}.  Such an expression must return a list; rather than the
old list itself becoming an element of the new list, all of the elements of
the old list are included in the new list.  This concept is easy to
understand, but hard to explain in words, so here are some examples.  For
these examples, assume that the variable @code{a} has the value @code{@{2, 3,
4@}} and that @code{b} has the value @code{@{"Foo", "Bar"@}}:

@example
@{1, a, 5@}   @result{}  @{1, @{2, 3, 4@}, 5@}
@{1, @@a, 5@}  @result{}  @{1, 2, 3, 4, 5@}
@{a, @@a@}     @result{}  @{@{2, 3, 4@}, 2, 3, 4@}
@{@@a, @@b@}    @result{}  @{2, 3, 4, "Foo", "Bar"@}
@end example

If the splicing operator (@samp{@@}) precedes an expression whose value
is not a list, then @code{E_TYPE} is raised as the value of the list
construction as a whole.

The list membership expression tests whether or not a given MOO value is an
element of a given list and, if so, with what index:

@example
@var{expression-1} in @var{expression-2}
@end example

@var{Expression-2} must return a list; otherwise, @code{E_TYPE} is raised.
If the value of @var{expression-1} is in that list, then the index of its first
occurrence in the list is returned; otherwise, the @samp{in} expression returns
0.

@example
2 in @{5, 8, 2, 3@}               @result{}  3
7 in @{5, 8, 2, 3@}               @result{}  0
"bar" in @{"Foo", "Bar", "Baz"@}  @result{}  2
@end example

@noindent
Note that the list membership operator is case-insensitive in comparing
strings, just like the comparison operators.  To perform a case-sensitive list
membership test, use the @samp{is_member} function described later.  Note also
that since it returns zero only if the given value is not in the given list,
the @samp{in} expression can be used either as a membership test or as an
element locator.

@node Scattering, Property Values, More On Lists, Expressions
@comment  node-name,  next,  previous,  up
@subsection Spreading List Elements Among Variables

It is often the case in MOO programming that you will want to access the
elements of a list individually, with each element stored in a separate
variables.  This desire arises, for example, at the beginning of almost every
MOO verb, since the arguments to all verbs are delivered all bunched together
in a single list.  In such circumstances, you @emph{could} write statements
like these:

@example
first = args[1];
second = args[2];
if (length(args) > 2)
  third = args[3];
else
  third = 0;
endif
@end example

@noindent
This approach gets pretty tedious, both to read and to write, and it's prone to
errors if you mistype one of the indices.  Also, you often want to check
whether or not any @emph{extra} list elements were present, adding to the
tedium.

MOO provides a special kind of assignment expression, called @dfn{scattering
assignment} made just for cases such as these.  A scattering assignment
expression looks like this:

@example
@{@var{target}, @dots{}@} = @var{expr}
@end example

@noindent
where each @var{target} describes a place to store elements of the list that
results from evaluating @var{expr}.  A @var{target} has one of the following
forms:

@table @code
@item @var{variable}
This is the simplest target, just a simple variable; the list element in the
corresponding position is assigned to the variable.  This is called a
@dfn{required} target, since the assignment is required to put one of the list
elements into the variable.

@item ?@var{variable}
This is called an @dfn{optional} target, since it doesn't always get assigned
an element.  If there are any list elements left over after all of the required
targets have been accounted for (along with all of the other optionals to the
left of this one), then this variable is treated like a required one and the
list element in the corresponding position is assigned to the variable.  If
there aren't enough elements to assign one to this target, then no assignment
is made to this variable, leaving it with whatever its previous value was.

@item ?@var{variable} = @var{default-expr}
This is also an optional target, but if there aren't enough list elements
available to assign one to this target, the result of evaluating
@var{default-expr} is assigned to it instead.  Thus, @var{default-expr}
provides a @dfn{default value} for the variable.  The default value expressions
are evaluated and assigned working from left to right @emph{after} all of the
other assignments have been performed.

@item @@@var{variable}
By analogy with the @code{@@} syntax in list construction, this variable is
assigned a list of all of the `leftover' list elements in this part of the list
after all of the other targets have been filled in.  It is assigned the empty
list if there aren't any elements left over.  This is called a @dfn{rest}
target, since it gets the rest of the elements.  There may be at most one rest
target in each scattering assignment expression.
@end table

@noindent
If there aren't enough list elements to fill all of the required targets, or if
there are more than enough to fill all of the required and optional targets but
there isn't a rest target to take the leftover ones, then @code{E_ARGS} is
raised.

Here are some examples of how this works.  Assume first that the verb
@code{me:foo()} contains the following code:

@example
b = c = e = 17;
@{a, ?b, ?c = 8, @@d, ?e = 9, f@} = args;
return @{a, b, c, d, e, f@};
@end example

@noindent
Then the following calls return the given values:

@example
me:foo(1)                        @error{}   E_ARGS
me:foo(1, 2)                     @result{}   @{1, 17, 8, @{@}, 9, 2@}
me:foo(1, 2, 3)                  @result{}   @{1, 2, 8, @{@}, 9, 3@}
me:foo(1, 2, 3, 4)               @result{}   @{1, 2, 3, @{@}, 9, 4@}
me:foo(1, 2, 3, 4, 5)            @result{}   @{1, 2, 3, @{@}, 4, 5@}
me:foo(1, 2, 3, 4, 5, 6)         @result{}   @{1, 2, 3, @{4@}, 5, 6@}
me:foo(1, 2, 3, 4, 5, 6, 7)      @result{}   @{1, 2, 3, @{4, 5@}, 6, 7@}
me:foo(1, 2, 3, 4, 5, 6, 7, 8)   @result{}   @{1, 2, 3, @{4, 5, 6@}, 7, 8@}
@end example

Using scattering assignment, the example at the begining of this section could
be rewritten more simply, reliably, and readably:

@example
@{first, second, ?third = 0@} = args;
@end example

@noindent
It is good MOO programming style to use a scattering assignment at the top of
nearly every verb, since it shows so clearly just what kinds of arguments the
verb expects.

@node Property Values, Calling, Scattering, Expressions
@comment  node-name,  next,  previous,  up
@subsection Getting and Setting the Values of Properties

Usually, one can read the value of a property on an object with a simple
expression:

@example
@var{expression}.@var{name}
@end example

@var{Expression} must return an object number; if not, @code{E_TYPE} is
raised.  If the object with that number does not exist, @code{E_INVIND} is
raised.  Otherwise, if the object does not have a property with that name,
then @code{E_PROPNF} is raised.  Otherwise, if the named property is not
readable by the owner of the current verb, then @code{E_PERM} is raised.
Finally, assuming that none of these terrible things happens, the value of the
named property on the given object is returned.

I said ``usually'' in the paragraph above because that simple expression only
works if the name of the property obeys the same rules as for the names of
variables (i.e., consists entirely of letters, digits, and underscores, and
doesn't begin with a digit).  Property names are not restricted to this set,
though.  Also, it is sometimes useful to be able to figure out what property
to read by some computation.  For these more general uses, the following
syntax is also allowed:

@example
@var{expression-1}.(@var{expression-2})
@end example

As before, @var{expression-1} must return an object number.  @var{Expression-2}
must return a string, the name of the property to be read; @code{E_TYPE}
is raised otherwise.  Using this syntax, any property can be read,
regardless of its name.

Note that, as with almost everything in MOO, case is not significant in the
names of properties.  Thus, the following expressions are all equivalent:

@example
foo.bar
foo.Bar
foo.("bAr")
@end example

The LambdaCore database uses several properties on @code{#0}, the @dfn{system
object}, for various special purposes.  For example, the value of
@code{#0.room} is the ``generic room'' object, @code{#0.exit} is the ``generic
exit'' object, etc.  This allows MOO programs to refer to these useful objects
more easily (and more readably) than using their object numbers directly.  To
make this usage even easier and more readable, the expression

@example
$@var{name}
@end example

@noindent
(where @var{name} obeys the rules for variable names) is an abbreviation for

@example
#0.@var{name}
@end example

@noindent
Thus, for example, the value @code{$nothing} mentioned earlier is really
@code{#-1}, the value of @code{#0.nothing}.

As with variables, one uses the assignment operator (@samp{=}) to change the
value of a property.  For example, the expression

@example
14 + (#27.foo = 17)
@end example

@noindent
changes the value of the @samp{foo} property of the object numbered 27 to be
17 and then returns 31.  Assignments to properties check that the owner of the
current verb has write permission on the given property, raising
@code{E_PERM} otherwise.  Read permission is not required.

@node Calling, Catch, Property Values, Expressions
@comment  node-name,  next,  previous,  up
@subsection Calling Built-in Functions and Other Verbs

MOO provides a large number of useful functions for performing a wide
variety of operations; a complete list, giving their names, arguments,
and semantics, appears in a separate section later.  As an example to
give you the idea, there is a function named @samp{length} that returns
the length of a given string or list.

The syntax of a call to a function is as follows:

@example
@var{name}(@var{expr-1}, @var{expr-2}, @dots{}, @var{expr-N})
@end example

@noindent
where @var{name} is the name of one of the built-in functions.  The
expressions between the parentheses, called @dfn{arguments}, are each
evaluated in turn and then given to the named function to use in its
appropriate way.  Most functions require that a specific number of arguments
be given; otherwise, @code{E_ARGS} is raised.  Most also require that
certain of the arguments have certain specified types (e.g., the
@code{length()} function requires a list or a string as its argument);
@code{E_TYPE} is raised if any argument has the wrong type.

As with list construction, the splicing operator @samp{@@} can precede
any argument expression.  The value of such an expression must be a
list; @code{E_TYPE} is raised otherwise.  The elements of this list
are passed as individual arguments, in place of the list as a whole.

Verbs can also call other verbs, usually using this syntax:

@example
@var{expr-0}:@var{name}(@var{expr-1}, @var{expr-2}, @dots{}, @var{expr-N})
@end example

@noindent
@var{Expr-0} must return an object number; @code{E_TYPE} is raised otherwise.
If the object with that number does not exist, @code{E_INVIND} is raised.  If
this task is too deeply nested in verbs calling verbs calling verbs, then
@code{E_MAXREC} is raised; the default limit is 50 levels, but this can be
changed from within the database; see the chapter on server assumptions about
the database for details.  If neither the object nor any of its ancestors
defines a verb matching the given name, @code{E_VERBNF} is raised.
Otherwise, if none of these nasty things happens, the named verb on the given
object is called; the various built-in variables have the following initial
values in the called verb:

@table @code
@item this
an object, the value of @var{expr-0}
@item verb
a string, the @var{name} used in calling this verb
@item args
a list, the values of @var{expr-1}, @var{expr-2}, etc.
@item caller
an object, the value of @code{this} in the calling verb
@item player
an object, the same value as it had initially in the calling verb or, if the
calling verb is running with wizard permissions, the same as the current value
in the calling verb.
@end table

@noindent
All other built-in variables (@code{argstr}, @code{dobj}, etc.) are initialized
with the same values they have in the calling verb.

As with the discussion of property references above, I said ``usually'' at the
beginning of the previous paragraph because that syntax is only allowed when
the @var{name} follows the rules for allowed variable names.  Also as with
property reference, there is a syntax allowing you to compute the name of the
verb:

@example
@var{expr-0}:(@var{expr-00})(@var{expr-1}, @var{expr-2}, @dots{}, @var{expr-N})
@end example

@noindent
The expression @var{expr-00} must return a string; @code{E_TYPE} is raised
otherwise.

The splicing operator (@samp{@@}) can be used with verb-call arguments,
too, just as with the arguments to built-in functions.

In many databases, a number of important verbs are defined on @code{#0}, the
@dfn{system object}.  As with the @samp{$foo} notation for properties on
@code{#0}, the server defines a special syntax for calling verbs on @code{#0}:

@example
$@var{name}(@var{expr-1}, @var{expr-2}, @dots{}, @var{expr-N})
@end example

@noindent
(where @var{name} obeys the rules for variable names) is an abbreviation for

@example
#0:@var{name}(@var{expr-1}, @var{expr-2}, @dots{}, @var{expr-N})
@end example

@node Catch, Precedence, Calling, Expressions
@comment  node-name,  next,  previous,  up
@subsection Catching Errors in Expressions

It is often useful to be able to @dfn{catch} an error that an expression
raises, to keep the error from aborting the whole task, and to keep on running
as if the expression had returned some other value normally.  The following
expression accomplishes this:

@example
` @var{expr-1} ! @var{codes} => @var{expr-2} '
@end example

@noindent
@strong{Note:} the open- and close-quotation marks in the previous line are
really part of the syntax; you must actually type them as part of your MOO
program for this kind of expression.

The @var{codes} part is either the keyword @code{ANY} or else a
comma-separated list of expressions, just like an argument list.  As in an
argument list, the splicing operator (@samp{@@}) can be used here.  The
@code{=> @var{expr-2}} part of the error-catching expression is optional.

First, the @var{codes} part is evaluated, yielding a list of error codes that
should be caught if they're raised; if @var{codes} is @code{ANY}, then it is
equivalent to the list of all possible MOO values.

Next, @var{expr-1} is evaluated.  If it evaluates normally, without raising an
error, then its value becomes the value of the entire error-catching
expression.  If evaluating @var{expr-1} results in an error being raised, then
call that error @var{E}.  If @var{E} is in the list resulting from evaluating
@var{codes}, then @var{E} is considered @dfn{caught} by this error-catching
expression.  In such a case, if @var{expr-2} was given, it is evaluated to get
the outcome of the entire error-catching expression; if @var{expr-2} was
omitted, then @var{E} becomes the value of the entire expression.  If @var{E}
is @emph{not} in the list resulting from @var{codes}, then this expression does
not catch the error at all and it continues to be raised, possibly to be caught
by some piece of code either surrounding this expression or higher up on the
verb-call stack.

@noindent
Here are some examples of the use of this kind of expression:

@example
`x + 1 ! E_TYPE => 0'
@end example
@noindent
Returns @code{x + 1} if @code{x} is an integer, returns @code{0} if @code{x} is
not an integer, and raises @code{E_VARNF} if @code{x} doesn't have a value.

@example
`x.y ! E_PROPNF, E_PERM => 17'
@end example
@noindent
Returns @code{x.y} if that doesn't cause an error, @code{17} if @code{x}
doesn't have a @code{y} property or that property isn't readable, and raises
some other kind of error (like @code{E_INVIND}) if @code{x.y} does.

@example
`1 / 0 ! ANY'
@end example
@noindent
Returns @code{E_DIV}.

@node Precedence,  , Catch, Expressions
@comment  node-name,  next,  previous,  up
@subsection Parentheses and Operator Precedence

As shown in a few examples above, MOO allows you to use parentheses to make it
clear how you intend for complex expressions to be grouped.  For example, the
expression

@example
3 * (4 + 5)
@end example

@noindent
performs the addition of 4 and 5 before multiplying the result by 3.

If you leave out the parentheses, MOO will figure out how to group the
expression according to certain rules.  The first of these is that some
operators have higher @dfn{precedence} than others; operators with higher
precedence will more tightly bind to their operands than those with lower
precedence.  For example, multiplication has higher precedence than addition;
thus, if the parentheses had been left out of the expression in the previous
paragraph, MOO would have grouped it as follows:

@example
(3 * 4) + 5
@end example

The table below gives the relative precedence of all of the MOO
operators; operators on higher lines in the table have higher precedence
and those on the same line have identical precedence:

@example
!       - @r{(without a left operand)}
^
*       /       %
+       -
==      !=      <       <=      >       >=      in
&&      ||
@dots{} ? @dots{} | @dots{} @r{(the conditional expression)}
=
@end example

@noindent
Thus, the horrendous expression

@example
x = a < b && c > d + e * f ? w in y | - q - r
@end example

@noindent
would be grouped as follows:

@example
x = (((a < b) && (c > (d + (e * f)))) ? (w in y) | ((- q) - r))
@end example

@noindent
It is best to keep expressions simpler than this and to use parentheses
liberally to make your meaning clear to other humans.

@node Statements, Tasks, Expressions, Language
@comment  node-name,  next,  previous,  up
@section MOO Language Statements

Statements are MOO constructs that, in contrast to expressions, perform some
useful, non-value-producing operation.  For example, there are several kinds of
statements, called `looping constructs', that repeatedly perform some set of
operations.  Fortunately, there are many fewer kinds of statements in MOO than
there are kinds of expressions.

@menu
* Statement Errors::         Errors While Executing Statements
* Simple Statements::        Simple Statements
* Conditionals::             Statements for Testing Conditions
* Iteration::                Statements for Looping
* Breaking::                 Terminating One or All Iterations of a Loop
* Returning::                Returning a Value from a Verb
* Handling Errors::          Handling Errors in Statements
* Finally::                  Cleaning Up After Errors
* Forking::                  Executing Statements at a Later Time
@end menu

@node Statement Errors, Simple Statements, Statements, Statements
@comment  node-name,  next,  previous,  up
@subsection Errors While Executing Statements

Statements do not return values, but some kinds of statements can, under
certain circumstances described below, generate errors.  If such an error is
generated in a verb whose @samp{d} (debug) bit is not set, then the error is
ignored and the statement that generated it is simply skipped; execution
proceeds with the next statement.

@quotation
@strong{Note:} this error-ignoring behavior is very error prone, since it
affects @emph{all} errors, including ones the programmer may not have
anticipated.  The @samp{d} bit exists only for historical reasons; it was once
the only way for MOO programmers to catch and handle errors.  The
error-catching expression and the @code{try}-@code{except} statement are far
better ways of accomplishing the same thing.
@end quotation

If the @samp{d} bit is set, as it usually is, then the error is @dfn{raised}
and can be caught and handled either by code surrounding the expression in
question or by verbs higher up on the chain of calls leading to the current
verb.  If the error is not caught, then the server aborts the entire task and,
by default, prints a message to the current player.  See the descriptions of
the error-catching expression and the @code{try}-@code{except} statement for
the details of how errors can be caught, and the chapter on server assumptions
about the database for details on the handling of uncaught errors.

@node Simple Statements, Conditionals, Statement Errors, Statements
@comment  node-name,  next,  previous,  up
@subsection Simple Statements

The simplest kind of statement is the @dfn{null} statement, consisting of just
a semicolon:

@example
;
@end example

@noindent
It doesn't do anything at all, but it does it very quickly.

The next simplest statement is also one of the most common, the expression
statement, consisting of any expression followed by a semicolon:

@example
@var{expression};
@end example

@noindent
The given expression is evaluated and the resulting value is ignored.
Commonly-used kinds of expressions for such statements include
assignments and verb calls.  Of course, there's no use for such a
statement unless the evaluation of @var{expression} has some side-effect,
such as changing the value of some variable or property, printing some
text on someone's screen, etc.

@node Conditionals, Iteration, Simple Statements, Statements
@comment  node-name,  next,  previous,  up
@subsection Statements for Testing Conditions

The @samp{if} statement allows you to decide whether or not to perform some
statements based on the value of an arbitrary expression:

@example
if (@var{expression})
  @var{statements}
endif
@end example

@noindent
@var{Expression} is evaluated and, if it returns a true value, the statements
are executed in order; otherwise, nothing more is done.

One frequently wants to perform one set of statements if some condition is
true and some other set of statements otherwise.  The optional @samp{else}
phrase in an @samp{if} statement allows you to do this:

@example
if (@var{expression})
  @var{statements-1}
else
  @var{statements-2}
endif
@end example

@noindent
This statement is executed just like the previous one, except that
@var{statements-1} are executed if @var{expression} returns a true value and
@var{statements-2} are executed otherwise.

Sometimes, one needs to test several conditions in a kind of nested
fashion:

@example
if (@var{expression-1})
  @var{statements-1}
else
  if (@var{expression-2})
    @var{statements-2}
  else
    if (@var{expression-3})
      @var{statements-3}
    else
      @var{statements-4}
    endif
  endif
endif
@end example

@noindent
Such code can easily become tedious to write and difficult to read.  MOO
provides a somewhat simpler notation for such cases:

@example
if (@var{expression-1})
  @var{statements-1}
elseif (@var{expression-2})
  @var{statements-2}
elseif (@var{expression-3})
  @var{statements-3}
else
  @var{statements-4}
endif
@end example

@noindent
Note that @samp{elseif} is written as a single word, without any spaces.  This
simpler version has the very same meaning as the original: evaluate
@var{expression-i} for @var{i} equal to 1, 2, and 3, in turn, until one of
them returns a true value; then execute the @var{statements-i} associated with
that expression.  If none of the @var{expression-i} return a true value, then
execute @var{statements-4}.

Any number of @samp{elseif} phrases can appear, each having this form:

@example
elseif (@var{expression}) @var{statements}
@end example

The complete syntax of the @samp{if} statement, therefore, is as follows:

@example
if (@var{expression})
  @var{statements}
@var{zero-or-more-elseif-phrases}
@var{an-optional-else-phrase}
endif
@end example

@node Iteration, Breaking, Conditionals, Statements
@comment  node-name,  next,  previous,  up
@subsection Statements for Looping

MOO provides three different kinds of looping statements, allowing you to have
a set of statements executed (1) once for each element of a given list, (2)
once for each integer or object number in a given range, and (3) over and over
until a given condition stops being true.

To perform some statements once for each element of a given list, use this
syntax:

@example
for @var{variable} in (@var{expression})
  @var{statements}
endfor
@end example

@noindent
The expression is evaluated and should return a list; if it does not,
@code{E_TYPE} is raised.  The @var{statements} are then executed once for
each element of that list in turn; each time, the given @var{variable} is
assigned the value of the element in question.  For example, consider
the following statements:

@example
odds = @{1, 3, 5, 7, 9@};
evens = @{@};
for n in (odds)
  evens = @{@@evens, n + 1@};
endfor
@end example

@noindent
The value of the variable @samp{evens} after executing these statements
is the list

@example
@{2, 4, 6, 8, 10@}
@end example

To perform a set of statements once for each integer or object number in a given
range, use this syntax:

@example
for @var{variable} in [@var{expression-1}..@var{expression-2}]
  @var{statements}
endfor
@end example

@noindent
The two expressions are evaluated in turn and should either both return integers
or both return object numbers; @code{E_TYPE} is raised otherwise.  The
@var{statements} are then executed once for each integer (or object number, as
appropriate) greater than or equal to the value of @var{expression-1} and less
than or equal to the result of @var{expression-2}, in increasing order.  Each
time, the given variable is assigned the integer or object number in question.
For example, consider the following statements:

@example
evens = @{@};
for n in [1..5]
  evens = @{@@evens, 2 * n@};
endfor
@end example

@noindent
The value of the variable @samp{evens} after executing these statements
is just as in the previous example: the list

@example
@{2, 4, 6, 8, 10@}
@end example

The following loop over object numbers prints out the number and name of every
valid object in the database:

@example
for o in [#0..max_object()]
  if (valid(o))
    notify(player, tostr(o, ": ", o.name));
  endif
endfor
@end example

The final kind of loop in MOO executes a set of statements repeatedly as long
as a given condition remains true:

@example
while (@var{expression})
  @var{statements}
endwhile
@end example

@noindent
The expression is evaluated and, if it returns a true value, the
@var{statements} are executed; then, execution of the @samp{while} statement
begins all over again with the evaluation of the expression.  That is,
execution alternates between evaluating the expression and executing the
statements until the expression returns a false value.  The following
example code has precisely the same effect as the loop just shown above:

@example
evens = @{@};
n = 1;
while (n <= 5)
  evens = @{@@evens, 2 * n@};
  n = n + 1;
endwhile
@end example

@quotation
@emph{Fine point:}  It is also possible to give a `name' to a @samp{while}
loop, using this syntax:
 
@example
while @var{name} (@var{expression})
  @var{statements}
endwhile
@end example

@noindent
which has precisely the same effect as

@example
while (@var{name} = @var{expression})
  @var{statements}
endwhile
@end example

@noindent
This naming facility is only really useful in conjunction with the @samp{break}
and @samp{continue} statements, described in the next section.
@end quotation

With each kind of loop, it is possible that the statements in the body of the
loop will never be executed at all.  For iteration over lists, this happens
when the list returned by the expression is empty.  For iteration on integers,
it happens when @var{expression-1} returns a larger integer than
@var{expression-2}.  Finally, for the @samp{while} loop, it happens if the
expression returns a false value the very first time it is evaluated.

@node Breaking, Returning, Iteration, Statements
@comment  node-name,  next,  previous,  up
@subsection Terminating One or All Iterations of a Loop

Sometimes, it is useful to exit a loop before it finishes all of its
iterations.  For example, if the loop is used to search for a particular kind
of element of a list, then it might make sense to stop looping as soon as the
right kind of element is found, even if there are more elements yet to see.
The @samp{break} statement is used for this purpose; it has the form

@example
break;
@end example

@noindent
or

@example
break @var{name};
@end example

@noindent
Each @samp{break} statement indicates a specific surrounding loop; if
@var{name} is not given, the statement refers to the innermost one.  If it is
given, @var{name} must be the name appearing right after the @samp{for} or
@samp{while} keyword of the desired enclosing loop.  When the @samp{break}
statement is executed, the indicated loop is immediately terminated and
executing continues just as if the loop had completed its iterations normally.

MOO also allows you to terminate just the current iteration of a loop, making
it immediately go on to the next one, if any.  The @samp{continue} statement
does this; it has precisely the same forms as the @samp{break} statement:

@example
continue;
@end example

@noindent
or

@example
continue @var{name};
@end example

@node Returning, Handling Errors, Breaking, Statements
@comment  node-name,  next,  previous,  up
@subsection Returning a Value from a Verb

The MOO program in a verb is just a sequence of statements.  Normally, when
the verb is called, those statements are simply executed in order and then the
integer 0 is returned as the value of the verb-call expression.  Using the
@samp{return} statement, one can change this behavior.  The @samp{return}
statement has one of the following two forms:

@example
return;
@end example

@noindent
or

@example
return @var{expression};
@end example

@noindent
When it is executed, execution of the current verb is terminated immediately
after evaluating the given @var{expression}, if any.  The verb-call expression
that started the execution of this verb then returns either the value of
@var{expression} or the integer 0, if no @var{expression} was provided.

@node Handling Errors, Finally, Returning, Statements
@comment  node-name,  next,  previous,  up
@subsection Handling Errors in Statements

Normally, whenever a piece of MOO code raises an error, the entire task is
aborted and a message printed to the user.  Often, such errors can be
anticipated in advance by the programmer and code written to deal with them in
a more graceful manner.  The @code{try}-@code{except} statement allows you to
do this; the syntax is as follows:

@example
try
  @var{statements-0}
except @var{variable-1} (@var{codes-1})
  @var{statements-1}
except @var{variable-2} (@var{codes-2})
  @var{statements-2}
@dots{}
endtry
@end example

@noindent
where the @var{variable}s may be omitted and each @var{codes} part is either
the keyword @code{ANY} or else a comma-separated list of expressions, just like
an argument list.  As in an argument list, the splicing operator (@samp{@@})
can be used here.  There can be anywhere from 1 to 255 @code{except} clauses.

First, each @var{codes} part is evaluated, yielding a list of error codes that
should be caught if they're raised; if a @var{codes} is @code{ANY}, then it is
equivalent to the list of all possible MOO values.

Next, @var{statements-0} is executed; if it doesn't raise an error, then that's
all that happens for the entire @code{try}-@code{except} statement.  Otherwise,
let @var{E} be the error it raises.  From top to bottom, @var{E} is searched
for in the lists resulting from the various @var{codes} parts; if it isn't
found in any of them, then it continues to be raised, possibly to be caught by
some piece of code either surrounding this @code{try}-@code{except} statement
or higher up on the verb-call stack.

If @var{E} is found first in @var{codes-i}, then @var{variable-i} (if provided)
is assigned a value containing information about the error being raised and
@var{statements-i} is executed.  The value assigned to @var{variable-i} is a
list of four elements:
@example
@{@var{code}, @var{message}, @var{value}, @var{traceback}@}
@end example
@noindent
where @var{code} is @var{E}, the error being raised, @var{message} and
@var{value} are as provided by the code that raised the error, and
@var{traceback} is a list like that returned by the @samp{callers()} function,
including line numbers.  The @var{traceback} list contains entries for every
verb from the one that raised the error through the one containing this
@code{try}-@code{except} statement.

Unless otherwise mentioned, all of the built-in errors raised by expressions,
statements, and functions provide @code{tostr(@var{code})} as @var{message} and
zero as @var{value}.

Here's an example of the use of this kind of statement:

@example
try
  result = object:(command)(@@arguments);
  player:tell("=> ", toliteral(result));
except v (ANY)
  tb = v[4];
  if (length(tb) == 1)
    player:tell("** Illegal command: ", v[2]);
  else
    top = tb[1];
    tb[1..1] = @{@};
    player:tell(top[1], ":", top[2], ", line ", top[6], ":",
                v[2]);
    for fr in (tb)
      player:tell("... called from ", fr[1], ":", fr[2],
                  ", line ", fr[6]);
    endfor
    player:tell("(End of traceback)");
  endif
endtry
@end example

@node Finally, Forking, Handling Errors, Statements
@comment  node-name,  next,  previous,  up
@subsection Cleaning Up After Errors

Whenever an error is raised, it is usually the case that at least some MOO code
gets skipped over and never executed.  Sometimes, it's important that a piece
of code @emph{always} be executed, whether or not an error is raised.  Use the
@code{try}-@code{finally} statement for these cases; it has the following
syntax:

@example
try
  @var{statements-1}
finally
  @var{statements-2}
endtry
@end example

@noindent
First, @var{statements-1} is executed; if it completes without raising an
error, returning from this verb, or terminating the current iteration of a
surrounding loop (we call these possibilities @dfn{transferring control}), then
@var{statements-2} is executed and that's all that happens for the entire
@code{try}-@code{finally} statement.

Otherwise, the process of transferring control is interrupted and
@var{statments-2} is executed.  If @var{statements-2} itself completes without
transferring control, then the interrupted control transfer is resumed just
where it left off.  If @var{statements-2} does transfer control, then the
interrupted transfer is simply forgotten in favor of the new one.

In short, this statement ensures that @var{statements-2} is executed after
control leaves @var{statements-1} for whatever reason; it can thus be used to
make sure that some piece of cleanup code is run even if @var{statements-1}
doesn't simply run normally to completion.

Here's an example:

@example
try
  start = time();
  object:(command)(@@arguments);
finally
  end = time();
  this:charge_user_for_seconds(player, end - start);
endtry
@end example

@node Forking,  , Finally, Statements
@comment  node-name,  next,  previous,  up
@subsection Executing Statements at a Later Time

It is sometimes useful to have some sequence of statements execute at a later
time, without human intervention.  For example, one might implement an object
that, when thrown into the air, eventually falls back to the ground; the
@samp{throw} verb on that object should arrange to print a message about the
object landing on the ground, but the message shouldn't be printed until some
number of seconds have passed.

The @samp{fork} statement is intended for just such situations and has the
following syntax:

@example
fork (@var{expression})
  @var{statements}
endfork
@end example

@noindent
The @samp{fork} statement first executes the expression, which must return a
integer; call that integer @var{n}.  It then creates a new MOO @dfn{task} that
will, after at least @var{n} seconds, execute the statements.  When the new
task begins, all variables will have the values they had at the time the
@samp{fork} statement was executed.  The task executing the @samp{fork}
statement immediately continues execution.  The concept of tasks is discussed
in detail in the next section.

By default, there is no limit to the number of tasks any player may fork, but
such a limit can be imposed from within the database.  See the chapter on
server assumptions about the database for details.

Occasionally, one would like to be able to kill a forked task before it even
starts; for example, some player might have caught the object that was thrown
into the air, so no message should be printed about it hitting the ground.  If
a variable name is given after the @samp{fork} keyword, like this:

@example
fork @var{name} (@var{expression})
  @var{statements}
endfork
@end example

@noindent
then that variable is assigned the @dfn{task ID} of the newly-created task.
The value of this variable is visible both to the task executing the fork
statement and to the statements in the newly-created task.  This ID can be
passed to the @code{kill_task()} function to keep the task from running and
will be the value of @code{task_id()} once the task begins execution.

@node Tasks, Builtins, Statements, Language
@comment  node-name,  next,  previous,  up
@section MOO Tasks

A @dfn{task} is an execution of a MOO program.  There are five kinds of tasks
in LambdaMOO:

@itemize @bullet
@item
Every time a player types a command, a task is created to execute that
command; we call these @dfn{command tasks}.
@item
Whenever a player connects or disconnects from the MOO, the server starts a
task to do whatever processing is necessary, such as printing out
@samp{Munchkin has connected} to all of the players in the same room; these
are called @dfn{server tasks}.
@item
The @samp{fork} statement in the programming language creates a task whose
execution is delayed for at least some given number of seconds; these are
@dfn{forked tasks}.
@item 
The @code{suspend()} function suspends the execution of the current task.  A
snapshot is taken of whole state of the execution, and the execution will be
resumed later.  These are called @dfn{suspended tasks}.
@item 
The @code{read()} function also suspends the execution of the current task, in
this case waiting for the player to type a line of input.  When the line is
received, the task resumes with the @code{read()} function returning the input
line as result.  These are called @dfn{reading tasks}.
@end itemize

@noindent
The last three kinds of tasks above are collectively known as @dfn{queued
tasks} or @dfn{background tasks}, since they may not run immediately.

To prevent a maliciously- or incorrectly-written MOO program from running
forever and monopolizing the server, limits are placed on the running time of
every task.  One limit is that no task is allowed to run longer than a certain
number of seconds; command and server tasks get five seconds each while other
tasks get only three seconds.  This limit is, in practice, rarely reached.  The
reason is that there is also a limit on the number of operations a task may
execute.

The server counts down @dfn{ticks} as any task executes.  Roughly speaking, it
counts one tick for every expression evaluation (other than variables and
literals), one for every @samp{if}, @samp{fork} or @samp{return} statement, and
one for every iteration of a loop.  If the count gets all the way down to zero,
the task is immediately and unceremoniously aborted.  By default, command and
server tasks begin with an store of 30,000 ticks; this is enough for almost all
normal uses.  Forked, suspended, and reading tasks are allotted 15,000 ticks
each.  

These limits on seconds and ticks may be changed from within the database, as
can the behavior of the server after it aborts a task for running out; see the
chapter on server assumptions about the database for details.

Because queued tasks may exist for long periods of time before they begin
execution, there are functions to list the ones that you own and to kill them
before they execute.  These functions, among others, are discussed in the
following section.

@node Builtins,  , Tasks, Language
@comment  node-name,  next,  previous,  up
@section Built-in Functions

There are a large number of built-in functions available for use by MOO
programmers.  Each one is discussed in detail in this section.  The
presentation is broken up into subsections by grouping together functions with
similar or related uses.

For most functions, the expected types of the arguments are given; if the
actual arguments are not of these types, @code{E_TYPE} is raised.  Some
arguments can be of any type at all; in such cases, no type specification is
given for the argument.  Also, for most functions, the type of the result of
the function is given.  Some functions do not return a useful result; in such
cases, the specification @samp{none} is used.  A few functions can potentially
return any type of value at all; in such cases, the specification @samp{value}
is used.

Most functions take a certain fixed number of required arguments and, in some
cases, one or two optional arguments.  If a function is called with too many or
too few arguments, @code{E_ARGS} is raised.

Functions are always called by the program for some verb; that program is
running with the permissions of some player, usually the owner of the verb in
question (it is not always the owner, though; wizards can use
@code{set_task_perms()} to change the permissions `on the fly').  In the
function descriptions below, we refer to the player whose permissions are being
used as the @dfn{programmer}.

Many built-in functions are described below as raising @code{E_PERM} unless
the programmer meets certain specified criteria.  It is possible to restrict
use of any function, however, so that only wizards can use it; see the chapter
on server assumptions about the database for details.

@menu
* Passing::                  Object-Oriented Programming
* Manipulating Values::      Manipulating MOO Values
* Manipulating Objects::     Manipulating Objects
* Manipulating Connections::  Operations on Network Connections
* Time::                     Operations Involving Times and Dates
* Evaluation and Tasks::     MOO-Code Evaluation and Task Manipulation
* Administrative::           Administrative Operations
@end menu

@node Passing, Manipulating Values, Builtins, Builtins
@comment  node-name,  next,  previous,  up
@subsection Object-Oriented Programming

One of the most important facilities in an object-oriented programming language
is ability for a child object to make use of a parent's implementation of some
operation, even when the child provides its own definition for that operation.
The @code{pass()} function provides this facility in MOO.

@deftypefun value pass (@var{arg}, @dots{})
Often, it is useful for a child object to define a verb that @emph{augments}
the behavior of a verb on its parent object.  For example, in the LambdaCore
database, the root object (which is an ancestor of every other object) defines
a verb called @samp{description} that simply returns the value of
@code{this.description}; this verb is used by the implementation of the
@code{look} command.  In many cases, a programmer would like the description of
some object to include some non-constant part; for example, a sentence about
whether or not the object was `awake' or `sleeping'.  This sentence should be
added onto the end of the normal description.  The programmer would like to
have a means of calling the normal @code{description} verb and then appending
the sentence onto the end of that description.  The function @samp{pass()} is
for exactly such situations.

@code{pass} calls the verb with the same name as the current verb but as
defined on the parent of the object that defines the current verb.  The
arguments given to @code{pass} are the ones given to the called verb and the
returned value of the called verb is returned from the call to @code{pass}.
The initial value of @code{this} in the called verb is the same as in the
calling verb.

Thus, in the example above, the child-object's @code{description} verb might
have the following implementation:

@example
return pass() + "  It is " + (this.awake ? "awake." | "sleeping.");
@end example

@noindent
That is, it calls its parent's @code{description} verb and then appends to the
result a sentence whose content is computed based on the value of a property on
the object.

In almost all cases, you will want to call @samp{pass()} with the same
arguments as were given to the current verb.  This is easy to write in MOO;
just call @code{pass(@@args)}.
@end deftypefun

@node Manipulating Values, Manipulating Objects, Passing, Builtins
@comment  node-name,  next,  previous,  up
@subsection Manipulating MOO Values

There are several functions for performing primitive operations on MOO values,
and they can be cleanly split into two kinds: those that do various very
general operations that apply to all types of values, and those that are
specific to one particular type.  There are so many operations concerned with
objects that we do not list them in this section but rather give them their own
section following this one.

@menu
* General Operations::       General Operations Applicable to all Values
* Manipulating Numbers::     Operations on Numbers
* Manipulating Strings::     Operations on Strings
* Manipulating Lists::       Operations on Lists
@end menu

@node General Operations, Manipulating Numbers, Manipulating Values, Manipulating Values
@comment  node-name,  next,  previous,  up
@subsubsection General Operations Applicable to all Values

@deftypefun int typeof (@var{value})
Takes any MOO value and returns an integer representing the type of @var{value}.
The result is the same as the initial value of one of these built-in variables:
@code{INT}, @code{FLOAT}, @code{STR}, @code{LIST}, @code{OBJ}, or @code{ERR}.
Thus, one usually writes code like this:

@example
if (typeof(x) == LIST) @dots{}
@end example

@noindent
and not like this:

@example
if (typeof(x) == 3) @dots{}
@end example

@noindent
because the former is much more readable than the latter.
@end deftypefun

@deftypefun str tostr (@var{value}, @dots{})
Converts all of the given MOO values into strings and returns the concatenation
of the results.

@example
tostr(17)                  @result{}   "17"
tostr(1.0/3.0)             @result{}   "0.333333333333333"
tostr(#17)                 @result{}   "#17"
tostr("foo")               @result{}   "foo"
tostr(@{1, 2@})              @result{}   "@{list@}"
tostr(E_PERM)              @result{}   "Permission denied"
tostr("3 + 4 = ", 3 + 4)   @result{}   "3 + 4 = 7"
@end example

@noindent
Note that @code{tostr()} does not do a good job of converting lists into
strings; all lists, including the empty list, are converted into the string
@code{"@{list@}"}.  The function @code{toliteral()}, below, is better for this
purpose.
@end deftypefun

@deftypefun str toliteral (@var{value})
Returns a string containing a MOO literal expression that, when evaluated,
would be equal to @var{value}.

@example
toliteral(17)         @result{}   "17"
toliteral(1.0/3.0)    @result{}   "0.333333333333333"
toliteral(#17)        @result{}   "#17"
toliteral("foo")      @result{}   "\"foo\""
toliteral(@{1, 2@})     @result{}   "@{1, 2@}"
toliteral(E_PERM)     @result{}   "E_PERM"
@end example
@end deftypefun

@deftypefun int toint (@var{value})
@deftypefunx int tonum (@var{value})
Converts the given MOO value into an integer and returns that integer.
Floating-point numbers are rounded toward zero, truncating their fractional
parts.  Object numbers are converted into the equivalent integers.  Strings are
parsed as the decimal encoding of a real number which is then converted to an
integer.  Errors are converted into integers obeying the same ordering (with
respect to @code{<=} as the errors themselves.  @code{Toint()} raises
@code{E_TYPE} if @var{value} is a list.  If @var{value} is a string but the
string does not contain a syntactically-correct number, then @code{toint()}
returns 0.

@example
toint(34.7)        @result{}   34
toint(-34.7)       @result{}   -34
toint(#34)         @result{}   34
toint("34")        @result{}   34
toint("34.7")      @result{}   34
toint(" - 34  ")   @result{}   -34
toint(E_TYPE)      @result{}   1
@end example
@end deftypefun

@deftypefun obj toobj (@var{value})
Converts the given MOO value into an object number and returns that object
number.  The conversions are very similar to those for @code{toint()} except
that for strings, the number @emph{may} be preceded by @samp{#}.

@example
toobj("34")       @result{}   #34
toobj("#34")      @result{}   #34
toobj("foo")      @result{}   #0
toobj(@{1, 2@})     @error{}   E_TYPE
@end example
@end deftypefun

@deftypefun float tofloat (@var{value})
Converts the given MOO value into a floating-point number and returns that
number.  Integers and object numbers are converted into the corresponding
integral floating-point numbers.  Strings are parsed as the decimal encoding of
a real number which is then represented as closely as possible as a
floating-point number.  Errors are first converted to integers as in
@code{toint()} and then converted as integers are.  @code{Tofloat()} raises
@code{E_TYPE} if @var{value} is a list.  If @var{value} is a string but the
string does not contain a syntactically-correct number, then @code{tofloat()}
returns 0.

@example
tofloat(34)          @result{}   34.0
tofloat(#34)         @result{}   34.0
tofloat("34")        @result{}   34.0
tofloat("34.7")      @result{}   34.7
tofloat(E_TYPE)      @result{}   1.0
@end example
@end deftypefun

@deftypefun int equal (@var{value1}, @var{value2})
Returns true if @var{value1} is completely indistinguishable from @var{value2}.
This is much the same operation as ``@code{@var{value1} == @var{value2}}''
except that, unlike @code{==}, the @code{equal()} function does not treat
upper- and lower-case characters in strings as equal.

@example
"Foo" == "foo"         @result{}   1
equal("Foo", "foo")    @result{}   0
equal("Foo", "Foo")    @result{}   1
@end example
@end deftypefun

@deftypefun int value_bytes (@var{value})
Returns the number of bytes of the server's memory required to store the given
@var{value}.
@end deftypefun

@deftypefun str value_hash (@var{value})
Returns the same string as @code{string_hash(toliteral(@var{value}))}; see the
description of @code{string_hash()} for details.
@end deftypefun

@node Manipulating Numbers, Manipulating Strings, General Operations, Manipulating Values
@comment  node-name,  next,  previous,  up
@subsubsection Operations on Numbers

@deftypefun int random ([int @var{mod}])
@var{mod} must be a positive integer; otherwise, @code{E_INVARG} is raised.  An
integer is chosen randomly from the range @code{[1..@var{mod}]} and returned.
If @var{mod} is not provided, it defaults to the largest MOO integer,
2147483647.
@end deftypefun

@deftypefun num min (num @var{x}, @dots{})
@deftypefunx num max (num @var{x}, @dots{})
These two functions return the smallest or largest of their arguments,
respectively.  All of the arguments must be numbers of the same kind (i.e.,
either integer or floating-point); otherwise @code{E_TYPE} is raised.
@end deftypefun

@deftypefun num abs (num @var{x})
Returns the absolute value of @var{x}.  If @var{x} is negative, then the result
is @code{-@var{x}}; otherwise, the result is @var{x}.  The number @var{x} can
be either integer or floating-point; the result is of the same kind.
@end deftypefun

@deftypefun str floatstr(float @var{x}, int @var{precision} [, @var{scientific}])
Converts @var{x} into a string with more control than provided by either
@code{tostr()} or @code{toliteral()}.  @var{Precision} is the number of digits
to appear to the right of the decimal point, capped at 4 more than the maximum
available precision, a total of 19 on most machines; this makes it possible to
avoid rounding errors if the resulting string is subsequently read back as a
floating-point value.  If @var{scientific} is false or not provided, the result
is a string in the form @code{"MMMMMMM.DDDDDD"}, preceded by a minus sign if
and only if @var{x} is negative.  If @var{scientific} is provided and true, the
result is a string in the form @code{"M.DDDDDDe+EEE"}, again preceded by a
minus sign if and only if @var{x} is negative.
@end deftypefun

@deftypefun float sqrt (float @var{x})
Returns the square root of @var{x}.  Raises @code{E_INVARG} if @var{x} is
negative.
@end deftypefun

@deftypefun float sin (float @var{x})
@deftypefunx float cos (float @var{x})
@deftypefunx float tan (float @var{x})
Returns the sine, cosine, or tangent of @var{x}, respectively.
@end deftypefun

@deftypefun float asin (float @var{x})
@deftypefunx float acos (float @var{x})
Returns the arc-sine or arc-cosine (inverse sine or cosine) of @var{x}, in the
range @code{[-pi/2..pi/2]} or @code{[0..pi]}, respectively.  Raises
@code{E_INVARG} if @var{x} is outside the range @code{[-1.0..1.0]}.
@end deftypefun

@deftypefun float atan (float @var{y} [, float @var{x}])
Returns the arc-tangent (inverse tangent) of @var{y} in the range
@code{[-pi/2..pi/2]} if @var{x} is not provided, or of @code{@var{y}/@var{x}}
in the range @code{[-pi..pi]} if @var{x} is provided.
@end deftypefun

@deftypefun float sinh (float @var{x})
@deftypefunx float cosh (float @var{x})
@deftypefunx float tanh (float @var{x})
Returns the hyperbolic sine, cosine, or tangent of @var{x}, respectively.
@end deftypefun

@deftypefun float exp (float @var{x})
Returns @var{e} raised to the power of @var{x}.
@end deftypefun

@deftypefun float log (float @var{x})
@deftypefunx float log10 (float @var{x})
Returns the natural or base 10 logarithm of @var{x}.  Raises @code{E_INVARG} if
@var{x} is not positive.
@end deftypefun

@deftypefun float ceil (float @var{x})
Returns the smallest integer not less than @var{x}, as a floating-point number.
@end deftypefun

@deftypefun float floor (float @var{x})
Returns the largest integer not greater than @var{x}, as a floating-point
number.
@end deftypefun

@deftypefun float trunc (float @var{x})
Returns the integer obtained by truncating @var{x} at the decimal point, as a
floating-point number.  For negative @var{x}, this is equivalent to
@code{ceil()}; otherwise it is equivalent to @code{floor()}.
@end deftypefun

@node Manipulating Strings, Manipulating Lists, Manipulating Numbers, Manipulating Values
@comment  node-name,  next,  previous,  up
@subsubsection Operations on Strings

@deftypefun int length (str @var{string})
Returns the number of characters in @var{string}.  It is also permissible to
pass a list to @code{length()}; see the description in the next section.

@example
length("foo")   @result{}   3
length("")      @result{}   0
@end example
@end deftypefun

@deftypefun str strsub (str @var{subject}, str @var{what}, str @var{with} [, @var{case-matters}])
Replaces all occurrences in @var{subject} of @var{what} with @var{with},
performing string substitution.  The occurrences are found from left to right
and all substitutions happen simultaneously.  By default, occurrences of
@var{what} are searched for while ignoring the upper/lower case distinction.
If @var{case-matters} is provided and true, then case is treated as significant
in all comparisons.

@example
strsub("%n is a fink.", "%n", "Fred")   @result{}   "Fred is a fink."
strsub("foobar", "OB", "b")             @result{}   "fobar"
strsub("foobar", "OB", "b", 1)          @result{}   "foobar"
@end example
@end deftypefun

@deftypefun int index (str @var{str1}, str @var{str2} [, @var{case-matters}])
@deftypefunx int rindex (str @var{str1}, str @var{str2} [, @var{case-matters}])
The function @code{index()} (@code{rindex()}) returns the index of the first
character of the first (last) occurrence of @var{str2} in @var{str1}, or zero
if @var{str2} does not occur in @var{str1} at all.  By default the search for
an occurrence of @var{str2} is done while ignoring the upper/lower case
distinction.  If @var{case-matters} is provided and true, then case is treated
as significant in all comparisons.

@example
index("foobar", "o")        @result{}   2
rindex("foobar", "o")       @result{}   3
index("foobar", "x")        @result{}   0
index("foobar", "oba")      @result{}   3
index("Foobar", "foo", 1)   @result{}   0
@end example
@end deftypefun

@deftypefun int strcmp (str @var{str1}, str @var{str2})
Performs a case-sensitive comparison of the two argument strings.  If
@var{str1} is lexicographically less than @var{str2}, the
@code{strcmp()} returns a negative integer.  If the two strings are
identical, @code{strcmp()} returns zero.  Otherwise, @code{strcmp()}
returns a positive integer.  The ASCII character ordering is used for the
comparison.
@end deftypefun

@deftypefun list decode_binary (str @var{bin-string} [, @var{fully}])
Returns a list of strings and/or integers representing the bytes in the binary
string @var{bin_string} in order.  If @var{fully} is false or omitted, the list
contains an integer only for each non-printing, non-space byte; all other
characters are grouped into the longest possible contiguous substrings.  If
@var{fully} is provided and true, the list contains only integers, one for each
byte represented in @var{bin_string}.  Raises @code{E_INVARG} if
@var{bin_string} is not a properly-formed binary string.  (See the early
section on MOO value types for a full description of binary strings.)

@example
decode_binary("foo")               @result{}   @{"foo"@}
decode_binary("~~foo")             @result{}   @{"~foo"@}
decode_binary("foo~0D~0A")         @result{}   @{"foo", 13, 10@}
decode_binary("foo~0Abar~0Abaz")   @result{}   @{"foo", 10, "bar", 10, "baz"@}
decode_binary("foo~0D~0A", 1)      @result{}   @{102, 111, 111, 13, 10@}
@end example
@end deftypefun

@deftypefun str encode_binary (@var{arg}, @dots{})
Each argument must be an integer between 0 and 255, a string, or a list
containing only legal arguments for this function.  This function translates
each integer and string in turn into its binary string equivalent, returning the
concatenation of all these substrings into a single binary string.  (See the
early section on MOO value types for a full description of binary strings.)

@example
encode_binary("~foo")                     @result{}   "~7Efoo"
encode_binary(@{"foo", 10@}, @{"bar", 13@})   @result{}   "foo~0Abar~0D"
encode_binary("foo", 10, "bar", 13)       @result{}   "foo~0Abar~0D"
@end example
@end deftypefun

@deftypefun list match (str @var{subject}, str @var{pattern} [, @var{case-matters}])
@deftypefunx list rmatch (str @var{subject}, str @var{pattern} [, @var{case-matters}])
The function @code{match()} (@code{rmatch()}) searches for the first (last)
occurrence of the regular expression @var{pattern} in the string @var{subject}.
If @var{pattern} is syntactically malformed, then @code{E_INVARG} is raised.
The process of matching can in some cases consume a great deal of memory in the
server; should this memory consumption become excessive, then the matching
process is aborted and @code{E_QUOTA} is raised.

If no match is found, the empty list is returned; otherwise, these functions
return a list containing information about the match (see below).  By default,
the search ignores upper-/lower-case distinctions.  If @var{case-matters} is
provided and true, then case is treated as significant in all comparisons.

The list that @code{match()} (@code{rmatch()}) returns contains the details
about the match made.  The list is in the form:

@example
@{@var{start}, @var{end}, @var{replacements}, @var{subject}@}
@end example

@noindent
where @var{start} is the index in @var{subject} of the beginning of the match,
@var{end} is the index of the end of the match, @var{replacements} is a list
described below, and @var{subject} is the same string that was given as the
first argument to the @code{match()} or @code{rmatch()}.

The @var{replacements} list is always nine items long, each item itself being a
list of two integers, the start and end indices in @var{string} matched by some
parenthesized sub-pattern of @var{pattern}.  The first item in
@var{replacements} carries the indices for the first parenthesized sub-pattern,
the second item carries those for the second sub-pattern, and so on.  If there
are fewer than nine parenthesized sub-patterns in @var{pattern}, or if some
sub-pattern was not used in the match, then the corresponding item in
@var{replacements} is the list @{0, -1@}.  See the discussion of @samp{%)},
below, for more information on parenthesized sub-patterns.

@example
match("foo", "^f*o$")        @result{}  @{@}
match("foo", "^fo*$")        @result{}  @{1, 3, @{@{0, -1@}, @dots{}@}, "foo"@}
match("foobar", "o*b")       @result{}  @{2, 4, @{@{0, -1@}, @dots{}@}, "foobar"@}
rmatch("foobar", "o*b")      @result{}  @{4, 4, @{@{0, -1@}, @dots{}@}, "foobar"@}
match("foobar", "f%(o*%)b")
        @result{}  @{1, 4, @{@{2, 3@}, @{0, -1@}, @dots{}@}, "foobar"@}
@end example

@dfn{Regular expression} matching allows you to test whether a string fits into
a specific syntactic shape.  You can also search a string for a substring that
fits a pattern.

A regular expression describes a set of strings.  The simplest case is one that
describes a particular string; for example, the string @samp{foo} when regarded
as a regular expression matches @samp{foo} and nothing else.  Nontrivial
regular expressions use certain special constructs so that they can match more
than one string.  For example, the regular expression @samp{foo%|bar} matches
either the string @samp{foo} or the string @samp{bar}; the regular expression
@samp{c[ad]*r} matches any of the strings @samp{cr}, @samp{car}, @samp{cdr},
@samp{caar}, @samp{cadddar} and all other such strings with any number of
@samp{a}'s and @samp{d}'s.

Regular expressions have a syntax in which a few characters are special
constructs and the rest are @dfn{ordinary}.  An ordinary character is a simple
regular expression that matches that character and nothing else.  The special
characters are @samp{$}, @samp{^}, @samp{.}, @samp{*}, @samp{+}, @samp{?},
@samp{[}, @samp{]} and @samp{%}.  Any other character appearing in a regular
expression is ordinary, unless a @samp{%} precedes it.

For example, @samp{f} is not a special character, so it is ordinary, and
therefore @samp{f} is a regular expression that matches the string @samp{f} and
no other string.  (It does @emph{not}, for example, match the string
@samp{ff}.)  Likewise, @samp{o} is a regular expression that matches only
@samp{o}.

Any two regular expressions @var{a} and @var{b} can be concatenated.  The
result is a regular expression which matches a string if @var{a} matches some
amount of the beginning of that string and @var{b} matches the rest of the
string.

As a simple example, we can concatenate the regular expressions @samp{f} and
@samp{o} to get the regular expression @samp{fo}, which matches only the string
@samp{fo}.  Still trivial.

The following are the characters and character sequences that have special
meaning within regular expressions.  Any character not mentioned here is not
special; it stands for exactly itself for the purposes of searching and
matching.

@table @samp
@item .
is a special character that matches any single character.  Using concatenation,
we can make regular expressions like @samp{a.b}, which matches any
three-character string that begins with @samp{a} and ends with @samp{b}.

@item *
is not a construct by itself; it is a suffix that means that the preceding
regular expression is to be repeated as many times as possible.  In @samp{fo*},
the @samp{*} applies to the @samp{o}, so @samp{fo*} matches @samp{f} followed
by any number of @samp{o}'s.

The case of zero @samp{o}'s is allowed: @samp{fo*} does match @samp{f}.

@samp{*} always applies to the @emph{smallest} possible preceding expression.
Thus, @samp{fo*} has a repeating @samp{o}, not a repeating @samp{fo}.

The matcher processes a @samp{*} construct by matching, immediately, as many
repetitions as can be found.  Then it continues with the rest of the pattern.
If that fails, it backtracks, discarding some of the matches of the @samp{*}'d
construct in case that makes it possible to match the rest of the pattern.  For
example, matching @samp{c[ad]*ar} against the string @samp{caddaar}, the
@samp{[ad]*} first matches @samp{addaa}, but this does not allow the next
@samp{a} in the pattern to match.  So the last of the matches of @samp{[ad]} is
undone and the following @samp{a} is tried again.  Now it succeeds.

@item +
@samp{+} is like @samp{*} except that at least one match for the preceding
pattern is required for @samp{+}.  Thus, @samp{c[ad]+r} does not match
@samp{cr} but does match anything else that @samp{c[ad]*r} would match.

@item ?
@samp{?} is like @samp{*} except that it allows either zero or one match for
the preceding pattern.  Thus, @samp{c[ad]?r} matches @samp{cr} or @samp{car} or
@samp{cdr}, and nothing else.

@item [ @dots{} ]
@samp{[} begins a @dfn{character set}, which is terminated by a @samp{]}.  In
the simplest case, the characters between the two brackets form the set.  Thus,
@samp{[ad]} matches either @samp{a} or @samp{d}, and @samp{[ad]*} matches any
string of @samp{a}'s and @samp{d}'s (including the empty string), from which it
follows that @samp{c[ad]*r} matches @samp{car}, etc.

Character ranges can also be included in a character set, by writing two
characters with a @samp{-} between them.  Thus, @samp{[a-z]} matches any
lower-case letter.  Ranges may be intermixed freely with individual characters,
as in @samp{[a-z$%.]}, which matches any lower case letter or @samp{$},
@samp{%} or period.

Note that the usual special characters are not special any more inside a
character set.  A completely different set of special characters exists inside
character sets: @samp{]}, @samp{-} and @samp{^}.

To include a @samp{]} in a character set, you must make it the first character.
For example, @samp{[]a]} matches @samp{]} or @samp{a}.  To include a @samp{-},
you must use it in a context where it cannot possibly indicate a range: that
is, as the first character, or immediately after a range.

@item [^ @dots{} ]
@samp{[^} begins a @dfn{complement character set}, which matches any character
except the ones specified.  Thus, @samp{[^a-z0-9A-Z]} matches all characters
@emph{except} letters and digits.

@samp{^} is not special in a character set unless it is the first character.
The character following the @samp{^} is treated as if it were first (it may be
a @samp{-} or a @samp{]}).

@item ^
is a special character that matches the empty string -- but only if at the
beginning of the string being matched.  Otherwise it fails to match anything.
Thus, @samp{^foo} matches a @samp{foo} which occurs at the beginning of the
string.

@item $
is similar to @samp{^} but matches only at the @emph{end} of the string.  Thus,
@samp{xx*$} matches a string of one or more @samp{x}'s at the end of the
string.

@item %
has two functions: it quotes the above special characters (including @samp{%}),
and it introduces additional special constructs.

Because @samp{%} quotes special characters, @samp{%$} is a regular expression
that matches only @samp{$}, and @samp{%[} is a regular expression that matches
only @samp{[}, and so on.

For the most part, @samp{%} followed by any character matches only that
character.  However, there are several exceptions: characters that, when
preceded by @samp{%}, are special constructs.  Such characters are always
ordinary when encountered on their own.

No new special characters will ever be defined.  All extensions to the regular
expression syntax are made by defining new two-character constructs that begin
with @samp{%}.

@item %|
specifies an alternative.  Two regular expressions @var{a} and @var{b} with
@samp{%|} in between form an expression that matches anything that either
@var{a} or @var{b} will match.

Thus, @samp{foo%|bar} matches either @samp{foo} or @samp{bar} but no other
string.

@samp{%|} applies to the largest possible surrounding expressions.  Only a
surrounding @samp{%( @dots{} %)} grouping can limit the grouping power of
@samp{%|}.

Full backtracking capability exists for when multiple @samp{%|}'s are used.

@item %( @dots{} %)
is a grouping construct that serves three purposes:

@enumerate 1
@item
To enclose a set of @samp{%|} alternatives for other operations.  Thus,
@samp{%(foo%|bar%)x} matches either @samp{foox} or @samp{barx}.

@item
To enclose a complicated expression for a following @samp{*}, @samp{+}, or
@samp{?} to operate on.  Thus, @samp{ba%(na%)*} matches @samp{bananana}, etc.,
with any number of @samp{na}'s, including none.

@item
To mark a matched substring for future reference.
@end enumerate

This last application is not a consequence of the idea of a parenthetical
grouping; it is a separate feature that happens to be assigned as a second
meaning to the same @samp{%( @dots{} %)} construct because there is no conflict
in practice between the two meanings.  Here is an explanation of this feature:

@item %@var{digit}
After the end of a @samp{%( @dots{} %)} construct, the matcher remembers the
beginning and end of the text matched by that construct.  Then, later on in the
regular expression, you can use @samp{%} followed by @var{digit} to mean
``match the same text matched by the @var{digit}'th @samp{%( @dots{} %)}
construct in the pattern.''  The @samp{%( @dots{} %)} constructs are numbered
in the order that their @samp{%(}'s appear in the pattern.

The strings matching the first nine @samp{%( @dots{} %)} constructs appearing
in a regular expression are assigned numbers 1 through 9 in order of their
beginnings.  @samp{%1} through @samp{%9} may be used to refer to the text
matched by the corresponding @samp{%( @dots{} %)} construct.

For example, @samp{%(.*%)%1} matches any string that is composed of two
identical halves.  The @samp{%(.*%)} matches the first half, which may be
anything, but the @samp{%1} that follows must match the same exact text.

@item %b
matches the empty string, but only if it is at the beginning or
end of a word.  Thus, @samp{%bfoo%b} matches any occurrence of
@samp{foo} as a separate word.  @samp{%bball%(s%|%)%b} matches
@samp{ball} or @samp{balls} as a separate word.

For the purposes of this construct and the five that follow, a word is defined
to be a sequence of letters and/or digits.

@item %B
matches the empty string, provided it is @emph{not} at the beginning or
end of a word.

@item %<
matches the empty string, but only if it is at the beginning
of a word.

@item %>
matches the empty string, but only if it is at the end of a word.

@item %w
matches any word-constituent character (i.e., any letter or digit).

@item %W
matches any character that is not a word constituent.
@end table
@end deftypefun

@deftypefun str substitute (str @var{template}, list @var{subs})
Performs a standard set of substitutions on the string @var{template}, using
the information contained in @var{subs}, returning the resulting, transformed
@var{template}.  @var{Subs} should be a list like those returned by
@code{match()} or @code{rmatch()} when the match succeeds; otherwise,
@code{E_INVARG} is raised.

In @var{template}, the strings @samp{%1} through @samp{%9} will be replaced by
the text matched by the first through ninth parenthesized sub-patterns when
@code{match()} or @code{rmatch()} was called.  The string @samp{%0} in
@var{template} will be replaced by the text matched by the pattern as a whole
when @code{match()} or @code{rmatch()} was called.  The string @samp{%%} will
be replaced by a single @samp{%} sign.  If @samp{%} appears in @var{template}
followed by any other character, @code{E_INVARG} will be raised.

@example
subs = match("*** Welcome to LambdaMOO!!!", "%(%w*%) to %(%w*%)");
substitute("I thank you for your %1 here in %2.", subs)
        @result{}   "I thank you for your Welcome here in LambdaMOO."
@end example
@end deftypefun

@deftypefun str crypt (str @var{text} [, str @var{salt}])
Encrypts the given @var{text} using the standard UNIX encryption method.  If
provided, @var{salt} should be a string at least two characters long, the first
two characters of which will be used as the extra encryption ``salt'' in the
algorithm.  If @var{salt} is not provided, a random pair of characters is used.
In any case, the salt used is also returned as the first two characters of the
resulting encrypted string.

Aside from the possibly-random selection of the salt, the encryption algorithm
is entirely deterministic.  In particular, you can test whether or not a given
string is the same as the one used to produce a given piece of encrypted text;
simply extract the first two characters of the encrypted text and pass the
candidate string and those two characters to @code{crypt()}.  If the result is
identical to the given encrypted text, then you've got a match.

@example
crypt("foobar")         @result{}   "J3fSFQfgkp26w"
crypt("foobar", "J3")   @result{}   "J3fSFQfgkp26w"
crypt("mumble", "J3")   @result{}   "J3D0.dh.jjmWQ"
crypt("foobar", "J4")   @result{}   "J4AcPxOJ4ncq2"
@end example
@end deftypefun

@deftypefun str string_hash (str @var{text})
@deftypefunx str binary_hash (str @var{bin-string})
Returns a 32-character hexadecimal string encoding the result of applying the
MD5 cryptographically secure hash function to the contents of the string
@var{text} or the binary string @var{bin-string}.  MD5, like other such
functions, has the property that, if
@example
string_hash(@var{x}) == string_hash(@var{y})
@end example
@noindent
then, almost certainly,
@example
equal(@var{x}, @var{y})
@end example
@noindent
This can be useful, for example, in certain networking applications: after
sending a large piece of text across a connection, also send the result of
applying @code{string_hash()} to the text; if the destination site also
applies @code{string_hash()} to the text and gets the same result, you can be
quite confident that the large text has arrived unchanged.
@end deftypefun

@node Manipulating Lists,  , Manipulating Strings, Manipulating Values
@comment  node-name,  next,  previous,  up
@subsubsection Operations on Lists

@deftypefun int length (list @var{list})
Returns the number of elements in @var{list}.  It is also permissible to
pass a string to @code{length()}; see the description in the previous
section.

@example
length(@{1, 2, 3@})   @result{}   3
length(@{@})          @result{}   0
@end example
@end deftypefun

@deftypefun int is_member (@var{value}, list @var{list})
Returns true if there is an element of @var{list} that is completely
indistinguishable from @var{value}.  This is much the same operation as
``@code{@var{value} in @var{list}}'' except that, unlike @code{in}, the
@code{is_member()} function does not treat upper- and lower-case characters in
strings as equal.

@example
"Foo" in @{1, "foo", #24@}            @result{}   2
is_member("Foo", @{1, "foo", #24@})   @result{}   0
is_member("Foo", @{1, "Foo", #24@})   @result{}   2
@end example
@end deftypefun

@deftypefun list listinsert (list @var{list}, @var{value} [, int @var{index}])
@deftypefunx list listappend (list @var{list}, @var{value} [, int @var{index}])
These functions return a copy of @var{list} with @var{value} added as a new
element.  @code{listinsert()} and @code{listappend()} add @var{value} before
and after (respectively) the existing element with the given @var{index}, if
provided.

The following three expressions always have the same value:

@example
listinsert(@var{list}, @var{element}, @var{index})
listappend(@var{list}, @var{element}, @var{index} - 1)
@{@@@var{list}[1..@var{index} - 1], @var{element}, @@@var{list}[@var{index}..length(@var{list})]@}
@end example

If @var{index} is not provided, then @code{listappend()} adds the @var{value}
at the end of the list and @code{listinsert()} adds it at the beginning; this
usage is discouraged, however, since the same intent can be more clearly
expressed using the list-construction expression, as shown in the examples
below.

@example
x = @{1, 2, 3@};
listappend(x, 4, 2)   @result{}   @{1, 2, 4, 3@}
listinsert(x, 4, 2)   @result{}   @{1, 4, 2, 3@}
listappend(x, 4)      @result{}   @{1, 2, 3, 4@}
listinsert(x, 4)      @result{}   @{4, 1, 2, 3@}
@{@@x, 4@}               @result{}   @{1, 2, 3, 4@}
@{4, @@x@}               @result{}   @{4, 1, 2, 3@}
@end example
@end deftypefun

@deftypefun list listdelete (list @var{list}, int @var{index})
Returns a copy of @var{list} with the @var{index}th element removed.  If
@var{index} is not in the range @code{[1..length(@var{list})]}, then
@code{E_RANGE} is raised.

@example
x = @{"foo", "bar", "baz"@};
listdelete(x, 2)   @result{}   @{"foo", "baz"@}
@end example
@end deftypefun

@deftypefun list listset (list @var{list}, @var{value}, int @var{index})
Returns a copy of @var{list} with the @var{index}th element replaced by
@var{value}.  If @var{index} is not in the range
@code{[1..length(@var{list})]}, then @code{E_RANGE} is raised.

@example
x = @{"foo", "bar", "baz"@};
listset(x, "mumble", 2)   @result{}   @{"foo", "mumble", "baz"@}
@end example

@noindent
This function exists primarily for historical reasons; it was used heavily
before the server supported indexed assignments like @code{x[i] = v}.  New code
should always use indexed assignment instead of @samp{listset()} wherever
possible.
@end deftypefun

@deftypefun list setadd (list @var{list}, @var{value})
@deftypefunx list setremove (list @var{list}, @var{value})
Returns a copy of @var{list} with the given @var{value} added or removed, as
appropriate.  @code{setadd()} only adds @var{value} if it is not already an
element of @var{list}; @var{list} is thus treated as a mathematical set.
@var{value} is added at the end of the resulting list, if at all.  Similarly,
@code{setremove()} returns a list identical to @var{list} if @var{value} is not
an element.  If @var{value} appears more than once in @var{list}, only the
first occurrence is removed in the returned copy.

@example
setadd(@{1, 2, 3@}, 3)         @result{}   @{1, 2, 3@}
setadd(@{1, 2, 3@}, 4)         @result{}   @{1, 2, 3, 4@}
setremove(@{1, 2, 3@}, 3)      @result{}   @{1, 2@}
setremove(@{1, 2, 3@}, 4)      @result{}   @{1, 2, 3@}
setremove(@{1, 2, 3, 2@}, 2)   @result{}   @{1, 3, 2@}
@end example
@end deftypefun

@node Manipulating Objects, Manipulating Connections, Manipulating Values, Builtins
@comment  node-name,  next,  previous,  up
@subsection Manipulating Objects

Objects are, of course, the main focus of most MOO programming and, largely due
to that, there are a lot of built-in functions for manipulating them.

@menu
* Fundamentals::             Fundamental Operations on Objects
* Movement::                 Object Movement
* Property Functions::       Operations on Properties
* Verb Functions::           Operations on Verbs
* Manipulating Players::     Operations on Player Objects
@end menu

@node Fundamentals, Movement, Manipulating Objects, Manipulating Objects
@comment  node-name,  next,  previous,  up
@subsubsection Fundamental Operations on Objects

@deftypefun obj create (obj @var{parent} [, obj @var{owner}])
Creates and returns a new object whose parent is @var{parent} and whose owner
is as described below.  Either the given @var{parent} object must be @code{#-1}
or valid and fertile (i.e., its @samp{f} bit must be set) or else the
programmer must own @var{parent} or be a wizard; otherwise @code{E_PERM} is
raised.  @code{E_PERM} is also raised if @var{owner} is provided and not
the same as the programmer, unless the programmer is a wizard.  After the new
object is created, its @code{initialize} verb, if any, is called with no
arguments.

The new object is assigned the least non-negative object number that has not
yet been used for a created object.  Note that no object number is ever reused,
even if the object with that number is recycled.

The owner of the new object is either the programmer (if @var{owner} is not
provided), the new object itself (if @var{owner} was given as @code{#-1}), or
@var{owner} (otherwise).

The other built-in properties of the new object are initialized as follows:
@example
name         ""
location     #-1
contents     @{@}
programmer   0
wizard       0
r            0
w            0
f            0
@end example
The function @samp{is_player()} returns false for newly created objects.

In addition, the new object inherits all of the other properties on
@var{parent}.  These properties have the same permission bits as on
@var{parent}.  If the @samp{c} permissions bit is set, then the owner of the
property on the new object is the same as the owner of the new object itself;
otherwise, the owner of the property on the new object is the same as that on
@var{parent}.  The initial value of every inherited property is @dfn{clear};
see the description of the built-in function @code{clear_property()} for
details.

If the intended owner of the new object has a property named
@samp{ownership_quota} and the value of that property is an integer, then
@code{create()} treats that value as a @dfn{quota}.  If the quota is less than
or equal to zero, then the quota is considered to be exhausted and
@code{create()} raises @code{E_QUOTA} instead of creating an object.
Otherwise, the quota is decremented and stored back into the
@samp{ownership_quota} property as a part of the creation of the new object.
@end deftypefun

@deftypefun none chparent (obj @var{object}, obj @var{new-parent})
Changes the parent of @var{object} to be @var{new-parent}.  If @var{object} is
not valid, or if @var{new-parent} is neither valid nor equal to @code{#-1},
then @code{E_INVARG} is raised.  If the programmer is neither a wizard or the
owner of @var{object}, or if @var{new-parent} is not fertile (i.e., its
@samp{f} bit is not set) and the programmer is neither the owner of
@var{new-parent} nor a wizard, then @code{E_PERM} is raised.  If
@var{new-parent} is equal to @code{object} or one of its current ancestors,
@code{E_RECMOVE} is raised.  If @var{object} or one of its descendants
defines a property with the same name as one defined either on @var{new-parent}
or on one of its ancestors, then @code{E_INVARG} is raised.

Changing an object's parent can have the effect of removing some properties
from and adding some other properties to that object and all of its descendants
(i.e., its children and its children's children, etc.).  Let @var{common} be
the nearest ancestor that @var{object} and @var{new-parent} have in common
before the parent of @var{object} is changed.  Then all properties defined by
ancestors of @var{object} under @var{common} (that is, those ancestors of
@var{object} that are in turn descendants of @var{common}) are removed from
@var{object} and all of its descendants.  All properties defined by
@var{new-parent} or its ancestors under @var{common} are added to @var{object}
and all of its descendants.  As with @code{create()}, the newly-added
properties are given the same permission bits as they have on @var{new-parent},
the owner of each added property is either the owner of the object it's added
to (if the @samp{c} permissions bit is set) or the owner of that property on
@var{new-parent}, and the value of each added property is @dfn{clear}; see the
description of the built-in function @code{clear_property()} for details.  All
properties that are not removed or added in the reparenting process are
completely unchanged.

If @var{new-parent} is equal to @code{#-1}, then @var{object} is given no
parent at all; it becomes a new root of the parent/child hierarchy.  In this
case, all formerly inherited properties on @var{object} are simply removed.
@end deftypefun

@deftypefun int valid (obj @var{object})
Returns a non-zero integer (i.e., a true value) if @var{object} is a valid
object (one that has been created and not yet recycled) and zero (i.e., a false
value) otherwise.

@example
valid(#0)    @result{}   1
valid(#-1)   @result{}   0
@end example
@end deftypefun

@deftypefun obj parent (obj @var{object})
@deftypefunx list children (obj @var{object})
These functions return the parent and a list of the children of @var{object},
respectively.  If @var{object} is not valid, then @code{E_INVARG} is raised.
@end deftypefun

@deftypefun none recycle (obj @var{object})
The given @var{object} is destroyed, irrevocably.  The programmer must either
own @var{object} or be a wizard; otherwise, @code{E_PERM} is raised.  If
@var{object} is not valid, then @code{E_INVARG} is raised.  The children of
@var{object} are reparented to the parent of @var{object}.  Before @var{object}
is recycled, each object in its contents is moved to @code{#-1} (implying a
call to @var{object}'s @code{exitfunc} verb, if any) and then @var{object}'s
@samp{recycle} verb, if any, is called with no arguments.

After @var{object} is recycled, if the owner of the former object has a
property named @samp{ownership_quota} and the value of that property is a
integer, then @code{recycle()} treats that value as a @dfn{quota} and increments
it by one, storing the result back into the @samp{ownership_quota} property.
@end deftypefun

@deftypefun int object_bytes (obj @var{object})
Returns the number of bytes of the server's memory required to store the given
@var{object}, including the space used by the values of all of its non-clear
properties and by the verbs and properties defined directly on the object.
Raised @code{E_INVARG} if @var{object} is not a valid object and @code{E_PERM}
if the programmer is not a wizard.
@end deftypefun

@deftypefun obj max_object ()
Returns the largest object number yet assigned to a created object.  Note that
the object with this number may no longer exist; it may have been recycled.
The next object created will be assigned the object number one larger than the
value of @code{max_object()}.
@end deftypefun

@node Movement, Property Functions, Fundamentals, Manipulating Objects
@comment  node-name,  next,  previous,  up
@subsubsection Object Movement

@deftypefun none move (obj @var{what}, obj @var{where})
Changes @var{what}'s location to be @var{where}.  This is a complex process
because a number of permissions checks and notifications must be performed.
The actual movement takes place as described in the following paragraphs.

@var{what} should be a valid object and @var{where} should be either a valid
object or @code{#-1} (denoting a location of `nowhere'); otherwise
@code{E_INVARG} is raised.  The programmer must be either the owner of
@var{what} or a wizard; otherwise, @code{E_PERM} is raised.

If @var{where} is a valid object, then the verb-call

@example
@var{where}:accept(@var{what})
@end example

@noindent
is performed before any movement takes place.  If the verb returns a
false value and the programmer is not a wizard, then @var{where} is
considered to have refused entrance to @var{what}; @code{move()} raises
@code{E_NACC}.  If @var{where} does not define an @code{accept} verb, then it
is treated as if it defined one that always returned false.

If moving @var{what} into @var{where} would create a loop in the containment
hierarchy (i.e., @var{what} would contain itself, even indirectly), then
@code{E_RECMOVE} is raised instead.

The @samp{location} property of @var{what} is changed to be @var{where}, and
the @samp{contents} properties of the old and new locations are modified
appropriately.  Let @var{old-where} be the location of @var{what} before it was
moved.  If @var{old-where} is a valid object, then the verb-call

@example
@var{old-where}:exitfunc(@var{what})
@end example

@noindent
is performed and its result is ignored; it is not an error if @var{old-where}
does not define a verb named @samp{exitfunc}.  Finally, if @var{where} and
@var{what} are still valid objects, and @var{where} is still the location of
@var{what}, then the verb-call

@example
@var{where}:enterfunc(@var{what})
@end example

@noindent
is performed and its result is ignored; again, it is not an error if
@var{where} does not define a verb named @samp{enterfunc}.
@end deftypefun

@node Property Functions, Verb Functions, Movement, Manipulating Objects
@comment  node-name,  next,  previous,  up
@subsubsection Operations on Properties

@deftypefun list properties (obj @var{object})
Returns a list of the names of the properties defined directly on the given
@var{object}, not inherited from its parent.  If @var{object} is not valid,
then @code{E_INVARG} is raised.  If the programmer does not have read
permission on @var{object}, then @code{E_PERM} is raised.
@end deftypefun

@deftypefun list property_info (obj @var{object}, str @var{prop-name})
@deftypefunx none set_property_info (obj @var{object}, str @var{prop-name}, list @var{info})
These two functions get and set (respectively) the owner and permission bits
for the property named @var{prop-name} on the given @var{object}.  If
@var{object} is not valid, then @code{E_INVARG} is raised.  If @var{object}
has no non-built-in property named @var{prop-name}, then @code{E_PROPNF} is
raised.  If the programmer does not have read (write) permission on the
property in question, then @code{property_info()} (@code{set_property_info()})
raises @code{E_PERM}.  Property info has the following form:

@example
@{@var{owner}, @var{perms} [, @var{new-name}]@}
@end example

@noindent
where @var{owner} is an object, @var{perms} is a string containing only
characters from the set @samp{r}, @samp{w}, and @samp{c}, and @var{new-name} is
a string; @var{new-name} is never part of the value returned by
@code{property_info()}, but it may optionally be given as part of the value
provided to @code{set_property_info()}.  This list is the kind of value
returned by @code{property_info()} and expected as the third argument to
@code{set_property_info()}; the latter function raises @code{E_INVARG} if
@var{owner} is not valid, if @var{perms} contains any illegal characters, or,
when @var{new-name} is given, if @var{prop-name} is not defined directly on
@var{object} or @var{new-name} names an existing property defined on
@var{object} or any of its ancestors or descendants.
@end deftypefun

@deftypefun none add_property (obj @var{object}, str @var{prop-name}, @var{value}, list @var{info})
Defines a new property on the given @var{object}, inherited by all of its
descendants; the property is named @var{prop-name}, its initial value is
@var{value}, and its owner and initial permission bits are given by @var{info}
in the same format as is returned by @code{property_info()}, described above.
If @var{object} is not valid or @var{info} does not specify a valid owner and
well-formed permission bits or @var{object} or its ancestors or descendants
already defines a property named @var{prop-name}, then @code{E_INVARG} is
raised.  If the programmer does not have write permission on @var{object} or
if the owner specified by @var{info} is not the programmer and the programmer
is not a wizard, then @code{E_PERM} is raised.
@end deftypefun

@deftypefun none delete_property (obj @var{object}, str @var{prop-name})
Removes the property named @var{prop-name} from the given @var{object} and all
of its descendants.  If @var{object} is not valid, then @code{E_INVARG} is
raised.  If the programmer does not have write permission on @var{object},
then @code{E_PERM} is raised.  If @var{object} does not directly define a
property named @var{prop-name} (as opposed to inheriting one from its parent),
then @code{E_PROPNF} is raised.
@end deftypefun

@deftypefun int is_clear_property (obj @var{object}, str @var{prop-name})
@deftypefunx none clear_property (obj @var{object}, str @var{prop-name})
These two functions test for clear and set to clear, respectively, the property
named @var{prop-name} on the given @var{object}.  If @var{object} is not valid,
then @code{E_INVARG} is raised.  If @var{object} has no non-built-in property
named @var{prop-name}, then @code{E_PROPNF} is raised.  If the programmer
does not have read (write) permission on the property in question, then
@code{is_clear_property()} (@code{clear_property()}) raises @code{E_PERM}.
If a property is clear, then when the value of that property is queried the
value of the parent's property of the same name is returned.  If the parent's
property is clear, then the parent's parent's value is examined, and so on.
If @var{object} is the definer of the property @var{prop-name}, as opposed to
an inheritor of the property, then @code{clear_property()} raises
@code{E_INVARG}.
@end deftypefun

@node Verb Functions, Manipulating Players, Property Functions, Manipulating Objects
@comment  node-name,  next,  previous,  up
@subsubsection Operations on Verbs

@deftypefun list verbs (obj @var{object})
Returns a list of the names of the verbs defined directly on the given
@var{object}, not inherited from its parent.  If @var{object} is not valid,
then @code{E_INVARG} is raised.  If the programmer does not have read
permission on @var{object}, then @code{E_PERM} is raised.
@end deftypefun

Most of the remaining operations on verbs accept a string containing the verb's
name to identify the verb in question.  Because verbs can have multiple names
and because an object can have multiple verbs with the same name, this practice
can lead to difficulties.  To most unambiguously refer to a particular verb,
one can instead use a positive integer, the index of the verb in the list
returned by @code{verbs()}, described above.

For example, suppose that @code{verbs(#34)} returns this list:

@example
@{"foo", "bar", "baz", "foo"@}
@end example

@noindent
Object @code{#34} has two verbs named @samp{foo} defined on it (this may not be
an error, if the two verbs have different command syntaxes).  To refer
unambiguously to the first one in the list, one uses the integer 1; to refer to
the other one, one uses 4.

In the function descriptions below, an argument named @var{verb-desc} is either
a string containing the name of a verb or else a positive integer giving the
index of that verb in its defining object's @code{verbs()} list.

@quotation
For historical reasons, there is also a second, inferior mechanism for
referring to verbs with numbers, but its use is strongly discouraged.  If the
property @code{$server_options.support_numeric_verbname_strings} exists with a
true value, then functions on verbs will also accept a numeric string (e.g.,
@code{"4"}) as a verb descriptor.  The decimal integer in the string works
more-or-less like the positive integers described above, but with two
significant differences:

@enumerate 1
@item
The numeric string is a @emph{zero-based} index into @code{verbs()}; that is,
in the string case, you would use the number one less than what you would use
in the positive integer case.

@item
When there exists a verb whose actual name looks like a decimal integer, this
numeric-string notation is ambiguous; the server will in all cases assume that
the reference is to the first verb in the list for which the given string could
be a name, either in the normal sense or as a numeric index.
@end enumerate

@noindent
Clearly, this older mechanism is more difficult and risky to use; new code
should only be written to use the current mechanism, and old code using numeric
strings should be modified not to do so.
@end quotation

@deftypefun list verb_info (obj @var{object}, str @var{verb-desc})
@deftypefunx none set_verb_info (obj @var{object}, str @var{verb-desc}, list @var{info})
These two functions get and set (respectively) the owner, permission bits, and
name(s) for the verb as specified by @var{verb-desc} on the given @var{object}.
If @var{object} is not valid, then @code{E_INVARG} is raised.  If @var{object}
does not define a verb as specified by @var{verb-desc}, then @code{E_VERBNF} is
raised.  If the programmer does not have read (write) permission on the verb in
question, then @code{verb_info()} (@code{set_verb_info()}) raises
@code{E_PERM}.  Verb info has the following form:

@example
@{@var{owner}, @var{perms}, @var{names}@}
@end example

@noindent
where @var{owner} is an object, @var{perms} is a string containing only
characters from the set @samp{r}, @samp{w}, @samp{x}, and @samp{d}, and
@var{names} is a string.  This is the kind of value returned by
@code{verb_info()} and expected as the third argument to
@code{set_verb_info()}.  @code{set_verb_info()} raises @code{E_INVARG} if
@var{owner} is not valid, if @var{perms} contains any illegal characters, or if
@var{names} is the empty string or consists entirely of spaces; it raises
@code{E_PERM} if @var{owner} is not the programmer and the programmer is not a
wizard.
@end deftypefun

@deftypefun list verb_args (obj @var{object}, str @var{verb-desc})
@deftypefunx none set_verb_args (obj @var{object}, str @var{verb-desc}, list @var{args})
These two functions get and set (respectively) the direct-object, preposition,
and indirect-object specifications for the verb as specified by @var{verb-desc}
on the given @var{object}.  If @var{object} is not valid, then @code{E_INVARG}
is raised.  If @var{object} does not define a verb as specified by
@var{verb-desc}, then @code{E_VERBNF} is raised.  If the programmer does not
have read (write) permission on the verb in question, then @code{verb_args()}
(@code{set_verb_args()}) raises @code{E_PERM}.  Verb args specifications have
the following form:

@example
@{@var{dobj}, @var{prep}, @var{iobj}@}
@end example

@noindent
where @var{dobj} and @var{iobj} are strings drawn from the set @code{"this"},
@code{"none"}, and @code{"any"}, and @var{prep} is a string that is either
@code{"none"}, @code{"any"}, or one of the prepositional phrases listed much
earlier in the description of verbs in the first chapter.  This is the kind of
value returned by @code{verb_args()} and expected as the third argument to
@code{set_verb_args()}.  Note that for @code{set_verb_args()}, @var{prep} must
be only one of the prepositional phrases, not (as is shown in that table) a set
of such phrases separated by @samp{/} characters.  @code{set_verb_args} raises
@code{E_INVARG} if any of the @var{dobj}, @var{prep}, or @var{iobj} strings is
illegal.

@example
verb_args($container, "take")
                    @result{}   @{"any", "out of/from inside/from", "this"@}
set_verb_args($container, "take", @{"any", "from", "this"@})
@end example
@end deftypefun

@deftypefun none add_verb (obj @var{object}, list @var{info}, list @var{args})
Defines a new verb on the given @var{object}.  The new verb's owner, permission
bits and name(s) are given by @var{info} in the same format as is returned by
@code{verb_info()}, described above.  The new verb's direct-object,
preposition, and indirect-object specifications are given by @var{args} in the
same format as is returned by @code{verb_args}, described above.  The new verb
initially has the empty program associated with it; this program does nothing
but return an unspecified value.

If @var{object} is not valid, or @var{info} does not specify a valid owner and
well-formed permission bits and verb names, or @var{args} is not a legitimate
syntax specification, then @code{E_INVARG} is raised.  If the programmer does
not have write permission on @var{object} or if the owner specified by
@var{info} is not the programmer and the programmer is not a wizard, then
@code{E_PERM} is raised.
@end deftypefun

@deftypefun none delete_verb (obj @var{object}, str @var{verb-desc})
Removes the verb as specified by @var{verb-desc} from the given @var{object}.
If @var{object} is not valid, then @code{E_INVARG} is raised.  If the
programmer does not have write permission on @var{object}, then @code{E_PERM}
is raised.  If @var{object} does not define a verb as specified by
@var{verb-desc}, then @code{E_VERBNF} is raised.
@end deftypefun

@deftypefun list verb_code (obj @var{object}, str @var{verb-desc} [, @var{fully-paren} [, @var{indent}]])
@deftypefunx list set_verb_code (obj @var{object}, str @var{verb-desc}, list @var{code})
These functions get and set (respectively) the MOO-code program associated with
the verb as specified by @var{verb-desc} on @var{object}.  The program is
represented as a list of strings, one for each line of the program; this is the
kind of value returned by @code{verb_code()} and expected as the third argument
to @code{set_verb_code()}.  For @code{verb_code()}, the expressions in the
returned code are usually written with the minimum-necessary parenthesization;
if @var{full-paren} is true, then all expressions are fully parenthesized.
Also for @code{verb_code()}, the lines in the returned code are usually not
indented at all; if @var{indent} is true, each line is indented to better show
the nesting of statements.

If @var{object} is not valid, then @code{E_INVARG} is raised.  If @var{object}
does not define a verb as specified by @var{verb-desc}, then @code{E_VERBNF} is
raised.  If the programmer does not have read (write) permission on the verb in
question, then @code{verb_code()} (@code{set_verb_code()}) raises
@code{E_PERM}.  If the programmer is not, in fact. a programmer, then
@code{E_PERM} is raised.

For @code{set_verb_code()}, the result is a list of strings, the error messages
generated by the MOO-code compiler during processing of @var{code}.  If the
list is non-empty, then @code{set_verb_code()} did not install @var{code}; the
program associated with the verb in question is unchanged.
@end deftypefun

@deftypefun list disassemble (obj @var{object}, str @var{verb-desc})
Returns a (longish) list of strings giving a listing of the server's internal
``compiled'' form of the verb as specified by @var{verb-desc} on @var{object}.
This format is not documented and may indeed change from release to release,
but some programmers may nonetheless find the output of @code{disassemble()}
interesting to peruse as a way to gain a deeper appreciation of how the server
works.

If @var{object} is not valid, then @code{E_INVARG} is raised.  If @var{object}
does not define a verb as specified by @var{verb-desc}, then @code{E_VERBNF} is
raised.  If the programmer does not have read permission on the verb in
question, then @code{disassemble()} raises @code{E_PERM}.
@end deftypefun

@node Manipulating Players,  , Verb Functions, Manipulating Objects
@comment  node-name,  next,  previous,  up
@subsubsection Operations on Player Objects

@deftypefun list players ()
Returns a list of the object numbers of all player objects in the database.
@end deftypefun

@deftypefun int is_player (obj @var{object})
Returns a true value if the given @var{object} is a player object and a false
value otherwise.  If @var{object} is not valid, @code{E_INVARG} is raised.
@end deftypefun

@deftypefun none set_player_flag (obj @var{object}, @var{value})
Confers or removes the ``player object'' status of the given @var{object},
depending upon the truth value of @var{value}.  If @var{object} is not valid,
@code{E_INVARG} is raised.  If the programmer is not a wizard, then
@code{E_PERM} is raised.

If @var{value} is true, then @var{object} gains (or keeps) ``player object''
status: it will be an element of the list returned by @code{players()}, the
expression @code{is_player(@var{object})} will return true, and the server will
treat a call to @code{$do_login_command()} that returns @var{object} as
logging in the current connection.

If @var{value} is false, the @var{object} loses (or continues to lack) ``player
object'' status: it will not be an element of the list returned by
@code{players()}, the expression @code{is_player(@var{object})} will return
false, and users cannot connect to @var{object} by name when they log into the
server.  In addition, if a user is connected to @var{object} at the time that
it loses ``player object'' status, then that connection is immediately broken,
just as if @code{boot_player(@var{object})} had been called (see the
description of @code{boot_player()} below).
@end deftypefun

@node Manipulating Connections, Time, Manipulating Objects, Builtins
@comment  node-name,  next,  previous,  up
@subsection Operations on Network Connections

@deftypefun list connected_players ([@var{include-all}])
Returns a list of the object numbers of those player objects with
currently-active connections.  If @var{include-all} is provided and true, then
the list includes the object numbers associated with @emph{all} current
connections, including ones that are outbound and/or not yet logged-in.
@end deftypefun

@deftypefun int connected_seconds (obj @var{player})
@deftypefunx int idle_seconds (obj @var{player})
These functions return the number of seconds that the currently-active
connection to @var{player} has existed and been idle, respectively.  If
@var{player} is not the object number of a player object with a
currently-active connection, then @code{E_INVARG} is raised.
@end deftypefun

@deftypefun none notify (obj @var{conn}, str @var{string} [, @var{no-flush}])
Enqueues @var{string} for output (on a line by itself) on the connection
@var{conn}.  If the programmer is not @var{conn} or a wizard, then
@code{E_PERM} is raised.  If @var{conn} is not a currently-active connection,
then this function does nothing.  Output is normally written to connections
only between tasks, not during execution.

The server will not queue an arbitrary amount of output for a connection; the
@code{MAX_QUEUED_OUTPUT} compilation option (in @samp{options.h}) controls the
limit.  When an attempt is made to enqueue output that would take the server
over its limit, it first tries to write as much output as possible to the
connection without having to wait for the other end.  If that doesn't result in
the new output being able to fit in the queue, the server starts throwing away
the oldest lines in the queue until the new ouput will fit.  The server
remembers how many lines of output it has `flushed' in this way and, when next
it can succeed in writing anything to the connection, it first writes a line
like @code{>> Network buffer overflow: @var{X} lines of output to you have been
lost <<} where @var{X} is the number of flushed lines.

If @var{no-flush} is provided and true, then @code{notify()} never flushes any
output from the queue; instead it immediately returns false.  @code{Notify()}
otherwise always returns true.
@end deftypefun

@deftypefun int buffered_output_length ([obj @var{conn}])
Returns the number of bytes currently buffered for output to the connection
@var{conn}.  If @var{conn} is not provided, returns the maximum number of bytes
that will be buffered up for output on any connection.
@end deftypefun

@deftypefun str read ([obj @var{conn} [, @var{non-blocking}]])
Reads and returns a line of input from the connection @var{conn} (or, if not
provided, from the player that typed the command that initiated the current
task).  If @var{non-blocking} is false or not provided, this function suspends
the current task, resuming it when there is input available to be read.  If
@var{non-blocking} is provided and true, this function never suspends the
calling task; if there is no input currently available for input, @code{read()}
simply returns 0 immediately.

If @var{player} is provided, then the programmer must either be a wizard or the
owner of @code{player}; if @code{player} is not provided, then @code{read()}
may only be called by a wizard and only in the task that was last spawned by a
command from the connection in question.  Otherwise, @code{E_PERM} is raised.
If the given @code{player} is not currently connected and has no pending lines
of input, or if the connection is closed while a task is waiting for input but
before any lines of input are received, then @code{read()} raises
@code{E_INVARG}.

The restriction on the use of @code{read()} without any arguments preserves the
following simple invariant: if input is being read from a player, it is for the
task started by the last command that player typed.  This invariant adds
responsibility to the programmer, however.  If your program calls another verb
before doing a @code{read()}, then either that verb must not suspend or else
you must arrange that no commands will be read from the connection in the
meantime.  The most straightforward way to do this is to call
@example
set_connection_option(player, "hold-input", 1)
@end example
@noindent
before any task suspension could happen, then make all of your calls to
@code{read()} and other code that might suspend, and finally call
@example
set_connection_option(player, "hold-input", 0)
@end example
@noindent
to allow commands once again to be read and interpreted normally.
@end deftypefun

@deftypefun none force_input (obj @var{conn}, str @var{line} [, @var{at-front}])
Inserts the string @var{line} as an input task in the queue for the connection
@var{conn}, just as if it had arrived as input over the network.  If
@var{at_front} is provided and true, then the new line of input is put at the
front of @var{conn}'s queue, so that it will be the very next line of input
processed even if there is already some other input in that queue.  Raises
@code{E_INVARG} if @var{conn} does not specify a current connection and
@code{E_PERM} if the programmer is neither @var{conn} nor a wizard.
@end deftypefun

@deftypefun none flush_input (obj @var{conn} [@var{show-messages}])
Performs the same actions as if the connection @var{conn}'s defined flush
command had been received on that connection, i.e., removes all pending lines
of input from @var{conn}'s queue and, if @var{show-messages} is provided and
true, prints a message to @var{conn} listing the flushed lines, if any.  See
the chapter on server assumptions about the database for more information about
a connection's defined flush command.
@end deftypefun

@deftypefun list output_delimiters (obj @var{player})
Returns a list of two strings, the current @dfn{output prefix} and @dfn{output
suffix} for @var{player}.  If @var{player} does not have an active network
connection, then @code{E_INVARG} is raised.  If either string is currently
undefined, the value @code{""} is used instead.  See the discussion of the
@code{PREFIX} and @code{SUFFIX} commands in the next chapter for more
information about the output prefix and suffix.
@end deftypefun

@deftypefun none boot_player (obj @var{player})
Marks for disconnection any currently-active connection to the given
@var{player}.  The connection will not actually be closed until the
currently-running task returns or suspends, but all MOO functions (such as
@code{notify()}, @code{connected_players()}, and the like) immediately behave
as if the connection no longer exists.  If the programmer is not either a
wizard or the same as @var{player}, then @code{E_PERM} is raised.  If there
is no currently-active connection to @var{player}, then this function does
nothing.

If there was a currently-active connection, then the following verb call is
made when the connection is actually closed:

@example
$user_disconnected(@var{player})
@end example

@noindent
It is not an error if this verb does not exist; the call is simply skipped.
@end deftypefun

@deftypefun str connection_name (obj @var{player})
Returns a network-specific string identifying the connection being used by the
given player.  If the programmer is not a wizard and not @var{player}, then
@code{E_PERM} is raised.  If @var{player} is not currently connected, then
@code{E_INVARG} is raised.

For the TCP/IP networking configurations, for in-bound connections, the string
has the form
@example
"port @var{lport} from @var{host}, port @var{port}"
@end example
@noindent
where @var{lport} is the decimal TCP listening port on which the connection
arrived, @var{host} is either the name or decimal TCP address of the host from
which the player is connected, and @var{port} is the decimal TCP port of the
connection on that host.

For outbound TCP/IP connections, the string has the form
@example
"port @var{lport} to @var{host}, port @var{port}"
@end example
@noindent
where @var{lport} is the decimal local TCP port number from which the
connection originated, @var{host} is either the name or decimal TCP address of
the host to which the connection was opened, and @var{port} is the decimal TCP
port of the connection on that host.

For the System V `local' networking configuration, the string is the UNIX login
name of the connecting user or, if no such name can be found, something of the
form
@example
"User #@var{number}"
@end example
@noindent
where @var{number} is a UNIX numeric user ID.

For the other networking configurations, the string is the same for all
connections and, thus, useless.
@end deftypefun

@deftypefun none set_connection_option (obj @var{conn}, str @var{option}, @var{value})
Controls a number of optional behaviors associated the connection @var{conn}.
Raises @code{E_INVARG} if @var{conn} does not specify a current connection and
@code{E_PERM} if the programmer is neither @var{conn} nor a wizard.  The
following values for @var{option} are currently supported:

@table @code
@item "hold-input"
If @var{value} is true, then input received on @var{conn} will never be treated
as a command; instead, it will remain in the queue until retrieved by a call to
@code{read()}.

@item "client-echo"
Send the Telnet Protocol @samp{WONT ECHO} or @samp{WILL ECHO} command,
depending on whether @var{value} is true or false, respectively.  For clients
that support the Telnet Protocol, this should toggle whether or not the client
echoes locally the characters typed by the user.  Note that the server itself
never echoes input characters under any circumstances.  (This option is only
available under the TCP/IP networking configurations.)

@item "binary"
If @var{value} is true, then both input from and output to @var{conn} can
contain arbitrary bytes.  Input from a connection in binary mode is not broken
into lines at all; it is delivered to either the read() function or the
built-in command parser as @dfn{binary strings}, in whatever size chunks come
back from the operating system.  (See the early section on MOO value types for
a description of the binary string representation.)  For output to a connection
in binary mode, the second argument to `notify()' must be a binary string; if
it is malformed, E_INVARG is raised.

@item "flush-command"
If @var{value} is a non-empty string, then it becomes the new @dfn{flush}
command for this connection, by which the player can flush all queued input
that has not yet been processed by the server.  If @var{value} is not a
non-empty string, then @var{conn} is set to have no flush command at all.  The
default value of this option can be set via the property
@code{$server_options.default_flush_command}; see the chapter on server
assumptions about the database for details.
@end table
@end deftypefun

@deftypefun list connection_options (obj @var{conn})
Returns a list of @code{@{@var{name}, @var{value}@}} pairs describing the
current settings of all of the allowed options for the connection @var{conn}.
Raises @code{E_INVARG} if @var{conn} does not specify a current connection and
@code{E_PERM} if the programmer is neither @var{conn} nor a wizard.
@end deftypefun

@deftypefun value connection_option (obj @var{conn}, str @var{name})
Returns the current setting of the option @var{name} for the connection
@var{conn}.  Raises @code{E_INVARG} if @var{conn} does not specify a current
connection and @code{E_PERM} if the programmer is neither @var{conn} nor a
wizard.
@end deftypefun

@deftypefun obj open_network_connection (@var{value}, @dots{})
Establishes a network connection to the place specified by the arguments and
more-or-less pretends that a new, normal player connection has been established
from there.  The new connection, as usual, will not be logged in initially and
will have a negative object number associated with it for use with
@code{read()}, @code{notify()}, and @code{boot_player()}.  This object number
is the value returned by this function.

If the programmer is not a wizard or if the @code{OUTBOUND_NETWORK} compilation
option was not used in building the server, then @code{E_PERM} is raised.  If
the network connection cannot be made for some reason, then other errors will
be returned, depending upon the particular network implementation in use.

For the TCP/IP network implementations (the only ones as of this writing that
support outbound connections), there must be two arguments, a string naming a
host (possibly using the numeric Internet syntax) and an integer specifying a TCP
port.  If a connection cannot be made because the host does not exist, the port
does not exist, the host is not reachable or refused the connection,
@code{E_INVARG} is raised.  If the connection cannot be made for other
reasons, including resource limitations, then @code{E_QUOTA} is raised.

The outbound connection process involves certain steps that can take quite a
long time, during which the server is not doing anything else, including
responding to user commands and executing MOO tasks.  See the chapter on
server assumptions about the database for details about how the server limits
the amount of time it will wait for these steps to successfully complete.

It is worth mentioning one tricky point concerning the use of this function.
Since the server treats the new connection pretty much like any normal player
connection, it will naturally try to parse any input from that connection as
commands in the usual way.  To prevent this treatment, you should use
@code{set_connection_option()} to set the @code{"hold-input"} option true on
the connection.
@end deftypefun

@deftypefun value listen (obj @var{object}, @var{point} [, @var{print-messages}])
Create a new point at which the server will listen for network connections,
just as it does normally.  @var{Object} is the object whose verbs
@code{do_login_command}, @code{do_command}, @code{do_out_of_band_command},
@code{user_connected}, @code{user_created}, @code{user_reconnected},
@code{user_disconnected}, and @code{user_client_disconnected} will be called at
appropriate points, just as these verbs are called on @code{#0} for normal
connections.  (See the chapter on server assumptions about the database for the
complete story on when these functions are called.)  @var{Point} is a
network-configuration-specific parameter describing the listening point.  If
@var{print-messages} is provided and true, then the various
database-configurable messages (also detailed in the chapter on server
assumptions) will be printed on connections received at the new listening
point.  @code{Listen()} returns @var{canon}, a `canonicalized' version of
@var{point}, with any configuration-specific defaulting or aliasing accounted
for.

This raises @code{E_PERM} if the programmer is not a wizard, @code{E_INVARG} if
@var{object} is invalid or there is already a listening point described by
@var{point}, and @code{E_QUOTA} if some network-configuration-specific error
occurred.

For the TCP/IP configurations, @var{point} is a TCP port number on which to
listen and @var{canon} is equal to @var{point} unless @var{point} is zero, in
which case @var{canon} is a port number assigned by the operating system.

For the local multi-user configurations, @var{point} is the UNIX file name to
be used as the connection point and @var{canon} is always equal to @var{point}.

In the single-user configuration, the can be only one listening point at a
time; @var{point} can be any value at all and @var{canon} is always zero.
@end deftypefun

@deftypefun none unlisten (@var{canon})
Stop listening for connections on the point described by @var{canon}, which
should be the second element of some element of the list returned by
@code{listeners()}.  Raises @code{E_PERM} if the programmer is not a wizard and
@code{E_INVARG} if there does not exist a listener with that description.
@end deftypefun

@deftypefun list listeners ()
Returns a list describing all existing listening points, including the default
one set up automatically by the server when it was started (unless that one has
since been destroyed by a call to @code{unlisten()}).  Each element of the list
has the following form:

@example
@{@var{object}, @var{canon}, @var{print-messages}@}
@end example

@noindent
where @var{object} is the first argument given in the call to @code{listen()}
to create this listening point, @var{print-messages} is true if the third
argument in that call was provided and true, and @var{canon} was the value
returned by that call.  (For the initial listening point, @var{object} is
@code{#0}, @var{canon} is determined by the command-line arguments or a
network-configuration-specific default, and @var{print-messages} is true.)
@end deftypefun

Please note that there is nothing special about the initial listening point
created by the server when it starts; you can use @code{unlisten()} on it just
as if it had been created by @code{listen()}.  This can be useful; for example,
under one of the TCP/IP configurations, you might start up your server on some
obscure port, say 12345, connect to it by yourself for a while, and then open
it up to normal users by evaluating the statments
@example
unlisten(12345); listen(#0, 7777, 1)
@end example

@node Time, Evaluation and Tasks, Manipulating Connections, Builtins
@comment  node-name,  next,  previous,  up
@subsection Operations Involving Times and Dates

@deftypefun int time ()
Returns the current time, represented as the number of seconds that have
elapsed since midnight on 1 January 1970, Greenwich Mean Time.
@end deftypefun

@deftypefun str ctime ([int @var{time}])
Interprets @var{time} as a time, using the same representation as given in the
description of @code{time()}, above, and converts it into a 28-character,
human-readable string in the following format:

@example
Mon Aug 13 19:13:20 1990 PDT
@end example

@noindent
If the current day of the month is less than 10, then an extra blank appears
between the month and the day:

@example
Mon Apr  1 14:10:43 1991 PST
@end example

@noindent
If @var{time} is not provided, then the current time is used.

Note that @code{ctime()} interprets @var{time} for the local time zone of the
computer on which the MOO server is running.
@end deftypefun

@node Evaluation and Tasks, Administrative, Time, Builtins
@comment  node-name,  next,  previous,  up
@subsection MOO-Code Evaluation and Task Manipulation

@deftypefun none raise (@var{code} [, str @var{message} [, @var{value}]])
Raises @var{code} as an error in the same way as other MOO expressions,
statements, and functions do.  @var{Message}, which defaults to the value of
@code{tostr(@var{code})}, and @var{value}, which defaults to zero, are made
available to any @code{try}-@code{except} statements that catch the error.  If
the error is not caught, then @var{message} will appear on the first line of
the traceback printed to the user.
@end deftypefun

@deftypefun value call_function (str @var{func-name}, @var{arg}, @dots{})
Calls the built-in function named @var{func-name}, passing the given arguments,
and returns whatever that function returns.  Raises @code{E_INVARG} if
@var{func-name} is not recognized as the name of a known built-in function.
This allows you to compute the name of the function to call and, in particular,
allows you to write a call to a built-in function that may or may not exist in
the particular version of the server you're using.
@end deftypefun

@deftypefun list function_info ([str @var{name}])
Returns descriptions of the built-in functions available on the server.  If
@var{name} is provided, only the description of the function with that name is
returned.  If @var{name} is omitted, a list of descriptions is returned, one
for each function available on the server.  Raised @code{E_INVARG} if
@var{name} is provided but no function with that name is available on the
server.

Each function description is a list of the following form:

@example
@{@var{name}, @var{min-args}, @var{max-args}, @var{types}
@end example

@noindent
where @var{name} is the name of the built-in function, @var{min-args} is the
minimum number of arguments that must be provided to the function,
@var{max-args} is the maximum number of arguments that can be provided to the
function or @code{-1} if there is no maximum, and @var{types} is a list of
@var{max-args} integers (or @var{min-args} if @var{max-args} is @code{-1}),
each of which represents the type of argument required in the corresponding
position.  Each type number is as would be returned from the @code{typeof()}
built-in function except that @code{-1} indicates that any type of value is
acceptable and @code{-2} indicates that either integers or floating-point
numbers may be given.  For example, here are several entries from the list:

@example
@{"listdelete", 2, 2, @{4, 0@}@}
@{"suspend", 0, 1, @{0@}@}
@{"server_log", 1, 2, @{2, -1@}@}
@{"max", 1, -1, @{-2@}@}
@{"tostr", 0, -1, @{@}@}
@end example

@noindent
@code{Listdelete()} takes exactly 2 arguments, of which the first must be a
list (@code{LIST == 4}) and the second must be an integer (@code{INT == 0}).
@code{Suspend()} has one optional argument that, if provided, must be an
integer.  @code{Server_log()} has one required argument that must be a string
(@code{STR == 2}) and one optional argument that, if provided, may be of any
type.  @code{Max()} requires at least one argument but can take any number
above that, and the first argument must be either an integer or a
floating-point number; the type(s) required for any other arguments can't be
determined from this description.  Finally, @code{tostr()} takes any number of
arguments at all, but it can't be determined from this description which
argument types would be acceptable in which positions.
@end deftypefun

@deftypefun list eval (str @var{string})
The MOO-code compiler processes @var{string} as if it were to be the program
associated with some verb and, if no errors are found, that fictional verb is
invoked.  If the programmer is not, in fact, a programmer, then @code{E_PERM}
is raised.  The normal result of calling @code{eval()} is a two element list.
The first element is true if there were no compilation errors and false
otherwise.  The second element is either the result returned from the fictional
verb (if there were no compilation errors) or a list of the compiler's error
messages (otherwise).

When the fictional verb is invoked, the various built-in variables have values
as shown below:

@example
player    @r{the same as in the calling verb}
this      #-1
caller    @r{the same as the initial value of @code{this} in the calling verb}

args      @{@}
argstr    ""

verb      ""
dobjstr   ""
dobj      #-1
prepstr   ""
iobjstr   ""
iobj      #-1
@end example

The fictional verb runs with the permissions of the programmer and as if its
@samp{d} permissions bit were on.

@example
eval("return 3 + 4;")   @result{}   @{1, 7@}
@end example
@end deftypefun

@deftypefun none set_task_perms (obj @var{who})
Changes the permissions with which the currently-executing verb is running to
be those of @var{who}.  If the programmer is neither @var{who} nor a wizard,
then @code{E_PERM} is raised.

@quotation
@strong{Note}: This does not change the owner of the currently-running verb,
only the permissions of this particular invocation.  It is used in verbs owned
by wizards to make themselves run with lesser (usually non-wizard) permissions.
@end quotation
@end deftypefun

@deftypefun obj caller_perms ()
Returns the permissions in use by the verb that called the currently-executing
verb.  If the currently-executing verb was not called by another verb (i.e., it
is the first verb called in a command or server task), then
@code{caller_perms()} returns @code{#-1}.
@end deftypefun

@deftypefun int ticks_left ()
@deftypefunx int seconds_left ()
These two functions return the number of ticks or seconds (respectively) left
to the current task before it will be forcibly terminated.  These are useful,
for example, in deciding when to call @samp{suspend()} to continue a long-lived
computation.
@end deftypefun

@deftypefun int task_id ()
Returns the non-zero, non-negative integer identifier for the
currently-executing task.  Such integers are randomly selected for each task and
can therefore safely be used in circumstances where unpredictability is
required.
@end deftypefun

@deftypefun value suspend ([int @var{seconds}])
Suspends the current task, and resumes it after at least @var{seconds} seconds.
(If @var{seconds} is not provided, the task is suspended indefinitely; such a
task can only be resumed by use of the @code{resume()} function.)  When the
task is resumed, it will have a full quota of ticks and seconds.  This function
is useful for programs that run for a long time or require a lot of ticks.  If
@var{seconds} is negative, then @code{E_INVARG} is raised.  @code{Suspend()}
returns zero unless it was resumed via @code{resume()}, in which case it
returns the second argument given to that function.

In some sense, this function forks the `rest' of the executing task.  However,
there is a major difference between the use of @samp{suspend(@var{seconds})}
and the use of the @samp{fork (@var{seconds})}.  The @samp{fork} statement
creates a new task (a @dfn{forked task}) while the currently-running task still
goes on to completion, but a @code{suspend()} suspends the currently-running
task (thus making it into a @dfn{suspended task}).  This difference may be best
explained by the following examples, in which one verb calls another:

@example
.program   #0:caller_A
#0.prop = 1;
#0:callee_A();
#0.prop = 2;
.

.program   #0:callee_A
fork(5)
  #0.prop = 3;
endfork
.

.program   #0:caller_B
#0.prop = 1;
#0:callee_B();
#0.prop = 2;
.

.program   #0:callee_B
suspend(5);
#0.prop = 3;
.
@end example

@noindent
Consider @code{#0:caller_A}, which calls @code{#0:callee_A}.  Such a task would
assign 1 to @code{#0.prop}, call @code{#0:callee_A}, fork a new task, return to
@code{#0:caller_A}, and assign 2 to @code{#0.prop}, ending this task.  Five
seconds later, if the forked task had not been killed, then it would begin to
run; it would assign 3 to @code{#0.prop} and then stop.  So, the final value of
@code{#0.prop} (i.e., the value after more than 5 seconds) would be 3.

Now consider @code{#0:caller_B}, which calls @code{#0:callee_B} instead of
@code{#0:callee_A}.  This task would assign 1 to @code{#0.prop}, call
@code{#0:callee_B}, and suspend.  Five seconds later, if the suspended task had
not been killed, then it would resume; it would assign 3 to @code{#0.prop},
return to @code{#0:caller_B}, and assign 2 to @code{#0.prop}, ending the task.
So, the final value of @code{#0.prop} (i.e., the value after more than 5
seconds) would be 2.

A suspended task, like a forked task, can be described by the
@code{queued_tasks()} function and killed by the @code{kill_task()} function.
Suspending a task does not change its task id.  A task can be suspended again
and again by successive calls to @code{suspend()}.

By default, there is no limit to the number of tasks any player may suspend,
but such a limit can be imposed from within the database.  See the chapter on
server assumptions about the database for details.
@end deftypefun

@deftypefun none resume (int @var{task-id} [, @var{value}])
Immediately ends the suspension of the suspended task with the given
@var{task-id}; that task's call to @code{suspend()} will return @var{value},
which defaults to zero.  If @var{value} is of type @code{ERR}, it will be
raised, rather than returned, in the suspended task.  @code{Resume()} raises
@code{E_INVARG} if @var{task-id} does not specify an existing suspended task
and @code{E_PERM} if the programmer is neither a wizard nor the owner of the
specified task.
@end deftypefun

@deftypefun list queue_info ([obj @var{player}])
If @var{player} is omitted, returns a list of object numbers naming all players
that currently have active task queues inside the server.  If @var{player} is
provided, returns the number of background tasks currently queued for that
user.  It is guaranteed that @code{queue_info(@var{X})} will return zero for
any @var{X} not in the result of @code{queue_info()}.
@end deftypefun

@deftypefun list queued_tasks ()
Returns information on each of the background tasks (i.e., forked, suspended or
reading) owned by the programmer (or, if the programmer is a wizard, all queued
tasks).  The returned value is a list of lists, each of which encodes certain
information about a particular queued task in the following format:

@example
@{@var{task-id}, @var{start-time}, @var{x}, @var{y},
 @var{programmer}, @var{verb-loc}, @var{verb-name}, @var{line}, @var{this}@}
@end example

@noindent
where @var{task-id} is an integer identifier for this queued task,
@var{start-time} is the time after which this task will begin execution (in
@code{time()} format), @var{x} and @var{y} are obsolete values that are no
longer interesting, @var{programmer} is the permissions with which this task
will begin execution (and also the player who @dfn{owns} this task),
@var{verb-loc} is the object on which the verb that forked this task was
defined at the time, @var{verb-name} is that name of that verb, @var{line} is
the number of the first line of the code in that verb that this task will
execute, and @var{this} is the value of the variable @samp{this} in that verb.
For reading tasks, @var{start-time} is @code{-1}.

The @var{x} and @var{y} fields are now obsolete and are retained only for
backward-compatibility reasons.  They may be reused for new purposes in some
future version of the server.
@end deftypefun

@deftypefun none kill_task (int @var{task-id})
Removes the task with the given @var{task-id} from the queue of waiting tasks.
If the programmer is not the owner of that task and not a wizard, then
@code{E_PERM} is raised.  If there is no task on the queue with the given
@var{task-id}, then @code{E_INVARG} is raised.
@end deftypefun

@deftypefun list callers ([@var{include-line-numbers}])
Returns information on each of the verbs and built-in functions currently
waiting to resume execution in the current task.  When one verb or function
calls another verb or function, execution of the caller is temporarily
suspended, pending the called verb or function returning a value.  At any given
time, there could be several such pending verbs and functions: the one that
called the currently executing verb, the verb or function that called that one,
and so on.  The result of @code{callers()} is a list, each element of which
gives information about one pending verb or function in the following format:

@example
@{@var{this}, @var{verb-name}, @var{programmer}, @var{verb-loc}, @var{player}, @var{line-number}@}
@end example

@noindent
For verbs, @var{this} is the initial value of the variable @samp{this} in that
verb, @var{verb-name} is the name used to invoke that verb, @var{programmer} is
the player with whose permissions that verb is running, @var{verb-loc} is the
object on which that verb is defined, @var{player} is the initial value of the
variable @samp{player} in that verb, and @var{line-number} indicates which line
of the verb's code is executing.  The @var{line-number} element is included
only if the @var{include-line-numbers} argument was provided and true.

For functions, @var{this}, @var{programmer}, and @var{verb-loc} are all
@code{#-1}, @var{verb-name} is the name of the function, and @var{line-number}
is an index used internally to determine the current state of the built-in
function.  The simplest correct test for a built-in function entry is

@example
(VERB-LOC == #-1  &&  PROGRAMMER == #-1  &&  VERB-NAME != "")
@end example

The first element of the list returned by @code{callers()} gives information on
the verb that called the currently-executing verb, the second element describes
the verb that called that one, and so on.  The last element of the list
describes the first verb called in this task.
@end deftypefun

@deftypefun list task_stack (int @var{task-id} [, @var{include-line-numbers}])
Returns information like that returned by the @code{callers()} function, but
for the suspended task with the given @var{task-id}; the
@var{include-line-numbers} argument has the same meaning as in
@code{callers()}.  Raises @code{E_INVARG} if @var{task-id} does not specify an
existing suspended task and @code{E_PERM} if the programmer is neither a wizard
nor the owner of the specified task.
@end deftypefun

@node Administrative,  , Evaluation and Tasks, Builtins
@comment  node-name,  next,  previous,  up
@subsection Administrative Operations

@deftypefun str server_version ()
Returns a string giving the version number of the running MOO server.
@end deftypefun

@deftypefun none server_log (str @var{message} [, @var{is-error}])
The text in @var{message} is sent to the server log with a distinctive prefix
(so that it can be distinguished from server-generated messages).  If the
programmer is not a wizard, then @code{E_PERM} is raised.  If @var{is-error}
is provided and true, then @var{message} is marked in the server log as an
error.
@end deftypefun

@deftypefun obj renumber (obj @var{object})
The object number of the object currently numbered @var{object} is changed to
be the least nonnegative object number not currently in use and the new object
number is returned.  If @var{object} is not valid, then @code{E_INVARG} is
raised.  If the programmer is not a wizard, then @code{E_PERM} is raised.
If there are no unused nonnegative object numbers less than @var{object}, then
@var{object} is returned and no changes take place.

The references to @var{object} in the parent/children and location/contents
hierarchies are updated to use the new object number, and any verbs, properties
and/or objects owned by @var{object} are also changed to be owned by the new
object number.  The latter operation can be quite time consuming if the
database is large.  No other changes to the database are performed; in
particular, no object references in property values or verb code are updated.

This operation is intended for use in making new versions of the LambdaCore
database from the then-current LambdaMOO database, and other similar
situations.  Its use requires great care.
@end deftypefun

@deftypefun none reset_max_object ()
The server's idea of the highest object number ever used is changed to be the
highest object number of a currently-existing object, thus allowing reuse of
any higher numbers that refer to now-recycled objects.  If the programmer is
not a wizard, then @code{E_PERM} is raised.

This operation is intended for use in making new versions of the LambdaCore
database from the then-current LambdaMOO database, and other similar
situations.  Its use requires great care.
@end deftypefun

@deftypefun list memory_usage ()
On some versions of the server, this returns statistics concerning the server
consumption of system memory.  The result is a list of lists, each in the
following format:

@example
@{@var{block-size}, @var{nused}, @var{nfree}@}
@end example

@noindent
where @var{block-size} is the size in bytes of a particular class of memory
fragments, @var{nused} is the number of such fragments currently in use in the
server, and @var{nfree} is the number of such fragments that have been reserved
for use but are currently free.

On servers for which such statistics are not available, @code{memory_usage()}
returns @code{@{@}}.  The compilation option @code{USE_GNU_MALLOC} controls
whether or not statistics are available; if the option is not provided,
statistics are not available.
@end deftypefun

@deftypefun none dump_database ()
Requests that the server checkpoint the database at its next opportunity.  It
is not normally necessary to call this function; the server automatically
checkpoints the database at regular intervals; see the chapter on server
assumptions about the database for details.  If the programmer is not a wizard,
then @code{E_PERM} is raised.
@end deftypefun

@deftypefun int db_disk_size ()
Returns the total size, in bytes, of the most recent full representation of the
database as one or more disk files.  Raises @code{E_QUOTA} if, for some reason,
no such on-disk representation is currently available.
@end deftypefun

@deftypefun none shutdown ([str @var{message}])
Requests that the server shut itself down at its next opportunity.  Before
doing so, a notice (incorporating @var{message}, if provided) is printed to all
connected players.  If the programmer is not a wizard, then @code{E_PERM} is
raised.
@end deftypefun

@node Server, Function Index, Language, Top
@comment  node-name,  next,  previous,  up
@chapter Server Commands and Database Assumptions

This chapter describes all of the commands that are built into the server and
every property and verb in the database specifically accessed by the server.
Aside from what is listed here, no assumptions are made by the server
concerning the contents of the database.

@menu
* Server Builtins::          Built-in Commands
* Assumptions::              Server Assumptions About the Database
@end menu

@node Server Builtins, Assumptions, Server, Server
@comment  node-name,  next,  previous,  up
@section Built-in Commands

As was mentioned in the chapter on command parsing, there are five commands
whose interpretation is fixed by the server: @code{PREFIX},
@code{OUTPUTPREFIX}, @code{SUFFIX}, @code{OUTPUTSUFFIX}, and @code{.program}.
The first four of these are intended for use by programs that connect to the
MOO, so-called `client' programs.  The @code{.program} command is used by
programmers to associate a MOO program with a particular verb.  The server can,
in addition, recognize a sixth special command on any or all connections, the
@dfn{flush} command.

The server also performs special processing on command lines that begin with
certain punctuation characters.

This section discusses these built-in pieces of the command-interpretation
process.

@menu
* Delimiters::               Command-Output Delimiters
* Programming::              Programming
* Flushing::                 Flushing Unprocessed Input
* Initial Punctuation::      Initial Punctuation in Commands
@end menu

@node Delimiters, Programming, Server Builtins, Server Builtins
@comment  node-name,  next,  previous,  up
@subsection Command-Output Delimiters

Every MOO network connection has associated with it two strings, the
@dfn{output prefix} and the @dfn{output suffix}.  Just before executing a
command typed on that connection, the server prints the output prefix, if any,
to the player.  Similarly, just after finishing the command, the output suffix,
if any, is printed to the player.  Initially, these strings are not defined, so
no extra printing takes place.

The @code{PREFIX} and @code{SUFFIX} commands are used to set and clear these
strings.  They have the following simple syntax:

@example
PREFIX  @var{output-prefix}
SUFFIX  @var{output-suffix}
@end example

@noindent
That is, all text after the command name and any following spaces is used as
the new value of the appropriate string.  If there is no non-blank text after
the command string, then the corresponding string is cleared.  For
compatibility with some general MUD client programs, the server also recognizes
@code{OUTPUTPREFIX} as a synonym for @code{PREFIX} and @code{OUTPUTSUFFIX} as a
synonym for @code{SUFFIX}.

These commands are intended for use by programs connected to the MOO, so that
they can issue MOO commands and reliably determine the beginning and end of the
resulting output.  For example, one editor-based client program sends this
sequence of commands on occasion:

@example
PREFIX >>MOO-Prefix<<
SUFFIX >>MOO-Suffix<<
@@list @var{object}:@var{verb} without numbers
PREFIX
SUFFIX
@end example

@noindent
The effect of which, in a LambdaCore-derived database, is to print out the code
for the named verb preceded by a line containing only @samp{>>MOO-Prefix<<} and
followed by a line containing only @samp{>>MOO-Suffix<<}.  This enables the
editor to reliably extract the program text from the MOO output and show it to
the user in a separate editor window.  There are many other possible uses.

The built-in function @code{output_delimiters()} can be used by MOO code to
find out the output prefix and suffix currently in effect on a particular
network connection.

@node Programming, Flushing, Delimiters, Server Builtins
@comment  node-name,  next,  previous,  up
@subsection Programming

The @code{.program} command is a common way for programmers to associate a
particular MOO-code program with a particular verb.  It has the following
syntax:

@example
.program @var{object}:@var{verb}
@dots{}@var{several lines of MOO code}@dots{}
.
@end example

@noindent
That is, after typing the @code{.program} command, then all lines of input from
the player are considered to be a part of the MOO program being defined.  This
ends as soon as the player types a line containing only a dot (@samp{.}).  When
that line is received, the accumulated MOO program is checked for proper MOO
syntax and, if correct, associated with the named verb.

If, at the time the line containing only a dot is processed, (a) the player is
not a programmer, (b) the player does not have write permission on the named
verb, or (c) the property @code{$server_options.protect_set_verb_code} exists
and has a true value and the player is not a wizard, then an error message is
printed and the named verb's program is not changed.

In the @code{.program} command, @var{object} may have one of three forms:

@itemize @bullet
@item
The name of some object visible to the player.  This is exactly like the kind
of matching done by the server for the direct and indirect objects of ordinary
commands.  See the chapter on command parsing for details.  Note that the
special names @samp{me} and @samp{here} may be used.

@item
An object number, in the form @code{#@var{number}}.

@item
A @dfn{system property} (that is, a property on @code{#0}), in the form
@code{$@var{name}}.  In this case, the current value of @code{#0.@var{name}}
must be a valid object.
@end itemize

@node Flushing, Initial Punctuation, Programming, Server Builtins
@comment  node-name,  next,  previous,  up
@subsection Flushing Unprocessed Input

It sometimes happens that a user changes their mind about having typed one or
more lines of input and would like to `untype' them before the server actually
gets around to processing them.  If they react quickly enough, they can type
their connection's defined @dfn{flush} command; when the server first reads
that command from the network, it immediately and completely flushes any as-yet
unprocessed input from that user, printing a message to the user describing
just which lines of input were discarded, if any.

@quotation
@emph{Fine point:} The flush command is handled very early in the server's
processing of a line of input, before the line is entered into the task queue
for the connection and well before it is parsed into words like other commands.
For this reason, it must be typed exactly as it was defined, alone on the line,
without quotation marks, and without any spaces before or after it.
@end quotation

When a connection is first accepted by the server, it is given an initial flush
command setting taken from the current default.  This initial setting can be
changed later using the @code{set_connection_option()} command.

By default, each connection is initially given @samp{.flush} as its flush
command.  If the property @code{$server_options.default_flush_command} exists,
then its value overrides this default.  If
@code{$server_options.default_flush_command} is a non-empty string, then that
string is the flush command for all new connections; otherwise, new connections
are initially given no flush command at all.

@node Initial Punctuation,  , Flushing, Server Builtins
@comment  node-name,  next,  previous,  up
@subsection Initial Punctuation in Commands

The server interprets command lines that begin with any of the following
characters specially:

@example
"        :        ;
@end example

@noindent
Before processing the command, the initial punctuation character is replaced by
the corresponding word below, followed by a space:

@example
say      emote    eval
@end example

@noindent
For example, the command line

@example
"Hello, there.
@end example

@noindent
is transformed into

@example
say Hello, there.
@end example

@noindent
before parsing.

@node Assumptions,  , Server Builtins, Server
@comment  node-name,  next,  previous,  up
@section Server Assumptions About the Database

There are a small number of circumstances under which the server directly and
specifically accesses a particular verb or property in the database.  This
section gives a complete list of such circumstances.

@menu
* Server Options::           Server Options Set in the Database
* Server Messages::          Server Messages Set in the Database
* Checkpointing::            Checkpointing the Database
* Network Connections::      Accepting and Initiating Network Connections
* Logging In::               Associating Network Connections with Players
* Out-of-band Commands::     Out-of-Band Commands
* First Tasks::              The First Tasks Run By the Server
* Controlling Tasks::        Controlling the Execution of Tasks
* Aborted Tasks::            Controlling the Handling of Aborted Tasks
* Matching::                 Matching in Command Parsing
* Restricting Built-ins::    Restricting Access to Certain Built-in Functions
* Creating and Recycling::   Creating and Recycling Objects
* Object Movement::          Object Movement
* Obsolete Features::        Temporarily Enabling Obsolete Server Features
@end menu

@node Server Options, Server Messages, Assumptions, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Server Options Set in the Database

Many optional behaviors of the server can be controlled from within the
database by creating the property @code{#0.server_options} (also known as
@code{$server_options}), assigning as its value a valid object number, and then
defining various properties on that object.  At a number of times, the server
checks for whether the property @code{$server_options} exists and has an object
number as its value.  If so, then the server looks for a variety of other
properties on that @code{$server_options} object and, if they exist, uses their
values to control how the server operates.

The specific properties searched for are each described in the appropriate
section below, but here is a brief list of all of the relevant properties for
ease of reference:

@table @code
@item bg_seconds
The number of seconds allotted to background tasks.
@item bg_ticks
The number of ticks allotted to background tasks.
@item connect_timeout
The maximum number of seconds to allow an un-logged-in in-bound connection to
remain open.
@item default_flush_command
The initial setting of each new connection's flush command.
@item fg_seconds
The number of seconds allotted to foreground tasks.
@item fg_ticks
The number of ticks allotted to foreground tasks.
@item max_stack_depth
The maximum number of levels of nested verb calls.
@item name_lookup_timeout
The maximum number of seconds to wait for a network hostname/address lookup.
@item outbound_connect_timeout
The maximum number of seconds to wait for an outbound network connection to
successfully open.
@item protect_@var{property}
Restrict reading of built-in @var{property} to wizards.
@item protect_@var{function}
Restrict use of built-in @var{function} to wizards.
@item support_numeric_verbname_strings
Enables use of an obsolete verb-naming mechanism.
@end table

@node Server Messages, Checkpointing, Server Options, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Server Messages Set in the Database

There are a number of circumstances under which the server itself generates
messages on network connections.  Most of these can be customized or even
eliminated from within the database.  In each such case, a property on
@code{$server_options} is checked at the time the message would be printed.  If
the property does not exist, a default message is printed.  If the property
exists and its value is not a string or a list containing strings, then no
message is printed at all.  Otherwise, the string(s) are printed in place of
the default message, one string per line.  None of these messages are ever
printed on an outbound network connection created by the function
@code{open_network_connection()}.

The following list covers all of the customizable messages, showing for each
the name of the relevant property on @code{$server_options}, the default
message, and the circumstances under which the message is printed:

@table @code
@item boot_msg = "*** Disconnected ***"
The function @code{boot_player()} was called on this connection.

@item connect_msg = "*** Connected ***"
The user object that just logged in on this connection existed before
@code{$do_login_command()} was called.

@item create_msg = "*** Created ***"
The user object that just logged in on this connection did not exist before
@code{$do_login_command()} was called.

@item recycle_msg = "*** Recycled ***"
The logged-in user of this connection has been recycled or renumbered (via the
renumber() function).

@item redirect_from_msg = "*** Redirecting connection to new port ***"
The logged-in user of this connection has just logged in on some other
connection.

@item redirect_to_msg = "*** Redirecting old connection to this port ***"
The user who just logged in on this connection was already logged in on some
other connection.

@item server_full_msg
Default:
@example
*** Sorry, but the server cannot accept any more connections right now.
*** Please try again later.
@end example
@noindent
This connection arrived when the server really couldn't accept any more
connections, due to running out of a critical operating system resource.

@item timeout_msg = "*** Timed-out waiting for login. ***"
This in-bound network connection was idle and un-logged-in for at least
@code{CONNECT_TIMEOUT} seconds (as defined in the file @samp{options.h} when
the server was compiled).
@end table

@quotation
@emph{Fine point:} If the network connection in question was received at a
listening point (established by the @samp{listen()} function) handled by an
object @var{obj} other than @code{#0}, then system messages for that connection
are looked for on @code{@var{obj}.server_options}; if that property does not
exist, then @code{$server_options} is used instead.
@end quotation

@node Checkpointing, Network Connections, Server Messages, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Checkpointing the Database

The server maintains the entire MOO database in main memory, not on disk.  It
is therefore necessary for it to dump the database to disk if it is to persist
beyond the lifetime of any particular server execution.  The server is careful
to dump the database just before shutting down, of course, but it is also
prudent for it to do so at regular intervals, just in case something untoward
happens.

To determine how often to make these @dfn{checkpoints} of the database, the
server consults the value of @code{#0.dump_interval}.  If it exists and its
value is an integer greater than or equal to 60, then it is taken as the number
of seconds to wait between checkpoints; otherwise, the server makes a new
checkpoint every 3600 seconds (one hour).  If the value of
@code{#0.dump_interval} implies that the next checkpoint should be scheduled at
a time after 3:14:07 a.m. on Tuesday, January 19, 2038, then the server instead
uses the default value of 3600 seconds in the future.

The decision about how long to wait between checkpoints is made again
immediately after each one begins.  Thus, changes to @code{#0.dump_interval}
will take effect after the next checkpoint happens.

Whenever the server begins to make a checkpoint, it makes the following verb
call:

@example
$checkpoint_started()
@end example

@noindent
When the checkpointing process is complete, the server makes the following verb
call:

@example
$checkpoint_finished(@var{success})
@end example

@noindent
where @var{success} is true if and only if the checkpoint was successfully
written on the disk.  Checkpointing can fail for a number of reasons, usually
due to exhaustion of various operating system resources such as virtual memory
or disk space.  It is not an error if either of these verbs does not exist; the
corresponding call is simply skipped.

@node Network Connections, Logging In, Checkpointing, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Accepting and Initiating Network Connections

When the server first accepts a new, incoming network connection, it is given
the low-level network address of computer on the other end.  It immediately
attempts to convert this address into the human-readable host name that will be
entered in the server log and returned by the @code{connection_name()}
function.  This conversion can, for the TCP/IP networking configurations,
involve a certain amount of communication with remote name servers, which can
take quite a long time and/or fail entirely.  While the server is doing this
conversion, it is not doing anything else at all; in particular, it it not
responding to user commands or executing MOO tasks.

By default, the server will wait no more than 5 seconds for such a name lookup
to succeed; after that, it behaves as if the conversion had failed, using
instead a printable representation of the low-level address.  If the property
@code{name_lookup_timeout} exists on @code{$server_options} and has an integer
as its value, that integer is used instead as the timeout interval.

When the @code{open_network_connection()} function is used, the server must
again do a conversion, this time from the host name given as an argument into
the low-level address necessary for actually opening the connection.  This
conversion is subject to the same timeout as in the in-bound case; if the
conversion does not succeed before the timeout expires, the connection attempt
is aborted and @code{open_network_connection()} raises @code{E_QUOTA}.

After a successful conversion, though, the server must still wait for the
actual connection to be accepted by the remote computer.  As before, this can
take a long time during which the server is again doing nothing else.  Also as
before, the server will by default wait no more than 5 seconds for the
connection attempt to succeed; if the timeout expires,
@code{open_network_connection()} again raises @code{E_QUOTA}.  This default
timeout interval can also be overridden from within the database, by defining
the property @code{outbound_connect_timeout} on @code{$server_options} with an
integer as its value.

@node Logging In, Out-of-band Commands, Network Connections, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Associating Network Connections with Players

When a network connection is first made to the MOO, it is identified by a
unique, negative object number.  Such a connection is said to be
@dfn{un-logged-in} and is not yet associated with any MOO player object.

Each line of input on an un-logged-in connection is first parsed into words in
the usual way (see the chapter on command parsing for details) and then these
words are passed as the arguments in a call to the verb
@code{$do_login_command()}.  For example, the input line

@example
connect Munchkin frebblebit
@end example

@noindent
would result in the following call being made:

@example
$do_login_command("connect", "Munchkin", "frebblebit")
@end example

@noindent
In that call, the variable @code{player} will have as its value the negative
object number associated with the appropriate network connection.  The
functions @code{notify()} and @code{boot_player()} can be used with such object
numbers to send output to and disconnect un-logged-in connections.  Also, the
variable @code{argstr} will have as its value the unparsed command line as
received on the network connection.

If @code{$do_login_command()} returns a valid player object and the connection
is still open, then the connection is considered to have @dfn{logged into} that
player.  The server then makes one of the following verbs calls, depending on
the player object that was returned:

@example
$user_created(@var{player})
$user_connected(@var{player})
$user_reconnected(@var{player})
@end example

@noindent
The first of these is used if the returned object number is greater than the
value returned by the @code{max_object()} function before
@code{$do_login_command()} was invoked, that is, it is called if the returned
object appears to have been freshly created.  If this is not the case, then one
of the other two verb calls is used.  The @code{$user_connected()} call is used
if there was no existing active connection for the returned player object.
Otherwise, the @code{$user_reconnected()} call is used instead.

@quotation
@emph{Fine point:} If a user reconnects and the user's old and new connections
are on two different listening points being handled by different objects (see
the description of the @code{listen()} function for more details), then
@code{user_client_disconnected} is called for the old connection and
@code{user_connected} for the new one.
@end quotation

If an in-bound network connection does not successfully log in within a certain
period of time, the server will automatically shut down the connection, thereby
freeing up the resources associated with maintaining it.  Let @var{L} be the
object handling the listening point on which the connection was received (or
@code{#0} if the connection came in on the initial listening point).  To
discover the timeout period, the server checks on
@code{@var{L}.server_options} or, if it doesn't exist, on
@code{$server_options} for a @code{connect_timeout} property.  If one is found
and its value is a positive integer, then that's the number of seconds the
server will use for the timeout period.  If the @code{connect_timeout} property
exists but its value isn't a positive integer, then there is no timeout at
all.  If the property doesn't exist, then the default timeout is 300 seconds.

When any network connection (even an un-logged-in or outbound one) is
terminated, by either the server or the client, then one of the following two
verb calls is made:

@example
$user_disconnected(@var{player})
$user_client_disconnected(@var{player})
@end example

@noindent
The first is used if the disconnection is due to actions taken by the server
(e.g., a use of the @code{boot_player()} function or the un-logged-in timeout
described above) and the second if the disconnection was initiated by the
client side.

It is not an error if any of these five verbs do not exist; the corresponding
call is simply skipped.

@quotation
@strong{Note}: Only one network connection can be controlling a given player
object at a given time; should a second connection attempt to log in as that
player, the first connection is unceremoniously closed (and
@code{$user_reconnected()} called, as described above).  This makes it easy to
recover from various kinds of network problems that leave connections open but
inaccessible.
@end quotation

When the network connection is first established, the null command is
automatically entered by the server, resulting in an initial call to
@code{$do_login_command()} with no arguments.  This signal can be used by the
verb to print out a welcome message, for example.

@quotation
@strong{Warning}: If there is no @code{$do_login_command()} verb defined, then
lines of input from un-logged-in connections are simply discarded.  Thus, it is
@emph{necessary} for any database to include a suitable definition for this
verb.
@end quotation

@node Out-of-band Commands, First Tasks, Logging In, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Out-of-Band Commands

It is possible to compile the server with an option defining an
@dfn{out-of-band prefix} for commands.  This is a string that the server will
check for at the beginning of every line of input from players, regardless of
whether or not those players are logged in and regardless of whether or not
reading tasks are waiting for input from those players.  If a given line of
input begins with the defined out-of-band prefix (leading spaces, if any, are
@emph{not} stripped before testing), then it is not treated as a normal command
or as input to any reading task.  Instead, the line is parsed into a list of
words in the usual way and those words are given as the arguments in a call to
@code{$do_out_of_band_command()}.  For example, if the out-of-band prefix were
defined to be @samp{#$#}, then the line of input

@example
#$# client-type fancy
@end example

@noindent
would result in the following call being made in a new server task:

@example
$do_out_of_band_command("#$#", "client-type", "fancy")
@end example

During the call to @code{$do_out_of_band_command()}, the variable @code{player}
is set to the object number representing the player associated with the
connection from which the input line came.  Of course, if that connection has
not yet logged in, the object number will be negative.  Also, the variable
@code{argstr} will have as its value the unparsed input line as received on the
network connection.

Out-of-band commands are intended for use by fancy client programs that may
generate asynchronous @dfn{events} of which the server must be notified.  Since
the client cannot, in general, know the state of the player's connection
(logged-in or not, reading task or not), out-of-band commands provide the only
reliable client-to-server communications channel.

@node First Tasks, Controlling Tasks, Out-of-band Commands, Assumptions
@comment  node-name,  next,  previous,  up
@subsection The First Tasks Run By the Server

Whenever the server is booted, there are a few tasks it runs right at the
beginning, before accepting connections or getting the value of
@code{#0.dump_interval} to schedule the first checkpoint (see below for more
information on checkpoint scheduling).

First, the server calls @code{$user_disconnected()} once for each user who
was connected at the time the database file was written; this allows for any
cleaning up that's usually done when users disconnect (e.g., moving their
player objects back to some `home' location, etc.).

Next, it checks for the existence of the verb @code{$server_started()}.  If
there is such a verb, then the server runs a task invoking that verb with no
arguments and with @code{player} equal to @code{#-1}.  This is useful for
carefully scheduling checkpoints and for re-initializing any state that is not
properly represented in the database file (e.g., re-opening certain outbound
network connections, clearing out certain tables, etc.).

@node Controlling Tasks, Aborted Tasks, First Tasks, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Controlling the Execution of Tasks

As described earlier, in the section describing MOO tasks, the server places
limits on the number of seconds for which any task may run continuously and the
number of ``ticks,'' or low-level operations, any task may execute in one
unbroken period.  By default, foreground tasks may use 30,000 ticks and five
seconds, and background tasks may use 15,000 ticks and three seconds.  These
defaults can be overridden from within the database by defining any or all of
the following properties on @code{$server_options} and giving them integer
values:

@table @code
@item bg_seconds
The number of seconds allotted to background tasks.
@item bg_ticks
The number of ticks allotted to background tasks.
@item fg_seconds
The number of seconds allotted to foreground tasks.
@item fg_ticks
The number of ticks allotted to foreground tasks.
@end table

The server ignores the values of @code{fg_ticks} and @code{bg_ticks} if they
are less than 100 and similarly ignores @code{fg_seconds} and @code{bg_seconds}
if their values are less than 1.  This may help prevent utter disaster should
you accidentally give them uselessly-small values.

Recall that command tasks and server tasks are deemed @dfn{foreground} tasks,
while forked, suspended, and reading tasks are defined as @dfn{background}
tasks.  The settings of these variables take effect only at the beginning of
execution or upon resumption of execution after suspending or reading.

The server also places a limit on the number of levels of nested verb calls,
raising @code{E_MAXREC} from a verb-call expression if the limit is exceeded.
The limit is 50 levels by default, but this can be increased from within the
database by defining the @code{max_stack_depth} property on
@code{$server_options} and giving it an integer value greater than 50.  The
maximum stack depth for any task is set at the time that task is created and
cannot be changed thereafter.  This implies that suspended tasks, even after
being saved in and restored from the DB, are not affected by later changes to
$server_options.max_stack_depth.

Finally, the server can place a limit on the number of forked or suspended
tasks any player can have queued at a given time.  Each time a @code{fork}
statement or a call to @code{suspend()} is executed in some verb, the server
checks for a property named @code{queued_task_limit} on the programmer.  If
that property exists and its value is a non-negative integer, then that integer
is the limit.  Otherwise, if @code{$server_options.queued_task_limit} exists
and its value is a non-negative integer, then that's the limit.  Otherwise,
there is no limit.  If the programmer already has a number of queued tasks that
is greater than or equal to the limit, @code{E_QUOTA} is raised instead of
either forking or suspending.  Reading tasks are affected by the queued-task
limit.

@node Aborted Tasks, Matching, Controlling Tasks, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Controlling the Handling of Aborted Tasks

The server will abort the execution of tasks for either of two reasons:
@enumerate 1
@item an error was raised within the task but not caught, or
@item the task exceeded the limits on ticks and/or seconds.
@end enumerate
@noindent
In each case, after aborting the task, the server attempts to call a particular
@dfn{handler verb} within the database to allow code there to handle this
mishap in some appropriate way.  If this verb call suspends or returns a true
value, then it is considered to have handled the situation completely and no
further processing will be done by the server.  On the other hand, if the
handler verb does not exist, or if the call either returns a false value
without suspending or itself is aborted, the server takes matters into its own
hands.

First, an error message and a MOO verb-call stack @dfn{traceback} are
printed to the player who typed the command that created the original aborted
task, explaining why the task was aborted and where in the task the problem
occurred.  Then, if the call to the handler verb was itself aborted, a second
error message and traceback are printed, describing that problem as well.  Note
that if the handler-verb call itself is aborted, no further `nested' handler
calls are made; this policy prevents what might otherwise be quite a vicious
little cycle.

The specific handler verb, and the set of arguments it is passed, differs for
the two causes of aborted tasks.

If an error is raised and not caught, then the verb-call
@example
$handle_uncaught_error(@var{code}, @var{msg}, @var{value}, @var{traceback}, @var{formatted})
@end example
@noindent
is made, where @var{code}, @var{msg}, @var{value}, and @var{traceback} are the
values that would have been passed to a handler in a @code{try}-@code{except}
statement and @var{formatted} is a list of strings being the lines of error and
traceback output that will be printed to the player if
@code{$handle_uncaught_error} returns false without suspending.

If a task runs out of ticks or seconds, then the verb-call
@example
$handle_task_timeout(@var{resource}, @var{traceback}, @var{formatted})
@end example
@noindent
is made, where @var{resource} is the appropriate one of the strings
@code{"ticks"} or @code{"seconds"}, and @var{traceback} and @var{formatted} are
as above.

@node Matching, Restricting Built-ins, Aborted Tasks, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Matching in Command Parsing

In the process of matching the direct and indirect object strings in a command
to actual objects, the server uses the value of the @code{aliases} property, if
any, on each object in the contents of the player and the player's location.
For complete details, see the chapter on command parsing.

@node Restricting Built-ins, Creating and Recycling, Matching, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Restricting Access to Built-in Properties and Functions

Whenever verb code attempts to read the value of a built-in property @var{prop}
on any object, the server checks to see if the property
@code{$server_options.protect_@var{prop}} exists and has a true value.  If so,
then @code{E_PERM} is raised if the programmer is not a wizard.

Whenever verb code calls a built-in function @code{@var{func}()} and the caller
is not the object @code{#0}, the server checks to see if the property
@code{$server_options.protect_@var{func}} exists and has a true value.  If so,
then the server next checks to see if the verb @code{$bf_@var{func}()} exists;
if that verb exists, then the server calls it @emph{instead} of the built-in
function, returning or raising whatever that verb returns or raises.  If the
@code{$bf_@var{func}()} does not exist and the programmer is not a wizard, then
the server immediately raises @code{E_PERM}, @emph{without} actually calling
the function.  Otherwise (if the caller is @code{#0}, if
@code{$server_options.protect_@var{func}} either doesn't exist or has a false
value, or if @code{$bf_@var{func}()} exists but the programmer is a wizard),
then the built-in function is called normally.

@node Creating and Recycling, Object Movement, Restricting Built-ins, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Creating and Recycling Objects

Whenever the @code{create()} function is used to create a new object, that
object's @code{initialize} verb, if any, is called with no arguments.  The call
is simply skipped if no such verb is defined on the object.

Symmetrically, just before the @code{recycle()} function actually destroys an
object, the object's @code{recycle} verb, if any, is called with no arguments.
Again, the call is simply skipped if no such verb is defined on the object.

Both @code{create()} and @code{recycle()} check for the existence of an
@code{ownership_quota} property on the owner of the newly-created or -destroyed
object.  If such a property exists and its value is an integer, then it is
treated as a @dfn{quota} on object ownership.  Otherwise, the following two
paragraphs do not apply.

The @code{create()} function checks whether or not the quota is positive; if
so, it is reduced by one and stored back into the @code{ownership_quota}
property on the owner.  If the quota is zero or negative, the quota is
considered to be exhausted and @code{create()} raises @code{E_QUOTA}.

The @code{recycle()} function increases the quota by one and stores it back
into the @code{ownership_quota} property on the owner.

@node Object Movement, Obsolete Features, Creating and Recycling, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Object Movement

During evaluation of a call to the @code{move()} function, the server can make
calls on the @code{accept} and @code{enterfunc} verbs defined on the
destination of the move and on the @code{exitfunc} verb defined on the source.
The rules and circumstances are somewhat complicated and are given in detail in
the description of the @code{move()} function.

@node Obsolete Features,  , Object Movement, Assumptions
@comment  node-name,  next,  previous,  up
@subsection Temporarily Enabling Obsolete Server Features

If the property @code{$server_options.support_numeric_verbname_strings} exists
and has a true value, then the server supports a obsolete mechanism for less
ambiguously referring to specific verbs in various built-in functions.  For
more details, see the discussion given just following the description of the
@code{verbs()} function.

@ifset INDEX
@node Function Index,  , Server, Top
@comment  node-name,  next,  previous,  up
@chapter Function Index
@printindex fn
@end ifset

@ignore
@unnumbered Concept Index
@printindex cp
@end ignore

@iftex
@contents
@end iftex

@bye

@c $Id: ProgrammersManual.texinfo,v 1.32 1997/03/04 22:17:00 eostrom Exp $

@c $Log: ProgrammersManual.texinfo,v $
@c Revision 1.32  1997/03/04 22:17:00  eostrom
@c Documented that resume(<a task>, <an error>) raises rather than
@c returns the error in the suspended task.
@c
@c Revision 1.31  1996/05/21 17:27:03  pavel
@c Fixed misspelling of equal() as `equals()' throughout the text.
@c
@c Revision 1.30  1996/05/14  05:41:16  pavel
@c Fixed a few small problems pointed out by H. Peter Anvin.
@c
@c Revision 1.29  1996/05/12  21:25:19  pavel
@c Updated to cover everything through the 1.8.0p5 release.
@c
@c Revision 1.28  1996/03/04  01:33:15  pavel
@c Brought up to date with release 1.7.9p2 of the server.
@c
@c Revision 1.27  1994/08/06  01:46:30  pavel
@c Fixed typo (said `verb_info' in two places where `verb_args' was meant) in
@c description of `verb_args()'.
@c
@c Revision 1.26  1994/03/07  21:46:20  pavel
@c Updated numeric IP address in reference to LambdaMOO server.
@c
@c Revision 1.25  1993/10/12  01:23:44  pavel
@c -- Updated for release 1.7.6.
@c -- Incorporated Info-ization provided by Mark-Jason Dominus.
@c
@c Revision 1.24  1993/08/05  00:55:43  pavel
@c For 1.7.3, removed reference to spurious blank line of input on newly-opened
@c outbound connections.
@c
@c Revision 1.23  1993/08/04  05:23:37  pavel
@c Updated various dates and version numbers.
@c
@c Revision 1.22  1993/08/04  05:21:35  pavel
@c Fixed a few typos and updated to reflect the (minor) changes made in release
@c 1.7.2 of the server.
@c
@c Revision 1.21  1992/10/25  00:06:17  pavel
@c Fixed typo.
@c
@c Revision 1.20  1992/10/24  23:39:44  pavel
@c Documented the out-of-band command mechanism, the coming elimination of the
@c `.program' built-in command, the behavior of read() when the connection
@c gets closed during the wait for data, and the `f' (fertile) bit on objects.
@c
@c Revision 1.19  1992/10/23  17:00:55  pavel
@c Documented fix to substitute(), in which `%%' is replaced by `%' instead of
@c causing E_INVARG to be returned.
@c
@c Revision 1.18  1992/09/21  17:31:37  pjames
@c Updated subrange assignment.  Added [is_]clear_property documentation
@c
@c Revision 1.17  1992/09/03  17:02:56  pjames
@c Added is_clear_property() and clear_property().  Updated chparent()
@c and create() descriptions to mention `clear' properties.
@c
@c Revision 1.16  1992/09/02  20:12:26  pavel
@c Fixed thinko in match() examples.
@c
@c Revision 1.15  1992/08/29  00:03:38  pjames
@c Updated for 1.6.5
@c
@c Revision 1.14  1992/08/21  00:47:02  pavel
@c Added note about server_log() prepending a distinctive prefix to its
@c argument.
@c
@c Revision 1.13  1992/08/15  20:19:47  pavel
@c Fixed a typo in the description of match().
@c
@c Revision 1.12  1992/08/15  03:29:40  pavel
@c Fixed a formatting problem.
@c
@c Revision 1.11  1992/08/15  03:22:43  pavel
@c Fixed a couple of texinfo bugs.
@c
@c Revision 1.10  1992/08/15  03:21:16  pavel
@c Neatened up and fleshed out the discussion of pattern matching and
@c replacement.
@c
@c Revision 1.9  1992/08/14  21:37:34  pjames
@c *** empty log message ***
@c
@c Revision 1.8  1992/08/14  21:24:01  pjames
@c Explained what match() (rmatch()) returns.
@c
@c Revision 1.7  1992/08/14  19:31:25  pjames
@c Changed copyrights from `1991, 1992' to `1992'
@c
@c Revision 1.6  1992/08/14  19:29:29  pjames
@c Updated with match(), rmatch(), substitute(), regular expression info.
@c
@c Revision 1.5  1992/08/12  02:07:37  pjames
@c *** empty log message ***
@c
@c Revision 1.4  1992/08/08  00:48:00  pavel
@c First useful RCS-controlled version.
@c

@c Local Variables:
@c texinfo-column-for-description: 29
@c makeinfo-options: "--fill-column 79 --no-split"
@c fill-column: 79
@c End: