Exportall?

question

#1

Is there a way to export ALL the symbols declared in a module? Just to avoid writing them all under export.


#2

No. You typically don’t want to do this.


#3

I am just following this tip:
https://docs.julialang.org/en/stable/manual/workflow-tips/

which I find very useful. However since I am constantly changing the package, it is very inconvenient to track exported variables. So I think this is a use-case for exportall. Why is it so dangerous? I think it could be useful in certain scenarios.


#4

I would prefix the module name before the functions you are using when developing (or do something like const m = MyPackage and use m.f().

For improved workflow, I would look at https://github.com/timholy/Revise.jl


#5

What is the advantage of that, versus exportall? I am just trying to see the downside of having exportall as a feature.


#6

Global namespace is global.


#7

Julz has a function for exporting all vars (that were included using the package)

Maybe you can do something like this:


#8

A practice which I like but I see others employ only rarely is putting export statements immediately following definitions like so

f(x::AbstractFloat) = # do some stuff
function f(x::Complex{<:AbstractFloat})
    # do some other stuff
end
export f

I agree that creating an exportall keyword would be asking for trouble.


#10

Can you explain this code a bit? It seems to be exporting all files, not symbols of a module.


#11

That does seem good for readability while the code is being written, but I wonder if it will become more difficult for other people (or a future you) to understand what the code does. Looking at a list of exports is one of the ways that I typically start to understand a new package.

I think I might try this style on my next project and see how it works…


#12

I haven’t particularly found reading the export lists useful without a good handle on what the functions actually do. Sometimes having argument types is enough for this, but the names alone usually aren’t (for me at least).

Granted, it does make it easy to lose track of which functions are being exported.


#13

Yea, I felt like exportall was a little dodgy (so I scoped it on files for Julz).

I believe the following code does exactly what you want

// at least it did in v0.5


#14

The following simple snippet seems to work:

module Foo
        foo(x) = x+1
        bar(x) = x-1
 
        # exportall:
        for n in names(current_module(), true)
            if Base.isidentifier(n) && n ∉ (Symbol(current_module()), :eval)
                @eval export $n
            end
        end
end

#15

@stevengj Sometimes I have a module spread over multiple files. Is there a way to specialize this to only export symbols defined in the current file?