不清楚为什么在执行ERROR: LoadError: UndefVarError: subtypes not defined文件时获得.jl,而不是从REPL执行。
例如。
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...but在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:6Julia版本1.4.1,在OSX Catalina上执行(10.15.4)
发布于 2020-05-26 01:20:01
您需要在调用using InteractiveUtils之前添加subtypes。默认情况下,启动Julia时已经加载了该文件。
因此,您的文件应该如下所示:
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]https://stackoverflow.com/questions/62012171
复制相似问题