💾 Archived View for tranarchy.fish › ~autumn › apl2 › appendixA.gmi captured on 2023-06-16 at 16:16:47. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-04-19)
-=-=-=-=-=-=-
<div class="chapter-rule">
<hr class="chapter-long">
<p>Appendix</p>
<hr class="chapter-short">
<div>
<div>
A
</div>
</div>
</div>
<h2 id="the-display-function">The <code>DISPLAY</code> Function</h2>
<p>The following is the <code>DISPLAY</code> function as distributed by <span class="small-caps">IBM</span> in <span class="small-caps">APL2</span> Release 2, Program number 5668-899.</p>
<p>On most <span class="small-caps">APL2</span> systems that provide the <code>DISPLAY</code> function, you can find it in library 1 by entering:</p>
<pre> )COPY 1 DISPLAY DISPLAY</pre>
<p>This function uses characters from the <span class="small-caps">APL2</span> character set to draw the best box it can. Sometimes a second function <code>DISPLAYG</code> is provided that uses non-<span class="small-caps">APL</span> graphic characters to draw better boxes on suitably-equipped terminals.</p>
<center>
<div class="line-block">Copyright <span class="small-caps">IBM</span> Corporation, 1984.<br>
Reprinted with permission.</div>
</center>
<!--the '⍷' on line 31 has been edited from the (incorrect) 'V̲' in the original text so that this code snippet actually works as intended-->
<pre> ∇ D←S DISPLAY A;⎕IO;R;C;HL;HC;HT;HB;VL;VB;V;W;N;B
[1] ⍝ (C) SEE COIBM. 5668-899 DISPLAY (DISPLAY)
[2] ⍝ NORMAL CALL IS MONADIC. DYADIC CALL USED ONLY IN
[3] ⍝ RECURSION TO SPECIFY DISPLAY RANK, SHAPE, AND DEPTH.
[4] ⎕IO←0
[5] ⍎(0=⎕NC 'S')/'S←⍴A'
[6] R←↑⍴,S ⍝ PSEUDO RANK.
[7] C←'..''''' ⍝ UR, UL, LL, AND LR CORNERS.
[8] HL←'-' ⍝ HORIZONTAL LINE.
[9] HC←HL,'⊖→',HL,'∼+∊' ⍝ HORIZONTAL BORDERS.
[10] HT←HC[(0<R)×1+0<↑¯1↑,S]
[11] W←,0≡¨↑0⍴⊂(1⌈⍴A)↑A
[12] HB←HC[3+3⌊(∨/W)+(∧/0 1∊W)+3×1<⍴⍴S]
[13] VL←'|' ⍝ VERTICAL LINE.
[14] VB←VL,'⌽↓' ⍝ VERTICAL BORDER.
[15] V←VB[(1<R)×1+0<¯1↑¯1↓,S]
[16] ⍎(0∊⍴A)/'A←(1⌈⍴A)⍴⊂↑A' ⍝ SHOW PROTOTYPE OF EMPTIES.
[17] →(1<≡A)/GEN
[18] →(2<⍴⍴A)/D3
[19] D←⍕A ⍝ SIMPLE ARRAYS.
[20] W←1↑⍴D←(¯2↑1 1,⍴D)⍴D
[21] N←¯1+1↓⍴D
[22] →(0=⍴⍴A)/SS
[23] D←(C[1],V,((W−1)⍴VL),C[2]),((HT,N⍴HL),[0]D,[0]HB,N⍴HL),C[0],(W⍴VL),C[3]
[24] →0
[25] SS:HB←((0 ' ')=↑0⍴⊂A)/' -’
[261 D←(B,B,((W−1)⍴B),B),((((⍴HT)⍴B),N⍴B),[0]D,[0]HB,N⍴B),B,(W⍴B),B←' '
[27] →0
[28] GEN:D←⍕DISPLAY¨A ⍝ ENCLOSED ...
[29] N←D∨.≠' '
[30] D←(N∨∼1⌽N)⌿D
[31] D←(∨⌿∼' '⍷D)/D
[32] D←((1,⍴S)⍴S)DISPLAY D
[33] →(2≥⍴,S)↓D3E,0
[34] D3:D←0 ¯1↓0 1↓⍕⊂A ⍝ MULT-DIMENSIONAL ...
[35] W←1↑⍴D
[36] N←¯1+1↓⍴D
[37] D←(C[1],V,((W−1)⍴VL),C[2]),((HT,N⍴HL),[0]D,[0]HB,N⍴HL),C[0],(W⍴VL),C[3]
[38] D3E:N←¯2+⍴,S
[39] V←C[N⍴1],[0]VB[1+0<¯2↓,S],[0](((¯3+↑⍴D),N)⍴VL),[0]C[N⍴2]
[40] D←V,D
[41] ∇</pre>