x paren y draws lines connecting matching parentheses in phrase y using box drawing characters x . If x is elided then those specified in the J session configuration are used.
depth =: [: +/\ =/\@(''''&~:) * 1 _1 0 {~ '()' i. ]
levels=: i.@-@(>./) </ ]
i4 =: 2 #.\"(1) 0 ,. ]
paren2=: (' ',6 8 10{[) {~ i4@levels@depth@]
paren =: (9!:6 '')&$: : (],paren2)For example:
paren 5!:5 <'depth'
[: +/\ =/\@(''''&~:) * 1 _1 0 {~ '()' i. ]
└───────┘
paren 5!:6 <'depth'
[: ((+/)\) ((((=/)\)@(''''&~:)) * (1 _1 0 ({~) ('()' i. ])))
└──┘
└─────┘ └───────┘ └──┘ └─────────┘
└──┘ └─────────────────┘ └───────────────────────┘
└─────┘ └───────────────────────────────────────────────┘
Contributed by RogerHui. An earlier version appeared in the J Forum on 2008-07-31.
