[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: guile-lib things

From: Andy Wingo
Subject: Re: guile-lib things
Date: Thu, 08 Jul 2004 20:01:17 +0100

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

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 <address@hidden>
(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)))
           (let ((old-module #f))
                 (lambda () (set! old-module (set-current-module new-mod)))
                 (lambda () (require sym) #t)
                 (lambda () (set-current-module old-module)))))
            (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))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]