The line delimiter for unix is LF.
The line delimiter from the PC is CRLF.
The line delimiter for mac is CR.
Sometimes a trailing fragment (after the last end of line)
in a text file is treated as a valid line. Sometimes,
it's not.
Conceptually, you could write a routine which accepts all
these standards.
For example, a function f could be defined such that
f 'abc',LF,'def',CRLF,'ghi',CR,'jkl'
is equivalent to
;: 'abc def ghi jkl'
Unfortunately, ;: is not suitable for this task, because it
cannot emit empty words. However, the definition of f could
be modified so that it includes the delimiter characters at
the right hand side of each line. Then the above result would
be equivalent to
('abc',LF);('def',CRLF);('ghi',CR);'jkl'
Unfortunately, ;: is still not suitable for this task, because
there is no mechanism for it to incorporate the LF after a CR as
the same line when both CR and LF alone are line end characters.
(At least, not that I'm aware of.)
So here's another approach:
require 'regex'
RxLine=: rxcomp'[^\r\n]*(\n|\r\n|\r)?'
splitlines=: RxLine rxall ]
(I was going to go on and treat a sequence of blocks with this, but
I've got some other issues distracting me. Maybe later.)
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm