forked from fricas/fricas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmt.spad
1757 lines (1510 loc) · 65.3 KB
/
fmt.spad
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
-------------------------------------------------------------------
---
--- FriCAS Formatting Framework
--- Copyright (C) 2020, 2023 Ralf Hemmecke <ralf@hemmecke.org>
---
-------------------------------------------------------------------
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions
-- are met:
--
-- 1. Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
--
-- 2. 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.
--
-- 3. Neither the name of the copyright holder 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 HOLDER 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.
-------------------------------------------------------------------
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{article}
\usepackage{literatedoc}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{A formatting framework for \SYSTEM{}}
\author{Ralf Hemmecke}
\date{09-Apr-2020}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\maketitle
\begin{abstract}
We describe a formatting framework for values of \SYSTEM{} domains.
\end{abstract}
\tableofcontents
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Overview}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The default way in \SYSTEM{} to output something is via coercion into
\spadtype{OutputForm}. Nearly every domain in \SYSTEM{} provides a
function
\begin{verbcode}
coerce: % -> OutputForm
\end{verbcode}
that transforms an element of the current domain into an element of
\spadtype{OutputForm}. The domain \spadtype{OutputForm} itself is
meant to be an abstraction from the visual form of an expression, but,
in fact, is actually a mixture of a representation of an expression in
a tree form and a small number of styling elements, like
\spad{blankSeparate} or \spad{vconcat}.
We believe that it would be better to actually get rid of the styling
part and create a proper expression tree domain for values with an
easily extensible set of possible tree nodes as, for example, it is
already done in the Aldor algebra library, see
\url{https://github.com/aldorlang/aldor/tree/master/aldor/lib/algebra/src/extree}.
\spadtype{OutputForm} looks like being tailored for 2D-output and the
ability to format the output in \TeX{} form look like an afterthought.
Nevertheless the following framework builds solely on what
\spadtype{OutputForm} provides and creates a domain
\spadtype{FormattedOutput} that is able to display different formats.
The proposed way to enable disable the output of a certain format is
like shown in the following piece of code, i.e, one sets a list of
formatter in the \spadtype{FormattedOutput} domain.
\begin{verbcode}
)set output formatted on
F ==> Formatter
l := [F FormatLaTeX, F Format2D, F Format1D];
setFormats!(l pretend List(OutputFormatterCategory))$FormattedOutput
\end{verbcode}
%$
The formatters themselves simply provide functionality to turn an
element of \spadtype{OutputForm} into an element of
\spadtype{OutputBox}. They have no knowledge of how they are put into
a file or onto a console and therefore can be used standalone.
The domain \spadtype{OutputBox} is our abstraction for the visual
representation of an output form. It can hold a 2D-monospaced
representation (by a number of lines) or the \LaTeX{} expression (just
one line) for the \SYSTEM{} expression in question.
The domain \spadtype{Formatter} is an auxiliary domain that provides
code to put text before and after the actual formatted expression
which can be modified at runtime. A natural usage is to let the
\LaTeX{} format appear inside a special \LaTeX{} mathematics
environment. Furthermore, \spadtype{Formatter} turns the actual
formatters like for example, \spadtype{FormatLaTeX} or
\spadtype{Format2D}, into a domain of category
\spadtype{OutputFormatterCategory}, i.e.,
\begin{verbcode}
convert: (OutputForm, Integer) -> %
display: % -> Void
\end{verbcode}
is available to display an element of \spadtype{OutputForm} in the
respective format on the screen or to put it into a file.
\spadtype{FormatCategory} abstracts from the \spadtype{OutputForm}
operations and lists a number of functions that every Formatter in
\SYSTEM{} must provide so that formatting and expression of type
\spadtype{OutputForm} is easily achievable.
Formatters like, for example, \spadtype{FormatLaTeX} or
\spadtype{Format2D} can be adapted during a session to the needs of a
user. For this to work, each formatter provides a data structure
(represented by the domain \spadtype{OperatorHandlers}) that holds the
functions that are called in order to format the respective operator
of \spadtype{OutputForm}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Implementation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{The domain \spadtype{OutputBox}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The domain \spadtype{OutputBox} is an auxiliary domain that is mainly
intended to hold a number of string that are later to be output
(separated by newlines) onto a stream. Initially it was intended to
hold the 2D representation of a certain expression, but later it
became also useful to hold other representations like, for example,
\LaTeX{}.
Functions are provided to put these boxes horizontally and vertically
together. Therefore, an \spadtype{OutputBox} knows about its size,
namely the
\begin{description}
\item[height:] that is the number of lines above and including the
baseline;
\item[depth:] that is the number of lines below the baseline; and
\item[width:] that is the number of characters of each line of the box.
\end{description}
The idea of such a format strategy is that the respective sub-parts of
an expression are (recursively) put into boxes and then put together
into a bigger box. It allows for the representation of 2D output as
well as other outputs such as 1D, \LaTeX{} or HTML.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
)abbrev domain OUTBOX OutputBox
++ The domain \spad{OutputBox} represents the two-dimensional form of
++ an expression by a number of strings (lines). Such a box has a
++ baseline (at which such boxes will be horizontally aligned, a
++ height (size above and including the baseline), a depth (size below
++ the baseline), and a width (horizontal size).
OutputBox : Exports == Implementation where
N ==> NonNegativeInteger
Z ==> Integer
asN x ==> qcoerce(x)@N
Exports ==> CoercibleTo OutputForm with
empty: () -> %
++ Create an empty box of size 0.
empty?: % -> Boolean
++ empty?(b) returns true of the box has height and depth equal to 0.
box: String -> %
++ \spad{box(s)} creates a box that contains the string s.
height: % -> N
++ \spad{height(box)} returns the height of the box (above the
++ baseline) including the baseline.
width: % -> N
++ \spad{width(box)} returns the width of the box.
depth: % -> N
++ \spad{depth(box)} returns the height of the box below the
++ baseline.
lines: % -> List String
++ \spad{lines(box)} returns the contents of the box as strings
++ (all of the same length (width(box)).
pad: (N, N, N, N) -> % -> %
++ \spad{pad(t, b, l, r)(box)} returns a new box that is padded by
++ t empty lines at the top,
++ b empty lines at the bottom,
++ l space characters at the left,
++ r space characters at the right.
++ If w, h, d are the width, height and depth of box then the
++ resulting box will have width l+w+r and height t+h and depth
++ d+b.
hcenter: N -> % -> %
++ \spad{hcenter(w)(box)} centers the box horizontally inside a
++ box of width w.
vconcat: (List %, N, Z) -> %
++ \spad{vconcat(lbox, h, adjust)} computes the maximal width of
++ the boxes in the list lbox; then if \spad{adjust<0}, left
++ adjusts, if \spad{adjust>0}, right adjusts, and otherwise
++ centers each smaller box in a new box of this maximal width
++ and returns a box by putting all the boxes vertically on top
++ of each other. The height of the new box is given by
++ \spad{h}, the depth results from the difference of the number
++ of lines and \spad{h}.
vconcat: (List %, N) -> %
++ \spad{vconcat(lbox, h)} returns \spad{vconcat(lbox,h, 0)},
hconcat: List % -> %
++ \spad{hconcat(lbox)} aligns the boxes at their baseline and
++ concats those boxes horizontally from left to right.
Implementation ==> add
Rep ==> Record(ht: N, dp: N, wd: N, ct: List String)
import from Rep
rep x ==> (x@%) pretend Rep
per x ==> (x@Rep) pretend %
coerce(x: %): OutputForm == rep(x)::OutputForm
empty(): % == per [0, 0, 0, empty()$List(String)]
box(s: String): % == per [1, 0, #s, [s]]
height(box: %): N == rep(box).ht
depth(box: %): N == rep(box).dp
width(box: %): N == rep(box).wd
lines(box: %): List String == rep(box).ct
empty?(box: %): Boolean == zero? height box and zero? depth box
pad(t: N, b: N, l: N, r: N): % -> % == (box: %): % +->
w := width box
nw: N := l + w + r
nh: N := t + height box
nd: N := b + depth box
emptyLine: String := new(nw, char " ")
newLines: List String := empty()
for i in 1..t repeat newLines := cons(copy emptyLine, newLines)
for boxline in lines(box) repeat
line: String := copy emptyLine
for i in 1..w repeat line(i+l) := boxline.i
newLines := cons(line, newLines)
for i in 1..b repeat newLines := cons(copy emptyLine, newLines)
per [nh, nd, nw, reverse! newLines]
hcenter(w: N): % -> % == (box: %): % +->
d: Z := w - width box
d < 0 => error "cannot fit into box"
l: N := asN shift(d, -1)
r: N := l
if odd? d then l := l+1 -- one more space on the left
pad(0, 0, l, r)(box)
vconcat(lb: List %, h: N, adjust: Z): % ==
empty? lb => empty()
w: N := max [width b for b in lb]
newLines: List String :=
adjust < 0 => -- left adjust
concat [lines pad(0,0,0,(w-width(b))::N)(b) for b in lb]
adjust > 0 => -- right adjust
concat [lines pad(0,0,(w-width(b))::N,0)(b) for b in lb]
-- center
concat [lines hcenter(w)(b) for b in lb]
d: Z := #newLines - h
d < 0 => error "vconcat: negative depth"
per [h, asN d, w, newLines]
vconcat(lb: List %, h: N): % == vconcat(lb, h, 0)
hconcat(lb: List %): % ==
empty? lb => empty()
h: N := max [height b for b in lb]
d: N := max [depth b for b in lb]
w: N := reduce(_+, [width b for b in lb])
emptyLine: String := new(w, char " ")
newLines: List String := empty()
for i in 1..h+d repeat
newLine := copy emptyLine
wx := 0
for b in lb repeat
wb := width b
hb := height b
ix := hb - h + i
if 0 < ix and ix <= hb + depth b then -- copy line ix
line := lines(b).ix
for j in 1..wb repeat newLine(wx+j) := line.j
wx := wx + wb
newLines := cons(newLine, newLines)
per [h, d, w, reverse! newLines]
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{The OperatorHandlers Domain}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
)abbrev domain OPHANDL OperatorHandlers
++ OperatorHandlers is an auxiliary domain. It is used holds functions
++ for each operator of \spad{OutputForm}, classified by the arity and
++ the name of that operator.
OperatorHandlers(HANDLER: Type): Exports == Implementation where
Z ==> Integer
S ==> String
Exports == with
new: () -> %
++ \spad{new()} creates an empty structure of handlers.
knownHandler?: (%, Z, S) -> Boolean
++ \spad{knownHandler?(x, n, op)} checks
++ whether a handler for operator \spad{op} is known.
++ The number \spad{n} denotes the number of arguments that the
++ operator can take.
++ It is OK if both \spad{knownOperator?(m, op)} and
++ \spad{knownOperator?(n, op)} return true for different
++ \spad{m} and \spad{n}.
handler: (%, Z, S) -> HANDLER
++ \spad{handler(x, n, op)} is only valid if
++ \spad{knownHandler?(n, op)} is true.
++ It returns the respective handler stored in \spad{x}.
setHandler!: (%, Z, S, HANDLER) -> HANDLER
++ \spad{setHandler!(x, n, op, hdl)} puts \spad{hdl} into the
++ data structure \spad{x} such that it can be queried
++ afterwards.
removeHandler!: (%, Z, S) -> Void
++ \spad{removeHandler!(n, op)} removes any handler from an
++ internal data structure (for the pair \spad{(n, op)} such
++ that afterwards \spad{knownHandler?(x, n, op)} returns false.
Implementation == add
T ==> XHashTable(S, HANDLER)
Rep ==> XHashTable(Z, T)
N ==> -1 -- means n-ary.
import from Z, Rep
rep x ==> (x@%) pretend Rep
per x ==> (x@Rep) pretend %
new(): % == per empty()
knownHandler?(t: %, n: Z, op: S): Boolean ==
key?(n, rep t) and key?(op, rep(t).n)
handler(t: %, n: Z, op: S): HANDLER == rep(t).n.op
setHandler!(t: %, n: Z, op: S, h: HANDLER): HANDLER ==
if not key?(n, rep t) then rep(t).n := empty()
rep(t).n.op := h
removeHandler!(t: %, n: Z, op: S): Void ==
if key?(n, rep t) then remove!(op, rep(t).n)
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{The FormatterCategory Category}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The category \spadtype{FormatterCategory} is intended to provide
functionality for formatter domains.
A formatter domain must essentially provide 3 parts.
\begin{enumerate}
\item A \spad{defaultPrologue}, that is a function that given a
label returns an \spadtype{OutputBox} that must be printed before
the actual expression is printed.
\item The \spad{defaultEpilogue}, that is a function that given a
label returns an \spad{OutputBox} that must be printed after the
actual expression.
\item The actual output box of the expression through a call to the
function \spad{formatExpression}.
\end{enumerate}
Since in this framework a formatter can change its behaviour at the
request of a user, there are a number of other functions provided to
do this. Where generically possible some of those functions come with
a default implementation in this category.
For some examples below we use \SYSTEM{} 1.3.6 and the following
definitions.
\begin{verbcode}
E ==> Expression Integer
OF ==> OutputForm
macro R == Record(OUTPUTFORM:OF, SEXPRESSION: SExpression)
macro e x == (_
o:=x::OF;_
print(([o, outputTran(o)$Lisp]$R)::OF);_
x)
a: OF := "a"::Symbol::OF
aa: OF := "aa"::Symbol::OF
b: OF := "b"::Symbol::OF
bb: OF := "bb"::Symbol::OF
\end{verbcode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
)abbrev category FMTCAT FormatterCategory
FormatterCategory: Category == Exports where
E ==> OutputForm
Z ==> Integer
N ==> NonNegativeInteger
S ==> String
LE ==> List E
BOX ==> OutputBox
LBOX ==> S -> BOX -- Label box for prologue and epilogue
HANDLER ==> (Z, LE) -> OutputBox -- (precedence, arguments) +-> resulting box
H ==> HANDLER
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Exported Functions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The main function is \spad{formatExpression(e, p)} (which comes
already with a default implementation.
%
This dispatcher routine first checks whether the given expression $e$
is a nullary operator or has 1 or 2 or more arguments. Depending on
the number of arguments it checks whether the given operator of the
respective arity is known and calls the respective handler. If the
operator is not known, \spad{formatExpression} checks for a known
$n$-ary case and calls the respective handler. If the operator in the
expression $e$ is unknown, it is interpreted as a function symbol and
formatted as a function call with arguments.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
Exports ==> CoercibleTo OutputForm with
defaultPrologue: LBOX
++ \spad{defaultPrologue(label)} returns a box that is used at the
++ beginning of every format.
defaultEpilogue: LBOX
++ \spad{defaultEpilogue(label)} returns a box that is used at
++ the end of every format.
minPrecedence: () -> Z -- default is 0
++ minPrecedence() returns the minimal precedence value.
maxPrecedence: () -> Z -- default is 10000
++ maxPrecedence() returns the maximal precedence value,
formatExpression: (E, Z) -> BOX -- has default implementation
++ \spad{formatExpression(o, p)} returns an \spadtype{OutputBox}
++ that represent the expression \spad{o} in the respective
++ format when considered in a context with outer precedence
++ \spad{p}. This function is the main dispatcher function. It
++ first checks whether \spad{o} is an integer or a string and
++ treats these cases. Then, if the number n of arguments is
++ less than 3, it tries to find a handler for the top-level
++ operator of \spad{o}. If none is found, it checks for a
++ handler of an n-ary operator. If no handler is found, the
++ operator is treated as a function symbol and formatted as
++ such.
formatExpression: E -> BOX -- has default implementation
++ \spad{formatExpression(o)} returns
++ \spad{formatExpression(o, minPrecedence())}.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The following functions are exported to create formatters that format
certain leaf types in a special way. Sometimes, the representation in
\spadtype{OutputForm} does not clearly distinguish between the
different leaf types. In fact, these \emph{leaf functions} are
somewhat questionable. Nevertheless they are useful for the
implementation of new formatters.
Unfortunately, the representation of a floating point number in
\spadtype{OutputForm} is given by a string representation of its
decimal expansion. In the default implementation of
\spad{formatExpression} we try to detect floating point numbers.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
formatInteger: Z -> BOX -- has default implementation
++ \spad{formatInteger(n)} formats an integer.
formatFloat: S -> BOX -- has default implementation
++ \spad{formatFloat(s)} formats a floating point number from it
++ string representation in \spadtype{OutputForm}.
formatString: S -> BOX
++ \spad{formatString(s)} formats a string.
formatSymbol: S -> BOX
++ \spad{formatSymbol(s)} formats a symbol.
formatFunctionSymbol: S -> BOX
++ \spad{formatFunctionSymbol(s)} formats an otherwise unknown
++ function symbol.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The following functions are only exported to aid with changing
a formatting domain during a session.
To a certain extend there exists a handler for each operator in
\spadtype{OutputForm}. In fact, the functions below come with enough
parameters to produce a common interface to work for several
formatters. These functions are stored in an
\spadtype{OperatorHandlers} data structure.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
operatorHandlers: () -> OperatorHandlers(HANDLER)
++ \spad{operatorHandlers()} returns an internal data structure
++ that is used for the selection of respective handlers.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Precedence of operators is used to decide whether or not to put parentheses
around an expression.
We fix minimal and maximal precedence, although it would be possible to
use any range, since the code mostly only relies on a linear order,
but putting the minimal or maximal precedence value can sometimes
force or prevent an appearance of parentheses.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
parenthesize: (S, S, BOX) -> BOX
++ \spad{parenthesize(lb, rb, bx)} returns the box bx with
++ left and right brackets (lb and rb) around it.
parenthesizeIf: (Boolean, BOX) -> BOX -- has default implementation
++ \spad{parenthesizeIf(paren?, bx)} returns parentheses (of
++ appropriate size if \spad{paren?} is true. Otherwise,
++ \spad{bx} is returned.
nothing: () -> H -- default is empty box
++ \spad{nothing()} returns a handler \spad{h} such that
++ \spad{h(prec, args)} returns an empty box.
++ This corresponds to NOTHING in \spad{OutputForm}.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A constant operator is a special operator with no arguments. Examples
are \verb|%pi| or \verb|%i| that in \spad{OutputForm} represent
themselves. In \SYSTEM{} there are only a few such operators like the
above and \verb|%e| and \verb|%infinity|.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
formatConstant: S -> H -- default is a the operator string itself
++ \spad{formatConstant(op)} is a handler to format constant
++ operators.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The function \spad{handler(p)} is a handler that formats only one
argument in a context with precedence \spad{p}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
formatExpression: Z -> H -- default is formatExpression perhaps inside (, )
++ \spad{formatExpression(p)} returns a handler \spad{h} that
++ \spad{h(prec, args)} returns
++ \spad{formatExpression(first args, p)}.
++ This handler is used to change the precedence context in
++ which the argument is formatted.
precedence: (Z, H) -> H -- default
++ \spad{precedence(p, hh)} returns a handler \spad{h} such that
++ \spad{h(prec, args)} returns \spad{hh(p, args)}. This handler
++ can be used to change the context in which an expression is
++ formatted.
bracket: (S, S, H) -> H -- has default
++ \spad{bracket(lb, rb, hh)} returns a handler \spad{h} such
++ that \spad{h(prec, args)} formats its first argument
++ according to \spad{hh} and then put left and right brackets
++ given by \spad{lb} and \spad{rb} around the resulting box.
prefix: (S, Z, H) -> H -- has default
++ \spad{prefix(s, p, hh)} returns a handler \spad{h} such that
++ \spad{h(prec, args)} formats args according to \spad{hh} and
++ then prefixes this box by \spad{box s}.
++ Outer parentheses are added if \spad{p < prec}.
binary: (H, H) -> H --has default
++ \spad{binary(h1, h2)} returns a handler \spad{h} such that
++ \spad{h(prec, args)} formats the first argument according to
++ \spad{h1} and the second argument by \spad{h2}. Both boxes
++ will be horizontally concatenated.
++ binary(h1, h2) is equal to infix("", maxPrecedence(), h1, h2)
infix: (S, Z, H, H) -> H -- has default
++ \spad{infix(op, p, h1, h2)} returns a handler \spad{h} such
++ that \spad{h(prec, args)} formats the first argument by
++ \spad{h1} and the second argument by \spad{h2}. Both boxes
++ will be horizontally concatenated with \spad{box op} in the
++ middle. Outer parentheses are added if \spad{p < prec}.
nary: (S, Z, H) -> H -- has default
++ \spad{nary(s, p, hh)} returns a handler \spad{h} such that
++ \spad{h(prec, args)} formats each argument according to
++ \spad{hh}. All resulting boxes will be horizontally
++ concatenated with \spad{box s} inbetween.
++ Outer parentheses are added if \spad{p < prec}.
naryPlus: (S, S, Z, H) -> H -- has default
++ \spad{nary(plus, minus, p, hh)} returns a handler \spad{h}
++ such that \spad{h(prec, args)} formats each argument
++ according to \spad{hh}. All resulting boxes will be
++ horizontally concatenated with \spad{box minus} or
++ \spad{box plus} inbetween depending on whether the respective
++ argument starts with a unary minus or not.
++ Outer parentheses are added if \spad{p < prec}.
++ This is a special handler that treats the case that a sum is
++ represented as a nary expression that contains unary
++ subexpressions that are unary minus expressions. This handler
++ transforms something like (+ a (- b)) into a - b.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The following functions treat sums, products, and integrals.
Such expressions either come with two or three parameters. For example:
\begin{verbcode}
(product(x, y))::OutputForm pretend SExpression
(PI y x)
\end{verbcode}
\begin{verbcode}
(sum(sin y, y=u..v))::OutputForm pretend SExpression
(SIGMA2 (= y u) v (sin y))
\end{verbcode}
\begin{verbcode}
(integral(sin y * cos y, y))::OutputForm pretend SExpression
(INTSIGN (NOTHING) y (* (* (cos %N) (sin %N)) (CONCAT d %N)))
\end{verbcode}
In case of three parameters, the first two are the lower and upper
limits and the third is the argument that the (sum, product, integral)
quantor applies to.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The \spad{integral} handler corresponds to the
\spad{INTSIGN} operator of \spadtype{OutputForm}.
\begin{verbcode}
(41) -> e(int(a))
++
[OUTPUTFORM = | a , SEXPRESSION = (INTSIGN (NOTHING) (NOTHING) a)]
++
(42) -> e(int(a, b))
++
[OUTPUTFORM = | a , SEXPRESSION = (INTSIGN b (NOTHING) a)]
++
b
(43) -> e(integrate(x^x, x)^2)
x 2
++ %A
[OUTPUTFORM = | %A d%A ,
++
SEXPRESSION = (^ (INTSIGN (NOTHING) x (* (^ %A %A) (CONCAT d %A))) 2)]
\end{verbcode}
Note that in order to show the expression under the integral sign in a
natural way, it should be checked whether it is of the form:
\begin{verbcode}
(* x (CONCAT d y))
\end{verbcode}
and then formatted without an explicit multiplication sign.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
integral: Z -> H
++ \spad{integral(p)} returns a handler \spad{h} such that
++ \spad{h(prec, args)} formats the expression as an integral
++ with integral sign and respective limits.
++ Outer parentheses are added if \spad{p < prec}.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The \spad{sum} handler corresponds to the \spad{SIGMA}, \spad{SIGMA2}
operators of \spadtype{OutputForm}.
\begin{verbcode}
(44) -> e sum(a)
--+
[OUTPUTFORM = > a, SEXPRESSION = (SIGMA (NOTHING) a)]
--+
(45) -> e sum(x^x, x)
--+ x
[OUTPUTFORM = > x , SEXPRESSION = (SIGMA x (^ x x))]
--+
x
(46) -> e sum(x^x, x=u..v)
v
--+ x
[OUTPUTFORM = > x , SEXPRESSION = (SIGMA2 (= x u) v (^ x x))]
--+
x = u
\end{verbcode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
sum: Z -> H
++ \spad{sum(p)} returns a handler \spad{h} such that
++ \spad{h(prec, args)} formats a sum expression with
++ summation sign and respective limits.
++ Outer parentheses are added if \spad{p < prec}.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The \spad{product} handler corresponds to the \spad{PI} and \spad{PI2}
operators of \spadtype{OutputForm}.
\begin{verbcode}
(47) -> e prod(a)
++-++
[OUTPUTFORM = | | a, SEXPRESSION = (PI (NOTHING) a)]
| |
(50) -> e product(x^x, x)
++-++ x
[OUTPUTFORM = | | x , SEXPRESSION = (PI x (^ x x))]
| |
x
(48) -> e(product(x^x, x=u..v)^2)
v 2
++-++ x
[OUTPUTFORM = ( | | x ) , SEXPRESSION = (^ (PI2 (= x u) v (^ x x)) 2)]
| |
x = u
(49) -> e(product(x^x, x=1..u/v)^(r+s))
u s + r
-
v
++-++ x
[OUTPUTFORM = ( | | x ) ,
| |
x = 1
SEXPRESSION = (^ (PI2 (= x 1) (/ u v) (^ x x)) (+ s r))]
\end{verbcode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
product: Z -> H
++ \spad{product(p)} returns a handler \spad{h} such that
++ \spad{h(prec, args)} formats a product with product sign and
++ respective limits.
++ Outer parentheses are added if \spad{p < prec}.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
For
\begin{verbcode}
(positive?$Integer)::OutputForm pretend SExpression
\end{verbcode}
%$
we get
\begin{verbcode}
(theMap INS-;positive?;SB;4 655)
\end{verbcode}
From that we can extract the text between the first and second semicolon
of the first argument.
Unfortunately, for
\begin{verbcode}
addx x == ((y: Integer): Integer +-> x + y)
((addx 10)::OutputForm) pretend SExpression
\end{verbcode}
we will see
\begin{verbcode}
(theMap
#<FUNCTION (LAMBDA (#:G719 |envArg|) :IN |*1;addx;1;initial|) {1004405F2B}>
655)
\end{verbcode}
where the second entry cannot be formatted by \spad{formatExpression},
since it is an atom but neither a string nor a symbol.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
theMap: H
++ \spad{theMap} is a special handler to format a function.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The \spad{overbar} handler corresponds to the \spad{OVERBAR} operator
of \spadtype{OutputForm}.
\begin{verbcode}
(155) -> e overbar(a+b*aa)
________
[OUTPUTFORM = a + b aa, SEXPRESSION = (OVERBAR (+ a (* b aa)))]
(309) -> e decimal(1/352)
__
[OUTPUTFORM = 0.0028409,
SEXPRESSION = (CONCAT 0 "." (CONCAT 0 0 2 8 4) (OVERBAR (CONCAT 0 9)))]
\end{verbcode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
overbar: (Z, H) -> H
++ \spad{overbar(p, hh)} returns a handler \spad{h} such that
++ \spad{h(prec, args)} formats arguments via
++ \spad{hh(p, args)} and then draws a bar over the resulting box.
++ Outer parentheses are added if \spad{p < prec}.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The \spad{box} handler corresponds to the \spad{BOX} operator of
\spadtype{OutputForm}.
\begin{verbcode}
(157) -> e box{123}$OF
+-----+
[OUTPUTFORM = | 123 |, SEXPRESSION = (BOX 123)]
+-----+
\end{verbcode}
%$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
box: H -> H
++ \spad{box(hh)} returns a handler \spad{h} such that
++ \spad{h(prec, args)} formats the arguments via
++ \spad{hh(prec, args)} and then draws a box frame around the
++ resulting box.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The \spad{nthRoot} handler corresponds to the \spad{ROOT} operator of
\spadtype{OutputForm}.
\begin{verbcode}
(165) -> e((5 + sqrt 63 + sqrt 847)^(1/3))
+-----------+
3| +-+
[OUTPUTFORM = \|14 \|7 + 5 , SEXPRESSION = (ROOT (+ (* 14 (ROOT 7)) 5) 3)]
(166) -> e(root(5)$OF + root(a+b, a+2)$OF)
+-+ a + 2+-----+
[OUTPUTFORM = \|5 + \|a + b ,
SEXPRESSION = (+ (ROOT 5) (ROOT (+ a b) (+ a 2)))]
\end{verbcode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
nthRoot: (Z, H, H) -> H --has default
++ Format square roots and nth roots.
++ \spad{nthRoot(p, h1, h2)} returns a handler \spad{h} such that
++ \spad{h(prec, args)} formats the first argument according to
++ \spad{h1}.
++ If there is no second argument, then the nth root is a square
++ root and formatted accordingly. Otherwise the second argument
++ is formatted by \spad{h2}.
++ Outer parentheses are added if \spad{p < prec}.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The \spad{scripts} handler corresponds to the \spad{SUPERSUB} operator
of \spadtype{OutputForm}. It formats subscripts, superscripts,
pre-superscripts and pre-subscripts.
\begin{verbcode}
(187) -> e super(a, b)$OF
b
[OUTPUTFORM = a , SEXPRESSION = (SUPERSUB a " " b)]
(189) -> e super(a+aa, b+bb)$OF
b + bb
[OUTPUTFORM = a + aa , SEXPRESSION = (SUPERSUB (+ a aa) " " (+ b bb))]
(283) -> e box presub(F::OF, 2::OF)
+-----+
| |
[OUTPUTFORM = | F |, SEXPRESSION = (BOX (SUPERSUB F " " " " " " 2))]
| 2 |
+-----+
(285) -> e box scripts(F::OF, [2::OF, empty()$OF, empty()$OF, 1::OF])
+-----+
| |
[OUTPUTFORM = | F |,
| 1 2 |
+-----+
SEXPRESSION = (BOX (SUPERSUB F 2 (NOTHING) (NOTHING) 1))]
(288) -> e box scripts(F, [2,4])$OF
+----+
| 4 |
[OUTPUTFORM = | F |, SEXPRESSION = (BOX (SUPERSUB F 2 4))]
| 2 |
+----+
(289) -> e box scripts(F, [2,4,7])$OF
+-----+
| 7 4 |
[OUTPUTFORM = | F |, SEXPRESSION = (BOX (SUPERSUB F 2 4 7))]
| 2 |
+-----+
(290) -> e box scripts(F, [2,4,7,11])$OF
+------+
| 7 4 |
[OUTPUTFORM = | F |, SEXPRESSION = (BOX (SUPERSUB F 2 4 7 11))]
| 11 2 |
+------+
(345) -> e script(Mammoth, [[i,j],[k,l],[0,1],[2],[u,v,w]])
0, 1 k, l
[OUTPUTFORM = Mammoth (u,v,w),
2 i, j
SEXPRESSION
=
((SUPERSUB Mammoth (AGGLST i j) (AGGLST k l) (AGGLST 0 1) 2) u v w)
]
(355) -> e(superscript(v, [1,n,t])^4)
1, n, t4
[OUTPUTFORM = v ,
SEXPRESSION = (^ (SUPERSUB v (AGGLST) (AGGLST 1 n t)) 4)]
\end{verbcode}
%$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
scripts: Z -> H
++ Formats super- and subscripts also presuper and presub.
++ \spad{scripts(p)} returns a handler \spad{h} such that
++ \spad{h(prec, args)} formats the first argument with respect
++ to the precedence \spad{p}. The other arguments are
++ interpreted as subscript, superscript, presuperscript, and
++ presubscript (in this order).
++ Outer parentheses are added if \spad{p < prec}.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The \spad{subscript} handler corresponds to the \spad{SUB} operator of
\spadtype{OutputForm}.
\begin{verbcode}
(274) -> e sub(a, b)$OF
[OUTPUTFORM = a , SEXPRESSION = (SUB a b)]
b
(276) -> e sub(a+b, a+bb)$OF
[OUTPUTFORM = a + b , SEXPRESSION = (SUB (+ a b) (+ a bb))]
a + bb
(354) -> e(subscript(v, [1,n,t])^3)
3
[OUTPUTFORM = v , SEXPRESSION = (^ (SUB v (AGGLST 1 n t)) 3)]
1, n, t
\end{verbcode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
)endif
subscript: Z -> H
++ \spad{subscript(p)} returns a handler such that
++ \spad{subscript(p)(prec, args)} formats the first argument
++ with respect to the precedence \spad{p}.
++ The other arguments are formatted without parentheses and
++ interpreted as subscripts separated by commas.
++ Outer parentheses are added if \spad{p < prec}.
)if LiterateDoc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The \spad{aldtsupersub} handler corresponds to the \spad{ALTSUPERSUB}
operator of \spadtype{OutputForm}.
\begin{verbcode}
(259) -> e supersub(aa+bb,[a])
[OUTPUTFORM = aa + bb , SEXPRESSION = (ALTSUPERSUB (+ aa bb) a (NOTHING))]
a
(260) -> e supersub(a,[a,b,1,2,3,4])
b 2 4
[OUTPUTFORM = a , SEXPRESSION = (ALTSUPERSUB a a b 1 2 3 4)]