> please point me to that "flatten" link.  I haven't come across this yet.

http://jsoftware.com/help/user/script_format.htm#flatten

Or in other words:

   require 'format'
   flatten
+-+-+-------------------------------------------------+
|3|:|dat=. ": y                                       |
| | |select. # $ dat                                  |
| | |case. 1 do.                                      |
| | |case. 2 do.                                      |
| | |  }. , LF ,. dat                                 |
| | |case. do.                                        |
| | |  dat=. 1 1}. _1 _1}. ": < dat                   |
| | |  }: (,|."1 [ 1,.-. *./\"1 |."1 dat=' ')#,dat,.LF|
| | |end.                                             |
+-+-+-------------------------------------------------+

The   scriptdoc 'format'  entry reads:

        flatten (v) flatten array to a character string
        flattens array to a character string with same display

It is most handy when you want to fwrite data to files or stdout:

   ] m =. 'fi', 'fo',: 'fum'
fi 
fo 
fum

   empty  m (1!:2) 4
fi fo fum               <- 3*3 characters

   empty  (flatten m)  (1!:2) 4
fi
fo
fum
   a. i. flatten m
102 105 10 102 111 10 102 117 109    <- Look Ma, linefeeds!

The initial ": in the function will take care of numeric and boxed
data.  After flattening data, I usually append a trailing LF, too.

                                                        Martin
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to