[Jprogramming] multiple boxing

Dan Bron j at bron.us
Fri Nov 25 11:49:30 HKT 2011


Raul Miller wrote:
>     foo=: <^:{./.~ [: +/\ 0,2 ~:/\ ]

REB asked for a foo such that:

	   foo 1 1 2 2 3 3 4 2 3 4 4 1 2 2 2 1
	+---+---------------------------+-+-------+-+
	|1 1|+---+---------+-+---------+|1|+-----+|1|
	|   ||2 2|+---+---+|2|+-+-----+|| ||2 2 2|| |
	|   ||   ||3 3|+-+|| ||3|+---+||| |+-----+| |
	|   ||   ||   ||4||| || ||4 4|||| |       | |
	|   ||   ||   |+-+|| || |+---+||| |       | |
	|   ||   |+---+---+| |+-+-----+|| |       | |
	|   |+---+---------+-+---------+| |       | |
	+---+---------------------------+-+-------+-+

Your foo gives:

	   foo 1 1 2 2 3 3 4 2 3 4 4 1 2 2 2 1
	+---+-----+-------+-------+---+-----+---------+-+-------+-+
	|1 1|+---+|+-----+|+-----+|+-+|+---+|+-------+|1|+-----+|1|
	|   ||2 2|||+---+|||+---+|||2|||+-+|||+-----+|| ||2 2 2|| |
	|   |+---+|||3 3|||||+-+|||+-+|||3|||||+---+||| |+-----+| |
	|   |     ||+---+|||||4||||   ||+-+|||||4 4|||| |       | |
	|   |     |+-----+|||+-+|||   |+---+|||+---+||| |       | |
	|   |     |       ||+---+||   |     ||+-----+|| |       | |
	|   |     |       |+-----+|   |     |+-------+| |       | |
	+---+-----+-------+-------+---+-----+---------+-+-------+-+

That is, you have the depth of each element right, but you still need to
group the elements appropriately.  It helps to think of 1 1 2 2 3 3 4 2 3 4
4 1 2 2 2 1 as representing a parenthesized expression, with greater numbers
being more deeply nested.

-Dan



More information about the Programming mailing list