I think having examples in the wiki is a great idea. For many years
(starting c. 1990) my profile.ijs included my definitions of
fread=: 1!:1@<
fwrite=: 1!:2 <
a year or so ago I commented out my definitions in my profile so that
when I tried something for/from the forum I would be using the
definitions provided with the system. The idea of an argument to make
boxes 'b' or a matrix 'm' may be useful, but it looses a certain amount
of flexibility in answering the original question of how to sort a text
file. That flexibility is mainly lost because of the use of <;._2
(instead of <;.2) for boxing the file. Often times, "helpful features"
make more complicated solutions (things I encounter in M$ Word and Excel
leap to mind...)
The original question of how to sort the lines of a text file could be
written, with no cover functions at all, as -
sortfile=: ([:;[:/:~[:<;.2[:][:1!:1<)1!:2[:<'sorted.'"_,]
Where the output file is prefixed with 'sorted.' to avoid destroying the
original file. I'm sure that (13 : generated) tacit definition could be
made more readable - but the point is that having "convenient cover
functions" can make things obscure in a different way. Note that
sortfile completely avoids the issues around "line end character(s)" and
works for lines ending with CR, LF, or CR,LF.
A ground up set of examples of file fiddling in J would be a useful
project. Some things need to be stated at the beginning, e.g. All files
are treated as text strings (character vectors). Text strings such as
'3.14159 2.71828' have to be changed to numbers for calculations.
Numeric results have to be converted to character vectors to be written
into files.
There are various utilities provided to manipulate special/binary text
vectors (e.g. files of binary data [read as text] can be converted using
3!:n). That reminds me of my favorite FORTRAN trivia question - what
FORMAT command is used to write binary representations of numbers
(integers floating point etc.)? The answer is A (alphabetic) since if
you use I (integer) or F (floating point), what is written in your file
is character representations (EBCDIC in the day, surely ASCII these
days) of the numbers...
A discussion about the idea of "lines" and line/record delimiters, and
so forth. By the way, it would be useful to note that some widely used
programs (e.g. Excel) write text files as lines, but without the final
line end character, thus causing <;.2 to fail... Why the choice was made
to create a file that isn't complete is lost to history, but it is
unlikely to change.
Maybe if the wiki page was set up in a way that contributors could fill
in things about their personal tricks, examples would show up. I have
been enjoying rummaging in system files with J (and APL before that) for
40+ years. I'm still amazed at some of the things I find that have been
generated by professional/standard programs (e.g. the HTML files named
something.xls that I ranted about in chat a few weeks ago).
It has been entertaining to follow some of these "simple questions" in
the forums of late - and it certainly indicates a need and opportunity
for the creation of more helpful learning materials.
On 2013/05/27 12:09 , Murray Eisenberg wrote:
Yes, to the wiki -- please! Or even to the J help system. (I seem to recall
that many of these script files used to be documented in the help system pages,
both as distributed with J and on-line at www.jsoftware.com).
On 27 May 2013 09:37:51 -0600, Don Guinn <[email protected]> wrote:
Look in the "Files" lab. Years ago I fought the same battle. At that time
the comments were still in "files.ijs" and I stole them to create the
"files" lab. This was all before the J WIKI existed, so I wrote the lab in
a reference style. Now it would be better to move the reference material to
WIKI and keep just examples in the lab. One of these days.
On Mon, May 27, 2013 at 8:47 AM, Murray Eisenberg <[email protected]>wrote:
On 26 May 2013 15:32:47 -0600, Don Guinn <[email protected]> wrote:
That does it; thanks!
But how do you know about the optional 'b' argument of fread? I cannot
find documentation about fread at all -- either in J701 or J801 using
scriptdoc or in the help pages, included with J or on-line.
Where did you find that documented?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm