You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Revise.jl修改Julia结构体未生效,遇常量重定义错误求助

使用Revise.jl修改Julia结构体遇到的问题

尝试用Revise.jl解决结构体字段修改的问题,初始代码保存在tmp_SE.jl文件中:

struct Person
    name::String
    male::Bool
    age::Float64
    children::Int
    # eyes::String
end

function describe(p::Person)
    println("Name: ", p.name, "Male: ", p.male)
    println("Age: ", p.age, "Children: ", p.children)
end

启动Julia REPL后执行以下操作,一切运行正常:

using Revise
include("tmp_SE.jl")
ted=Person("Ted", 1, 55, 0)
describe(ted)

随后执行edit("tmp_SE.jl")打开编辑器,取消结构体中最后一行# eyes::String的注释。此时:

  • 执行include("tmp_SE.jl")会报错:ERROR: LoadError: invalid redefinition of constant Person
  • 直接执行ted=Person("Ted", 1, 55, 0, "brown")会报错:ERROR: MethodError: no method matching Person(::String, ::Int64, ::Int64, ::Int64, ::String)

此时的行为和未使用Revise.jl时完全一致,希望得到解决方法,可能是遗漏了某些步骤。

内容的提问来源于stack exchange,提问作者Roger V.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 10:50:05