From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Noah Lavine Newsgroups: gmane.lisp.guile.devel Subject: Re: Accessing the environment's locale encoding settings Date: Wed, 16 Nov 2011 08:11:15 -0800 Message-ID: References: <877h30exfk.fsf@gnu.org> <201111160300.38410.bruno@clisp.org> <87r5189wxw.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1321459899 4667 80.91.229.12 (16 Nov 2011 16:11:39 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 16 Nov 2011 16:11:39 +0000 (UTC) Cc: Bruno Haible , guile-devel@gnu.org To: =?ISO-8859-1?Q?Ludovic_Court=E8s?= Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Nov 16 17:11:28 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RQi59-0000ty-DV for guile-devel@m.gmane.org; Wed, 16 Nov 2011 17:11:27 +0100 Original-Received: from localhost ([::1]:41633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQi57-0007XQ-IW for guile-devel@m.gmane.org; Wed, 16 Nov 2011 11:11:25 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:40279) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQi53-0007X6-Un for guile-devel@gnu.org; Wed, 16 Nov 2011 11:11:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RQi4z-0003vQ-KZ for guile-devel@gnu.org; Wed, 16 Nov 2011 11:11:21 -0500 Original-Received: from mail-gx0-f169.google.com ([209.85.161.169]:63779) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQi4z-0003vI-Ej; Wed, 16 Nov 2011 11:11:17 -0500 Original-Received: by ggnq1 with SMTP id q1so6399372ggn.0 for ; Wed, 16 Nov 2011 08:11:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=qN07VOHYzlDV/MAt2ijjQ0cWf8jDPgykqOs0UmainDc=; b=Tfe62sBYNMF5wGZ1SXac259Moz5+W1OqnmVoxPUXz/KEmkzGWNtNcn/Zdf1Yq78MgH lAS485DOB5c7lDSuP8HbBJYeGNxaX5QpPJCbalNaED0YuM88Nv8xNhTqBdNFjaDKGU/3 Jdm0K+y2ApSnXWuIMIzkTvpCcMDUi/9nYNFog= Original-Received: by 10.42.163.200 with SMTP id d8mr32163079icy.41.1321459875555; Wed, 16 Nov 2011 08:11:15 -0800 (PST) Original-Received: by 10.42.136.68 with HTTP; Wed, 16 Nov 2011 08:11:15 -0800 (PST) In-Reply-To: <87r5189wxw.fsf@gnu.org> X-Google-Sender-Auth: fJrBHVqfostboLIhcr_4jS7x7og X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.169 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:12905 Archived-At: Hello, It seems like the right thing to do might be to do setlocale(LC_ALL, "") in Guile's main(). Let me argue that this accomplishes two goals which we want to accomplish - it does the right thing by default: you want your program to be able to talk to the user in the user's own language. This accomplishes that, and also fixes the bug that has been discussed. - it lets the user customize Guile's behavior: the user has two options for going back to the old behavior. First of all, they can do setlocale(LC_ALL, "C") as soon as their program starts to get back the default behavior. Second, if they really don't want any locale changes, they can provide their own main function. We might even be able to offer a configuration option, so that they could use Guile's main except for the setlocale call. However, it seems like in this case, setlocale(LC_ALL, "") is the right thing in almost every case, and it should just be Guile's default. Noah On Wed, Nov 16, 2011 at 2:35 AM, Ludovic Court=E8s wrote: > Hi Bruno, > > Thanks for your quick and insightful feedback. > > Bruno Haible skribis: > >> That is precisely the point. Only in C, C++, Objective C, PHP, and Guile= , >> it is the user's responsibility to set the locale. Look at the many >> internationalization samples ("hello world" samples) in GNU gettext: >> In all other languages (and even many GUI toolkits based on C, C++, or >> Objective C) the setlocale call is implicit. > > It seems to me that the implicit call is often desirable, but at the > same time, it imposes a policy on the application. =A0In C, Guile, & co., > the application can choose to ignore the locale, or to just honor > LC_CTYPE, or to set something different. =A0Perhaps this point is moot if > the other languages allow the locale to be set afterward without any > loss of functionality, though... > >> The user should *not* have to worry about conversion of strings from/to >> locale encoding, because >> =A0 1) This is what people expect from a scripting language nowadays. >> =A0 2) In Guile strings are sequences of Unicode characters [1][2]. > > Agreed. > > [...] > >> So my suggestion is to do (setlocale LC_ALL "") as part of the Guile >> initialization, very early. Yes, this might lead to some complexity >> in the Guile implementation if you have the concept of locale also at >> the Guile level and need to make sure that the locale at the C level and >> the locale at the Guile level are consistent as soon as the latter is >> defined. But this is manageable. > > Are you suggesting that we could arrange to have Guile=92s =91main=92 cal= l > setlocale(LC_ALL, "") while still giving Scheme code the impression that > it=92s started under the C locale as is currently the case? > > Just adding setlocale(LC_ALL, "") in Guile=92s =91main=92 would be an > incompatible change, which would break Scheme applications relying on > the current behavior=96e.g., applications intended to be all-English. > > A reasonable option would be to setlocale(LC_CTYPE, "") from Guile=92s > =91main=92, so that scm_from_locale_string & co. would DTRT. =A0But again= that > would change the value of %default-port-encoding, leading to potential > application breakage. > > Thanks, > Ludo=92. > >