GNU bug report logs - #55464
(current-filename) is #f when guix pull'ing

Previous Next

Package: guix;

Reported by: Attila Lendvai <attila <at> lendvai.name>

Date: Mon, 16 May 2022 21:05:01 UTC

Severity: normal

Full log


View this message in rfc822 format

From: Attila Lendvai <attila <at> lendvai.name>
To: "55464 <at> debbugs.gnu.org" <55464 <at> debbugs.gnu.org>
Subject: bug#55464: alternative way
Date: Tue, 17 May 2022 00:09:03 +0000
as Ludovic kindly pointed out on IRC, i can use this instead:

(module-filename (current-module))

unfortunately, this returns a relative path, which is only useful using (search-path %load-path ...), which introduces some uncertainty about what actually gets loaded depending on the runtime value of %load-path... :|

therefore, i decided to read the file at macroexpand-time. after some struggle with hygienic macros:

(define-syntax read-module-relative-file
  (lambda (syn)
    (syntax-case syn ()
      ((_ filename)
       (with-syntax
           ;; Read the file at compile time and macroexpand to the first form.
           ((form (%read-module-relative-file (current-module)
                                              (syntax->datum #'filename))))
         #''form)))))

(define (%read-module-relative-file module filename)
  (with-input-from-file
      (or (search-path %load-path
                       (string-append (dirname (module-filename module))
                                      "/" filename))
          (error "%read-module-relative-file failed for" filename))
    read))

not beautiful, but works.

--
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“It is just as difficult and dangerous to try to free a people that wants to remain servile as it is to enslave a people that wants to remain free.”
	— Niccolò Machiavelli (1469–1527)





This bug report was last modified 3 years and 24 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.