I am trying to make sense of your requirements.
Your final example includes some parenthesis, but not others. It also
includes at the same boxing level content from different parenthesis
depths. How does this make sense?
My guess is you are asking for: each time boxing changes between level 0
and 1 you want a box fret. Box levels beyond 1 are ignored.
With that specification, here's my F:
F=: (]~:0,}:)@:(1<.])
Note, of course, that this definition (and the use of <;._2) assumes that
the first character of the argument to depth is a '('. But I think if you
could change your specification such that it boxes level 1 content deeper
than level 0 content that that would solve this one also.
Basically, I think you need to start from what your final result looks
like, and J's boxed type requires that everything be in boxes, so you
should probably want a final result that looks like this:
('a';(<'bdc');'g');'gg';(<<'ffff')
┌───────────┬──┬──────┐
│┌─┬─────┬─┐│gg│┌────┐│
││a│┌───┐│g││ ││ffff││
││ ││bdc││ ││ │└────┘│
││ │└───┘│ ││ │ │
│└─┴─────┴─┘│ │ │
└───────────┴──┴──────┘
In other words:
* Boxing level for characters is 1+depth.
* Box boundaries are increment boundaries.
* All adjacent content at a given increment level (or higher) gets
contained in one box.
* All parenthesis get removed.
Do you agree with this specification? (Why or why not?)
Thanks,
--
Raul
On Wed, Dec 7, 2016 at 11:56 AM, 'Pascal Jasmin' via Programming <
[email protected]> wrote:
> There is this useful essay
>
> http://code.jsoftware.com/wiki/Essays/Parentheses_Matching
>
> but consider,
>
> depth =: [: +/\ =/\@(''''&~:) * 1 _1 0 {~ '()' i. ]
>
> depth '(a(bdc)g)gg(ffff)'
> 1 1 2 2 2 2 1 1 0 0 0 1 1 1 1 1 0
>
> my goal is to box an expression such that at the "top level", at least 3
> boxes are generated
>
>
> 'outside (' ; 'inside outer ()' ; 'outside ) and outside next top level ('
>
>
> optionally followed by even number of boxes corresponding to last 2
> conditions.
>
> the most straightforward path I see is to create an argument to <;._2
> sucht that:
>
> F depth '(a(bdc)g)gg(ffff)'
> 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1
>
>
> and where,
>
>
> 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 1 ((<;._2) ' ' ,~ ]) '(a(bdc)g)gg(ffff)'
> ┌┬───────┬──┬────┬┐
> ││a(bdc)g│gg│ffff││
> └┴───────┴──┴────┴┘
>
> what is F?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm