For the general case (where ;: doesn't work for parsing the line) starting with
Noun, I think I'd start of by not turning the defined noun into a MxN table.
Assuming the key is fixed width, I'd use a combination of split and ;._2 for
example:
t1=: 0 : 0
{. curlylfdot
{: curlylfco
{:: curlylfcoco
} curlyrt
)
t2=: 0 : 0
Mon[day] Ian
Tues[day] Avril
We[dnesday] Barbara
)
3&split;._2 t1
+---+------------+
|{. | curlylfdot |
+---+------------+
|{: | curlylfco |
+---+------------+
|{::| curlylfcoco|
+---+------------+
|} | curlyrt |
+---+------------+
3&split;._2 t2
+---+-----------------+
|Mon|[day] Ian |
+---+-----------------+
|Tue|s[day] Avril |
+---+-----------------+
|We[|dnesday] Barbara|
+---+-----------------+
> From: Ian Clark
>
> > How do you do it in APL? Translate it into J.
>
> Sure, that's how I started out. I used to be able to write dtb{each}
> []SPLIT t[;{iota}4]
> but mindless translation to J looks Japlese to me (i.e. scope for
> improvement):
>
> ([: dtb&.> <"1)(i.4){"1 t
>
> It may be just a matter of taste / experience, but IMO that's neither
> elegant nor memorable.
>
> > {."1 ;: t
>
> Now that is nice!
> And it seems to work how I want it with other examples in the same
> vein:
>
> t=: >@((10{a.)&cut) 0 : 0
> Mon[day] Ian
> Tues[day] Avril
> We[dnesday] Barbara
> )
>
> Ian
>
> On Sun, Feb 14, 2010 at 4:58 AM, Roger Hui <[email protected]> wrote:
> > How do you do it in APL? Translate it into J.
> >
> > Alternatively, your table t is a very special table
> > and so admits some special phrases. e.g.
> >
> > {."1 ;: t
> >
> >
> >
> > ----- Original Message -----
> > From: Ian Clark <[email protected]>
> > Date: Saturday, February 13, 2010 20:50
> > Subject: [Jprogramming] Slicing and dicing a 2D char mx
> > To: Programming forum <[email protected]>
> >
> >> 1. If I have a M-by-N table with entries like this (you may
> recognise
> >> the example ;)...
> >>
> >> ...
> >> {. curlylfdot
> >> {: curlylfco
> >> {:: curlylfcoco
> >> } curlyrt
> >> ...
> >>
> >> how do I neatly slice off the first 3 columns (say) into a boxed
> list
> >> of tally M to serve as a lookup index?
> >> Ditto any given field, i.e. set of columns?
> >> I'm often doing it, but a different way each time, and the
> >> methods I
> >> use are cumbersome.
> >>
> >> 2. Is there already a slice'n'dice cookbook on the wiki, to give
> quick
> >> answers to questions like this?
> > ---------------------------------------------------------------------
> -
> > 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