Hello all! I'm very new to J and just discovered a concise way to display data
from
multiple lists in a columnar fashion, primarily in order to debug. It's quite
useful
when dealing with masks / transformations, to compare values at different
stages of
the process. For example,
parens =: [:-/'()'=/] NB. Mask of () in string, _1 for )
depthOf =: [:+/\ parens NB. () nesting depth at each index in string
input =. '((a^2)+((b)^2))=(c^2)' NB. A contrived example
parens input
1 1 0 0 0 _1 0 1 1 0 _1 0 0 _1 _1 0 1 0 0 0 _1
depthOf input
1 2 2 2 2 1 1 2 3 3 2 2 2 1 0 0 1 1 1 1 0
<"0&> input ; (parens input) ; (depthOf input)
┌─┬─┬─┬─┬─┬──┬─┬─┬─┬─┬──┬─┬─┬──┬──┬─┬─┬─┬─┬─┬──┐
│(│(│a│^│2│) │+│(│(│b│) │^│2│) │) │=│(│c│^│2│) │
├─┼─┼─┼─┼─┼──┼─┼─┼─┼─┼──┼─┼─┼──┼──┼─┼─┼─┼─┼─┼──┤
│1│1│0│0│0│_1│0│1│1│0│_1│0│0│_1│_1│0│1│0│0│0│_1│
├─┼─┼─┼─┼─┼──┼─┼─┼─┼─┼──┼─┼─┼──┼──┼─┼─┼─┼─┼─┼──┤
│1│2│2│2│2│1 │1│2│3│3│2 │2│2│1 │0 │0│1│1│1│1│0 │
└─┴─┴─┴─┴─┴──┴─┴─┴─┴─┴──┴─┴─┴──┴──┴─┴─┴─┴─┴─┴──┘
In essence, it boxes each element of the given lists/strings, then stacks them
in a
table so data can easily be compared, with each table column representing the
matching
indices of each list. Its behavior is quite similar to ,[0.5] in Dyalog APL,
which was
the inspiration for finding a J equivalent.
Is this a known technique, and is there a common name for this? I'm inclined to
call it
the "pit droid" operator for fun, since it reminds me of the Star Wars
character, but
I'm interested to hear if others have found/named this.
~ Katrina
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm