guile-user
[Top][All Lists]
Advanced

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

Re: Namespaces for HB-Guile modules? Help. :(


From: Neil Jerram
Subject: Re: Namespaces for HB-Guile modules? Help. :(
Date: 16 Nov 2001 09:21:48 +0000
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

>>>>> "Alejandro" == Alejandro Forero Cuervo <address@hidden> writes:

    Alejandro> I have been working in making it possible and practical
    Alejandro> to create HB modules in Guile.  Once I get most of this
    Alejandro> done, it will be very easy to create dynamic web
    Alejandro> functionality programmed in Guile files and have HB
    Alejandro> workout the rest.

Sounds fun.

    Alejandro> Now lets get to my questions...  There are some things
    Alejandro> I don't fully understand in Guile's module system.
...
    Alejandro> However, it seems that (1) modules need to be on
    Alejandro> specific locations designated from them (rather than
    Alejandro> wherever the users can place them, usually in the
    Alejandro> public HTML tree) and (2) the programmer has to fill
    Alejandro> their Guile file for a module with lots of special
    Alejandro> calls to the effect of defining a new module.

It sounds like you just need to create modules dynamically rather than
through static declarations like (define-module ...).

As Rob suggests, look at `make-safe-module'; if this isn't already
enough for you, you should at least be able to see how a module can be
created dynamically.

Another possibly helpful example is what I do in my Elisp translator
to set up a dynamically named module:

(define-macro (use-elisp-file file-name . imports)
  "Load Elisp code file @var{file-name} and import its definitions
into the current Scheme module.  If any @var{imports} are specified,
they are interpreted as selection and renaming specifiers as per
@code{use-modules}."
  (let ((export-module-name (export-module-name)))
    `(begin
       (fluid-set! ,elisp-export-module (resolve-module ',export-module-name))
       (beautify-user-module! (resolve-module ',export-module-name))
       (load-elisp-file ,file-name)
       (use-modules (,export-module-name ,@imports))
       (fluid-set! ,elisp-export-module #f))))

The key bits here are
- construct the module name dynamically however you like, to result in
  a list of symbols
- use `resolve-module' to turn this into a module object
- use `beautify-user-module!' on the module object to ... err ... I
  forget, but it was necessary for my purposes.

Having done this, you could do

(save-module-excursion (lambda ()
                         (set-current-module MODULE)
                         (load "whatever.guile")))

to load "whatever.guile" into that module, or you could just use
`module-define!', `module-set!' and so on to put bindings into the
module one by one.

        Neil




reply via email to

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