unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: Needed: per-port reader options
Date: Tue, 16 Oct 2012 16:22:11 -0400	[thread overview]
Message-ID: <87k3uqtbf0.fsf@tines.lan> (raw)
In-Reply-To: <87ehkyza6v.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Tue, 16 Oct 2012 17:52:08 +0200")

ludo@gnu.org (Ludovic Courtès) writes:
> Mark H Weaver <mhw@netris.org> skribis:
>
>> I recently tried to implement reader directives, e.g.:
>>
>>   #!fold-case     (from R7RS)
>>   #!no-fold-case  (from R7RS)
>>   #!curly-infix   (from SRFI-105)
>>
>> However, I ran into a rather serious problem.  Guile's reader options
>> are global to the entire process, but clearly these reader directives
>> should affect only the port they are read from.  So we need to support
>> per-port reader options.
>
> I think we should instead be able to instantiate new readers–i.e., have
> a higher-order ‘make-reader’ procedure (that’s how Guile-Reader started,
> actually.)
>
> That, combined with the ‘current-reader’ fluid, should provide good
> flexibility.

Being able to easily create new readers sounds great to me, but that's
not sufficient to implement the reader directives above, the first two
of which are mandated by both R6RS and R7RS (draft).

Those standards mandate that we be able to change the case-sensitivity
flag on a per-port basis, while in the *middle* of reading a datum,
anywhere that comments are permitted.

Suppose we ignore those standards requirements.  If someone wants to
distribute a portable module with case-insensitive symbols or
curly-infix syntax, how would you recommend that they portably arrange
for their file to be read by a special reader?

Even if you ignore these problems (which are bad enough), there's also
the issue that one must reimplement the entire reader in order to add
one new feature.  This means reimplementing things like Guile's array
syntax (which is quite hairy), somehow hooking into 'read-hash-extend',
and keeping all of these reader implementations in sync with each other.

SRFI-105 is actually quite simple to implement, and in my latest patch
it required modification in only a few places.

> Also, I think ports should remain reader-oblivious.  ‘read’ is
> fundamentally at a higher level of abstraction, so I’d personally prefer
> not to have ports fiddle with it.

I agree.  In my patch, ports don't know anything about read.  I merely
made the values of 'scm_i_port_weak_hash' into alists.  Previously their
values were unused, and always #f.  In Guile 2.2, I'd like to move this
alist into the port structure itself for better efficiency.  The
built-in reader just adds an item to this alist if per-port read options
are set.

What do you think?

      Mark



  reply	other threads:[~2012-10-16 20:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-13 18:51 Needed: per-port reader options Mark H Weaver
2012-10-16 15:52 ` Ludovic Courtès
2012-10-16 20:22   ` Mark H Weaver [this message]
2012-10-16 21:39     ` Ludovic Courtès
2012-10-16 21:57       ` Noah Lavine
2012-10-16 22:01         ` Ludovic Courtès
2012-10-17  3:34       ` Mark H Weaver
2012-10-18 16:20         ` Ludovic Courtès
2012-10-18 17:48           ` Mark H Weaver
2012-10-19  2:12             ` Mark H Weaver
2012-10-21 21:40               ` Ludovic Courtès

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=87k3uqtbf0.fsf@tines.lan \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    --cc=ludo@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).