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: [PATCH] Per-port read options, reader directives, SRFI-105
Date: Wed, 24 Oct 2012 10:41:47 -0400	[thread overview]
Message-ID: <874nlkx784.fsf@tines.lan> (raw)
In-Reply-To: <87k3ug6mjj.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Wed, 24 Oct 2012 15:13:04 +0200")

ludo@gnu.org (Ludovic Courtès) writes:
> Mark H Weaver <mhw@netris.org> skribis:
>> ludo@gnu.org (Ludovic Courtès) writes:
>>> So, what about exposing a ‘set-port-read-options!’ procedure, and then
>>> using it to write tests?
>>
>> That's a lot of extra work.  It means designing, implementing, and
>> documenting a new non-trivial API that we'll have to maintain forever.
>> I'd rather not do that work now.  I'm quite overloaded and have more
>> important things to do.
>>
>> Can the API be added later, by someone who is motivated to do that work?
>
> Yeah, we can think about it later.  The thing is, that API exists in
> read.c anyway, so I didn’t think it would be so much extra work.

APIs that we expose to the outside world need to be maintained
approximately forever, so we should expend a great deal of effort to
make sure they are future proof.  We don't have to worry so much about a
private interface that's accessible only within read.c.

> Now, I agree that the less we expose, the better.  ;-)

At least until we have the time to come up with a good interface.

>>> Mark H Weaver <mhw@netris.org> skribis:
>>>> +set_per_port_read_option (SCM port, int shift, int value)
>>>
>>> Also change ‘shift’ to ‘option’, and ‘int value’ to something like
>>> ‘enum t_option_state value’, where:
>>>
>>>   enum t_option_state
>>>   {
>>>     OPTION_INHERITED,    /* global option setting inherited */
>>>     OPTION_DISABLED,
>>>     OPTION_ENABLED
>>>   };
>>>
>>> the goal being to hide as much of the bit-twiddling as possible.
>>
>> Right now, this single function can be used for all the options (both
>> the boolean options and the keyword style option).  If I change it as
>> you suggest, then I would have to split it into two nearly-identical
>> functions, and it wouldn't hide _any_ bit-twiddling.  Apart from
>> duplicating the code, the only changes would be to rename
>> OVERRIDE_DEFAULT to OPTION_INHERITED, and to make the non-inherit case
>> more complex by changing a simple assignment (of the 2-bit bit-field
>> into scm_t_read_opts) into a switch statement to convert these new enum
>> values into a value appropriate for scm_t_read_opts.
>>
>> Is this added complexity really necessary?  This is all internal logic
>> that's confined to a few static functions in read.c.
>
> Well, I was more thinking in terms of the interface I’d like for the
> concepts at hand: we have per-ports and global settings, which we want
> to manipulate, and we want to know which ones are applicable at a given
> point.
>
> Thus, I thought we’d logically have these 3 functions:
> set_port_read_options, port_read_options, and applicable_read_options.

Logically, I agree that this would be a nice interface.  The problem is
really one of efficiency.  It's quite expensive to access the per-port
read options directly, because it requires locking the port table mutex,
doing a hash table lookup, and then an alist lookup.  That's not
something I want to do more than once per call to 'read'.  (Even doing
it once is slightly painful).

Efficiency is the main reason that I chose to compute all of the
applicable read options and place them in OPTS at the start of 'read'.
Efficiency is also the reason that I packed all of the read option
overrides into a single integer.

> Whether these are implemented in terms of bit fields is not the first
> thing I want to see when I open read.c.
>
> Perhaps this is just a matter of presentation, but my impression was
> that set_port_read_options and the various constants would force me to
> think in terms of bit-twiddling more than in terms or read options.

FWIW, all of the details of the bit-twiddling and the storage mechanism
of per-port read options are confined to just two static functions:
'init_read_options' and 'set_per_port_read_option'.

The rest of read.c needn't think about bit-twiddling at all.  The
relevant interface for the rest of read.c is as follows:

* Look up applicable read options in OPTS.
* Set per-port read options by calling 'set_per_port_*'.

So nothing else need think about the bit-twiddling.  That said, I agree
that it's unfortunate to see this bit-twiddling at the beginning of
read.c.  How about moving it to the end? :)

What do you think?

      Mark



  reply	other threads:[~2012-10-24 14:41 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-16 10:32 [PATCH] Per-port read options, reader directives, SRFI-105 Mark H Weaver
2012-10-23  6:06 ` Mark H Weaver
2012-10-23 20:44   ` Ludovic Courtès
2012-10-23 20:45   ` Ludovic Courtès
2012-10-23 20:53   ` Ludovic Courtès
2012-10-23 20:54   ` Ludovic Courtès
2012-10-23 20:57   ` Ludovic Courtès
2012-10-23 20:58   ` Ludovic Courtès
2012-10-23 21:26   ` Ludovic Courtès
2012-10-24  4:04     ` Mark H Weaver
2012-10-24 13:13       ` Ludovic Courtès
2012-10-24 14:41         ` Mark H Weaver [this message]
2012-10-26 17:30           ` Ludovic Courtès
2012-10-23 21:30   ` Ludovic Courtès
2012-10-24 19:00   ` Mark H Weaver
2012-10-24 21:52     ` David A. Wheeler
2012-10-26 17:41     ` Ludovic Courtès
2012-10-26 17:44     ` Ludovic Courtès
2012-10-26 21:21     ` Ludovic Courtès
2012-10-27  1:33       ` Mark H Weaver
2012-10-29 11:14         ` 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=874nlkx784.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).