unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Leo Prikler <leo.prikler@student.tugraz.at>
To: dalepsmith@gmail.com, 43025@debbugs.gnu.org
Subject: bug#43025: re-export-public-interface fails on Guile 3
Date: Mon, 24 Aug 2020 21:50:32 +0200	[thread overview]
Message-ID: <aa9c0dbf56dbbdb3b6f787350c93a66dd67502d8.camel@student.tugraz.at> (raw)
In-Reply-To: <CAFGZJC6MX_a3OxOD-yi+L9kttA+k=TQ6G6hB_tTKcsVzsFfFag@mail.gmail.com>

Hi Dale.

Am Montag, den 24.08.2020, 12:11 -0400 schrieb Dale Smith:
> This is actually reported by daviid on IRC.
> 
> This definition of re-export-public-interface works fine on Guile
> 2.x,
> fails with Guile 3:
> (hope this makes it through the mails cleanly)

> ;;;
> ;;; re-export-public-interface
> ;;;
> 
> [...]
I'm going to skip the specifics of the macro here, it is not needed for
an MWE.

> ;;;
> ;;; A module that uses the above
> ;;;
> 
> 
> (define-module (a)
>   #:use-module (srfi srfi-1)
>   #:use-module (modules)
> 
>   #:export (map-a))
> 
> 
> (eval-when (expand load eval)
>   (re-export-public-interface (srfi srfi-1)))
> 
> 
> (define (map-a)
>   (map (lambda (item)
>          (display item)
>          (display " "))
>     (iota 5))
>   (newline)
>   (values))
> 

For the sake of minimalism, I will shorten this to

(define-module (a))

(module-use! (module-public-interface (current-module))
             (resolve-interface '(srfi srfi-1)))

I hope you don't mind.

> [sessions]

My solution for this problem would be to build on some of the module
"intrinsics", which sadly are not all that well documented.

(define-module (a))

(let ((obs (module-obarray (resolve-interface '(srfi srfi-1))))
      (iface (module-public-interface (current-module))))
  (hash-fold
   (lambda (key value seed)
     (module-add! iface key value)
     seed)
   *unspecified*
   obs))

If you want to make this a macro, you really only need to syntax-
unquote a module into the (resolve-interface ...) portion of this
snippet.

Some sessions for reference:

GNU Guile 3.0.4
Copyright (C) 1995-2020 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (add-to-load-path "/tmp")
scheme@(guile-user)> ,use (a)
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /tmp/a.scm
;;; compiled $HOME/.cache/guile/ccache/3.0-LE-8-4.3/tmp/a.scm.go
scheme@(guile-user)> map
WARNING: (guile-user): imported module (a) overrides core binding `map'
$1 = #<procedure map (f l) | (f l1 l2) | (f l1 . rest)>
scheme@(guile-user)> ,q

GNU Guile 3.0.2
Copyright (C) 1995-2020 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (add-to-load-path "/tmp")
scheme@(guile-user)> ,use (a)
;;; note: source file /tmp/a.scm
;;;       newer than compiled /home/yuri/.cache/guile/ccache/3.0-LE-8-
4.2/tmp/a.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /tmp/a.scm
;;; compiled $HOME/.cache/guile/ccache/3.0-LE-8-4.2/tmp/a.scm.go
scheme@(guile-user)> map
WARNING: (guile-user): imported module (a) overrides core binding `map'
$1 = #<procedure map (f l) | (f l1 l2) | (f l1 . rest)>
scheme@(guile-user)> ,q

GNU Guile 2.2.7
Copyright (C) 1995-2019 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (add-to-load-path "/tmp")
scheme@(guile-user)> ,use (a)
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /tmp/a.scm
;;; compiled $HOME/.cache/guile/ccache/2.2-LE-8-3.A/tmp/a.scm.go
scheme@(guile-user)> map
$1 = #<procedure map (f l) | (f l1 l2) | (f l1 . rest)>
scheme@(guile-user)> ,q

Interestingly, versions newer than 3.0.2 warn about core override in
this case, as does #:re-export.  If I am not mistaken, this is the way
re-export works for variables normally.  module-use! on the other hand
does not modify the module-obarray, it instead adds the module to a
list of uses, which are handled separately in variable lookup during
`module_imported_variable`.  This C function does look up variables
exported by a module, but does not traverse module-uses recursively.  I
have no idea, how this works for 2.2.7, I only checked the Guile 3 code
here.

Regards,
Leo







  reply	other threads:[~2020-08-24 19:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-24 16:11 bug#43025: re-export-public-interface fails on Guile 3 Dale Smith
2020-08-24 19:50 ` Leo Prikler [this message]
2020-08-26 16:51   ` Dale Smith
2020-08-26 17:06     ` Leo Prikler
2020-08-27  2:21     ` Dale Smith
2020-08-28  0:12       ` Dale Smith
2020-08-28 19:22         ` Dale Smith
2021-03-12 14:12 ` Dale Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aa9c0dbf56dbbdb3b6f787350c93a66dd67502d8.camel@student.tugraz.at \
    --to=leo.prikler@student.tugraz.at \
    --cc=43025@debbugs.gnu.org \
    --cc=dalepsmith@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).