-
-
Notifications
You must be signed in to change notification settings - Fork 115
Open
Description
Hi!
I have this in one of my packages:
"""
@constfield foo::Int
A macro providing compatibility for `const` fields in mutable structs.
Gives a `const` `Expr` if supported, otherwise is a noop and just returns the field.
"""
macro constfield(ex::Expr)
(ex.head == Symbol("::") && length(ex.args) == 2) || throw(ArgumentError("`@constfield` only supports expressions of the form `field::Type`!"))
ex = esc(ex)
if VERSION < v"1.8"
ex
else
Expr(:const, ex)
end
endand wanted to ask whether there's interest to have this macro in Compat? It's used like this:
struct Foo
@constfield foo::Int
endThe idea is to have a noop (if unsupported) replacement for const foo::Int in struct definitions.
Metadata
Metadata
Assignees
Labels
No labels