unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Weird module behaviour
@ 2014-09-25 14:04 Panicz Maciej Godek
  2014-09-25 14:25 ` Taylan Ulrich Bayirli/Kammer
  2014-09-25 16:31 ` Barry Schwartz
  0 siblings, 2 replies; 5+ messages in thread
From: Panicz Maciej Godek @ 2014-09-25 14:04 UTC (permalink / raw
  To: guile-user@gnu.org

Hi all,
I'm trying to use Aleix Conchillo's guile-redis module for my project,
and it revealed a surprising use-case.
Namely, guile-redis consists of several modules that are put together
in one meta-module, which looks more or less like this:

(define-module (redis)
  #:use-module (redis main)
  #:use-module (redis commands connection)
  #:use-module (redis commands hashes)
  #:use-module (redis commands keys)
  ...)

(define-syntax re-export-modules
  (syntax-rules ()
    ((_ (mod ...) ...)
     (begin
       (module-use! (module-public-interface (current-module))
         (resolve-interface '(mod ...)))
        ...))))

(re-export-modules
  (redis main)
  (redis commands connection)
  (redis commands hashes)
  (redis commands keys)
  ...)

So basically the meta-module adds the interfaces of its child modules.
This isn't particularly surprising, because another way of creating a
meta-module would be to enumerat all bindings from its child modules,
which is a lot of work that would create an opportunity for
desynchronization.

However, it turns out that the modules export some names that would
interfere with another names used in my project.
Therefore, I decided to use the dedicated feature for avoiding such
conflicts -- namely, renaming.

If I (use-modules (redis)), everything works perfectly fine.
However, if I try to use #:select, e.g.

(use-modules ((redis) #:select (redis-connect))),

I get an error:

"no binding `redis-connect` in module (redis)".

Furthermore, when I try to use the #:renamer feature, like

(use-modules ((redis) #:renamer (symbol-prefix-proc 'redis:)))

then I get neither redis-connect nor redis:redis-connect exported.

I am almost certain that this weird behaviour stems from the way the
meta-module is built (although I don't know the module system
implementation well enough to point to the exact reason).

However, the questions are:

- if "resolve-interface" and "module-use!" are documented in the
manual, shouldn't they inter-operate with #:select and #:rename
features of use-modules?

- if the above are to be considered dirty hacks, then what would be
the proper way of creating meta-modules (other than listing all the
exported bindings explicitly)?

- or am I getting something wrong?

Best regards,
M.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Weird module behaviour
  2014-09-25 14:04 Weird module behaviour Panicz Maciej Godek
@ 2014-09-25 14:25 ` Taylan Ulrich Bayirli/Kammer
  2014-09-25 14:57   ` Panicz Maciej Godek
  2014-09-25 16:31 ` Barry Schwartz
  1 sibling, 1 reply; 5+ messages in thread
From: Taylan Ulrich Bayirli/Kammer @ 2014-09-25 14:25 UTC (permalink / raw
  To: Panicz Maciej Godek; +Cc: guile-user@gnu.org

Panicz Maciej Godek <godek.maciek@gmail.com> writes:

> Furthermore, when I try to use the #:renamer feature, like
>
> (use-modules ((redis) #:renamer (symbol-prefix-proc 'redis:)))
>
> [...]

Just a tip: you can do e.g. (use-modules ((foo) #:prefix foo-)).  It
seems many people don't know of it.

Taylan



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Weird module behaviour
  2014-09-25 14:25 ` Taylan Ulrich Bayirli/Kammer
@ 2014-09-25 14:57   ` Panicz Maciej Godek
  2014-09-25 17:57     ` Taylan Ulrich Bayirli/Kammer
  0 siblings, 1 reply; 5+ messages in thread
From: Panicz Maciej Godek @ 2014-09-25 14:57 UTC (permalink / raw
  To: Taylan Ulrich Bayirli/Kammer; +Cc: guile-user@gnu.org

2014-09-25 16:25 GMT+02:00 Taylan Ulrich Bayirli/Kammer
<taylanbayirli@gmail.com>:
>> [...]
>
> Just a tip: you can do e.g. (use-modules ((foo) #:prefix foo-)).  It
> seems many people don't know of it.

No wonder, since there's not a single mention in the documentation,
which is perceived as the document that makes things official.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Weird module behaviour
  2014-09-25 14:04 Weird module behaviour Panicz Maciej Godek
  2014-09-25 14:25 ` Taylan Ulrich Bayirli/Kammer
@ 2014-09-25 16:31 ` Barry Schwartz
  1 sibling, 0 replies; 5+ messages in thread
From: Barry Schwartz @ 2014-09-25 16:31 UTC (permalink / raw
  To: Panicz Maciej Godek; +Cc: guile-user@gnu.org

Panicz Maciej Godek <godek.maciek@gmail.com> skribis:
> I'm trying to use Aleix Conchillo's guile-redis module for my project,
> and it revealed a surprising use-case.
> Namely, guile-redis consists of several modules that are put together
> in one meta-module, which looks more or less like this:
> 
> (define-module (redis)
>   #:use-module (redis main)
>   #:use-module (redis commands connection)
>   #:use-module (redis commands hashes)
>   #:use-module (redis commands keys)
>   ...)
> 
> (define-syntax re-export-modules
>   (syntax-rules ()
>     ((_ (mod ...) ...)
>      (begin
>        (module-use! (module-public-interface (current-module))
>          (resolve-interface '(mod ...)))
>         ...))))
> 
> (re-export-modules
>   (redis main)
>   (redis commands connection)
>   (redis commands hashes)
>   (redis commands keys)
>   ...)
> 
> So basically the meta-module adds the interfaces of its child modules.
> This isn't particularly surprising, because another way of creating a
> meta-module would be to enumerat all bindings from its child modules,
> which is a lot of work that would create an opportunity for
> desynchronization.

As a side note, FYI I have some stuff called ‘generate-reexporter’ to
help deal with the desync problem, at

   https://bitbucket.org/sortsmill/sortsmill-core-guile

I almost always use R⁶RS-style modules but there is some support for
Guilish notation in the stuff that is being re-exported.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Weird module behaviour
  2014-09-25 14:57   ` Panicz Maciej Godek
@ 2014-09-25 17:57     ` Taylan Ulrich Bayirli/Kammer
  0 siblings, 0 replies; 5+ messages in thread
From: Taylan Ulrich Bayirli/Kammer @ 2014-09-25 17:57 UTC (permalink / raw
  To: Panicz Maciej Godek; +Cc: guile-user@gnu.org

Panicz Maciej Godek <godek.maciek@gmail.com> writes:

> No wonder, since there's not a single mention in the documentation,
> which is perceived as the document that makes things official.

Oh snap. :-)

The stable-2.0 branch has it documented.  I also checked and it's even
in 2.0.5 which Debian stable has so the feature should be fine to use in
production code already.

Taylan



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-09-25 17:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-25 14:04 Weird module behaviour Panicz Maciej Godek
2014-09-25 14:25 ` Taylan Ulrich Bayirli/Kammer
2014-09-25 14:57   ` Panicz Maciej Godek
2014-09-25 17:57     ` Taylan Ulrich Bayirli/Kammer
2014-09-25 16:31 ` Barry Schwartz

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).