[plt-scheme] Help on newline when writing to a file
At Wed, 9 Jan 2008 13:23:10 +0000, Dave Gurnell wrote:
> Noel wrote:
> > Try this:
> >
> > (display "\r\n")
>
>
> So on Windows, (printf "~n") and (printf "\r\n") aren't equivalent?
No. `(printf "~n")', `(printf "\n")', and `(newline)' are all
equivalent.
If you're printing to a file port that was opened in 'text mode, then
all of those things produce #"\r\n". In 'binary mode (the default),
they produce #"\n".
> The documentation seems to suggest this:
>
> -- SNIP --
>
> - ~n or ~% prints a newline
>
> -- SNIP --
I'll clarify in the docs that it means `#\newline'.
> why have ~n at all?
It pre-dates "\n" support in string literals. I never use it anymore.
> The documentation for ~w
> below reads:
>
> -- SNIP --
>
> - ~w, where w is a whitespace character, skips characters in
> format-string
> until a non-whitespace character is encountered or until a second
> end-of-line
> is encountered (whichever happens first). An end-of-line is
> either #\return,
> #\newline, or #\return followed immediately by #\newline (on all
> platforms).
>
> -- SNIP --
>
> which implies that ~w is platform aware.
No, it means that "~w" recognizes all of the usual conventions
independent of what platform you're using.
> Is there call for a platform
> specific line break escape here?
I think that's best left to the port mode.
Matthew