guile-user
[Top][All Lists]
Advanced

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

Re: Two questions about the guile module system


From: Joris van der Hoeven
Subject: Re: Two questions about the guile module system
Date: Sat, 5 Apr 2003 18:39:56 +0200 (CEST)

Hi again,

Yet another difference between Guile 1.3.4 and 1.6.3:
I can no longer use 'use-modules' inside a function.
Why has this possibility been prohibited?

As to our previous discussion, it seems that
the following code yields a cleaner module system
for the applications I have in mind.
It redefines 'use-modules' so that I can continue
to use it inside functions. Notice also the trick
with texmacs-top-level-module, which allows me
to extend the top level environment and to make
it visible inside all imported modules.
The code works with Guile 1.6.3.
I will now check for backward compatability.

-----------------------------------------------
(define texmacs-top-level-module (current-module))

(defmacro use-modules modules
  `(eval-case
    ((load-toplevel)
     (process-use-modules
      (list ,@(map (lambda (m)
                     `(list ,@(compile-interface-spec m)))
                   modules))))
    (else
     (process-use-modules
      (list ,@(map (lambda (m)
                     `(list ,@(compile-interface-spec m)))
                   modules))))))

(define-macro (inherit-modules . which-list)
  (define (module-exports which)
    (let* ((m (resolve-module which))
           (m-public (module-ref m '%module-public-interface))
           (l '()))
      (module-for-each (lambda (symb . tail) (set! l (cons symb l))) m-public)
      l))
  (let ((l (apply append (map module-exports which-list))))
    `(begin
       (use-modules ,@which-list)
       (export ,@l))))

(define-macro (texmacs-module name . options)
  (define l '())
  (define (process action)
    (cond ((not (pair? action)) (noop))
          ((equal? (car action) :use)
           (set! l (cons (cons 'use-modules (cdr action)) l)))
          ((equal? (car action) :inherit)
           (set! l (cons (cons 'inherit-modules (cdr action)) l)))
          ((equal? (car action) :export)
           (set! l (cons (cons 'export (cdr action)) l)))))
  (for-each process options)
  ;(display "loading ") (display name) (display "\n")
  `(begin
     (define-module ,name)
     (module-use! (current-module) ,texmacs-top-level-module)
     ,@l))
-----------------------------------------------





reply via email to

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