From: Neil Jerram <neil@ossau.uklinux.net>
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] Per-module reader
Date: Mon, 26 Sep 2005 20:05:53 +0100 [thread overview]
Message-ID: <877jd3lkdq.fsf@ossau.uklinux.net> (raw)
In-Reply-To: <87u0gp9lm3.fsf@laas.fr> ( Ludovic Courtès's message of "Tue, 13 Sep 2005 14:51:32 +0200")
ludovic.courtes@laas.fr (Ludovic Courtès) writes:
> Hi,
>
> The patch below adds a `#:reader' keyword to `define-module' that allows
> modules to specify the reader that should be used to interpret them:
>
> (define-module (the-module)
> #:reader the-reader-for-my-favorite-syntax)
All looks good, except for concerns about (i) performance; (ii)
whether #:reader fits nicely in the big picture with the transformer
option; (iii) one possible bug.
> This way, module implementors can decide to use whatever syntax variant
> they prefer, while not having any side-effect on the code being read
> from other files or modules. For illustration, here is an example that
> makes use of my `guile-reader' thing:
>
> --8<---------------cut here---------------start------------->8---
> (define-module (module-with-reader)
> #:reader (let* ((elisp-char-tr
> (make-token-reader #\?
> (token-reader-procedure
> (standard-token-reader 'character)))))
> (make-reader (cons elisp-char-tr
> (map standard-token-reader
> '(whitespace
> sexp string number colon-keyword
> semicolon-comment
> symbol-upper-case symbol-lower-case
> quote-quasiquote-unquote)))))
> #:use-module (system reader))
This is nice; but concerns about whether it fits with transformer are:
- Transformer is specified with #:use-syntax followed by module name,
which is a lot different from your syntax. I prefer your syntax,
because use-syntax requires the transformer procedure to have the
same name as the module it's defined in, which seems rubbish. But
on the other hand perhaps there is a reason for forcing the
reader/transformer to be defined in another module - are we missing
some subtlety here?
- As well as the inline definition option shown here, does it also
work if the #:reader arg is a proc defined in one of the used
modules? I guess it can't possibly work in the circular reference
case -- i.e. where module A uses a reader defined in module B, but B
also uses A and B was loaded first -- so this is probably deemed
user error - but how is that error presented to the user?
- Does it make sense to have both #:reader and #:use-syntax? Should
we reimplement use-syntax as a special case of #:reader? Does it
make sense that the places where your reader affects libguile
(i.e. primitive-load) are different from the places where the module
transformer affects libguile (i.e. the various versions of eval)?
> Index: ice-9/boot-9.scm
> ===================================================================
> RCS file: /cvsroot/guile/guile/guile-core/ice-9/boot-9.scm,v
> retrieving revision 1.351
> diff -u -B -b -p -r1.351 boot-9.scm
> --- ice-9/boot-9.scm 31 Jul 2005 23:36:50 -0000 1.351
> +++ ice-9/boot-9.scm 13 Sep 2005 12:28:08 -0000
> @@ -1185,7 +1185,8 @@
> (make-record-type 'module
> '(obarray uses binder eval-closure transformer name kind
> duplicates-handlers duplicates-interface
> - observers weak-observers observer-id)
> + observers weak-observers observer-id
> + reader)
> %print-module))
>
> ;; make-module &opt size uses binder
> @@ -1221,7 +1222,8 @@
> uses binder #f #f #f #f #f #f
> '()
> (make-weak-value-hash-table 31)
> - 0)))
> + 0
> + read)))
Init value "read" here prevents your optimization in load.c from
taking effect - so don't you want #f ?
> Index: libguile/load.c
> ===================================================================
> RCS file: /cvsroot/guile/guile/guile-core/libguile/load.c,v
> retrieving revision 1.86
> diff -u -B -b -p -r1.86 load.c
> --- libguile/load.c 23 May 2005 19:57:20 -0000 1.86
> +++ libguile/load.c 13 Sep 2005 12:28:08 -0000
> @@ -82,15 +82,29 @@ SCM_DEFINE (scm_primitive_load, "primiti
> scm_call_1 (hook, filename);
>
> { /* scope */
> + SCM module = SCM_BOOL_F, reader = SCM_BOOL_F;
> SCM port = scm_open_file (filename, scm_from_locale_string ("r"));
> scm_frame_begin (SCM_F_FRAME_REWINDABLE);
> scm_i_frame_current_load_port (port);
>
> while (1)
> {
> - SCM form = scm_read (port);
> + SCM form;
> +
> + if (scm_current_module () != module)
> + {
> + module = scm_current_module ();
> + reader = SCM_MODULE_READER (module);
> + }
I'm worried that this could reduce performance noticeably, and it
seems unnecessarily inefficient. So ... <pause> ...
Surely the low level concept here is that an alternative reader is a
property of a port? In that case, I would expect that
- the switch to the alternative reader would be implemented inside
scm_read, using a new field on scm_t_port which can be set/read
using set-port-reader!/port-reader
- the module level #:reader option would be implemented by
define-module calling set-port-reader! on current-load-port. (Note
BTW that define-module should also do this when called to switch
context to an already existing module.)
Note that this also raises the question of what to do when someone
types (define-module (module-with-reader)) at the REPL ... perhaps
define-module should set the reader of the current input port also?
> Index: libguile/modules.h
> ===================================================================
> RCS file: /cvsroot/guile/guile/guile-core/libguile/modules.h,v
> retrieving revision 1.28
> diff -u -B -b -p -r1.28 modules.h
> --- libguile/modules.h 31 Jul 2005 23:36:14 -0000 1.28
> +++ libguile/modules.h 13 Sep 2005 12:28:08 -0000
> @@ -45,6 +45,7 @@ SCM_API scm_t_bits scm_module_tag;
> #define scm_module_index_binder 2
> #define scm_module_index_eval_closure 3
> #define scm_module_index_transformer 4
> +#define scm_module_index_reader 12
Why 12? From the context I'd expect 5.
Regards,
Neil
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
next prev parent reply other threads:[~2005-09-26 19:05 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-13 12:51 [PATCH] Per-module reader Ludovic Courtès
2005-09-26 12:29 ` Ludovic Courtès
2005-09-26 22:55 ` Kevin Ryde
2005-09-27 9:04 ` Ludovic Courtès
2005-09-26 19:05 ` Neil Jerram [this message]
2005-09-27 8:21 ` Ludovic Courtès
2005-10-11 11:26 ` Ludovic Courtès
2005-10-11 23:24 ` Neil Jerram
2005-10-12 9:11 ` Ludovic Courtès
2005-10-17 9:17 ` [PATCH] Per-module reader, take #2 Ludovic Courtès
2005-10-17 20:41 ` Neil Jerram
2005-10-18 7:42 ` Ludovic Courtès
2005-10-19 22:23 ` Neil Jerram
2005-10-20 1:22 ` Kevin Ryde
2005-10-20 7:59 ` Ludovic Courtès
2005-10-20 19:30 ` Kevin Ryde
2005-10-20 21:27 ` Neil Jerram
2005-10-20 7:48 ` Ludovic Courtès
2005-10-20 10:52 ` Tomas Zerolo
2005-10-20 14:42 ` Ludovic Courtès
2005-10-20 22:09 ` Neil Jerram
2005-10-21 7:43 ` Ludovic Courtès
2005-10-24 11:43 ` Ludovic Courtès
2005-10-28 21:26 ` Neil Jerram
2005-10-28 22:38 ` Kevin Ryde
2005-10-29 8:58 ` Neil Jerram
2005-10-30 19:55 ` Neil Jerram
2005-11-07 16:06 ` [PATCH] Per-module reader, take #3 Ludovic Courtès
2005-11-16 21:13 ` Neil Jerram
2005-11-17 10:03 ` Ludovic Courtès
2005-11-20 0:15 ` Marius Vollmer
2005-11-21 12:55 ` Ludovic Courtès
2005-12-03 20:02 ` Neil Jerram
2005-12-05 8:31 ` Ludovic Courtès
2005-12-07 0:04 ` Marius Vollmer
2005-12-14 1:00 ` Neil Jerram
2005-12-14 14:06 ` Ludovic Courtès
2005-12-14 19:37 ` Neil Jerram
2005-12-15 9:13 ` Ludovic Courtès
2005-12-15 19:47 ` Neil Jerram
2005-12-16 6:13 ` Tomas Zerolo
2005-12-16 8:32 ` Neil Jerram
2005-12-16 9:21 ` Tomas Zerolo
2005-12-16 8:55 ` Ludovic Courtès
2005-12-17 10:26 ` Neil Jerram
2005-12-17 13:09 ` Marius Vollmer
2005-12-29 10:27 ` Neil Jerram
2006-01-11 16:45 ` Ludovic Courtès
2006-01-13 17:38 ` Neil Jerram
2005-10-19 22:56 ` [PATCH] Per-module reader Neil Jerram
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=877jd3lkdq.fsf@ossau.uklinux.net \
--to=neil@ossau.uklinux.net \
--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).