From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Per-module reader Date: Mon, 26 Sep 2005 20:05:53 +0100 Message-ID: <877jd3lkdq.fsf@ossau.uklinux.net> References: <87u0gp9lm3.fsf@laas.fr> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1127761807 4478 80.91.229.2 (26 Sep 2005 19:10:07 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 26 Sep 2005 19:10:07 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Sep 26 21:10:03 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EJyKQ-0006bk-3M for guile-devel@m.gmane.org; Mon, 26 Sep 2005 21:07:54 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EJyKP-0001rD-Fe for guile-devel@m.gmane.org; Mon, 26 Sep 2005 15:07:53 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EJyJu-0001kc-Hx for guile-devel@gnu.org; Mon, 26 Sep 2005 15:07:22 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EJyJm-0001gt-7P for guile-devel@gnu.org; Mon, 26 Sep 2005 15:07:15 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EJyJk-0001fI-PX for guile-devel@gnu.org; Mon, 26 Sep 2005 15:07:13 -0400 Original-Received: from [80.84.72.33] (helo=mail3.uklinux.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EJyIm-0000Ii-WD for guile-devel@gnu.org; Mon, 26 Sep 2005 15:06:13 -0400 Original-Received: from laruns (host81-139-70-226.in-addr.btopenworld.com [81.139.70.226]) by mail3.uklinux.net (Postfix) with ESMTP id D4AE5409FA7; Mon, 26 Sep 2005 19:06:10 +0000 (UTC) Original-Received: from laruns (laruns [127.0.0.1]) by laruns (Postfix) with ESMTP id 6766A6F71C; Mon, 26 Sep 2005 20:05:53 +0100 (BST) Original-To: ludovic.courtes@laas.fr (=?iso-8859-1?q?Ludovic_Court=E8s?=) In-Reply-To: <87u0gp9lm3.fsf@laas.fr> ( =?iso-8859-1?q?Ludovic_Court=E8s's_message_of?= "Tue, 13 Sep 2005 14:51:32 +0200") User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:5242 Archived-At: ludovic.courtes@laas.fr (Ludovic Court=E8s) 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 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > 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)) >=20=20 > ;; 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 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > 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); >=20=20 > { /* scope */ > + SCM module =3D SCM_BOOL_F, reader =3D SCM_BOOL_F; > SCM port =3D scm_open_file (filename, scm_from_locale_string ("r")); > scm_frame_begin (SCM_F_FRAME_REWINDABLE); > scm_i_frame_current_load_port (port); >=20=20 > while (1) > { > - SCM form =3D scm_read (port); > + SCM form; > + > + if (scm_current_module () !=3D module) > + { > + module =3D scm_current_module (); > + reader =3D SCM_MODULE_READER (module); > + } I'm worried that this could reduce performance noticeably, and it seems unnecessarily inefficient. So ... ... 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 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > 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