From c98a0c6da29a028282f0decac3056f9df0e40c1c Mon Sep 17 00:00:00 2001
From: Ludovic Courtès
Date: Mon, 8 Mar 2010 00:29:21 +0100
Subject: Don't set module names when using Guile 2.x.

* src/guile/skribilo/module.scm (maybe-set-module-name!): New procedure.
---
 src/guile/skribilo/module.scm | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

(limited to 'src')

diff --git a/src/guile/skribilo/module.scm b/src/guile/skribilo/module.scm
index 1e898a0..b6d5f07 100644
--- a/src/guile/skribilo/module.scm
+++ b/src/guile/skribilo/module.scm
@@ -96,6 +96,22 @@
 ;;; Run-time document modules.
 ;;;
 
+(define maybe-set-module-name!
+  ;; In Guile 2.x, `psyntax' expect module names to be actually bound using
+  ;; `nested-define!' (see the definition of `module-name' in `boot-9.scm').
+  ;; Thus, if we want to change a custom module name, we should also do the
+  ;; `nested-define!' magic.  Failing to do that results in errors like:
+  ;;
+  ;;   <unnamed port>: In expression (use-modules (foo)):
+  ;;   <unnamed port>: Wrong number of arguments to #<program 8868a0 (y)>
+  ;;
+  ;; (Observed on Guile 1.9.5.)
+  ;;
+  ;; Consequently, on Guile 2.x, we just let Guile choose a module name and
+  ;; do the right thing.
+  (cond-expand ((not guile-2) set-module-name!)
+               (else          (lambda (m n) #t))))
+
 (define (make-skribe-user-module)
   "Return a new module that imports all the necessary bindings required for
 execution of legacy Skribe code/documents."
@@ -105,7 +121,7 @@ execution of legacy Skribe code/documents."
                                                     (car name+bindings)
                                                     (cdr name+bindings)))
                          %skribe-user-autoloads)))
-    (set-module-name! the-module '(skribe-user))
+    (maybe-set-module-name! the-module '(skribe-user))
     (module-use-interfaces! the-module
                             (cons the-scm-module
                                   (append (map resolve-interface
@@ -117,7 +133,7 @@ execution of legacy Skribe code/documents."
   "Return a new module that imports all the necessary bindings required for
 Skribilo documents."
   (let* ((the-module (make-module)))
-    (set-module-name! the-module '(skribilo-user))
+    (maybe-set-module-name! the-module '(skribilo-user))
     (module-use-interfaces! the-module
                             (cons the-scm-module
                                   (map resolve-interface
-- 
cgit v1.2.3