Things worked better with the new tbl1. I had been using your earlier post
of tbl2.
tbl1=: 1 : 0
:
(,x)u/(,y)
)
tbl1
1 : (':'; '(,x)u/(,y)')
tbl2=: 1 :'(,x)u/(,y)'
1 : '(,x)u/(,y)'
a=:2 3 5
b=:0 1 2 3
Over=: [: ({. ; }.) [: ": ,
By=:(' ' ; [: ,. [) ,. ]
Table1=: [ By ] Over +tbl1
Table2=: [ By ] Over +tbl2
a Table1 b
┌─┬───────┐
│ │0 1 2 3│
├─┼───────┤
│2│2 3 4 5│
│3│3 4 5 6│
│5│5 6 7 8│
└─┴───────┘
a Table2 b
|domain error: Table2
| a Table2 b
tbl1
(':'; '(,x)u/(,y)')
(':'; '(,x)u/(,y)')
┌─┬──────────┐
│:│(,x)u/(,y)│
└─┴──────────┘
You seemed to take care of all the misbehaving cases! It looks like inserting
each of the verbs > : ; in my simple table verb might work somehow. This
will give me something to think about during Thanksgiving. Enjoy the holiday
everyone. Thanks for participating in Challenge 1.
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Kip Murray
Sent: Sunday, November 20, 2011 4:53 PM
To: Programming forum
Subject: Re: [Jprogramming] table challenge in simple J
Linda,
tbl =: 1 : 0
:
(,x) u/ (,y)
)
tbl NB. Compare your one-line definition
1 : (':'; '(,x) u/ (,y)')
Table =: [ By ] Over +tbl
Table
[ By ] Over + (1 : (':'; '(,x) u/ (,y)'))
1 Table 2 3
+-+---+
| |2 3|
+-+---+
|1|3 4|
+-+---+
1 2 Table 3
+-+-+
| |3|
+-+-+
|1|4|
|2|5|
+-+-+
over=:({.;}.)@":@, NB. Dictionary's over and by
by=:' '&;@,.@[,.]
2 by 3 4 over 2 */ 3 4 NB. operation is * not +
+-+------+
| |3 |
+-+------+
|2| 4 6 8|
+-+------+
2 by 3 4 over 2 *tbl 3 4
+-+---+
| |3 4|
+-+---+
|2|6 8|
+-+---+
2 3 by 4 over 2 3 */ 4
+-+-----+
| |4 |
+-+-----+
|2| 8 12|
|3| |
+-+-----+
2 3 by 4 over 2 3 *tbl 4
+-+--+
| | 4|
+-+--+
|2| 8|
|3|12|
+-+--+
To me, the fact that adverb tbl works well with verbs by and over is a
strong selling point for a not very strong product: who cares about the
extreme cases enabled by tbl?
On 11/20/2011 10:22 AM, Linda Alvord wrote:
...
> I can't make your example with an adverb work.
>
> Over=: [: ({. ; }.) [: ": ,
> By=:(' ' ; [: ,. [) ,. ]
> tbl=: 1 : '(,x)u/(,y)'
> Table=: [ By ] Over +tbl
> a Table b
> |domain error: Table
> | a Table b
>
>
> I don't really think the problem is with +/ . Rather their needs to be a
> test if the left argument is a list and act accordingly.
>
> Cheers. This has been fun.
>
> Linda
>
>
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Kip Murray
> Sent: Sunday, November 20, 2011 8:39 AM
> To: Programming forum
> Subject: Re: [Jprogramming] table challenge in simple J
>
> Look just under "Flawed solution to Linda's challenge" below.
>
> On 11/20/2011 4:16 AM, Linda Alvord wrote:
>> What are your definitions of By and Over?
>> tbl
>> 1 : '(,x)u/(,y)'
>> Table=:[ by ] over +tbl
>>
>> a Table b
>> |domain error: Table
>> | a Table b
>>
>> by
>> ''&;@,.@[ ,. ]
>> over
>> ({. ; }.)@":@,
>>
>> Linda
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Kip Murray
>> Sent: Saturday, November 19, 2011 9:58 PM
>> To: [email protected]
>> Subject: Re: [Jprogramming] table challenge in simple J
>>
>> I think the correct way to deal with the misbehavior of Table in extreme
>> cases is to use adverb tbl below instead of adverb / , leaving the realm
>> of Simple J.
>>
>> Use
>>
>> tbl =: 1 : 0
>> :
>> (,x)u/(,y)
>> )
>>
>> and
>>
>> Table =: [ By ] Over +tbl
>>
>> then
>>
>> a Table b
>> +-+-------+
>> | |0 1 2 3|
>> +-+-------+
>> |2|2 3 4 5|
>> |3|3 4 5 6|
>> |5|5 6 7 8|
>> +-+-------+
>> 1 Table 2 3
>> +-+---+
>> | |2 3|
>> +-+---+
>> |1|3 4|
>> +-+---+
>> 1 2 Table 3
>> +-+-+
>> | |3|
>> +-+-+
>> |1|4|
>> |2|5|
>> +-+-+
>> 1 Table 2
>> +-+-+
>> | |2|
>> +-+-+
>> |1|3|
>> +-+-+
>>
>> The point is, if adverb tbl is used in place of / then not only is Table
>> fixed, but also By and Over handle extreme cases correctly.
>>
>> Incidentally, Over's use of Format ": enables Table to get heading
>> spacing right:
>>
>> 100 Table 2 3 4
>> +---+-----------+
>> | | 2 3 4|
>> +---+-----------+
>> |100|102 103 104|
>> +---+-----------+
>>
>>
>> On 11/18/2011 10:48 AM, Kip Murray wrote:
>>> It is 18 November, so below is my solution Table to Linda's challenge.
>>> It is the same as Raul's. However, it does not handle extreme cases
>>> well, and I leave it as a further challenge to repair Table.
>>>
>>> The difficulty:
>>>
>>> 1 Table 2 3
>>> +-+------+
>>> | |2 |
>>> +-+------+
>>> |1| 3 3 4|
>>> +-+------+
>>>
>>> 1 2 Table 3
>>> +-+----+
>>> | |3 |
>>> +-+----+
>>> |1| 4 5|
>>> |2| |
>>> +-+----+
>>>
>>> Flawed solution to Linda's puzzle:
>>>
>>> Over
>>> [: ({. ; }.) [: ": ,
>>>
>>> By
>>> (' ' ; [: ,. [) ,. ]
>>>
>>> Table
>>> [ By ] Over +/
>>>
>>> Table f.
>>> [ ((' ' ; [: ,. [) ,. ]) ] ([: ({. ; }.) [: ": ,) +/
>>>
>>> a Table b
>>> +-+-------+
>>> | |0 1 2 3|
>>> +-+-------+
>>> |2|2 3 4 5|
>>> |3|3 4 5 6|
>>> |5|5 6 7 8|
>>> +-+-------+
>>>
>>> Over and Bye can produce any operation table, but Table can only produce
>>> addition tables.
>>>
>>> a By b Over a */ b
>>> +-+---------+
>>> | |0 1 2 3|
>>> +-+---------+
>>> |2|0 2 4 6|
>>> |3|0 3 6 9|
>>> |5|0 5 10 15|
>>> +-+---------+
>>>
>>>
>>> -------- Original Message --------
>>> Subject: [Jprogramming] table challenge in simple J
>>> Date: Sun, 13 Nov 2011 20:51:50 -0500
>>> From: Linda Alvord<[email protected]>
>>> Reply-To: Programming forum<[email protected]>
>>> To: 'Programming forum'<[email protected]>
>>>
>>> In the dictionary in the section on "Verbs and Adverbs" there are two
>>> definitions designed to produce a table:
>>>
>>>
>>>
>>> over=:({.;}.)@":@,
>>>
>>> by=:' '&;@,.@[,.]
>>>
>>> a=: 2 3 5
>>>
>>> b=: 0 1 2 3
>>>
>>> a by b over a +/ b
>>>
>>> --T-------┐
>>>
>>> │ │0 1 2 3│
>>>
>>> +-+-------+
>>>
>>> │2│2 3 4 5│
>>>
>>> │3│3 4 5 6│
>>>
>>> │5│5 6 7 8│
>>>
>>> L-+--------
>>>
>>>
>>>
>>> Here is the challenge. Use the arguments a and b and define a single
> tacit
>>> function in "simple J" that does not use @ and provides the same result.
>>>
>>>
>>>
>>> a table b
>>>
>>> --T-------┐
>>> │ │0 1 2 3│
>>> +-+-------+
>>> │2│2 3 4 5│
>>> │3│3 4 5 6│
>>> │4│4 5 6 7│
>>> L-+--------
>>>
>>>
>>>
>>> To give a little time for thought, do not post a solution until November
>>> 18th. I'll post mine then too.
>>>
>>>
>>>
>>> Linda
>>>
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm