From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.devel Subject: Re: [Request] How about adding with-locale? Date: Sat, 24 Mar 2012 16:45:49 +0800 Message-ID: References: <877gyao5ed.fsf@netris.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=20cf30780b4e06b3b304bbf92b2c X-Trace: dough.gmane.org 1332578760 2405 80.91.229.3 (24 Mar 2012 08:46:00 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 24 Mar 2012 08:46:00 +0000 (UTC) Cc: guile-devel To: Mark H Weaver Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Mar 24 09:45:59 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SBMbm-0002bF-3f for guile-devel@m.gmane.org; Sat, 24 Mar 2012 09:45:58 +0100 Original-Received: from localhost ([::1]:52721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SBMbl-0008H2-IH for guile-devel@m.gmane.org; Sat, 24 Mar 2012 04:45:57 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:40506) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SBMbi-0008Gi-J0 for guile-devel@gnu.org; Sat, 24 Mar 2012 04:45:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SBMbg-000082-GO for guile-devel@gnu.org; Sat, 24 Mar 2012 04:45:54 -0400 Original-Received: from mail-vx0-f169.google.com ([209.85.220.169]:59536) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SBMbg-00007Y-9R for guile-devel@gnu.org; Sat, 24 Mar 2012 04:45:52 -0400 Original-Received: by vcbfk14 with SMTP id fk14so4250028vcb.0 for ; Sat, 24 Mar 2012 01:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=9vMR/xhFKwVQUoda8IND0ag19xP6xqX9EuMJHmLdxdE=; b=IDL4maMshYAw1Dv/8l86jrXSCkk0wYhlbOMHJUZao6okE1igYtxcGBpQbAqXIcOsRD M20nqE2WO8lS4eQboNma9hjaAJThwgRpIjGLWQpU5XJwsKgRRpBI14C3QQQ1hBnlkBYU +YzItC68BIGmwwNvi6+cGvmB0GddI/wFP+l2esC8pEkRV6JIOFR7TVGaAuQoMW66pxgA e2J/BA6lgNpRkSfnU0CuQZ0rCYODM/s3fDPrhRHwf9xnseIxku4nvzbqUptrQZEjxQNA OuTA0RCyERcuONyDJBAAmauOj5x7JM/wypOR8H8gBinWXvff5a7t+xSEIz/Mm+aihSu0 ej2Q== Original-Received: by 10.52.69.4 with SMTP id a4mr3631345vdu.87.1332578749952; Sat, 24 Mar 2012 01:45:49 -0700 (PDT) Original-Received: by 10.52.88.231 with HTTP; Sat, 24 Mar 2012 01:45:49 -0700 (PDT) In-Reply-To: <877gyao5ed.fsf@netris.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.220.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:14179 Archived-At: --20cf30780b4e06b3b304bbf92b2c Content-Type: text/plain; charset=UTF-8 On Sat, Mar 24, 2012 at 2:54 PM, Mark H Weaver wrote: > Nala Ginrut writes: > > I know it's not the best implementation, I didn't consider the > > multi-threads situation. > > Yes, unfortunately there is no way to set the locale on a per-thread > basis. This is a limitation of the C library. > > Will it be a proper solution if I use "monitor"? ------------------------------------------------------------------ (define-syntax-rule (with-locale i c e0 e1 ...) (let ([old (setlocale i)]) (monitor (dynamic-wind (lambda () (setlocale i c)) (lambda () (begin e0 e1 ...)) (lambda () (setlocale i old)))))) ------------------------------------------------------------------ But I believe it will drag my program based on multi-threads much slowly. And I'm considering to drop my old design, so that I can set locale to "C" in default. > > in many protocols, it needs > > the result of strftime be in English. > > For protocol use, IMO it's better to avoid 'strftime' and other > locale-specific formatting tools. For example, 'write-date' in > module/web/http.scm is a simple date formatter based on SRFI-19. > > I guess I should change the old code into new Guile web API. It's more completely. Regards. --20cf30780b4e06b3b304bbf92b2c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

On Sat, Mar 24, 2012 at 2:54 PM, Mark H = Weaver <mhw@netris.o= rg> wrote:
Nala Ginrut <n= alaginrut@gmail.com> writes:
> I know it's not the best implementation, I didn't consider the=
> multi-threads situation.

Yes, unfortunately there is no way to set the locale on a per-thread<= br> basis. =C2=A0This is a limitation of the C library.


Will it be a proper solut= ion if I use "monitor"?
-------------------------------------= -----------------------------
(define-syntax-rule (with-locale i c e0 e1= ...)
=C2=A0 (let ([old (setlocale i)])
=C2=A0=C2=A0=C2=A0 (monitor
=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (dynamic-wind
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 (lambda () (setlocale i c))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (la= mbda () (begin e0 e1 ...))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (lambda () (setlocale i old))))))
-= -----------------------------------------------------------------

Bu= t I believe it will drag my program based on multi-threads much slowly.
= And I'm considering to drop my old design, so that I can set locale to = "C" in default.
=C2=A0
> =C2=A0 =C2=A0 in many protocols, it needs
> =C2=A0 =C2=A0 the result of strftime be in English.

For protocol use, IMO it's better to avoid 'strftime' and= other
locale-specific formatting tools. =C2=A0For example, 'write-date' i= n
module/web/http.scm is a simple date formatter based on SRFI-19.


I guess I should change the old code into new Gui= le web API. It's more completely.=C2=A0

Regards.
--20cf30780b4e06b3b304bbf92b2c--