On Wed, 2021-03-24 at 20:59 -0700, Chris Marusich wrote:
> [..]
> 
> In guix/import/print.scm, package->code generates the code by invoking
> (origin-method source) to get the origin's "method", and then invoking
> (procedure-name method) on the method thus obtained.  It seems that
> procedure-name returns the name "url-fetch*" (the name used privately in
> the (guix download) module), but it should be returning the name
> "url-fetch" (the public name exported by the (guix download) module).
> 
> I wonder if there is any way to get the public name of the procedure
> programmatically, instead of the private one?

I believe there isn't, and I have spent some time around Guile's module
system.  Note that one could do ...

<start guile code>
(define-module (mod)
  #:export (x y z))

(define (fun) 'stuff)
(define x fun)
(define y fun
(define z fun)
<end guile code>

... in which case there would be more than one "public name".

However, there's a possible work-around.  It is change the procedure name
of a procedure, with the following

(define name (let ((visible-name (lambda () 'stuff))) visible-name))
(procedure-name name) ; -> visible-name

Patch attached (though written against a somewhat outdated tree).
Does this patch fixes the issue? (I'm not in the loop.)

Greetings, Maxime.
From 04f36da115e2cb60835561f461899bb0d67bb927 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email protected]>
Date: Thu, 25 Mar 2021 08:48:24 +0100
Subject: [PATCH] guix: Let the procedure name of "url-fetch*" be what "guix
 import" expects.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fixes: <https://issues.guix.gnu.org/47375>.
Reported-By: Léo Le Bouter <[email protected]>.

* guix/download.scm
  (define*-visible-name): Define a syntax for overriding the procedure name
  of a procedure returned by "procedure-name".
  (url-fetch*): Use this syntax to change the procedure name to "url-fetch"
  as "guix import" expects.

+++ b/guix/download.scm
@@ -6,6 +6,7 @@
 ;;; Copyright © 2016 David Craven <[email protected]>
 ;;; Copyright © 2017 Tobias Geerinckx-Rice <[email protected]>
 ;;; Copyright © 2019 Guy Fleury Iteriteka <[email protected]>
+;;; Copyright © 2021 Maxime Devos <[email protected]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? y
@@ -449,11 +450,19 @@ download by itself using its own dependencies."
                     ;; for that built-in is widespread.
                     #:local-build? #t)))

-(define* (url-fetch* url hash-algo hash
-                     #:optional name
-                     #:key (system (%current-system))
-                     (guile (default-guile))
-                     executable?)
+;; In guix/import/print.scm, the procedure package->code uses procedure-name
+;; and expects to see the user-visible procedure name.
+(define-syntax-rule (define*-with-name (name . args) procedure-name . code)
+  "Define a procedure as with 'define*', but in such a matter that
+'procedure-name' on NAME will return PROCEDURE-NAME instead of NAME."
+  (define name (let ((procedure-name (lambda* args . code))) procedure-name)))
+
+(define*-with-name (url-fetch* url hash-algo hash
+                               #:optional name
+                               #:key (system (%current-system))
+                               (guile (default-guile))
+                               executable?)
+  url-fetch
---
 guix/download.scm | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/guix/download.scm b/guix/download.scm
index 30f69c0325..25c26a2ebb 100644
--- a/guix/download.scm
+++ b/guix/download.scm
@@ -6,6 +6,7 @@
 ;;; Copyright © 2016 David Craven <[email protected]>
 ;;; Copyright © 2017 Tobias Geerinckx-Rice <[email protected]>
 ;;; Copyright © 2019 Guy Fleury Iteriteka <[email protected]>
+;;; Copyright © 2021 Maxime Devos <[email protected]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -449,11 +450,19 @@ download by itself using its own dependencies."
                     ;; for that built-in is widespread.
                     #:local-build? #t)))
 
-(define* (url-fetch* url hash-algo hash
-                     #:optional name
-                     #:key (system (%current-system))
-                     (guile (default-guile))
-                     executable?)
+;; In guix/import/print.scm, the procedure package->code uses procedure-name
+;; and expects to see the user-visible procedure name.
+(define-syntax-rule (define*-with-name (name . args) procedure-name . code)
+  "Define a procedure as with 'define*', but in such a matter that
+'procedure-name' on NAME will return PROCEDURE-NAME instead of NAME."
+  (define name (let ((procedure-name (lambda* args . code))) procedure-name)))
+
+(define*-with-name (url-fetch* url hash-algo hash
+                               #:optional name
+                               #:key (system (%current-system))
+                               (guile (default-guile))
+                               executable?)
+  url-fetch
   "Return a fixed-output derivation that fetches data from URL (a string, or a
 list of strings denoting alternate URLs), which is expected to have hash HASH
 of type HASH-ALGO (a symbol).  By default, the file name is the base name of
-- 
2.31.0

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to