假设我在Julia中指定了一个Person
类型:
type Person
name::String
male::Bool
age::Float64
children::Int
end
function describe(p::Person)
println("Name: ", p.name, " Male: ", p.male)
println("Age: ", p.age, " Children: ", p.children)
end
ted = Person("Ted",1,55,0)
describe(ted)
将使用以下函数输出:
Name: Ted Male: true
Age: 55.0 Children: 0
然后我修改了Person
类型的功能,我在其中添加了一个新类别eyes
type Person
name::String
male::Bool
age::Float64
children::Int
eyes::String
end
ted = Person("Ted",1,55,0,brown)
如果我现在运行该功能,我会收到错误
Error evaluating REPL:
invalid redefinition of constant Person
in include_string at loading.jl:97
在开发新代码时,解决此问题的最佳方法是什么?除了按julia FAQ
中的建议制作模块