From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Make `get-datum' conform more closely to R6RS semantics Date: Mon, 05 Nov 2012 00:07:57 -0500 Message-ID: <87objceixe.fsf@tines.lan> References: <1352073544-24166-1-git-send-email-a.rottmann@gmx.at> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1352092122 28656 80.91.229.3 (5 Nov 2012 05:08:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 5 Nov 2012 05:08:42 +0000 (UTC) Cc: guile-devel@gnu.org To: Andreas Rottmann Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Nov 05 06:08:51 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 1TVEvb-0006LO-8o for guile-devel@m.gmane.org; Mon, 05 Nov 2012 06:08:51 +0100 Original-Received: from localhost ([::1]:58767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TVEvS-0003J0-4p for guile-devel@m.gmane.org; Mon, 05 Nov 2012 00:08:42 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:49897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TVEvO-0003Ip-OA for guile-devel@gnu.org; Mon, 05 Nov 2012 00:08:39 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TVEvN-0007It-4Y for guile-devel@gnu.org; Mon, 05 Nov 2012 00:08:38 -0500 Original-Received: from world.peace.net ([96.39.62.75]:53691) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TVEvM-0007IY-S6 for guile-devel@gnu.org; Mon, 05 Nov 2012 00:08:37 -0500 Original-Received: from turntable.mit.edu ([18.160.0.29] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1TVEv3-00038G-W6; Mon, 05 Nov 2012 00:08:18 -0500 In-Reply-To: <1352073544-24166-1-git-send-email-a.rottmann@gmx.at> (Andreas Rottmann's message of "Mon, 5 Nov 2012 00:59:04 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 96.39.62.75 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:15089 Archived-At: Hi Andreas, Andreas Rottmann writes: > * module/rnrs/io/ports.scm (get-datum): Set reader options to be more > compatible with R6RS syntax. > > With Guile's default reader options, R6RS hex escape and EOL escape > behavior is missing. This change enables the former via the > `r6rs-hex-escapes' option, and gets us closer to the latter by setting > `hungry-eol-escapes'. > > * test-suite/tests/r6rs-ports.test ("8.2.9 Textual input")["get-datum"]: > New tests. > --- > module/rnrs/io/ports.scm | 13 +++++++++++-- > test-suite/tests/r6rs-ports.test | 28 ++++++++++++++++++++++++++++ > 2 files changed, 39 insertions(+), 2 deletions(-) > > diff --git a/module/rnrs/io/ports.scm b/module/rnrs/io/ports.scm > index fddb491..6e6a66d 100644 > --- a/module/rnrs/io/ports.scm > +++ b/module/rnrs/io/ports.scm > @@ -1,6 +1,6 @@ > ;;;; ports.scm --- R6RS port API -*- coding: utf-8 -*- > > -;;;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. > +;;;; Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc. > ;;;; > ;;;; This library is free software; you can redistribute it and/or > ;;;; modify it under the terms of the GNU Lesser General Public > @@ -437,7 +437,16 @@ return the characters accumulated in that port." > (with-textual-input-conditions port (read-char port))) > > (define (get-datum port) > - (with-textual-input-conditions port (read port))) > + (with-textual-input-conditions port > + (let ((saved-options (read-options))) > + (dynamic-wind > + (lambda () (read-options '(positions > + keywords #f > + square-brackets > + r6rs-hex-escapes > + hungry-eol-escapes))) > + (lambda () (read port)) > + (lambda () (read-options saved-options)))))) The problem with the approach above is that it sets the read options globally, which is obviously a bad idea in a multithreaded program. Until very recently there was no other practical option, but now 'read' starts by building a private struct 'scm_t_read_opts' and passes it down to all the helper functions explicitly. This was partly what enable per-port read options, which are now supported internally and accessible using reader directives such as #!fold-case, #!no-fold-case, and #!curly-infix. It also means that it is now feasible to provide another 'read' procedure that accepts a set of read options explicitly. I've been avoiding adding a public API for this, because I feel that the current 'read-options' API is poorly-designed and I'd rather take the opportunity to come up with a clean design. For now, I suggest that we add 'get-datum' as a C function in read.c, which initializes the 'scm_t_read_opts' as needed for R6RS. Also, while we're on the subject, now that we have per-port read options, perhaps #!r6rs ought to set some of them instead of being a no-op. See 'scm_read_shebang' in read.c. What do you think? Regards, Mark