> > Roger Hui wrote:
> > For the 5 examples I listed, can you produce programmatically
> > (not by hand) results that "look like" what the monad ": produces?
> > Also, can all the lines have the same width?  Currently the interior
> > lines are thicker than the external ones.
> >
> > Otherwise it looks promising.
 
> I wrote:
> 
> Next step is to handle the nested examples as well.
> 

The following seems to work ok. The obvious exception being that the alignment 
of row heights between planes is not achieved.

Note 'tests'
JARRAYSTYLE, dispArray i.2 2 3 4
JARRAYSTYLE, dispArray <"0 i.2 2 3 4
JARRAYSTYLE, dispArray 5!:2 <'assert'
JARRAYSTYLE, dispArray 2 3 4 $ i.&.> i.7
JARRAYSTYLE, dispArray x=: 2 2 3 $ (i.&.>i.6),<<2 5$'abcdefghij'
)

require 'strings'

sh     =: (*/@}: , {:)@(1&,)@$ ($,) ]
rows   =: */\...@}:@$
bl     =: }.@(,&0)@(+/)@(0&=)@(|/ i...@{.@(,&1))
mask   =: 1&,. #&, ,.&0@>:@i...@#
mat    =: m...@bl@rows { ' ' , sh

JARRAYSTYLE=: 0 : 0
<style type="text/css">
.jarray {font-family:monospace;}
table.jarray {border-collapse:collapse;}
table.jarray td {border:solid black thin;vertical-align: top;padding:0.3em;}
table.jarray tr.spacer td {border:none;}
</style>
)

dispSimpArray=: 3 : 0
  t=. mat ": y
  t=. _4}., t ,"1 '<br>'
  t=. t rplc ' ';'&nbsp;'
  '<div class="jarray">',t,'</div>'
)

dispBoxArray=: 3 : 0
  if. 0 = L. y do. y return. end.
  t=. dispBoxArray^:(0 < L.)&.> y
  cols=. {:$ t
  t=. (,&.>/)"1 ('<td>', ,&'</td>') &.> t
  t=. (,&.>/)"1 ('<tr>', ,&'</tr>') &.> t
  s=. '<tr class="spacer">',(cols ((* #) $ ])'<td>&nbsp;</td>'),'</tr>'
  while. 0 < #$ t do.
    t=. ([ , s , ])&.>/"1 t
    s=. s,s
  end.
  '<table class="jarray"><tbody>',(>t),'</tbody></table>'
)

dispArray=: [: dispBoxArray dispSimpArray L:0

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to