From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxim Cournoyer Newsgroups: gmane.lisp.guile.bugs Subject: bug#67412: [PATCH v2 2/2] r7rs-libraries: Better support R7RS SRFI library names. Date: Fri, 24 Nov 2023 16:19:06 -0500 Message-ID: <20231124212033.18967-2-maxim.cournoyer@gmail.com> References: <20231124212033.18967-1-maxim.cournoyer@gmail.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4846"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Maxim Cournoyer To: 67412@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Fri Nov 24 22:21:29 2023 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r6dc9-00013A-A2 for guile-bugs@m.gmane-mx.org; Fri, 24 Nov 2023 22:21:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r6dbg-0005Yy-61; Fri, 24 Nov 2023 16:21:00 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r6dbe-0005YO-Iu for bug-guile@gnu.org; Fri, 24 Nov 2023 16:20:58 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r6dbe-0000j4-Ag for bug-guile@gnu.org; Fri, 24 Nov 2023 16:20:58 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r6dbi-0005rc-Up for bug-guile@gnu.org; Fri, 24 Nov 2023 16:21:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 24 Nov 2023 21:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67412 X-GNU-PR-Package: guile Original-Received: via spool by 67412-submit@debbugs.gnu.org id=B67412.170086085622514 (code B ref 67412); Fri, 24 Nov 2023 21:21:02 +0000 Original-Received: (at 67412) by debbugs.gnu.org; 24 Nov 2023 21:20:56 +0000 Original-Received: from localhost ([127.0.0.1]:37343 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r6dbb-0005r3-IR for submit@debbugs.gnu.org; Fri, 24 Nov 2023 16:20:56 -0500 Original-Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]:43214) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r6dbX-0005qc-2M for 67412@debbugs.gnu.org; Fri, 24 Nov 2023 16:20:52 -0500 Original-Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-41cbd2cf3bbso26989531cf.0 for <67412@debbugs.gnu.org>; Fri, 24 Nov 2023 13:20:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700860840; x=1701465640; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GQ4RfE/JGzIzHrt8Idl0TL6t+sgCJRCGNyXy0UdsGmY=; b=W6wtMT/C68sUArhhN82fuPI1MrL86k2+HZNXkjcXm349flm0z5w7vRyZ8qc8NidNsO 6A0f5tPnjmNNnAl7IK9xkL/6PdJpL7PLGbfuOHWEUkFsRfd/cHiGr5iw/RrwnuVlZOtk nUoB0zJ8Gd8DGggusiQo9FkkVs/m3skH0PDwplP2JaEvUqaBwQluFjWAUKS0IRULUqXe 4UauS7locygKu8SySd/oToj+meucRi74PP0mKxWnMerxbdXOTn/UB0ACAOcKmyiThfFP wzApwQKQm4U+hL82iThM8wBNBhFqlLzLZShCgemM3ZXdq4zVRhIJwZ5PxfuitnQHS2bw tzSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700860840; x=1701465640; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GQ4RfE/JGzIzHrt8Idl0TL6t+sgCJRCGNyXy0UdsGmY=; b=JwbFrD0oVDYgRlZC7/bajwVA2EJVjdKrcLftjVKleu58hxc3IviWXYNBc8xy+8mOug 9KEysKY9dmSjCcyhUKiOI5t1v7pE6dmLXbSxgUV7DyuYBeUljCgoxHLkekjmYxR2w0f+ N+z/2TQeu2XFqDy1uDryqpZy7m+ZPYV5sG4VcSZLCMsy65cJ30xmEuoyAHzB3FcD6S/I 5g9waMaP7GkbbTA8ux9yN8sHxd9BEBSLi0zNVlFTkilMGEyLdq4f9nHmbcuco5I+F83m WAFdfCNZAK6vsMH7Gs9F6nH74m2OrHyv4yIxe7z5GLZV7pkE6AtZNOTzvvYbQtaRvKGw Sa0g== X-Gm-Message-State: AOJu0YyZ9q/rVNy8lub/yxqWQB24sl/1laWh8QV1yqJ6hMb4ier2xiS9 WIhIgCmgZ6KQF0rRMaK3l9Xski5ldGI= X-Google-Smtp-Source: AGHT+IG9ksVPVIRleROy2SMvIqONWib+AdyPusOlLtFxga0md5oun6MgtbCcUUrJlbn89t9DQzHaZQ== X-Received: by 2002:a0c:e88c:0:b0:67a:92f:f300 with SMTP id b12-20020a0ce88c000000b0067a092ff300mr6328076qvo.0.1700860840436; Fri, 24 Nov 2023 13:20:40 -0800 (PST) Original-Received: from localhost.localdomain (dsl-158-42.b2b2c.ca. [66.158.158.42]) by smtp.gmail.com with ESMTPSA id w28-20020a05620a0e9c00b0077d5d1461aesm1504001qkm.31.2023.11.24.13.20.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 13:20:39 -0800 (PST) X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231124212033.18967-1-maxim.cournoyer@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10722 Archived-At: * module/ice-9/r6rs-libraries.scm (resolve-r6rs-interface : Relax symbol requirements. Return a symbol. : Add a new syntax matching clause to avoid stripping the 3rd identifier in a R7RS SRFI module name. (library): Move R7RS specifics to... * module/ice-9/r7rs-libraries.scm (define-library): ... here. r6rs-name, r7rs-import->r6rs-import>: New nested procedures, used to translate the library name and import sets. * test-suite/tests/rnrs-libraries.test ("import features") <"renaming works">: Extend test. <"import works">: New test. Fixes: https://bugs.gnu.org/67412 --- Changes in v2: - Leave/improve some R7RS SRFI handling in r6rs-libraries, for 'import' - New 'import' test module/ice-9/r6rs-libraries.scm | 86 ++++++++-------------------- module/ice-9/r7rs-libraries.scm | 48 +++++++++++++++- test-suite/tests/rnrs-libraries.test | 12 +++- 3 files changed, 81 insertions(+), 65 deletions(-) diff --git a/module/ice-9/r6rs-libraries.scm b/module/ice-9/r6rs-libraries.scm index f27b07841..f02b13516 100644 --- a/module/ice-9/r6rs-libraries.scm +++ b/module/ice-9/r6rs-libraries.scm @@ -44,9 +44,9 @@ (define (srfi-name? stx) (syntax-case stx (srfi) ((srfi n rest ...) - (and (and-map sym? #'(rest ...)) - (or (n? #'n) - (colon-n? #'n)))) + (cond ((n? #'n) 'r7rs) + ((colon-n? #'n) 'r6rs) + (else #f))) (_ #f))) (define (module-name? stx) @@ -85,10 +85,19 @@ (module-and-uses mod))) (syntax-case import-spec (library only except prefix rename srfi) - ;; (srfi :n ...) -> (srfi srfi-n ...) + ;; XXX: This is R7RS-specific, but it's here since we want the + ;; `import' procedure below to accept (srfi 64) as well as + ;; (srfi :64). + ;; ;; (srfi n ...) -> (srfi srfi-n ...) ((library (srfi n rest ... (version ...))) - (srfi-name? #'(srfi n rest ...)) + (eq? 'r7rs (srfi-name? #'(srfi n rest ...))) + (let ((srfi-n (make-srfi-n #'srfi #'n))) + (resolve-r6rs-interface + #`(library (srfi #,srfi-n rest ... (version ...)))))) + ;; (srfi :n ...) -> (srfi srfi-n ...) + ((library (srfi n rest ... (version ...))) + (eq? 'r6rs (srfi-name? #'(srfi n rest ...))) (let ((srfi-n (make-srfi-n #'srfi #'n))) (resolve-r6rs-interface (syntax-case #'(rest ...) () @@ -98,7 +107,7 @@ ;; SRFI 97 says that the first identifier after the `n' ;; is used for the libraries name, so it must be ignored. #`(library (srfi #,srfi-n rest ... (version ...)))))))) - + ((library (name name* ... (version ...))) (and-map sym? #'(name name* ...)) (resolve-interface (syntax->datum #'(name name* ...)) @@ -107,7 +116,7 @@ ((library (name name* ...)) (and-map sym? #'(name name* ...)) (resolve-r6rs-interface #'(library (name name* ... ())))) - + ((only import-set identifier ...) (and-map sym? #'(identifier ...)) (let* ((mod (resolve-r6rs-interface #'import-set)) @@ -121,7 +130,7 @@ (hashq-set! (module-replacements iface) sym #t))) (syntax->datum #'(identifier ...))) iface)) - + ((except import-set identifier ...) (and-map sym? #'(identifier ...)) (let* ((mod (resolve-r6rs-interface #'import-set)) @@ -182,7 +191,7 @@ (module-remove! iface from) (hashq-remove! replacements from) (lp (cdr in) (cons (vector to replace? var) out)))))))) - + ((name name* ... (version ...)) (module-name? #'(name name* ...)) (resolve-r6rs-interface #'(library (name name* ... (version ...))))) @@ -196,45 +205,11 @@ (define (sym? stx) (symbol? (syntax->datum stx))) - (define (n? stx) - (let ((n (syntax->datum stx))) - (and (exact-integer? n) - (not (negative? n))))) - - (define (colon-n? x) - (let ((sym (syntax->datum x))) - (and (symbol? sym) - (let ((str (symbol->string sym))) - (and (string-prefix? ":" str) - (let ((num (string->number (substring str 1)))) - (and (exact-integer? num) - (not (negative? num))))))))) - - (define (srfi-name? stx) - (syntax-case stx (srfi) - ((srfi n rest ...) - (and (and-map sym? #'(rest ...)) - (or (n? #'n) - (colon-n? #'n)))) - (_ #f))) - (define (module-name? stx) - (or (srfi-name? stx) - (syntax-case stx () - ((name name* ...) - (and-map sym? #'(name name* ...))) - (_ #f)))) - - (define (make-srfi-n context n) - (datum->syntax - context - (string->symbol - (string-append - "srfi-" - (let ((n (syntax->datum n))) - (if (symbol? n) - (substring (symbol->string n) 1) - (number->string n))))))) + (syntax-case stx () + ((name name* ...) + (and-map sym? #'(name name* ...))) + (_ #f))) (define (compute-exports ifaces specs) (define (re-export? sym) @@ -282,17 +257,6 @@ (import ispec ...) body ...)) - ((_ (srfi n rest ... (version ...)) - (export espec ...) - (import ispec ...) - body ...) - (srfi-name? #'(srfi n rest ...)) - (let ((srfi-n (make-srfi-n #'srfi #'n))) - #`(library (srfi #,srfi-n rest ... (version ...)) - (export espec ...) - (import ispec ...) - body ...))) - ((_ (name name* ... (version ...)) (export espec ...) (import ispec ...) @@ -328,7 +292,7 @@ (export! x ...) (@@ @@ (name name* ...) body) ...)))))))) - + (define-syntax import (lambda (stx) (define (strip-for import-set) @@ -343,7 +307,7 @@ #'(eval-when (expand load eval) (let ((iface (resolve-r6rs-interface 'library-reference))) (call-with-deferred-observers - (lambda () - (module-use-interfaces! (current-module) (list iface))))) + (lambda () + (module-use-interfaces! (current-module) (list iface))))) ... (if #f #f))))))) diff --git a/module/ice-9/r7rs-libraries.scm b/module/ice-9/r7rs-libraries.scm index 429d82ad9..c6f70d73f 100644 --- a/module/ice-9/r7rs-libraries.scm +++ b/module/ice-9/r7rs-libraries.scm @@ -103,12 +103,56 @@ #'(rename (from-identifier to-identifier))) (identifier #'identifier))) + (define (r7rs-name->r6rs-name name) + ;; This is a hack to support (srfi N x ...) modules in R7RS. The + ;; longer term solution would be to add support at the level of + ;; resolve-interface (bug #40371). + (define (n? stx) + (let ((n (syntax->datum stx))) + (and (exact-integer? n) + (not (negative? n))))) + + (define (srfi-name? stx) + (syntax-case stx (srfi) + ((srfi n rest ...) + (n? #'n)) + (_ #f))) + + (define (make-srfi-n context n) + (datum->syntax + context + (string->symbol + (string-append + "srfi-" + (let ((n (syntax->datum n))) + (number->string n)))))) + + (syntax-case name (srfi) + ;; (srfi n ...) -> (srfi srfi-n ...) + ((srfi n rest ...) (srfi-name? #'(srfi n rest ...)) + #`(srfi #,(make-srfi-n #'srfi #'n) rest ...)) + (_ name))) + + (define (r7rs-import->r6rs-import import-set) + ;; Normalize SRFI names. + (syntax-case import-set (only except prefix rename) + ((only import-set identifier ...) + #`(only #,(r7rs-import->r6rs-import #'import-set) identifier ...)) + ((except import-set identifier ...) + #`(except #,(r7rs-import->r6rs-import #'import-set) identifier ...)) + ((prefix import-set identifier ...) + #`(prefix #,(r7rs-import->r6rs-import #'import-set) identifier ...)) + ((rename import-set (from-identifier to-identifier) ...) + #`(rename #,(r7rs-import->r6rs-import #'import-set) + (from-identifier to-identifier) ...)) + (_ (r7rs-name->r6rs-name import-set)))) + (syntax-case stx () ((_ name decl ...) (call-with-values (lambda () (partition-decls #'(decl ...) '() '() '())) (lambda (exports imports code) - #`(library name + #`(library #,(r7rs-name->r6rs-name #'name) (export . #,(map r7rs-export->r6rs-export exports)) - (import . #,imports) + (import . #,(map r7rs-import->r6rs-import imports)) . #,code))))))) diff --git a/test-suite/tests/rnrs-libraries.test b/test-suite/tests/rnrs-libraries.test index 86035e508..0fa7acb5c 100644 --- a/test-suite/tests/rnrs-libraries.test +++ b/test-suite/tests/rnrs-libraries.test @@ -205,9 +205,17 @@ (with-test-prefix "srfi" (pass-if "renaming works" (eq? (resolve-interface '(srfi srfi-1)) - (resolve-r6rs-interface '(srfi :1))) + (resolve-r6rs-interface '(srfi :1)) + (resolve-r6rs-interface '(srfi 1))) (eq? (resolve-interface '(srfi srfi-1)) - (resolve-r6rs-interface '(srfi :1 lists))))) + (resolve-r6rs-interface '(srfi :1 lists)) + (resolve-r6rs-interface '(srfi 1)))) + + (pass-if "import works" + (import (srfi srfi-1)) + (import (srfi :1)) + (import (srfi 1)) + #t)) (with-test-prefix "macro" (pass-if "multiple clauses" -- 2.41.0