Here's how that example looks with all the pieces in place:
2 3 1 1 ([ (*@[ #inv ] </.~ +/\@[ I. #\@])(+/@[ {. ])) i. 7
┌───┬─────┬─┬─┐
│0 1│2 3 4│5│6│
└───┴─────┴─┴─┘
The top level grammatical structure here is a fork. The left tine of
the fork is [ and the right tine of the fork is (+/@[ {. ]). Both of
these tines of the fork get both arguments.
2 3 1 1 [ i. 7
2 3 1 1
2 3 1 1 (+/@[ {. ]) i. 7
0 1 2 3 4 5 6
You can replace the left tine with 2 3 1 1 (which is its result) but
if you leave the right tine as a verb, you need to leave both of the
original arguments in place
2 3 1 1 (2 3 1 1 (*@[ #inv ] </.~ +/\@[ I. #\@])(+/@[ {. ])) i. 7
┌───┬─────┬─┬─┐
│0 1│2 3 4│5│6│
└───┴─────┴─┴─┘
You could also eliminate the arguments and replace the right tine with
its noun result (which, in this case, happens to be equal to i.7):
2 3 1 1 (*@[ #inv ] </.~ +/\@[ I. #\@]) i. 7
┌───┬─────┬─┬─┐
│0 1│2 3 4│5│6│
└───┴─────┴─┴─┘
Is that taking it far enough?
Thanks,
--
Raul
On Wed, Sep 19, 2012 at 10:25 PM, Linda Alvord <[email protected]> wrote:
> Raul, What causes the problem when you replace [ with 2 3 1 1 and
> ] by i.7 ? I thought it might work if I removed @ but it didn't help.
>
> takecut=: [ (*@[ #inv ] </.~ +/\@[ I. #\@])(+/@[ {. ])
> 2 3 1 1 takecut i.7
> ┌───┬─────┬─┬─┐
> │0 1│2 3 4│5│6│
> └───┴─────┴─┴─┘
>
> 2 3 1 1 (*@ 2 3 1 1 #inv (i.7) </.~ +/\@2 3 1 1 I. #\@(i.7))(+/@ 2 3 1 1
> {. i.7)
> |domain error
> | 2 3 1 1(*@2 3 1 1#inv(i.7)</.~+/\@2 3 1 1 I.#\@(i.7))( +/@2 3 1 1{.i.7)
>
> Linda
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Raul Miller
> Sent: Tuesday, September 18, 2012 10:12 AM
> To: [email protected]
> Subject: Re: [Jprogramming] cut y in segments of each size being x's items
>
> P.S. if you want to overtake (instead of length error when the right arg does
> not contain enough elements):
>
> takecut=: [ (*@[ #inv ] </.~ +/\@[ I. #\@]) (+/@[ {. ])
>
> --
> Raul
>
> On Tue, Sep 18, 2012 at 10:08 AM, Raul Miller <[email protected]> wrote:
>> On Mon, Sep 17, 2012 at 11:14 PM, June Kim (김창준) <[email protected]> wrote:
>>> It's not so difficult. However, generalizing takecut into allowing 0
>>> as an item in x seems complicated. That is,
>>>
>>> 3 0 2 2 takecut i.7
>>> +-----++---+---+
>>> |0 1 2||3 4|5 6|
>>> +-----++---+---+
>>> 0 0 4 3 0 takecut i.7
>>> +++-------+-----++
>>> |||0 1 2 3|4 5 6||
>>> +++-------+-----++
>>>
>>> Any ideas for simple solutions?
>>
>> takecut=: *@[ #inv ] </.~ +/\@[ I. #\@]
>> 0 0 3 3 0 2 takecut i. 7
>> ┌┬┬─────┬─────┬┬─┐
>> │││0 1 2│3 4 5││6│
>> └┴┴─────┴─────┴┴─┘
>>
>> --
>> Raul
> ----------------------------------------------------------------------
> 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