是否可以访问在朱莉娅的另一个函数中定义的函数?例如:在另一个函数中定义的访问函数
julia> function f(x)
function g(x)
x^2
end
x * g(x)
end
f (generic function with 1 method)
julia> f(2)
8
julia> f.g(2)
ERROR: type #f has no field g
in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
in macro expansion at ./REPL.jl:95 [inlined]
in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:68
除非您返回它或者在您想要使用它的地方定义的指针指向它。 –
您可以*返回*在另一个函数内定义的函数。那是你在找什么?例如,在你的例子中返回匿名函数x-> x * g(x)。 –