Thanks Roger.
You may have missed the example I gave, though. Here it is again:
I looked at "table" and couldn't see how to adapt it, except like this:
s=: 4 : '(<x;<y) { zz' NB. to pick out individual entries of table zz
s table i.5
...but that's a distressing way of doing it. Since the whole thrust of
the chapter is to generate the nim-multiplication table efficiently,
it seems to defeat the object to employ a verb: s that has to be
called once for every entry in the table.
I'm looking for a solution along these lines:
tabulate=: 3 : '2 2$('' '';2}.3":i.#y),(,. i.#y);y'
whereupon
tabulate mt 16
...will in fact reproduce the final table in
http://www.jsoftware.com/jwiki/Doc/Articles/Play191 .
But I can't see how to make the column headings line up in the general
case. It goes wonky when the given table (y) has only 1-digit entries,
say, and I don't want to fiddle about calculating the left argument of
Format (":).
I want to give the reader of APWJ a professional-looking model
expression for labelling arbitrary tables, and my "tabulate" is far
too crass for the purpose. There's got to be a simpler way.
Ian
On Tue, Nov 17, 2009 at 1:33 AM, Roger Hui <[email protected]> wrote:
> There is a standard utility adverb "table" that is loaded
> when J starts up:
>
> 1 2 3 ^ table 1 2 3 4 5
> +-+-------------+
> |^|1 2 3 4 5|
> +-+-------------+
> |1|1 1 1 1 1|
> |2|2 4 8 16 32|
> |3|3 9 27 81 243|
> +-+-------------+
>
> You can modify this to effect the result you requested.
>
>
>
> ----- Original Message -----
> From: Ian Clark <[email protected]>
> Date: Monday, November 16, 2009 16:16
> Subject: [Jprogramming] labelling a table
> To: Programming forum <[email protected]>
>
>> Suppose I have an arbitrary table, eg
>>
>> zz
>> 1 2 3 4 5
>> 2 3 1 8 10
>> 3 1 2 12 15
>> 4 8 12 6 2
>> 5 10 15 2 7
>>
>> what's a slick way of displaying it boxed and labelled, like
>> this? ...
>>
>> +-+-------------+
>> |s|0 1 2 3 4|
>> +-+-------------+
>> |0|1 2 3 4 5|
>> |1|2 3 1 8 10|
>> |2|3 1 2 12 15|
>> |3|4 8 12 6 2|
>> |4|5 10 15 2 7|
>> +-+-------------+
>>
>> Sorry to be lazy. It would do me good to work it out for myself, but
>> I'm pressed for time. Needed for APWJ. The best I can come up
>> with so
>> far is this:
>>
>> s=: 4 : '(<x;<y) { zz'
>> s table i.5
>> ...
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm