unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* When do you re-export?
@ 2022-10-11 21:28 jgart
  2022-10-12  6:21 ` Wojtek Kosior via
  2022-10-22 14:15 ` Maxim Cournoyer
  0 siblings, 2 replies; 3+ messages in thread
From: jgart @ 2022-10-11 21:28 UTC (permalink / raw)
  To: Guix Help

Hi,

When should I re-export something in a module?

docs say the following:

Add all variables (which must be symbols or pairs of symbols) to the
list of re-exported bindings of the current module. Pairs of symbols
are handled as in export. Re-exported bindings must be imported by the
current module from some other module.

The docs don't explain why you would want to even do a re-export in the first place...

Could someone provide some examples as to why I would want to use this? It
would be much appreciated!

--
jgart


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

* Re: When do you re-export?
  2022-10-11 21:28 When do you re-export? jgart
@ 2022-10-12  6:21 ` Wojtek Kosior via
  2022-10-22 14:15 ` Maxim Cournoyer
  1 sibling, 0 replies; 3+ messages in thread
From: Wojtek Kosior via @ 2022-10-12  6:21 UTC (permalink / raw)
  To: help-guix; +Cc: jgart

[-- Attachment #1: Type: text/plain, Size: 2540 bytes --]

> Hi,
> 
> When should I re-export something in a module?
> 
> docs say [...]
>
> The docs don't explain why you would want to even do a re-export in the first place...
> 
> Could someone provide some examples as to why I would want to use this? It
> would be much appreciated!
> 
> --
> jgart

Hello,

Although I have very little scheme knowledge (disclaimer) I thought I
could perhaps help using some generic programming knowledge.

It seems re-exporting things is just helpful for maintaining the
desired code structure. If you're for example writing a library, you
might find it useful to split the code into several modules.

Typically, only a subset of the functions and structures you define are
meant to be exported as library's external API. Meanwhile, as a result
of various dependencies between them, the definitions you want to make
public might have landed in different code files and effectively in
different modules. Now, in order to make them available to library
users by the means of a single import, it is perfectly justifiable to
have them imported by and re-exported by a single module.

Guix itself seems to be doing something like that[1].

And making a "re-export all public definitions" wrapper is just an
example. There may be other reasons we might want to have 'foo'
importable from module 'bar' despite it being originally defined in
some other module (e.g. 'baz') ☺

Best,
Wojtek

[1] https://git.savannah.gnu.org/cgit/guix.git/tree/guix.scm#n23


-- (sig_start)
website: https://koszko.org/koszko.html
PGP: https://koszko.org/key.gpg
fingerprint: E972 7060 E3C5 637C 8A4F  4B42 4BC5 221C 5A79 FD1A

Meet Kraków saints!           #37: blessed Michał Tomaszek
Poznaj świętych krakowskich!  #37: błogosławiony Michał Tomaszek
https://pl.wikipedia.org/wiki/Michał_Tomaszek
-- (sig_end)


On Tue, 11 Oct 2022 16:28:48 -0500
jgart <jgart@dismail.de> wrote:

> Hi,
> 
> When should I re-export something in a module?
> 
> docs say the following:
> 
> Add all variables (which must be symbols or pairs of symbols) to the
> list of re-exported bindings of the current module. Pairs of symbols
> are handled as in export. Re-exported bindings must be imported by the
> current module from some other module.
> 
> The docs don't explain why you would want to even do a re-export in the first place...
> 
> Could someone provide some examples as to why I would want to use this? It
> would be much appreciated!
> 
> --
> jgart
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: When do you re-export?
  2022-10-11 21:28 When do you re-export? jgart
  2022-10-12  6:21 ` Wojtek Kosior via
@ 2022-10-22 14:15 ` Maxim Cournoyer
  1 sibling, 0 replies; 3+ messages in thread
From: Maxim Cournoyer @ 2022-10-22 14:15 UTC (permalink / raw)
  To: jgart; +Cc: Guix Help

Hi jgart,

jgart <jgart@dismail.de> writes:

> Hi,
>
> When should I re-export something in a module?
>
> docs say the following:
>
> Add all variables (which must be symbols or pairs of symbols) to the
> list of re-exported bindings of the current module. Pairs of symbols
> are handled as in export. Re-exported bindings must be imported by the
> current module from some other module.
>
> The docs don't explain why you would want to even do a re-export in the first place...

I've used in two places, I think:

1. Move code around while preserving backward compatibility.
2. For convenience (when people importing B would typically also want
something from A).

Best used very sparingly, or not at all, I'd say :-).

-- 
Thanks,
Maxim


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

end of thread, other threads:[~2022-10-23 22:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-11 21:28 When do you re-export? jgart
2022-10-12  6:21 ` Wojtek Kosior via
2022-10-22 14:15 ` Maxim Cournoyer

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