0
예를 들어 함수가 포함 된 배열을 만들 수 있습니다.함수를 배열에 추가하는 방법은 무엇입니까?
julia> a(x) = x + 1
>> a (generic function with 1 method)
julia> [a]
>> 1-element Array{#a,1}:
a
그러나 나는 빈 배열로 기능을 추가 할 수없는 것 :
julia> append!([],a)
>> ERROR: MethodError: no method matching length(::#a)
Closest candidates are:
length(::SimpleVector) at essentials.jl:168
length(::Base.MethodList) at reflection.jl:256
length(::MethodTable) at reflection.jl:322
...
in _append!(::Array{Any,1}, ::Base.HasLength, ::Function) at .\collections.jl:25
in append!(::Array{Any,1}, ::Function) at .\collections.jl:21
내가 ulimately 내가 궁극적으로이를 통해지도 할 수 있도록 미리 정의 된 기능을 저장되고 싶지 가치. 예 :
x = 0.0
for each fn in vec
x = x + fn(x)
end
['추가'!] (HTTP의 두 번째 매개 변수 : //docs.julialang. org/en/release-0.5/stdlib/collections?? highlight = append # Base.append!)는 콜렉션입니다. 개별 항목에'! ([], a)'를 사용하거나 컬렉션에'(!, [a])'를 추가 할 수 있습니다 – Gomiero