jupyter notebook이나 REPL에서 이미 선언한 타입을 변경하거나 삭제하기는 어렵다.
workspace()등은 julia 1.0 이전에는 동작 했으나 그 이후에는 동작 하지 않는다.
개발시 잘 못된 type선을 수정하기기 어렵다. REPL이나 notebook을 다시 시작하는 경우가 많다.
해결책은 module을 사용하면 된다. module 내에 선언된 type은 다시 선언 하여 사용할 수 있기 때문에 변경이 용이 하다.
아래와 같이 XYZ을 선언하고 바로 아래에 수정된 XYZ을 선언하면 “invalid redefinition of constant XYZ” 에러가 발생한다.
mutable struct XYZ
a::Int
end
mutable struct XYZ
a::Int
b::String
end
invalid redefinition of constant XYZ
이런 경우 모듈을 사용 하면 된다
모듈명을 앞에 붙여 사용해야 하는 불편 함은 있다
module M01 end using Main.M01 module M01 f() = println(10) mutable struct XYZ a::Int end end c = XYZ(10) module M01 f() = println(11) mutable struct XYZ a::Int b::String end end c = M01.XYZ(20,"dd")