-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-exporting one module's symbols from another #1986
Comments
Actually, I would propose altering export's semantics to make this work: module B
using A
export names(A)
end |
This is a very good point. I've taken to doing |
This could be done with a macro, but maybe we should provide some syntax for it. |
My suggestion would be |
A potential downside is that it may make discovery of exported names a bit harder. Also, I'm disinclined to support reserving another name |
I don't understand your concern about discovery of exported names; could you clarify? |
Currently, it easy to parse any julia file, search for
|
I see, you are worried about manually parsing for exports. It's not too bad with If you are wedded to |
I'm just tossing around other proposals for consideration. Very likely, none of them are inherently better. I didn't mean to imply the |
I personally kind of like |
I made a macro that mostly works for this pupose. I say mostly because relative module syntax does not work. The parser parses |
If we ever get a resolution of this issue, we would be able to remove hundreds of lines' worth of redundant-seeming exports from Base.LinAlg and then again from Base. |
I'm with @staticfloat, in that I find What's the downside to adding that as a keyword? |
What does module A
exported = true
export exported
end
module B
exportall A
end Exporting bindings that are not accessible in |
Throw an error. Even though it's more verbose, I find it clearer and more natural than most of the proposed alternatives. |
If |
Whats the advantage of being a macro? It would be totally inconsistent if we have |
Minimalism? It would be one fewer reserved identifier, one fewer Expr head, and in Julia instead of C. It is already a little awkward if it joins I kind of see the symmetry, but it doesn't seem quite right to me: You can add bindings from another module to the current module and you can export bindings in the current module from the current module, but you cannot export bindings in another module from the current module unless those bindings are already also present in the current module. Personally, I would still prefer #5608 or #5626, which combine the loading and exporting of the bindings into one step. It seems to me that: using .Windows, .Periodogram, .FFTFilt, .FilterDesign, .Util
exportall Windows, Periodogram, FFTFilt, FilterDesign, Util is less elegant and easier to screw up than: @reexport using .Windows, .Periodogram, .FFTFilt, .FilterDesign, .Util But if everyone else wants |
Well, minimalism is a point that is always a concern when thinking about adding a keyword. I think the more general question is whether the regular Julia user should be confronted with the usage of macros. I would say no. This is an advanced thing and should not be part of the regular workflow. exportall is from my perspective something that will be needed in the "regular use" Its quite common to structure modules (namspaces, ...) into two levels. |
@tknopp: Yes, writing a macro might be an advanced thing that ordinary users should not need to worry about. However, I don't think using a macro is that advanced -- they don't even need to understand how a macro works behind the scene in order to use it. All what we need is to clearly document the macro's usage. For instance, Also, a code author should be quite tech savvy when he is worrying about something like re-exporting names. |
@lindahua: macros are great. But still they do "magical" code transformations that I think most users should not be confronted with. I think reexporting names will be not that uncommon in practice. The export mechanism is Julias way for information hiding. And having submodules in modules is common and should also be encouraged. |
A better example for "macros all users should be comfortable with" is |
Which I think should be replaced with a pure Julia implementation when we can. (I have one partially implemented.) |
We also have |
Probably |
Has there been any further progress, decision or discussion on this matter? Is @simonster 's |
Since I haven't seen any other options emerge, I think Reexport is the de facto standard. |
Thanks @johnmyleswhite :) I will be relying on it and will keep an eye on this thread. |
It would be really great if we could have this functionality in Base. It would be great to have metapackages that simply group several packages together in order to provide a larger set of functionality. |
Needs some design thoughts to figure out how we want this to work and interact with |
Crossref #14472 |
I put together a macro implementation of something like this for one of my PRs as a demo: https://github.com/JuliaLang/julia/pull/22147/files#diff-4fc3422b2208cb02c3e17c7cc0a56446R44 |
Seems feature-y. There might be syntax we could want, but we if that does happen we can live with a macro until 2.0. |
Re-export is evil. |
I disagree that Reexport is evil. In writing a package with many levels of submodules, I find Reexport very convenient for managing namespaces across levels without lots of boilerplate code and code duplication. I echo the sentiment expressed above that this would be great functionality to have in Base. |
how about introducing the import/using syntax to export aswell? I.e. using B
export B for reexporting all exported identifiers from B module A
using B
export A: B #same
export B: B #same
export B #different
end But given that exporting an imported module w/o exporting its fields doesn't make a lot of sense on its own right now, redefining |
Is Reexport.jl still the recommended way to do this? Lots of packages are using it, and seems to work fine. If there isn't anything we are planning to do here, we can close this. |
yes, Reexport.jl seems like an okay way to do this. The names are easy enough to get via reflection and eval into the current module |
Add Reexport.jl to the dependencies and use it to reexport QEDbase's symbols. This is the officially endorsed way to do this (JuliaLang/julia#1986). Fixes part of #24
It would be convenient if there were a way to do this.
Doing this explicitly (copy the long list of exports from A into B) is a bit ugly and error prone. I imagine any alternative would involve a new keyword though.
Concretely, Gadfly is useless without symbols from Compose (and probably DataFrames), but a bunch of compulsory using statements isn't great.
The text was updated successfully, but these errors were encountered: