guile-devel
[Top][All Lists]
Advanced

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

[PATCH] Transform R6RS SRFI module name on definition.


From: Taylan Ulrich Bayırlı/Kammer
Subject: [PATCH] Transform R6RS SRFI module name on definition.
Date: Fri, 02 Oct 2015 23:45:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Currently our R6RS 'import' form automatically transforms an import like
(srfi :n ...) to (srfi srfi-n ...).

This works fine with the SRFIs that ship with Guile and any extra SRFI
modules defined with the verbose name format (srfi srfi-n ...).

However, when one really defines a library named (srfi :n ...), then
'import' fails to find this because it only looks for the verbose name.

Here a transcript showcasing the issue:

--- snip ---
scheme@(guile-user)> (library (srfi :200) (export test) (import (rnrs base)) 
(define test 'test))
scheme@(srfi :200)> ,m guile-user
scheme@(guile-user)> (import (srfi :200))
While compiling expression:
ERROR: no code for module (srfi srfi-200)
scheme@(guile-user)> ,use (srfi :200)
scheme@(guile-user)> test
$2 = test
scheme@(guile-user)>
--- snip ---

(Use-modules actually finds it, as you see.)

The attached patch makes our R6RS 'library' form automatically transform
a library name like (srfi :n ...) to (srfi srfi-n ...).

Will this leak out to the user in such a way that it breaks conformance
or creates problems?  Is it bad that this time 'use-modules' won't be
able to find (srfi :n ...)?  I don't think it is; users should just use
(srfi :n ...) with 'import' and (srfi srfi-n ...) with 'use-modules'.

Note that it's actually not 'import' itself that does the reverse
transform but a deeper part of the system, and thus for instance the
'environment' form from (rnrs eval) also correctly resolves the module
name (srfi :n ...) to (srfi srfi-n ...).  If there are any "holes" left
where the transform doesn't happen, we should be able to plug those too.

WDYT?

>From 952870469d852ca910558810de1c853124abd830 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Taylan=20Ulrich=20Bay=C4=B1rl=C4=B1/Kammer?=
 <address@hidden>
Date: Fri, 2 Oct 2015 23:29:08 +0200
Subject: [PATCH] Transform R6RS SRFI module names on definition.

* module/ice-9/r6rs-libraries.scm (library): Transform the names of
  defined SRFI modules from (srfi :n ...) to (srfi srfi-n ...).
---
 module/ice-9/r6rs-libraries.scm | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/module/ice-9/r6rs-libraries.scm b/module/ice-9/r6rs-libraries.scm
index a68df3c..a7e7da7 100644
--- a/module/ice-9/r6rs-libraries.scm
+++ b/module/ice-9/r6rs-libraries.scm
@@ -1,6 +1,7 @@
 ;;; r6rs-libraries.scm --- Support for the R6RS `library' and `import' forms
 
-;;      Copyright (C) 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2015 Taylan Ulrich Bayırlı/Kammer <address@hidden>
 ;;
 ;; This library is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU Lesser General Public
@@ -158,7 +159,22 @@
               (else
                (lp #'rest (cons #'id e) r x))))))))
 
-    (syntax-case stx (export import)
+    (syntax-case stx (export import srfi)
+      ;; (srfi :n ...) -> (srfi srfi-n)
+      ((_ (srfi colon-n name ...) rest ...)
+       (and (and-map identifier? #'(srfi name ...))
+            (symbol? (syntax->datum #'colon-n))
+            (eqv? (string-ref (symbol->string (syntax->datum #'colon-n)) 0)
+                  #\:))
+       (let ((srfi-n (datum->syntax
+                      #'colon-n
+                      (string->symbol
+                       (string-append
+                        "srfi-"
+                        (substring (symbol->string (syntax->datum #'colon-n))
+                                   1))))))
+         #`(library (srfi #,srfi-n name ...)
+             rest ...)))
       ((_ (name name* ...)
           (export espec ...)
           (import ispec ...)
-- 
2.5.0


reply via email to

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