[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string port encodings

From: Alex Shinn
Subject: Re: string port encodings
Date: Wed, 16 Jan 2013 00:20:48 +0900

On Tue, Jan 15, 2013 at 11:36 PM, Andy Wingo <address@hidden> wrote:
Quiz: what does this do?

  (define (f s)
    (with-output-to-string (lambda () (display s))))

When called with a string, what should it do?  Like (f "foo").

If you answered, "return the string", that's what I would think it
should do.

But no, currently the answer is locale-specific.  It encodes the string
according to the current locale, then decodes it from that encoding.  If
your locale can't encode the string, tough luck for you!

This is a bit crazy.  Surely the port should be textual?  Surely the
default encoding for a string port should be utf-8 or something that can
actually handle all strings?

Yes, the POSIX locale should refer to the external environment -
notably the terminal, command-line args and env variables.

Default file encodings are open to interpretation, but either using
POSIX or ignoring it completely and using heuristics combined with
overrides (e.g. -*- coding: ... -*-) are both reasonable.

But string ports are entirely internal - there's no reason to use
the locale for them.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]