To avoid the fills, you must use boxing, as you suggest.
3 4 f2&.>~ 2 3 <@f1 4
+---+---+
|4 3|4 4|
|5 3|5 4|
| |6 4|
+---+---+
Henry Rich
Alexander Mikhailov wrote:
> Hi,
>
> I wonder how in J one should properly solve the following problem.
> Basically, one need to apply a dyad of rank 0 0 to equally long
> arrays of rank 1, with one array being calculated on the fly and
> having a variable length. Is it possible to avoid both boxing and
> the necessity to handle filling?
>
> Suppose one has a dyad f1, which takes atoms as both arguments and
> returns a list, rank 1, of variable length, for example
>
> f1 =: 4 : 'y + i. x' "0 0
>
> Suppose then one has another dyad, f2, also taking atoms as both
> arguments, like this:
>
> f2 =: 4 : 'x , y' "0 0
>
> If one wants to apply f1 to 2 and 3, and then apply f2 to the
> result of the previous operation and 3, he can write
>
> f2 & (3) 2 f1 3
>
> If one calls f1 with left array of rank 1 and right atom, he gets
> an array of rank 2, with fillers to make all partial results of
> the same size, like in
>
> 2 3 f1 4
> 4 5 0
> 4 5 6
>
> Suppose then he wants to apply f2 to such a result as y, with left
> x argument - consecutive items from a rank 1 array. Like this:
>
> f2 & (3 4) 2 3 f1 4
> 4 3
> 5 3
> 0 3
>
> 4 4
> 5 4
> 6 4
>
> But if he doesn't want to deal with the filler 0, which appeared in
> the top line of the f1 result, what he has to do? He can box partial
> results and then work with accumulated result, like here -
>
> 3 4 (f2~ >) "(0 0) 2 3 < @ f1 4
> 4 3
> 5 3
> 0 0
>
> 4 4
> 5 4
> 6 4
>
> So, here he has a boxing and unboxing only to avoid the fill.
>
> Is boxing justified here? Or is there another way to do what he needs?
>
> Thank you,
>
> Alexander
>
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm