# Workflow with redefining structs

**URL:** https://discourse.julialang.org/t/workflow-with-redefining-structs/102982
**Category:** General Usage
**Tags:** metaprogramming, revise
**Created:** [August 19, 2023, 3:23pm UTC](https://discourse.julialang.org/t/workflow-with-redefining-structs/102982 "2023-08-19T15:23:55Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)
#### Post date: [August 19, 2023, 3:23pm UTC](https://discourse.julialang.org/t/workflow-with-redefining-structs/102982/1 "2023-08-19T15:23:55Z")

</div>

Continuing the discussion from [Workflow challenges with redefining structs (from "Why I still recommend Julia")](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/24):

I have decided to continue in a separate topic, but please see the linked post. So, I have now managed to make up a macro for “wrapping & re-defining”.

The usage is like following

```julia
@mwf module Moo
    
x1 = 1
x2 = 2

struct F7
    z
end

function f8(x)
    return x+8
end

end

```

Now you can use all variables defined within the module `Moo` **directly** in the `Main` scope:

```julia
julia> x1
1

```

If you want to redefine the struct `F7` - just re-run the script.

The macro can also be applied directly to functions, structs and mutable structs like this:

```julia
@mwf struct Foo
    x
end

```

The effect would be the same as with

```julia
@mwf module ModModularWF_Foo
struct Foo
    x
end
end

```

For structs, it enables re-definition without restarting Julia. For functions, such a transparent wrapping into a module prevents inadvertent use of global variables within the function body and appearance of ghost methods (for which the source code doesn’t exist anymore).

For a bit more usage examples, see [https://github.com/Eben60/ModularWF/blob/main/test/runtests.jl](https://github.com/Eben60/ModularWF/blob/main/test/runtests.jl)

Now the most exciting thing: such a re-definition of a struct using `@mwf` appears to function from within a `Revise`-ed module. It is just important that `@mwf` is already there before module loading. @tim.holy, what do you think about it?

The package, not (yet) registered, is on GitHub: [GitHub - Eben60/ModularWF](https://github.com/Eben60/ModularWF)  
As I have only minimal experience with metaprogramming, I would be very grateful if somebody more experienced looks onto my code.
