Export enum


#1

Hi

I am defining an enum such as @enum myenum enumname1 enumname2 in a module using Julia 0.6. it seems I have to explicitly export both enum type name(myenum) and enum elements(enumname1,enumname2). I know this way is more explicit, but usually we want all elements of an enum type be exported too. is there a way to just do export myenum so that type name and all its elements be exported, or should this behavior be the default for export enum?

Alex


#2

Here’s a macro that does it:

macro exported_enum(name, args...)
    esc(quote
        @enum($name, $(args...))
        export $name
        $([:(export $arg) for arg in args]...)
        end)
end

@exported_enum fruit apple banana

#3

this macro is great, should be included in the base. thanks sharing.