这里的问题是两者names
and whos
list exported来自模块的名称。如果您想看到它们,那么您需要执行以下操作:
module Foo
export foo, bar
function foo()
"foo"
end
function bar()
"bar"
end
end # module
此时双方names
and whos
会列出一切。
如果您碰巧在 REPL 上工作并且出于某种原因不想导出任何名称,您可以通过输入以交互方式检查模块的内容Foo.[TAB]
。请参阅本次会议的示例:
julia> module Foo
function foo()
"foo"
end
function bar()
"bar"
end
end
julia> using Foo
julia> whos(Foo)
Foo Module
julia> names(Foo)
1-element Array{Symbol,1}:
:Foo
julia> Foo.
bar eval foo
不知何故,制表符补全正在查找未导出的名称,所以有must是让朱莉娅告诉你的一种方法。我只是不知道这个功能是什么。
EDIT
我做了一点挖掘。未导出的函数Base.REPLCompletions.completions
似乎有效,正如我们之前使用的 REPL 会话的延续所示:
julia> function functions_in(m::Module)
s = string(m)
out = Base.REPLCompletions.completions(s * ".", length(s)+1)
# every module has a function named `eval` that is not defined by
# the user. Let's filter that out
return filter(x-> x != "eval", out[1])
end
functions_in (generic function with 1 method)
julia> whos(Foo)
Foo Module
julia> names(Foo)
1-element Array{Symbol,1}:
:Foo
julia> functions_in(Foo)
2-element Array{UTF8String,1}:
"bar"
"foo"