不清楚为什么我得到ERROR: LoadError: UndefVarError: subtypes not defined
执行 .jl 文件时,但从 REPL 执行时则不然。
E.g.
abstract type Asset end
abstract type Property <: Asset end
abstract type Investment <: Asset end
abstract type Cash <: Asset end
println(subtypes(Asset))
> 3-element Array{Any,1}:
Cash
Investment
Property
...但是将完全相同的代码放入test.jl
,
julia test.jl
> ERROR: LoadError: UndefVarError: subtypes not defined
Stacktrace:
[1] top-level scope at /.../test.jl:6
[2] include(::Module, ::String) at ./Base.jl:377
[3] exec_options(::Base.JLOptions) at ./client.jl:288
[4] _start() at ./client.jl:484
in expression starting at /.../test.jl:6
Julia 版本 1.4.1,在 OSX Catalina (10.15.4) 上执行
你需要添加using InteractiveUtils
打电话之前subtypes
。默认情况下,启动 Julia REPL 时已加载该文件。
因此你的文件应该是这样的:
shell> more t.jl
using InteractiveUtils
abstract type Asset end
abstract type Property <: Asset end
abstract type Investment <: Asset end
abstract type Cash <: Asset end
println(subtypes(Asset))
shell> julia t.jl
Any[Cash, Investment, Property]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)