是否可以訪問在朱莉婭的另一個函數中定義的函數?例如:在另一個函數中定義的訪問函數
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)。 –