From: Andy Wingo <wingo@pobox.com>
Subject: Re: guile-lib things
Date: Thu, 08 Jul 2004 20:01:17 +0100 [thread overview]
Message-ID: <1089313277.19378.60.camel@localhost> (raw)
In-Reply-To: <873c4csn5t.fsf@trouble.defaultvalue.org>
[-- Attachment #1: Type: text/plain, Size: 1193 bytes --]
Hey Rob,
On Wed, 2004-06-30 at 17:20 -0500, Rob Browning wrote:
> For what it's worth, one part that I snipped from my earlier message
> (just to make it more concise) basically agress with you here.
That's cool. It's good to see we have a consensus about something :-)
> more concretely, say (slib format), (slib uri), and (slib posix-time),
> if slib were represented directly as guile modules.
This is interesting! I think I know how it could be done, too. Set a
custom module binder proc to (slib). Since submodules are (stupidly!)
bound to symbols within the parent module, we could catch undefined
symbols, and then require the lib. Bling. The tricky thing would be to
make sure that the interface of the modules doesn't also exhibit this
behavior.
Oh this is interesting indeed. I hacked up a prototype, and attached it.
First you have to use (slib), which sets up the lazy binder. Then when
you use (slib foo), it tries to require the foo. It's very much tied to
guile's module implementation, which is pretty evil, but it does work:
(use-modules ((slib) (slib stdio)))
(printf "%s" "Hello world!")
=| Hello world!
--
Andy Wingo <wingo@pobox.com>
http://ambient.2y.net/wingo/
[-- Attachment #2: Type: text/x-scheme, Size: 1290 bytes --]
(define-module (slib))
(define slib-module (current-module))
;; The issue: the binder proc can't reference any variables that aren't
;; local to this module, due to the lookup order in module_variable in
;; modules.c. So we put the binder in its own module.
(define-module (slib %binder-module)
#:use-module (ice-9 slib))
(define (binder module sym define?)
(pk sym)
(and (not (eq? sym '%module-public-interface))
(let ((new-mod (make-module 31)))
(set-module-kind! new-mod 'directory)
(set-module-name! new-mod `(slib ,sym))
(beautify-user-module! new-mod)
(module-use! new-mod (resolve-interface '(ice-9 slib)))
(and
(false-if-exception
(let ((old-module #f))
(dynamic-wind
(lambda () (set! old-module (set-current-module new-mod)))
(lambda () (require sym) #t)
(lambda () (set-current-module old-module)))))
(begin
(module-use! (module-public-interface new-mod) new-mod)
(make-variable new-mod))))))
(define-module (slib))
(set-module-binder! slib-module
(module-ref (resolve-module '(slib %binder-module))
'binder))
[-- Attachment #3: Type: text/plain, Size: 140 bytes --]
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
next prev parent reply other threads:[~2004-07-08 19:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-24 18:03 guile-lib things Andy Wingo
2004-06-25 11:48 ` Andy Wingo
2004-06-25 18:31 ` Rob Browning
2004-06-27 21:43 ` Linas Vepstas
2004-06-29 17:43 ` Andy Wingo
2004-06-30 22:20 ` Rob Browning
2004-07-08 19:01 ` Andy Wingo [this message]
2004-07-03 16:48 ` Thien-Thi Nguyen
2004-07-10 4:44 ` Linas Vepstas
2004-06-27 1:22 ` ASDF for guile (Was Re: guile-lib things) Chris Hall
2004-06-28 13:33 ` Matthew Trout
2004-06-28 13:48 ` Andy Wingo
2004-07-01 21:42 ` guile-lib things Neil Jerram
2004-07-08 19:09 ` Andy Wingo
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=1089313277.19378.60.camel@localhost \
--to=wingo@pobox.com \
/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).