Pardon any confused terminology in the title, but imagine I want to have a little macro to mark structs I create as usable for some nefarious purpose. I write this little module:
module Usable
export @usable, isusable
isusable(::Type{T}) where T = false
macro usable(expr::Expr)
name = expr.args[2]
return quote
$expr
Usable.isusable(::Type{$name}) = true # This in't working
end
end
end
However, trying to use my macro
julia> include("Usable.jl")
Main.Usable
julia> using Main.Usable
julia> @usable struct Foo
bar::String
end
results in
ERROR: UndefVarError: Foo not defined
The struct was evidently defined just fine
julia> Foo("soup")
Foo("soup")
so it would seem the definition is required earlier than I expect. I am obviously missing something, but I can't figure out what.