Using revise.jl to sort Invalid redefinition of constant

Hi,

I want edit the parameters in a struct. However when I try to change I get an error ERROR: invalid redifinition of constant ...

For example if I want to change from

mutable struct CasAgent
    id::Int
    pos::Dims{2}
end

to

mutable struct CasAgent
    id::Int
    pos::Dims{2}
    TS::Int
end

ERROR: invalid redifinition of constant CasAgent

I am aware that you can exit and restart to solve this issue however I saw a few posts suggesting that Revise.jl can be useful. But got no idea how to do so?. Any ideas how to use do this?

1 Like

It is, unfortunately, not possible to redefine types, even with Revise. As far as I know, the issue is that there is no mechanism to invalidate code that used the old definition.

The easiest workaround is to wrap your code in a module, then redefine the module when you change a struct. That works OK, though not quite as smooth as Revise.

4 Likes