|
From: | Elias Mårtenson |
Subject: | Re: [Bug-apl] Cell grid in ⎕CR output? |
Date: | Mon, 31 Mar 2014 00:19:37 +0800 |
Hi Elias,
this is actually not so easy and I can imaging a number of inner/outer line styles that could become
too complex for a ⎕CR mode to be useful. How about using APL? Like:
A←'╔╗╚╝║═╦╩╠╣╬║═' ⍝ all lines double
A←'╔╗╚╝║═╤╧╟╢┼│─' ⍝ outside lines double, inside lines single
B←3 4⍴1 2 3 4 'a' 'b' 'cde' 'f' 9 10 11 12
∇Z←A GRID B;⎕IO;B1;C1;C2;X;Y;ZX;ZY
⎕IO←1
⍝ add vertical lines, remember their X-coordinates in X
B1←(⊃,/⊃¨{ A[12],⍕B[;,⍵] }¨⍳¯1↑⍴B),A[5] ◊ B1[;1]←A[5]
C1←(⊃,/⊃¨{ ' ',⍕B[;,⍵]} ¨⍳¯1↑⍴B),' '
X←B1[1;] ≠ C1[1;]
⍝ add horizontal lines, remember their Y-coordinates in Y
(ZY ZX)←⍴Z←A[6]⍪(2 1×⍴B1)⍴B1,[1.5]A[13] ◊ Z[ZY;]←A[6]
C2←' '⍪(2 1×⍴C1)⍴C1,[1.5]' ' ◊ Y←Z[;2] ≠ C2[;2]
⍝
(Y⌿X/Z)←A[11] ⍝ crosses
(X/Z[1;])←A[7] ◊ (X/Z[ZY;])←A[8] ⍝ top/bottom lines
(Y⌿Z[;1])←A[9] ◊ (Y⌿Z[;ZX])←A[10] ⍝ left/right lines
Z[1,ZY; 1,ZX]←2 2⍴A ⍝ corners
∇
A GRID B
╔═╤══╤═════╤══╗
║1│ 2│ 3 │ 4║
╟─┼──┼─────┼──╢
║a│ b│ cde │ f║
╟─┼──┼─────┼──╢
║9│10│ 11 │12║
╚═╧══╧═════╧══╝
/// Jürgen
On 03/26/2014 02:35 PM, Elias Mårtenson wrote:
Would it be possible to add a ⎕CR mode where matrices are displayed in a grid?
In other words, instead of displaying 3 3⍴⍳9 like this:
┌→────┐↓1 2 3││4 5 6││7 8 9│└─────┘
I'd like it to be displayed like this:
┌→┬─┬─┐↓1│2│3│├─┼─┼─┤│4│5│6│├─┼─┼─┤│7│8│9│└─┴─┴─┘
I was looking at the code, and it actually seems slightly harder to do than I expected since the frame around a matrix is drawn separately from the actual content, and the grid-style requires that the frame changes depending on the alignment of the actual cells inside the matrix.
However, I still would like to ask if there is a way to do it, as there are cases where the grid notation is much more clear.
Regards,Elias
[Prev in Thread] | Current Thread | [Next in Thread] |