guile-user
[Top][All Lists]
Advanced

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

Problem with modules in Guile 2.0


From: Gubinelli Massimiliano
Subject: Problem with modules in Guile 2.0
Date: Tue, 6 Mar 2012 22:48:22 +0100

Hi all,
  I stumbled on a strange behaviour of Guile 2.0, I have the following three 
files: main.scm, test-module.scm and sub/mymodule.scm which respectively contain

---- main.scm 

(load "test-modules.scm")

(inherit-modules (sub mymodule))

(display (pippo 10 20)) (display "\n")


---- sub/mymodule.scm 

(texmacs-module (sub mymodule))


(display "Loading my module\n")

(define-public (pippo a b)
 (+ a b))
 
 
---- test-modules.scm 

(define texmacs-user (current-module))
(define temp-module (current-module))

(define-macro (with-module module . body)
  `(begin
     (set! temp-module (current-module))
     (set-current-module ,module)
     ,@body
     (set-current-module temp-module)))


(define-macro (import-from . modules)
        `(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)))
      (module-map (lambda (sym var) sym) m-public)))
  (let ((l (apply append (map module-exports which-list))))
    `(begin
       (use-modules ,@which-list)
       (re-export ,@l))))

(define-macro (texmacs-module name . options)
  (define (transform action)
    (cond ((not (pair? action)) (noop))
          ((equal? (car action) :use) (cons 'use-modules (cdr action)))
          ((equal? (car action) :inherit) (cons 'inherit-modules (cdr action)))
          ((equal? (car action) :export)
           (display "Warning] The option :export is no longer supported\n")
           (display "       ] Please use tm-define instead\n"))
          (else '(noop))))
  (let ((l (map-in-order transform options)))
        (set! l (cons `(module-use! (current-module) ,texmacs-user) l))
    (display "loading ") (display name) (display "\n")
    `(begin
       (define-module ,name)
       ,@l)))

-----------

the directory structure is the following

./main.scm
./test-modules.scm
./sub/mymodule.scm

these are pieces from a larger software (GNU TeXmacs) which used to work with 
any version of Guile up to 1.8 and fail to work with Guile 2.0. In an 
interactive session, after setting the GUILE_LOAD_PATH to the working directory 
I get


---------------------------
Jurgen:test-modules mgubi$ GUILE_LOAD_PATH=$PWD guile
GNU Guile 2.0.5
Copyright (C) 1995-2012 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (load "main.scm")
;;; note: source file /Users/mgubi/t/build-64-guile-2.0/test-modules/main.scm
;;;       newer than compiled 
/Users/mgubi/.cache/guile/ccache/2.0-LE-8-2.0/Users/mgubi/t/build-64-guile-2.0/test-modules/main.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /Users/mgubi/t/build-64-guile-2.0/test-modules/main.scm
;;; main.scm:3:0: warning: possibly unbound variable `inherit-modules'
;;; main.scm:3:17: warning: possibly unbound variable `sub'
;;; main.scm:3:17: warning: possibly unbound variable `mymodule'
;;; main.scm:5:9: warning: possibly unbound variable `pippo'
;;; compiled 
/Users/mgubi/.cache/guile/ccache/2.0-LE-8-2.0/Users/mgubi/t/build-64-guile-2.0/test-modules/main.scm.go
main.scm:3:17: In procedure #<procedure 109cfed80 ()>:
main.scm:3:17: In procedure module-lookup: Unbound variable: sub

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> 
---------------------------

The same code work fine with 1.6:

Jurgen:test-modules mgubi$ GUILE_LOAD_PATH=$PWD 
../../build-64-guile-1.6.8/usr/bin/guile
guile> (version)
"1.6.8"
guile> (load "main.scm")
loading (sub mymodule)
Loading my module
30
guile> 

---------------------------

Somebody has a clue on how to fix this and what is the origin of the problem?

Thanks,

Massimiliano Gubinelli






















reply via email to

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