How to write a macro to export all instances of an enum type

paalon
Wed, 15 Dec 2021 11:35:02 +0000
General Usage

A module has an enum type A and I want to export all its instances instances(A).
I want to write a macro @export_instances like

module MyModule
export A
@enum A a b c
@export_instances A
# `export a, b, c`
end # module

I have read Julia documentation’s metaprogramming page and Export enum - #4 by mathieu17g. I was able to implement the following function to return the expression to export all instances of an enum type T.

function export_instances(T)
    :(export $(Symbol.(instances(T))...))
end

Then, I have tried to write the desired macro but can’t. How do I?

3 posts - 2 participants