Huh... wait... charsub doesn't flatten the array.. I wonder why I was getting a flattened result earlier?
Anyways, some code cleanup possible because of my mistake... Thanks, -- Raul On Tue, Feb 19, 2019 at 11:22 AM Raul Miller <[email protected]> wrote: > > This could be turned into a one-liner: > > lzfmt=:3 :0 > fmt=.(' ',-.&' ')"1 ":10&#.inv,y > }."1,/"2($y)$fmt > ) > > lzfmt b=. 0 12 34 678 20 ,. 3 40 873 9 44 > 000 003 > 012 040 > 034 873 > 678 009 > 020 044 > > Also, you could use charsub instead: > > lzfmt=:3 :0 > fmt=.' ',"1' 0'charsub"1":,.,y > }."1,/"2($y)$fmt > ) > > but I am not sure that that's a better approach. > > I am also not sure why charsub uses an approach that flattens the > array - I would prefer this (but changing the name for compatibility > reasons): > > char_sub=:4 :0 > 'f t'=. |:_2]\x > (a.i.y){t(a.i.f)}a. > ) > > Thanks, > > -- > Raul > > On Tue, Feb 19, 2019 at 2:50 AM 'Skip Cave' via Programming > <[email protected]> wrote: > > > > Bob & Ric, > > > > Thanks! the pad verb does exactly what I specified. However, I have a more > > complex issue as well - > > padding a 2 dimensional array. > > > > ]b=. 0 12 34 678 20 ,. 3 40 873 9 44 > > > > 0 3 > > > > 12 40 > > > > 34 873 > > > > 678 9 > > > > 20 44 > > > > > > I need a pad1 verb that does this: > > > > pad1 b > > > > 000 003 > > > > 012 040 > > > > 034 873 > > > > 678 009 > > > > 020 044 > > > > > > What if some columns have 2-digit maximum widths? 4-digit maximum widths? > > > > Is it possible to auto-pad to the maximum digit width in a column? > > > > Also, Is it possible to generalize this padding to n-dimensional arrays? > > > > > > Skip > > > > > > On Mon, Feb 18, 2019 at 10:14 PM Ric Sherlock <[email protected]> wrote: > > > > > Thanks Bob - nice! > > > I think you could avoid the boxing using: > > > pad=: _3&({.!.'0')@":"0 > > > > > > > > > On Tue, Feb 19, 2019 at 4:39 PM 'robert therriault' via Programming < > > > [email protected]> wrote: > > > > > > > Hey Ric, > > > > > > > > I get a chance to repay the favour of helping me out on StackOverflow > > > > yesterday. > > > > This solution relies on some boxing, but it does use fill at its core. > > > > > > > > And yes Skip it does end up with a literal result. > > > > I don't know of a way around that, but I would be happy to be proved > > > wrong > > > > as well! > > > > > > > > a > > > > 0 12 34 678 20 > > > > pad=: > @ (_3&({.!.'0') @ ": each) > > > > pad a > > > > 000 > > > > 012 > > > > 034 > > > > 678 > > > > 020 > > > > > > > > Cheers, bob > > > > > > > > > On Feb 18, 2019, at 6:00 PM, Ric Sherlock <[email protected]> wrote: > > > > > > > > > > ('r<0>0.0' 8!:2 ]) ,. a > > > > > > > > ---------------------------------------------------------------------- > > > > 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
