Skip to content

Commit

Permalink
fix @DeFonce
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Dec 7, 2019
1 parent d0b8b1f commit 773997c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,21 @@ macro oncethen(expr::Expr)
end

"""
Stop Julia from complaining about redifined consts/types
Stop Julia from complaining about redifined struct/consts
@defonce type MyType
@defonce struct MyType
...
end
or
or
@defonce const pi = 3.14
"""
macro defonce(def)
name = namify(isexpr(def, :type) ? def.args[2] : def)

:(if !isdefined($(Expr(:quote, name)))
$(esc(def))
end)
name = namify(isexpr(def, :struct) ? def.args[2] : def)
if !isdefined(__module__, name)
return :($(esc(def)))
end
end

"""
Expand Down

0 comments on commit 773997c

Please sign in to comment.