[plt-scheme] Help on newline when writing to a file

From: Andrew Reilly (andrew-scheme at areilly.bpc-users.org)
Date: Wed Jan 16 19:13:37 EST 2008

On Wed, Jan 16, 2008 at 08:36:04PM +0000, Noel Welsh wrote:
> The basic issue is the difference between the representation on a
> newline on Unix and Windows.
> On Unix a newline is always just "\n".  Windows, for some reason I
> cannot fathom, decided that a newline should be the two characters
> "\r\n".  However, when a file is opened in text mode Windows processes
> the port so this two character sequence is read and written as the
> single "\n" as in Unix.  If a file is opened in binary mode this is
> not the case.  All this confusion comes from this design decision.

Not that I would normally leap to the defence of windows, but by
way of historical context: Windows inherited this from MS-DOS,
which inherited it from the common practice in almost every
non-Unix operating system in existence at that time.  It was
Unix, and a particular design decision by Ritchie and Thompson
that the actual mechanics of driving terminals (which is where
\r\n comes from) should be part of a terminal library and not
the text file, that was the innovation.

Note that many, many internet standards (like telnet and SMTP)
that pre-date Windows also specify \r\n end-of-line markers.

Also, just to be different (?), old-school Mac-OS uses just
\r as the end-of-line marker, presumably because that was the
character that you *typed* to end a line.

I've never used an EBCDIC machine, so I don't know what the
convention is, there.  Perhaps someone else can comment?

These issues are real: the world of computing isn't a
monoculture, and software that wants to be portable and
compatible just needs to be a bit flexible.  It's not all that
difficult, particularly if your language runtime has nice
features for handling text specially and smoothing over the
differences from you.



Posted on the users mailing list.