A note of explanation...

(I have been noticing that far too much software is poorly documented.
And while I cannot do an adequate job of documenting other people's
software, I can document software I write.)

   F=: </.~ +/\@(-.@+._1&|.)@:=&(<,'&')
   T=:  ;:'4&count int 3 8&inrange'

The first thing I do is find out where & appears:
   =&(<,'&') T
0 1 0 0 0 1 0

The second thing I do is rotate to the right and combine:
   (+. _1&|.) =&(<,'&') T
0 1 1 0 0 1 1

Except I want to mark the beginning of each section with a 1, and
right now they are zeros.
   (-.@+. _1&|.) =&(<,'&') T
1 0 0 1 1 0 0

As an aside, note that I could have cut that step out if I had started
by identifying where & does not appear (and then combine using logical
and instead of logical or):

   (* _1&|.) ~:&(<,'&') T
1 0 0 1 1 0 0

Next, I use plus scan to turn my markers into keys:

   +/\ (* _1&|.) ~:&(<,'&') T
1 1 1 2 3 3 3

Finally, I use these keys to group the original elements:

   T </.~ +/\ (* _1&|.) ~:&(<,'&') T
+-----------+-----+---------------+
|+-+-+-----+|+---+|+---+-+-------+|
||4|&|count|||int|||3 8|&|inrange||
|+-+-+-----+|+---+|+---+-+-------+|
+-----------+-----+---------------+

And that exposition pretty much follows the thought process I
originally used to compose the sentence.

Thanks,

-- 
Raul


On Mon, Jan 26, 2015 at 12:03 AM, Raul Miller <[email protected]> wrote:
>    F=: </.~ +/\@(-.@+._1&|.)@:=&(<,'&')
>    F ;:'4&count int 3 8&inrange'
> +-----------+-----+---------------+
> |+-+-+-----+|+---+|+---+-+-------+|
> ||4|&|count|||int|||3 8|&|inrange||
> |+-+-+-----+|+---+|+---+-+-------+|
> +-----------+-----+---------------+
>
> Thanks,
>
> --
> Raul
>
>
> On Sun, Jan 25, 2015 at 11:32 PM, 'Pascal Jasmin' via Programming
> <[email protected]> wrote:
>> I want the following output from parsing the string on the right,
>>
>>   1 1 1 0 2 2 2 </. ;: '4&count int 3 
>> 8&inrange'┌───────────┬─────┬───────────────┐
>> │┌─┬─┬─────┐│┌───┐│┌───┬─┬───────┐│
>> ││4│&│count│││int│││3 8│&│inrange││
>> │└─┴─┴─────┘│└───┘│└───┴─┴───────┘│
>>
>> └───────────┴─────┴───────────────┘
>>
>> or
>>
>> 0 1 2 2 2 </. ;: 'str int 3 8&inrange'
>> ┌─────┬─────┬───────────────┐
>> │┌───┐│┌───┐│┌───┬─┬───────┐│
>> ││str│││int│││3 8│&│inrange││
>> │└───┘│└───┘│└───┴─┴───────┘│
>> └─────┴─────┴───────────────┘
>>
>>
>> basically, I want to group 3 words together if the middle word is a '&'
>>
>>
>> How can I calculate either the left hand argument to </. or otherwise create 
>> the groupings?
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to