RedefStructs.jl

Documentation for RedefStructs.jl.

This package provides the macros @redef, @redef_print, and @kwredef which allow to create structures which are redefinable.

Examples

Using @redef:

julia> using RedefStructs

julia> @redef struct S
           s::String
       end

julia> S("Hello").s
"Hello"

julia> @redef mutable struct S
           n::Int
       end

julia> S(42).n
42

Using @redef_print:

julia> using RedefStructs

julia> @redef_print struct S
           s::String
       end

julia> S("Hello").s
"Hello"

julia> @redef_print mutable struct S
           n::Int
       end

julia> S(42).n
42

Using @redef:

julia> using RedefStructs

julia> @kwredef struct S
           s::String = "<empty>"
       end

julia> S("Hello").s
"Hello"

julia> @kwredef mutable struct S
           a::Int = 0
           b::Int
       end

julia> S(b=42).a
0

Library

Public

RedefStructs.@kwredefMacro
@kwredef [mutable] struct S [<: A]
    ...
end

Define a structure in a manner that allows redefinitions, using Base.@kwdef.

Behind the scenes, this creates a "secret" structure with gensym and assigns S to its name.

See also @redef and Base.@kwdef.

Examples

julia> using RedefStructs

julia> @kwredef struct S
           s::String = "<empty>"
       end

julia> S("Hello").s
"Hello"

julia> @kwredef mutable struct S
           a::Int = 0
           b::Int
       end

julia> S(b=42).a
0
source
RedefStructs.@redefMacro
@redef [mutable] struct S [<: A]
    ...
end

Define a structure in a manner that allows redefinitions.

Behind the scenes, this creates a "secret" structure with gensym and assigns S to its name.

See also @redef_print.

Examples

julia> using RedefStructs

julia> @redef struct S
           s::String
       end

julia> S("Hello").s
"Hello"

julia> @redef mutable struct S
           n::Int
       end

julia> S(42).n
42
source
RedefStructs.@redef_printMacro
@redef [mutable] struct S [<: A]
    ...
end

Define a structure in a manner that allows redefinitions.

Behind the scenes, this creates a "secret" structure with gensym and defines a specialized method of Base.show_datatype which shows S.

See also @redef.

Examples

julia> using RedefStructs

julia> @redef_print struct S
           s::String
       end

julia> S("Hello").s
"Hello"

julia> @redef_print mutable struct S
           n::Int
       end

julia> S(42).n
42
source

Private

RedefStructs.replace!Method
replace!(code::Expr, old::Symbol, new::Symbol)

Replaces every appearance of old in code with new. Modifies code and returns it.

source