aboutsummaryrefslogtreecommitdiff
path: root/src/interp/br-con.boot
blob: f8413bfa5a6684610819d27a58f740d082c60548 (plain)
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
-- Copyright (c) 1991-2002, The Numerical Algorithms Group Ltd.
-- All rights reserved.
-- Copyright (C) 2007-2010, Gabriel Dos Reis.
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are
-- met:
--
--     - Redistributions of source code must retain the above copyright
--       notice, this list of conditions and the following disclaimer.
--
--     - Redistributions in binary form must reproduce the above copyright
--       notice, this list of conditions and the following disclaimer in
--       the documentation and/or other materials provided with the
--       distribution.
--
--     - Neither the name of The Numerical Algorithms Group Ltd. nor the
--       names of its contributors may be used to endorse or promote products
--       derived from this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


import bc_-util
namespace BOOT


--====================> WAS b-con.boot <================================

--=======================================================================
--              Pages Initiated from HyperDoc Pages
--=======================================================================
--NOTE: This duplicate version was discovered 3/20/94 in br-search.boot
--called from buttons via bcCon, bcAbb, bcConform, dbShowCons1, dbSelectCon
--conPage(a,:b) ==
--  --The next 4 lines allow e.g. MATRIX INT  ==> Matrix Integer (see kPage)
--  $conArgstrings: local :=
--    atom a => b
--    a := conform2OutputForm a
--    [mathform2HtString x for x in rest a]
--  if cons? a then a := first a
--  da := DOWNCASE a
--  pageName := LASSQ(da,'((type . CategoryType)(union . DomainUnion)(record . DomainRecord)(mapping . DomainMapping))) =>
--    downlink pageName              --special jump out for primitive domains
--  line := conPageFastPath a        => kPage line  --lower case name of cons?
--  line := conPageFastPath UPCASE a => kPage line  --upper case an abbr?
--  ySearch a                        --slow search (include default packages)
--

--called from buttons via bcCon, bcAbb, bcConform, dbShowCons1, dbSelectCon
conPage(a,:b) ==
  --The next 4 lines allow e.g. MATRIX INT  ==> Matrix Integer (see kPage)
  form :=
    atom a => [a,:b]
    a
  $conArgstrings: local := [form2HtString x for x in KDR a]
  if cons? a then a := first a
  da := DOWNCASE a
  pageName := LASSQ(da,'((type . CategoryType)(union . DomainUnion)(record . DomainRecord)(mapping . DomainMapping)(enumeration . DomainEnumeration))) =>
    downlink pageName                --special jump out for primitive domains
  line := conPageFastPath da  => kPage(line,form) --lower case name of cons?
  line := conPageFastPath UPCASE a => kPage(line,form) --upper case an abbr?
  ySearch a       --slow search (include default packages)

conPageFastPath x == --called by conPage and constructorSearch
--gets line quickly for constructor name or abbreviation
  s := STRINGIMAGE x
  charPosition(char '_*,s,0) < #s => nil     --quit if name has * in it
  name := (string? x => INTERN x; x)
  entry := HGET($lowerCaseConTb,name) or return nil
  lineNumber := LASSQ('dbLineNumber,CDDR entry) =>
    --'dbLineNumbers property is set by function dbAugmentConstructorDataTable
    dbRead lineNumber --read record for constructor from libdb.text
  conPageConEntry first entry

conPageConEntry entry ==
  $conname: local := nil
  $conform: local := nil
  $exposed?:local := nil
  $doc:     local := nil
  $kind:    local := nil
  buildLibdbConEntry entry

--=======================================================================
--                    Constructor Page
--=======================================================================
-- in br-saturn.boot now
--% kPage(line,:options) == --any cat, dom, package, default package
--% --constructors    Cname\#\E\sig \args   \abb \comments (C is C, D, P, X)
--% ------------------> BRANCH OUT FOR SATURN
--%   true => kPageSaturn(line,options)
--%   parts := dbXParts(line,7,1)
--%   [kind,name,nargs,xflag,sig,args,abbrev,comments] := parts
--%   form := IFCAR options
--%   isFile := null kind
--%   kind := kind or '"package"
--%   parts.first := kind
--%   conform         := mkConform(kind,name,args)
--%   conname         := opOf conform
--%   capitalKind     := capitalize kind
--%   signature       := ncParseFromString sig
--%   sourceFileName  := dbSourceFile INTERN name
--%   constrings      :=
--%     KDR form => dbConformGenUnder form
--%     [strconc(name,args)]
--%   emString        := ['"{\sf ",:constrings,'"}"]
--%   heading := [capitalKind,'" ",:emString]
--%   if not isExposedConstructor conname then heading := ['"Unexposed ",:heading]
--%   if name=abbrev then abbrev := asyAbbreviation(conname,nargs)
--%   page := htInitPage(heading,nil)
--%   htpSetProperty(page,'isFile,true)
--%   htpSetProperty(page,'parts,parts)
--%   htpSetProperty(page,'heading,heading)
--%   htpSetProperty(page,'kind,kind)
--%   if asharpConstructorName? conname then
--%     htpSetProperty(page,'isAsharpConstructor,true)
--%   htpSetProperty(page,'conform,conform)
--%   htpSetProperty(page,'signature,signature)
--%   kdPageInfo(name,abbrev,nargs,conform,signature,isFile)
--%   htSayStandard  '"\newline"
--%   htBeginMenu(3)
--%   htSayStandard '"\item "
--%   htMakePage [['bcLinks,['"\menuitemstyle{Description}",
--%                 [['text,'"\tab{19}",'"General description"]],'kiPage,nil]]]
--%   satBreak()
--%   htMakePage [['bcLinks,['"\menuitemstyle{Operations}",
--%                 [['text,'"\tab{19}All exported operations"]],'koPage,'"operation"]]]
--%   if not asharpConstructorName? conname then
--%     satBreak()
--%     htMakePage [['bcLinks,['"\menuitemstyle{Attributes}",
--%                 [['text,'"\tab{19}All exported attributes"]],'koPage,'"attribute"]]]
--%   if kind ~= 'category and (pathname := dbHasExamplePage conname) then
--%     satBreak()
--%     htMakePage [['bcLinks,['"\menuitemstyle{Examples}",
--%                 [['text,'"\tab{19}Examples illustrating use"]],'kxPage,pathname]]]
--%   satBreak()
--%   htMakePage [['bcLinks,['"\menuitemstyle{Exports}",
--%     [['text,'"\tab{19}Explicit categories and operations"]],'kePage,nil]]]
--%   satBreak()
--%   htMakePage [['bcLinks,['"\menuitemstyle{Cross Reference}",
--%                 [['text,'"\tab{19}Hierarchy and usage information"]],'kcPage,nil]]]
--%   htEndMenu(3)
--%   if kind ~= 'category and nargs > 0 then addParameterTemplates conform
--%   htShowPage()
--% 
conform2String u ==
  x := form2String u
  atom x => STRINGIMAGE x
  strconc/[STRINGIMAGE y for y in x]

kxPage(htPage,name) == downlink name

kdPageInfo(name,abbrev,nargs,conform,signature,file?) ==
  htSay("{\sf ",name,'"}")
  if abbrev ~= name then bcHt [" has abbreviation ",abbrev]
  if file? then bcHt ['" is a source file."]
  if nargs = 0 then (if abbrev ~= name then bcHt '".")
    else
      if abbrev ~= name then bcHt '" and"
      bcHt
        nargs = 1 => '" takes one argument:"
        [" takes ",STRINGIMAGE nargs," arguments:"]
  htSaturnBreak()
  htSayStandard '"\indentrel{2}"
  if nargs > 0 then kPageArgs(conform,signature)
  htSayStandard '"\indentrel{-2}"
  if name.(#name-1) = char "&" then name := SUBSEQ(name, 0, #name-1)
--sourceFileName := dbSourceFile INTERN name
  sourceFileName := getConstructorSourceFileFromDB INTERN name
  filename := extractFileNameFromPath sourceFileName
  if filename ~= '"" then
    htSayStandard '"\newline{}"
    htSay('"The source code for the constructor is found in ")
  htMakePage [['text,'"\unixcommand{",filename,'"}{",textEditor(), '" ",
              sourceFileName, '" ", name, '"}"]]
  if nargs ~= 0 then htSay '"."
  htSaturnBreak()

kArgPage(htPage,arg) ==
  [op,:args] := conform := htpProperty(htPage,'conform)
  domname := htpProperty(htPage,'domname)
  heading := htpProperty(htPage,'heading)
  source := CDDAR getConstructorModemapFromDB op
  n := position(arg,args)
  typeForm := sublisFormal(args,source . n)
  domTypeForm := mkDomTypeForm(typeForm,conform,domname)
  descendants := domainDescendantsOf(typeForm,domTypeForm)
  htpSetProperty(htPage,'cAlist,descendants)
  rank :=
    n > 4 => nil
    ('(First Second Third Fourth Fifth)).n
  htpSetProperty(htPage,'rank,rank)
  htpSetProperty(htPage,'thing,'"argument")
--htpSetProperty(htPage,'specialMessage,['reportCategory,conform,typeForm,arg])
  dbShowCons(htPage,'names)

reportCategory(conform,typeForm,arg) ==
  htSay('"Argument {\em ",arg,'"}")
  [conlist,attrlist,:oplist] := categoryParts(conform,typeForm,true)
  htSay '" must "
  if conlist then
    htSay '"belong to "
    if conlist is [u] then
       htSay('"category ")
       bcConform first u
       bcPred rest u
    else
       htSay('"categories:")
       bcConPredTable(conlist,opOf conform)
       htSay '"\newline "
  if attrlist then
    if conlist then htSay '" and "
    reportAO('"attribute",attrlist)
    htSay '"\newline "
  if oplist then
    if conlist or attrlist then htSay '" and "
    reportAO('"operation",oplist)

reportAO(kind,oplist) ==
  htSay('"have ",kind,'":")
  for [op,sig,:pred] in oplist repeat
    htSay '"\newline "
    if #oplist = 1 then htSay '"\centerline{"
    if kind = '"attribute" then
      attr := form2String [op,:sig]
      satDownLink(attr,['"(|attrPage| '|",attr,'"|)"])
    else
      ops  := escapeSpecialChars STRINGIMAGE op
      sigs := form2HtString ['Mapping,:sig]
      satDownLink(ops,['"(|opPage| '|",ops,'"| |",sigs,'"|)"])
      htSay '": "
      bcConform ['Mapping,:sig]
    if #oplist = 1 then htSay '"}"
  htSay '"\newline "

mkDomTypeForm(typeForm,conform,domname) == --called by kargPage
  domname => SUBLISLIS(rest domname,rest conform,typeForm)
  typeForm is ['Join,:r] => ['Join,:[mkDomTypeForm(t,conform,domname) for t in r]]
  null hasIdent typeForm => typeForm
  nil

domainDescendantsOf(conform,domform) == main where --called by kargPage
  main() ==
    conform is [op,:r] =>
      op = 'Join => jfn(delete('(Type Object),r),delete('(Type Object),IFCDR domform))
      op = 'CATEGORY => nil
      domainsOf(conform,domform)
    domainsOf(conform,domform)
  jfn([y,:r],domlist) ==  --keep only those domains that appear in ALL parts of Join
    alist := domainsOf(y,IFCAR domlist)
    for x in r repeat
      domlist := IFCDR domlist
      x is ['CATEGORY,.,:r] => alist := catScreen(r,alist)
      keepList := nil
      for [item,:pred] in domainsOf(x,IFCAR domlist) repeat
        u := assoc(item,alist) =>
          keepList := [[item,:quickAnd(rest u,pred)],:keepList]
      alist := keepList
    for pair in alist repeat 
      pair.rest := simpHasPred rest pair
    listSort(function GLESSEQP, alist)
  catScreen(r,alist) ==
    for x in r repeat
      x isnt [op1,:.] and op1 in '(ATTRIBUTE SIGNATURE) => systemError x
      alist := [[item,:npred] for [item,:pred] in alist |
        (pred1 := simpHasPred ["has",item,x]) and (npred := quickAnd(pred1,pred))]
    alist

--=======================================================================
--                   Branches of Constructor Page
--=======================================================================

kiPage(htPage,junk) ==
  [kind,name,nargs,xflag,sig,args,abbrev,comments] := htpProperty(htPage,'parts)
  conform         := mkConform(kind,name,args)
  domname         := kDomainName(htPage,kind,name,nargs)
  domname is ['error,:.] => errorPage(htPage,domname)
  heading := ['"Description of ", capitalize kind,'" {\sf ",name,args,'"}"]
  page := htInitPage(heading,htCopyProplist htPage)
  $conformsAreDomains := domname
  dbShowConsDoc1(htPage,conform,nil)
  htShowPage()

kePage(htPage,junk) ==
  [kind,name,nargs,xflag,sig,args,abbrev,comments] := htpProperty(htPage,'parts)
  constring       := strconc(name,args)
  domname         := kDomainName(htPage,kind,name,nargs)
  domname is ['error,:.] => errorPage(htPage,domname)
  htpSetProperty(htPage,'domname,domname)
  $conformsAreDomains: local := domname
  conform         := mkConform(kind,name,args)
  conname         := opOf conform
  heading := [capitalize kind,'" {\sf ",
               (domname => form2HtString(domname,nil,true); constring),'"}"]
  data := sublisFormal(IFCDR domname or rest conform,
                       getConstructorExports((domname or conform),true))
  [conlist,attrlist,:oplist] := data
  if domname then
    for x in conlist repeat  x.rest := simpHasPred rest x
    for x in attrlist repeat x.rest.rest := simpHasPred CDDR x
    for x in oplist   repeat x.rest.rest := simpHasPred CDDR x
  prefix := pluralSay(#conlist + #attrlist + #oplist,'"Export",'"Exports")
  page := htInitPage([:prefix,'" of ",:heading],htCopyProplist htPage)
  htSayStandard '"\beginmenu "
  htpSetProperty(page,'data,data)
  if conlist then
    htMakePage [['bcLinks,[menuButton(),'"",'dbShowCons1,conlist,'names]]]
    htSayStandard '"\tab{2}"
    htSay  '"All attributes and operations from:"
    bcConPredTable(conlist,opOf conform,rest conform)
  if attrlist then
    if conlist then htBigSkip()
    kePageDisplay(page,'"attribute",kePageOpAlist attrlist)
  if oplist then
    if conlist or attrlist then htBigSkip()
    kePageDisplay(page,'"operation",kePageOpAlist oplist)
  htSayStandard '" \endmenu "
  htShowPage()

kePageOpAlist oplist ==
  opAlist := nil
  for [op,sig,:pred] in oplist repeat
    u := LASSOC(op,opAlist)
--was 
--    opAlist := insertAlist(op,[[sig,pred],:u],opAlist)
    opAlist := insertAlist(zeroOneConvert op,[[sig,pred],:u],opAlist)
  opAlist

kePageDisplay(htPage,which,opAlist) ==
  count := #opAlist
  total := +/[#(rest entry) for entry in opAlist]
  count = 0 => nil
  if which = '"operation"
    then htpSetProperty(htPage,'opAlist,opAlist)
    else htpSetProperty(htPage,'attrAlist,opAlist)
  expandProperty :=
    which = '"operation" => 'expandOperations
    'expandAttributes
  htpSetProperty(htPage,expandProperty,'lists)  --mark as unexpanded
  htMakePage [['bcLinks,[menuButton(),'"",'dbShowOps,which,'names]]]
  htSayStandard '"\tab{2}"
  if count ~= total then
    if count = 1
    then htSay('"1 name for ")
    else htSay(STRINGIMAGE count,'" names for ")
  if total > 1
    then htSay(STRINGIMAGE total,'" ",pluralize which,'" are explicitly exported:")
    else htSay('"1 ",which,'" is explicitly exported:")
  htSaySaturn '"\\"
  data := dbGatherData(htPage,opAlist,which,'names)
  dbShowOpItems(which,data,false)

ksPage(htPage,junk) ==
  [kind,name,nargs,xpart,sig,args,abbrev,comments] := htpProperty(htPage,'parts)
  domname         := kDomainName(htPage,kind,name,nargs)
  domname is ['error,:.] => errorPage(htPage,domname)
  heading :=
    null domname => htpProperty(htPage,'heading)
    ['"{\sf ",form2HtString(domname,nil,true),'"}"]
  if domname then
    htpSetProperty(htPage,'domname,domname)
    htpSetProperty(htPage,'heading,heading)
  domain  := (kind = '"category" => nil; eval domname)
  conform:= htpProperty(htPage,'conform)
  page := htInitPageNoScroll(htCopyProplist htPage,
                             ['"Search order for ",:heading])
  htSay '"When an operation is not defined by the domain, the following domains are searched in order for a _"default definition"
  htSayStandard '"\beginscroll "
  u := dbSearchOrder(conform,domname,domain)
  htpSetProperty(htPage,'cAlist,u)
  htpSetProperty(htPage,'thing,'"constructor")
  dbShowCons(htPage,'names)

dbSearchOrder(conform,domname,$domain) ==  --domain = nil or set to live domain
  conform := domname or conform
  name:= opOf conform
  $infovec: local := dbInfovec name or return nil  --exit for categories
  u := $infovec.3
  $predvec:=
    $domain => $domain . 3
    getConstructorPredicatesFromDB name
  catpredvec := first u
  catinfo    := second u
  catvec     := third u
  catforms := [[pakform,:pred] for i in 0..MAXINDEX catvec | test ] where
    test() ==
      pred := simpCatPredicate
        p:=SUBLISLIS(rest conform,$FormalMapVariableList,kTestPred catpredvec.i)
        $domain => eval p
        p
      if domname and CONTAINED('$,pred) then pred := substitute(domname,'$,pred)
--    which = '"attribute" => pred    --all categories
      (pak := catinfo . i) and pred   --only those with default packages
    pakform() ==
      pak and not IDENTP pak => devaluate pak --in case it has been instantiated
      catform := kFormatSlotDomain catvec . i
--    which = '"attribute" => dbSubConform(rest conform,catform)
      res := dbSubConform(rest conform,[pak,"$",:rest catform])
      if domname then res := substitute(domname,'$,res)
      res
  [:dbAddChain conform,:catforms]

kcPage(htPage,junk) ==
  [kind,name,nargs,xpart,sig,args,abbrev,comments] := htpProperty(htPage,'parts)
  domname         := kDomainName(htPage,kind,name,nargs)
  domname is ['error,:.] => errorPage(htPage,domname)
--  domain          := (kind = '"category" => nil; eval domname)
  conform := htpProperty(htPage,'conform)
  conname := opOf conform
  heading :=
    null domname => htpProperty(htPage,'heading)
    ['"{\sf ",form2HtString(domname,nil,true),'"}"]
  page := htInitPage(['"Cross Reference for ",:heading],htCopyProplist htPage)
  if domname then
    htpSetProperty(htPage,'domname,domname)
    htpSetProperty(htPage,'heading,heading)
  if kind = '"category" and dbpHasDefaultCategory? xpart then
    htSay '"This category has default package "
    bcCon(strconc(name,char '_&),'"")
  htSayStandard '"\newline"
  htBeginMenu(3)
  htSayStandard '"\item "
  message :=
    kind = '"category" => ['"Categories it directly extends"]
    ['"Categories the ",(kind = '"default package" => '"package"; kind),'" belongs to by assertion"]
  htMakePage [['bcLinks,['"\menuitemstyle{Parents}",
    [['text,'"\tab{12}",:message]],'kcpPage,nil]]]
  satBreak()
  message :=
    kind = '"category" => ['"All categories it is an extension of"]
    ['"All categories the ",kind,'" belongs to"]
  htMakePage [['bcLinks,['"\menuitemstyle{Ancestors}",
    [['text,'"\tab{12}",:message]],'kcaPage,nil]]]
  if kind = '"category" then
    satBreak()
    htMakePage [['bcLinks,['"\menuitemstyle{Children}",[['text,'"\tab{12}",
      '"Categories which directly extend this category"]],'kccPage,nil]]]

    satBreak()
    htMakePage [['bcLinks,['"\menuitemstyle{Descendants}",[['text,'"\tab{12}",
      '"All categories which extend this category"]],'kcdPage,nil]]]
  if not asharpConstructorName? conname then
    satBreak()
    message := '"Constructors mentioning this as an argument type"
    htMakePage [['bcLinks,['"\menuitemstyle{Dependents}",
      [['text,'"\tab{12}",message]],'kcdePage,nil]]]
  if not asharpConstructorName? conname and kind ~= '"category" then
    satBreak()
    htMakePage [['bcLinks,['"\menuitemstyle{Lineage}",
      '"\tab{12}Constructor hierarchy used for operation lookup",'ksPage,nil]]]
  if not asharpConstructorName? conname then
   if kind = '"category" then
    satBreak()
    htMakePage [['bcLinks,['"\menuitemstyle{Domains}",[['text,'"\tab{12}",
      '"All domains which are of this category"]],'kcdoPage,nil]]]
   if kind ~= '"category" then
    satBreak()
    htMakePage [['bcLinks,['"\menuitemstyle{Clients}",'"\tab{12}Constructors",'kcuPage,nil]]]
    if HGET($defaultPackageNamesHT,conname)
      then htSay('" which {\em may use} this default package")
--  htMakePage [['bcLinks,['"files",'"",'kcuPage,true]]]
      else htSay('" which {\em use} this ",kind)
  if kind ~= '"category" or dbpHasDefaultCategory? xpart then
    satBreak()
    message :=
      kind = '"category" => ['"Constructors {\em used by} its default package"]
      ['"Constructors {\em used by} the ",kind]
    htMakePage [['bcLinks,['"\menuitemstyle{Benefactors}",
      [['text,'"\tab{12}",:message]],'kcnPage,nil]]]
  --to remove "Capsule Information", comment out the next 5 lines
  if not asharpConstructorName? conname and hasNewInfoAlist conname then
    satBreak()
    message := ['"Cross reference for capsule implementation"]
    htMakePage [['bcLinks,['"\menuitemstyle{CapsuleInfo}",
      [['text,'"\tab{12}",:message]],'kciPage,nil]]]
  htEndMenu(3)
  htShowPage()

kcpPage(htPage,junk) ==
  [kind,name,nargs,xpart,sig,args,abbrev,comments] := htpProperty(htPage,'parts)
  domname         := kDomainName(htPage,kind,name,nargs)
  domname is ['error,:.] => errorPage(htPage,domname)
  heading :=
    null domname => htpProperty(htPage,'heading)
    ['"{\sf ",form2HtString(domname,nil,true),'"}"]
  if domname then
    htpSetProperty(htPage,'domname,domname)
    htpSetProperty(htPage,'heading,heading)
  conform := htpProperty(htPage,'conform)
  conname := opOf conform
  page := htInitPage(['"Parents of ",:heading],htCopyProplist htPage)
  parents := parentsOf conname --was listSort(function GLESSEQP, =this)
  if domname then parents := SUBLISLIS(rest domname,rest conform,parents)
  htpSetProperty(htPage,'cAlist,parents)
  htpSetProperty(htPage,'thing,'"parent")
  choice :=
    domname => 'parameters
    'names
  dbShowCons(htPage,choice)

reduceAlistForDomain(alist,domform,conform) == --called from kccPage
  alist := SUBLISLIS(rest domform,rest conform,alist)
  for pair in alist repeat 
    pair.rest := simpHasPred(rest pair,domform)
  [pair for (pair := [.,:pred]) in alist | pred]

kcaPage(htPage,junk) ==
  kcaPage1(htPage,'"category",'" an ",'"ancestor",function ancestorsOf, false)

kcdPage(htPage,junk) ==
  kcaPage1(htPage,'"category",'" a ",'"descendant",function descendantsOf,true)

kcdoPage(htPage,junk)==
  kcaPage1(htPage,'"domain",'" a ",'"descendant",function domainsOf, false)

kcaPage1(htPage,kind,article,whichever,fn, isCatDescendants?) ==
  [kind,name,nargs,xpart,sig,args,abbrev,comments] := htpProperty(htPage,'parts)
  domname         := kDomainName(htPage,kind,name,nargs)
  domname is ['error,:.] => errorPage(htPage,domname)
  heading :=
    null domname => htpProperty(htPage,'heading)
    ['"{\sf ",form2HtString(domname,nil,true),'"}"]
  if domname and not isCatDescendants? then
    htpSetProperty(htPage,'domname,domname)
    htpSetProperty(htPage,'heading,heading)
  conform := htpProperty(htPage,'conform)
  conname := opOf conform
  ancestors := FUNCALL(fn, conform, domname)
  if whichever ~= '"ancestor" then
    ancestors := augmentHasArgs(ancestors,conform)
  ancestors := listSort(function GLESSEQP,ancestors)
--if domname then ancestors := substitute(domname,'$,ancestors)
  htpSetProperty(htPage,'cAlist,ancestors)
  htpSetProperty(htPage,'thing,whichever)
  choice :=
--  domname => 'parameters
    'names
  dbShowCons(htPage,choice)

kccPage(htPage,junk) ==
  [kind,name,nargs,xpart,sig,args,abbrev,comments] := htpProperty(htPage,'parts)
  domname         := kDomainName(htPage,kind,name,nargs)
  domname is ['error,:.] => errorPage(htPage,domname)
  heading :=
    null domname => htpProperty(htPage,'heading)
    ['"{\sf ",form2HtString(domname,nil,true),'"}"]
  if domname then
    htpSetProperty(htPage,'domname,domname)
    htpSetProperty(htPage,'heading,heading)
  conform := htpProperty(htPage,'conform)
  conname := opOf conform
  page := htInitPage(['"Children of ",:heading],htCopyProplist htPage)
  children:= augmentHasArgs(childrenOf conform,conform)
  if domname then children := reduceAlistForDomain(children,domname,conform)
  htpSetProperty(htPage,'cAlist,children)
  htpSetProperty(htPage,'thing,'"child")
  dbShowCons(htPage,'names)

augmentHasArgs(alist,conform) ==
  conname := opOf conform
  args    := KDR conform or return alist
  n       := #args
  [[name,:pred] for [name,:p] in alist] where pred() ==
     extractHasArgs p is [a,:b] => p
     quickAnd(p,['hasArgs,:TAKE(n,KDR getConstructorForm opOf name)])

kcdePage(htPage,junk) ==
  [kind,name,nargs,xflag,sig,args,abbrev,comments] := htpProperty(htPage,'parts)
  conname         := INTERN name
  constring       := strconc(name,args)
  conform         :=
    kind ~= '"default package" => ncParseFromString constring
    [INTERN name,:rest ncParseFromString strconc(char 'd,args)]  --because of &
  pakname         :=
--  kind = '"category" => INTERN strconc(name,char '_&)
    opOf conform
  domList := getDependentsOfConstructor pakname
  cAlist := [[getConstructorForm x,:true] for x in domList]
  htpSetProperty(htPage,'cAlist,cAlist)
  htpSetProperty(htPage,'thing,'"dependent")
  dbShowCons(htPage,'names)

kcuPage(htPage,junk) ==
  [kind,name,nargs,xflag,sig,args,abbrev,comments] := htpProperty(htPage,'parts)
  conname         := INTERN name
  constring       := strconc(name,args)
  conform         :=
    kind ~= '"default package" => ncParseFromString constring
    [INTERN name,:rest ncParseFromString strconc(char 'd,args)]  --because of &
  pakname         :=
    kind = '"category" => INTERN strconc(name,char '_&)
    opOf conform
  domList := getUsersOfConstructor pakname
  cAlist := [[getConstructorForm x,:true] for x in domList]
  htpSetProperty(htPage,'cAlist,cAlist)
  htpSetProperty(htPage,'thing,'"user")
  dbShowCons(htPage,'names)

kcnPage(htPage,junk) ==
--if reached by a category, that category has a default package
  [kind,name,nargs,xpart,sig,args,abbrev,comments] := htpProperty(htPage,'parts)
  domname         := kDomainName(htPage,kind,name,nargs)
  domname is ['error,:.] => errorPage(htPage,domname)
  heading :=
    null domname => htpProperty(htPage,'heading)
    ['"{\sf ",form2HtString(domname,nil,true),'"}"]
  if domname then
    htpSetProperty(htPage,'domname,domname)
    htpSetProperty(htPage,'heading,heading)
  conform:= htpProperty(htPage,'conform)
  pakname         :=
    kind = '"category" => INTERN strconc(PNAME name,char '_&)
    opOf conform
  domList := getImports pakname
  if domname then
    domList := SUBLISLIS([domname,:rest domname],['$,:rest conform],domList)
  cAlist := [[x,:true] for x in domList]
  htpSetProperty(htPage,'cAlist,cAlist)
  htpSetProperty(htPage,'thing,'"benefactor")
  dbShowCons(htPage,'names)

koPageInputAreaUnchanged?(htPage, nargs) ==
  [htpLabelInputString(htPage,INTERN strconc('"*",STRINGIMAGE i)) for i in 1..nargs]
      = htpProperty(htPage,'inputAreaList)

kDomainName(htPage,kind,name,nargs) ==
  htpSetProperty(htPage,'domname,nil)
  inputAreaList :=
    [htpLabelInputString(htPage,var) for i in 1..nargs for var in $PatternVariableList]
  htpSetProperty(htPage,'inputAreaList,inputAreaList)
  conname := INTERN name
  args := [kArgumentCheck(domain?,x) or nil for x in inputAreaList
              for domain? in rest getDualSignatureFromDB conname]
  or/[null x for x in args] =>
    (n := +/[1 for x in args | x]) > 0 =>
      ['error,nil,'"\centerline{You gave values for only {\em ",n,'" } of the {\em ",#args,'"}}",'"\centerline{parameters of {\sf ",name,'"}}\vspace{1}\centerline{Please enter either {\em all} or {\em none} of the type parameters}"]
    nil
  argString :=
    null args => '"()"
    argTailPart :=
      strconc/[strconc/ ['",",:x] for x in KDR args]
    strconc/['"(",:first args,argTailPart,'")"]
  typeForm := CATCH($SpadReaderTag, unabbrev mkConform(kind,name,argString)) or
    ['error,'invalidType,strconc(name,argString)]
  null (evaluatedTypeForm := kisValidType typeForm) =>
    ['error,'invalidType,strconc(name,argString)]
  dbMkEvalable evaluatedTypeForm

kArgumentCheck(domain?,s) ==
  s = '"" => nil
  domain? and (form := conSpecialString? s) =>
    null KDR form => [STRINGIMAGE opOf form]
    form2String form
  [s]

dbMkEvalable form ==
--like mkEvalable except that it does NOT quote domains
--does not do "loadIfNecessary"
  [op,:.] := form
  kind := getConstructorKindFromDB op
  kind = 'category => form
  mkEvalable form

topLevelInterpEval x ==
  $ProcessInteractiveValue: fluid := true
  $noEvalTypeMsg: fluid := true
  processInteractive(x,nil)

kisValidType typeForm ==
  $ProcessInteractiveValue: fluid := true
  $noEvalTypeMsg: fluid := true
  CATCH($SpadReaderTag, processInteractive(typeForm,nil))
    is [m,:t] and member(m,$LangSupportTypes) =>
      kCheckArgumentNumbers t and t
  false

kCheckArgumentNumbers t ==
  [conname,:args] := t
  cosig := KDR getDualSignatureFromDB conname
  #cosig ~= #args => false
  and/[foo for domain? in cosig for x in args] where foo() ==
    domain? => kCheckArgumentNumbers x
    true

parseNoMacroFromString(s) ==
   s := next(function ncloopParse,
        next(function lineoftoks,incString s))
   StreamNull s => nil
   pf2Sex second first s
 


mkConform(kind,name,argString) ==
  kind ~= '"default package" =>
    form := strconc(name,argString)
    parse := parseNoMacroFromString form
    null parse =>
      sayBrightlyNT '"Won't parse: "
      pp form
      systemError '"Keywords in argument list?"
    atom parse => [parse]
    parse
  [INTERN name,:rest ncParseFromString strconc(char 'd,argString)]  --& case

--=======================================================================
--           Operation Page for a Domain Form from Scratch
--=======================================================================
conOpPage(htPage,conform) ==
  updown := dbCompositeWithMap htPage
  updown = '"DOWN" =>
    domname := htpProperty(htPage,'domname)
    conOpPage1(dbExtractUnderlyingDomain domname,[['updomain,:domname]])
  domname := htpProperty(htPage,'updomain)
  conOpPage1(domname,nil)

dbCompositeWithMap htPage ==
  htpProperty(htPage,'updomain) => '"UP"
  domain := htpProperty(htPage,'domname)
  null domain => false
  opAlist := htpProperty(htPage,'opAlist)
--not LASSOC('map,opAlist) => false
  dbExtractUnderlyingDomain htpProperty(htPage,'domname) => '"DOWN"
  false

dbExtractUnderlyingDomain domain == or/[x for x in KDR domain | isValidType x]

--conform is atomic if no parameters, otherwise must be valid domain form
conOpPage1(conform,:options) ==
--constructors    Cname\#\E\sig \args   \abb \comments (C is C, D, P, X)
  bindingsAlist := IFCAR options
  conname       := opOf conform
  MEMQ(conname,$DomainNames) =>
     dbSpecialOperations conname
  domname         :=                        --> !!note!! <--
    cons? conform => conform
    nil
  line := conPageFastPath conname
  [kind,name,nargs,xflag,sig,args,abbrev,comments]:=parts:= dbXParts(line,7,1)
  isFile := null kind
  kind := kind or '"package"
  parts.first := kind
  constring       := strconc(name,args)
  conform         := mkConform(kind,name,args)
  capitalKind     := capitalize kind
  signature       := ncParseFromString sig
  sourceFileName  := dbSourceFile INTERN name
  emString        := ['"{\sf ",constring,'"}"]
  heading := [capitalKind,'" ",:emString]
  if not isExposedConstructor conname then heading := ['"Unexposed ",:heading]
  page := htInitPage(heading,nil)
  htpSetProperty(page,'isFile,true)
  htpSetProperty(page,'fromConOpPage1,true)
  htpSetProperty(page,'parts,parts)
  htpSetProperty(page,'heading,heading)
  htpSetProperty(page,'kind,kind)
  htpSetProperty(page,'domname,domname)         --> !!note!! <--
  htpSetProperty(page,'conform,conform)
  htpSetProperty(page,'signature,signature)
  if selectedOperation := LASSOC('selectedOperation,IFCDR options) then
    htpSetProperty(page,'selectedOperation,selectedOperation)
  for [a,:b] in bindingsAlist repeat htpSetProperty(page,a,b)
  koPage(page,'"operation")

--=======================================================================
--           Operation Page from Main Page
--=======================================================================
koPage(htPage,which) ==
  [kind,name,nargs,xflag,sig,args,abbrev,comments] := htpProperty(htPage,'parts)
  constring       := strconc(name,args)
  conname         := INTERN name
  domname         :=
    (u := htpProperty(htPage,'domname)) is [=conname,:.]
      and  (htpProperty(htPage,'fromConOpPage1) = true or
             koPageInputAreaUnchanged?(htPage,nargs)) => u
    kDomainName(htPage,kind,name,nargs)
  domname is ['error,:.] => errorPage(htPage,domname)
  htpSetProperty(htPage,'domname,domname)
  headingString :=
    domname => form2HtString(domname,nil,true)
    constring
  heading := [capitalize kind,'" {\sf ",headingString,'"}"]
  htpSetProperty(htPage,'which,which)
  htpSetProperty(htPage,'heading,heading)
  koPageAux(htPage,which,domname,heading)

koPageFromKKPage(htPage,ao) ==
  koPageAux(htPage,ao,htpProperty(htPage,'domname),htpProperty(htPage,'heading))

koPageAux(htPage,which,domname,heading) == --from koPage, koPageFromKKPage
  htpSetProperty(htPage,'which,which)
  domname := htpProperty(htPage,'domname)
  conform := htpProperty(htPage,'conform)
  heading := htpProperty(htPage,'heading)
  opAlist          :=
    which = '"attribute" => koAttrs(conform,domname)
    which = '"general operation" => koOps(conform,domname,true)
    koOps(conform,domname)
  if selectedOperation := htpProperty(htPage,'selectedOperation) then
    opAlist := [assoc(selectedOperation,opAlist) or systemError()]
  dbShowOperationsFromConform(htPage,which,opAlist)

koPageAux1(htPage,opAlist) ==
  which   := htpProperty(htPage,'which)
  dbShowOperationsFromConform(htPage,which,opAlist)

koaPageFilterByName(htPage,functionToCall) ==
  htpLabelInputString(htPage,'filter) = '"" =>
    koaPageFilterByCategory(htPage,functionToCall)
  filter := pmTransFilter(dbGetInputString htPage)
--WARNING: this call should check for ['error,:.] returned
  which   := htpProperty(htPage,'which)
  opAlist :=
      [x for x in htpProperty(htPage,'opAlist) | superMatch?(filter,DOWNCASE STRINGIMAGE first x)]
  htpSetProperty(htPage,'opAlist,opAlist)
  FUNCALL(functionToCall,htPage,nil)

--=======================================================================
--                  Get Constructor Documentation
--=======================================================================

dbConstructorDoc(conform,$op,$sig) == fn conform where
  fn (conform := [conname,:$args]) ==
    or/[gn y for y in getConstructorDocumentationFromDB conname]
  gn([op,:alist]) ==
    op = $op and "or"/[doc or '("") for [sig,:doc] in alist | hn sig]
  hn sig ==
    #$sig = #sig and $sig = SUBLISLIS($args,$FormalMapVariableList,sig)

dbDocTable conform ==
--assumes $docTableHash bound --see dbExpandOpAlistIfNecessary
  table := HGET($docTableHash,conform) => table
  $docTable : local := hashTable 'EQ
  --process in reverse order so that closest cover up farthest
  for x in originsInOrder conform repeat dbAddDocTable x
  dbAddDocTable conform
  HPUT($docTableHash,conform,$docTable)
  $docTable

originsInOrder conform ==  --domain = nil or set to live domain
--from dcCats
  [con,:argl] := conform
  getConstructorKindFromDB con = "category" =>
      ASSOCLEFT ancestorsOf(conform,nil)
  acc := ASSOCLEFT parentsOf con
  for x in acc repeat
    for y in originsInOrder x repeat acc := insert(y,acc)
  acc

dbAddDocTable conform ==
  conname := opOf conform
  storedArgs := rest getConstructorForm conname
  for [op,:alist] in SUBLISLIS(["$",:rest conform],
    ["%",:storedArgs],getConstructorDocumentationFromDB opOf conform)
      repeat
       op1 :=
         op = '(Zero) => 0
         op = '(One) => 1
         op
       for [sig,doc] in alist repeat
         HPUT($docTable,op1,[[conform,:alist],:HGET($docTable,op1)])
    --note opOf is needed!!! for some reason, One and Zero appear within prens

dbGetDocTable(op,$sig,docTable,$which,aux) == main where
--docTable is [[origin,entry1,...,:code] ...] where
--  each entry is [sig,doc] and code is NIL or else a topic code for op
  main() ==
    if null FIXP op and
      digit?((s := STRINGIMAGE op).0) then op := string2Integer s
    -- the above hack should be removed after 3/94 when 0 is not |0|
    aux is [[packageName,:.],:pred] =>
      doc := dbConstructorDoc(first aux,$op,$sig)
      origin :=
        pred => ['ifp,:aux]
        first aux
      [origin,:doc]
    or/[gn x for x in HGET(docTable,op)]
  gn u ==  --u is [origin,entry1,...,:code]
    $conform := first u              --origin
    if atom $conform then $conform := [$conform]
    code     := LASTATOM u         --optional topic code
    comments := or/[p for entry in rest u | p := hn entry] or return nil
    [$conform,first comments,:code]
  hn [sig,:doc] ==
    $which = '"attribute" => sig is ['attribute,: =$sig] and doc
    pred := #$sig = #sig and
      alteredSig := SUBLISLIS(KDR $conform,$FormalMapVariableList,sig)
      alteredSig = $sig
    pred =>
      doc =>
        doc is ['constant,:r] => r
        doc
      '("")
    false

kTestPred n ==
  n = 0 => true
  $domain => testBitVector($predvec,n)
  simpHasPred $predvec.(n - 1)

dbAddChainDomain conform ==
  [name,:args] := conform
  $infovec := dbInfovec name or return nil  --exit for categories
  template := $infovec . 0
  null (form := template . 5) => nil
  dbSubConform(args,kFormatSlotDomain devaluate form)

dbSubConform(args,u) ==
  atom u =>
    (n := position(u,$FormalMapVariableList)) >= 0 => args . n
    u
  u is ['local,y] => dbSubConform(args,y)
  [dbSubConform(args,x) for x in u]

dbAddChain conform ==
  u := dbAddChainDomain conform =>
    atom u => nil
    [[u,:true],:dbAddChain u]
  nil

--=======================================================================
--                Constructor Page Menu
--=======================================================================

dbShowCons(htPage,key,:options) ==
  cAlist  := htpProperty(htPage,'cAlist)
  key = 'filter =>
    --if $saturn, IFCAR options is the filter string
    filter := pmTransFilter(IFCAR options or dbGetInputString htPage)
    filter is ['error,:.] => bcErrorPage filter
    abbrev? := htpProperty(htPage,'exclusion) = 'abbrs
    u := [x for x in cAlist | test] where test() ==
      conname := CAAR x
      subject := (abbrev? => constructor? conname; conname)
      superMatch?(filter,DOWNCASE STRINGIMAGE subject)
    null u => emptySearchPage('"constructor",filter)
    htPage := htInitPageNoScroll(htCopyProplist htPage)
    htpSetProperty(htPage,'cAlist,u)
    dbShowCons(htPage,htpProperty(htPage,'exclusion))
  if key in '(exposureOn exposureOff) then
    $exposedOnlyIfTrue :=
      key = 'exposureOn => 'T
      NIL
    key := htpProperty(htPage,'exclusion)
  dbShowCons1(htPage,cAlist,key)

conPageChoose conname ==
  cAlist := [[getConstructorForm conname,:true]]
  dbShowCons1(nil,cAlist,'names)

dbShowCons1(htPage,cAlist,key) ==
  conlist := removeDuplicates [item for x in cAlist | pred] where
    pred() ==
      item := first x
      $exposedOnlyIfTrue => isExposedConstructor opOf item
      item
--$searchFirstTime and (conlist is [.]) => conPage first conlist
--$searchFirstTime := false
  conlist is [.] => conPage
    htPage and htpProperty(htPage,'domname) => first conlist
    opOf first conlist
  conlist := [opOf x for x in conlist]
  kinds := "union"/[dbConstructorKind x for x in conlist]
  kind :=
    kinds is [a] => a
    'constructor
  proplist :=
    htPage => htCopyProplist htPage
    nil
  page := htInitPageNoScroll(proplist,dbConsHeading(htPage,conlist,key,kind))
  if u := htpProperty(page,'specialMessage) then apply(first u,rest u)
  htSayStandard('"\beginscroll ")
  htpSetProperty(page,'cAlist,cAlist)
  $conformsAreDomains: local := htpProperty(page,'domname)
  do
  --key = 'catfilter => dbShowCatFilter(page,key)
    key = 'names => bcNameConTable conlist
    key = 'abbrs =>
      bcAbbTable [getCDTEntry(con,true) for con in conlist]
    key = 'files =>
      flist :=
        [y for con in conlist |
          y := (fn := getConstructorSourceFileFromDB con)]
      bcUnixTable(listSort(function GLESSEQP,removeDuplicates flist))
    key = 'documentation   => dbShowConsDoc(page,conlist)
    if $exposedOnlyIfTrue then
      cAlist := [x for x in cAlist | isExposedConstructor opOf first x]
    key = 'conditions =>     dbShowConditions(page,cAlist,kind)
    key = 'parameters => bcConTable removeDuplicates ASSOCLEFT cAlist
    key = 'kinds => dbShowConsKinds cAlist
  dbConsExposureMessage()
  htSayStandard("\endscroll ")
  dbPresentCons(page,kind,key)
  htShowPageNoScroll()


dbConsExposureMessage() ==
  $atLeastOneUnexposed =>
      htSay '"\newline{}-------------\newline{}{\em *} = unexposed"

-- DUPLICATE DEF - ALSO in br-saturn.boot
-- dbShowConsKinds cAlist ==
-- ---------> !OBSELETE! <-------------
--  cats := doms := paks := defs := nil
--  for x in cAlist repeat
--    op := CAAR x
--    kind := dbConstructorKind op
--    kind  = 'category => cats := [x,:cats]
--    kind = 'domain    => doms := [x,:doms]
--    kind = 'package   => paks:= [x,:paks]
--    defs := [x,:defs]
--  lists := [nreverse cats,nreverse doms,nreverse paks,nreverse defs]
--  htBeginMenu(2)
--  htSayStandard '"\indent{1}"
--  kinds := +/[1 for x in lists | #x > 0]
--  for kind in '("category" "domain" "package" "default package") for x in lists | #x > 0 repeat
--    htSay('"\item")
--    if kinds = 1 then htSay menuButton() else
--      htMakePage [['bcLinks,[menuButton(),'"",'dbShowConsKindsFilter,[kind,x]]]]
--    htSayStandard '"\tab{1}"
--    htSay  '"{\em "
--    htSay (c := #x)
--    htSay '" "
--    htSay (c > 1 => pluralize kind; kind)
--    htSay '":}"
--    bcConTable removeDuplicates [CAAR y for y in x]
--  htEndMenu(2)
--  htSay '"\indent{0}"

dbShowConsKindsFilter(htPage,[kind,cAlist]) ==
  htpSetProperty(htPage,'cAlist,cAlist)
  dbShowCons(htPage,htpProperty(htPage,'exclusion))

dbShowConsDoc(htPage,conlist) ==
  null rest conlist => dbShowConsDoc1(htPage,getConstructorForm opOf first conlist,nil)
  cAlist := htpProperty(htPage,'cAlist)
  --the following code is necessary to skip over duplicates on cAlist
  index := 0
  for x in removeDuplicates conlist repeat
  -- for x in conlist repeat
    dbShowConsDoc1(htPage,getConstructorForm x,i) where i() ==
      while CAAAR cAlist ~= x repeat
        index := index + 1
        cAlist := rest cAlist
        null cAlist => systemError ()
      index

dbShowConsDoc1(htPage,conform,indexOrNil) ==
  [conname,:conargs] := conform
  MEMQ(conname,$DomainNames) =>
    conname := htpProperty(htPage,'conname)
    [["constructor",["NIL",doc]],:.] := GETL(conname,'documentation)
    sig := '((CATEGORY domain) (SetCategory) (SetCategory))
    displayDomainOp(htPage,'"constructor",conform,conname,sig,true,doc,indexOrNil,'dbSelectCon,nil,nil)
  exposeFlag := isExposedConstructor conname
  doc := [getConstructorDocumentation conname]
  signature := getConstructorSignature conname
  sig :=
    getConstructorKindFromDB conname = "category" =>
      SUBLISLIS(conargs,$TriangleVariableList,signature)
    sublisFormal(conargs,signature)
  htSaySaturn '"\begin{description}"
  displayDomainOp(htPage,'"constructor",conform,conname,sig,true,doc,indexOrNil,'dbSelectCon,null exposeFlag,nil)
  htSaySaturn '"\end{description}"
  --NOTE that we pass conform is as "origin"

getConstructorDocumentation conname ==
  LASSOC('constructor,getConstructorDocumentationFromDB conname)
    is [[nil,line,:.],:.] and line or '""

dbSelectCon(htPage,which,index) ==
  conPage opOf first htpProperty(htPage,'cAlist).index

dbShowConditions(htPage,cAlist,kind) ==
  conform := htpProperty(htPage,'conform)
  conname := opOf conform
  article := htpProperty(htPage,'article)
  whichever := htpProperty(htPage,'whichever)
  [consNoPred,:consPred] := splitConTable cAlist
  singular := [kind,'" is"]
  plural   := [pluralize STRINGIMAGE kind,'" are"]
  dbSayItems(#consNoPred,singular,plural,'" unconditional")
  htSaySaturn '"\\"
  bcConPredTable(consNoPred,conname)
  htSayHrule()
  dbSayItems(#consPred,singular,plural,'" conditional")
  htSaySaturn '"\\"
  bcConPredTable(consPred,conname)

dbConsHeading(htPage,conlist,view,kind) ==
  thing := htPage and htpProperty(htPage,'thing) or '"constructor"
  place :=
    htPage => htpProperty(htPage,'domname) or htpProperty(htPage,'conform)
    nil
  count := #(removeDuplicates conlist)
  -- count := #conlist
  thing = '"benefactor" =>
    [STRINGIMAGE count,'" Constructors Used by ",form2HtString(place,nil,true)]
  modifier :=
    thing = '"argument" =>
      rank := htPage and htpProperty(htPage,'rank)
      ['" Possible ",rank,'" "]
    kind = 'constructor => ['" "]
    ['" ",capitalize STRINGIMAGE kind,'" "]
--  count = 1 =>
--    ['"Select name or a {\em view} at the bottom"]
  exposureWord :=
    $exposedOnlyIfTrue => '(" Exposed ")
    nil
  prefix :=
    count = 1 => [STRINGIMAGE count,:modifier,capitalize thing]
    firstWord := (count = 0 => '"No "; STRINGIMAGE count)
    [firstWord,:exposureWord, :modifier,capitalize pluralize thing]
  placepart :=
    place => ['" of {\em ",form2HtString(place,nil,true),"}"]
    nil
  heading := [:prefix,:placepart]
  connective :=
    member(view,'(abbrs files kinds)) => '" as "
    '" with "
  if count ~= 0 and member(view,'(abbrs files parameters conditions)) then heading:= [:heading,'" viewed",connective,'"{\em ",STRINGIMAGE view,'"}"]
  heading

dbShowConstructorLines lines ==
  cAlist := [[getConstructorForm intern dbName line,:true] for line in lines]
  dbShowCons1(nil,listSort(function GLESSEQP,cAlist),'names)

bcUnixTable(u) ==
  htSay '"\newline"
  htBeginTable()
  firstTime := true
  for x in u repeat
    if firstTime then firstTime := false
    else htSaySaturn '"&"
    htSay '"{"
    ft :=
      isAsharpFileName? x => '("AS")
      '("SPAD")
    filename := NAMESTRING $FINDFILE(STRINGIMAGE x, ft)
    htMakePage [['text, '"\unixcommand{",PATHNAME_-NAME x, '"}{",
                   textEditor(), '" ", filename, '"} "]]
    htSay '"}"
  htEndTable()

isAsharpFileName? con == false

--=======================================================================
--             Special Code for Union, Mapping, and Record
--=======================================================================

dbSpecialDescription(conname) ==
  conform := getConstructorForm conname
  heading := ['"Description of Domain {\sf ",form2HtString conform,'"}"]
  page := htInitPage(heading,nil)
  htpSetProperty(page,'conname,conname)
  $conformsAreDomains := nil
  dbShowConsDoc1(page,conform,nil)
  htShowPage()

dbSpecialOperations(conname) ==
  page := htInitPage(nil,nil)
  conform := getConstructorForm conname
  opAlist := dbSpecialExpandIfNecessary(conform,rest GETL(conname,'documentation))
  fromHeading := ['" from domain {\sf ",form2HtString conform,'"}"]
  htpSetProperty(page,'fromHeading,fromHeading)
  htpSetProperty(page,'conform,conform)
  htpSetProperty(page,'opAlist,opAlist)
  htpSetProperty(page,'noUsage,true)
  htpSetProperty(page,'condition?,'no)
  dbShowOp1(page,opAlist,'"operation",'names)

dbSpecialExports(conname) ==
  conform := getConstructorForm conname
  page := htInitPage(['"Exports of {\sf ",form2HtString conform,'"}"],nil)
  opAlist := dbSpecialExpandIfNecessary(conform,rest GETL(conname,'documentation))
  kePageDisplay(page,'"operation",opAlist)
  htShowPage()

dbSpecialExpandIfNecessary(conform,opAlist) ==
  opAlist is [[op,[sig,:r],:.],:.] and rest r => opAlist
  for [op,:u] in opAlist repeat
    for pair in u repeat
      [sig,comments] := pair
      pair.rest := ['T,conform,'T,comments] --[sig,pred,origin,exposeFg,doc]
  opAlist

X := '"{\sf Record(a:A,b:B)} is used to create the class of pairs of objects made up of a value of type {\em A} selected by the symbol {\em a} and a value of type {\em B} selected by the symbol {\em b}. "

Y := '"In general, the {\sf Record} constructor can take any number of arguments and thus can be used to create aggregates of heterogeneous components of arbitrary size selectable by name. "

Z := '"{\sf Record} is a primitive domain of \Language{} which cannot be defined in the \Language{} language."

MESSAGE := strconc(X,Y,Z)

PUT('Record,'documentation,substitute(MESSAGE,'MESSAGE,'(
  (constructor (NIL MESSAGE))
 (_=  (((Boolean) _$ _$)
   "\spad{r = s} tests for equality of two records \spad{r} and \spad{s}"))
 (coerce (((OutputForm) _$)
   "\spad{coerce(r)} returns an representation of \spad{r} as an output form")
         ((_$ (List (Any)))
   "\spad{coerce(u)}, where \spad{u} is the list \spad{[x,y]} for \spad{x} of type \spad{A} and \spad{y} of type \spad{B}, returns the record \spad{[a:x,b:y]}"))
 (elt ((A $ "a")
   "\spad{r . a} returns the value stored in record \spad{r} under selector \spad{a}.")
      ((B $ "b")
   "\spad{r . b} returns the value stored in record \spad{r} under selector \spad{b}."))
 (setelt ((A $ "a" A)
   "\spad{r . a := x} destructively replaces the value stored in record \spad{r} under selector \spad{a} by the value of \spad{x}. Error: if \spad{r} has not been previously assigned a value.")
         ((B $ "b" B)
   "\spad{r . b := y} destructively replaces the value stored in record \spad{r} under selector \spad{b} by the value of \spad{y}. Error: if \spad{r} has not been previously assigned a value."))
   )))

X := '"{\sf Union(A,B)} denotes the class of objects which are which are either members of domain {\em A} or of domain {\em B}. The {\sf Union} constructor can take any number of arguments. "

Y := '"For an alternate form of {\sf Union} with _"tags_", see \downlink{Union(a:A,b:B)}{DomainUnion}. {\sf Union} is a primitive domain of \Language{} which cannot be defined in the \Language{} language."

MESSAGE := strconc(X,Y)

PUT('UntaggedUnion,'documentation,substitute(MESSAGE,'MESSAGE,'(
  (constructor (NIL MESSAGE))
  (_=  (((Boolean) $ $)
    "\spad{u = v} tests if two objects of the union are equal, that is, u and v are hold objects of same branch which are equal."))
  (case (((Boolean) $ "A")
    "\spad{u case A} tests if \spad{u} is of the type \spad{A} branch of the union.")
        (((Boolean) $ "B")
    "\spad{u case B} tests if \spad{u} is of the \spad{B} branch of the union."))
  (coerce ((A $)
    "\spad{coerce(u)} returns \spad{x} of type \spad{A} if \spad{x} is of the \spad{A} branch of the union. Error: if \spad{u} is of the \spad{B} branch of the union.")
          ((B $)
    "\spad{coerce(u)} returns \spad{x} of type \spad{B} if \spad{x} is of the \spad{B} branch of the union. Error: if \spad{u} is of the \spad{A} branch of the union.")
          (($ A)
    "\spad{coerce(x)}, where \spad{x} has type \spad{A}, returns \spad{x} as a union type.")
          (($ B)
    "\spad{coerce(y)}, where \spad{y} has type \spad{B}, returns \spad{y} as a union type."))
  )))

X := '"{\sf Union(a:A,b:B)} denotes the class of objects which are either members of domain {\em A} or of domain {\em B}. "

Y := '"The symbols {\em a} and {\em b} are called _"tags_" and are used to identify the two _"branches_" of the union. "

Z := '"The {\sf Union} constructor can take any number of arguments and has an alternate form without {\em tags} (see \downlink{Union(A,B)}{UntaggedUnion}). "

W := '"This tagged {\sf Union} type is necessary, for example, to disambiguate two branches of a union where {\em A} and {\em B} denote the same type. "

A := '"{\sf Union} is a primitive domain of \Language{} which cannot be defined in the \Language{} language."

MESSAGE := strconc(X,Y,Z,W,A)

PUT('Union,'documentation,substitute(MESSAGE,'MESSAGE,'(
  (constructor (NIL MESSAGE))
  (_=  (((Boolean) $ $)
    "\spad{u = v} tests if two objects of the union are equal, that is, \spad{u} and \spad{v} are objects of same branch which are equal."))
  (case (((Boolean) $ "A")
    "\spad{u case a} tests if \spad{u} is of branch \spad{a} of the union.")
                (((Boolean) $ "B")
    "\spad{u case b} tests if \spad{u} is of branch \spad{b} of the union."))
  (coerce ((A $)
    "\spad{coerce(u)} returns \spad{x} of type \spad{A} if \spad{x} is of branch \spad{a} of the union. Error: if \spad{u} is of branch \spad{b} of the union.")
          ((B $)
    "\spad{coerce(u)} returns \spad{x} of type \spad{B} if \spad{x} is of branch \spad{b} branch of the union. Error: if \spad{u} is of the \spad{a} branch of the union.")
          (($ A)
    "\spad{coerce(x)}, where \spad{x} has type \spad{A}, returns \spad{x} as a union type.")
          (($ B)
    "\spad{coerce(y)}, where \spad{y} has type \spad{B}, returns \spad{y} as a union type."))
  )))

X := '"{\sf Mapping(T,S,...)} denotes the class of objects which are mappings from a source domain ({\em S,...}) into a target domain {\em T}. The {\sf Mapping} constructor can take any number of arguments."

Y := '" All but the first argument is regarded as part of a source tuple for the mapping. For example, {\sf Mapping(T,A,B)} denotes the class of mappings from {\em (A,B)} into {\em T}. "

Z := '"{\sf Mapping} is a primitive domain of \Language{} which cannot be defined in the \Language{} language."

MESSAGE := strconc(X,Y,Z)

PUT('Mapping,'documentation, substitute(MESSAGE,'MESSAGE,'(
  (constructor (NIL MESSAGE))
  (_=  (((Boolean) $ $)
    "\spad{u = v} tests if mapping objects are equal."))
   )))

X := '"{\em Enumeration(a1, a2 ,..., aN)} creates an object which is exactly one of the N symbols {\em a1}, {\em a2}, ..., or {\em aN}, N > 0. "

Y := '" The {\em Enumeration} can constructor can take any number of symbols as arguments."

MESSAGE := strconc(X, Y)

PUT('Enumeration, 'documentation, substitute(MESSAGE, 'MESSAGE, '(
  (constructor (NIL MESSAGE))
  (_= (((Boolean) _$ _$)
    "\spad{e = f} tests for equality of two enumerations \spad{e} and \spad{f}"))
  (_~_= (((Boolean) _$ _$)
    "\spad{e ~= f} tests that two enumerations \spad{e} and \spad{f} are nont equal"))
  (coerce (((OutputForm) _$)
     "\spad{coerce(e)} returns a representation of enumeration \spad{r} as an output form")
          ((_$ (Symbol))
     "\spad{coerce(s)} converts a symbol \spad{s} into an enumeration which has \spad{s} as a member symbol"))
  )))


mkConArgSublis args ==
  [[arg,:INTERN digits2Names PNAME arg] for arg in args
     | (s := PNAME arg) and "or"/[digit? s.i for i in 0..MAXINDEX s]]

digits2Names s ==
--This is necessary since arguments of conforms CANNOT have digits in TechExplorer
  str := '""
  for i in 0..MAXINDEX s repeat
    c := s.i
    segment :=
      n := DIGIT_-CHAR_-P c =>
        ('("Zero" "One" "Two" "Three" "Four" "Five" "Six" "Seven" "Eight" "Nine")).n
      c
    strconc(str, segment)
  str