unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Andreas Rottmann <a.rottmann@gmx.at>
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] Make `get-datum' conform more closely to R6RS semantics
Date: Mon, 05 Nov 2012 00:07:57 -0500	[thread overview]
Message-ID: <87objceixe.fsf@tines.lan> (raw)
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")

Hi Andreas,

Andreas Rottmann <a.rottmann@gmx.at> 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



  reply	other threads:[~2012-11-05  5:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-04 23:59 [PATCH] Make `get-datum' conform more closely to R6RS semantics Andreas Rottmann
2012-11-05  5:07 ` Mark H Weaver [this message]
2012-11-05 17:52   ` Ludovic Courtès
2012-11-06  7:36     ` Improving the API for read options Mark H Weaver
2012-11-06 19:01       ` Ludovic Courtès
2012-11-11  7:56         ` Mark H Weaver
2012-11-06 19:55   ` [PATCH] Make `get-datum' conform more closely to R6RS semantics Andreas Rottmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87objceixe.fsf@tines.lan \
    --to=mhw@netris.org \
    --cc=a.rottmann@gmx.at \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).