代码如下:
julia> y = [1, 2]
2-element Array{Int64,1}:
1
2
julia> function t(x, y)
for i in x
println(i*y)
end
end
t (generic function with 1 method)
julia> f = x -> t(x, y)
#1 (generic function with 1 method)
julia> f(1)
[1, 2]
julia> f.([1, 2])
[1, 2]
[2, 4]
2-element Array{Nothing,1}:
nothing
nothing
为什么最后会输出nothing的数组?