function vs. getfield

Why doesn’t typeof return “function”?

julia> testint
#104 (generic function with 1 method)

julia> typeof(testint)
getfield(Main, Symbol("##104#113")){Array{getfield(Main, Symbol("##89#90")){getfield(Main, Symbol("##67#69")){Array{Array{Float64,1},1}},getfield(Main, Symbol("##76#78")){typeof(sin1),getfield(Main, Symbol("##75#77")){getfield(Main, Symbol("##67#69")){Array{Array{Float64,1},1}},Int64}}},1}}


This is a more specific subtype of Function.

1 Like

Then why do I get this error?

julia> testpl = play(testint,16.0)
ERROR: MethodError: no method matching play(::getfield(Main, Symbol("##48#57")){Array{getfield(Main, Symbol("##33#34")){getfield(Main, Symbol("##11#13")){Array{Array{Float64,1},1}},getfield(Main, Symbol("##20#22")){typeof(sin1),getfield(Main, Symbol("##19#21")){getfield(Main, Symbol("##11#13")){Array{Array{Float64,1},1}},Int64}}},1}}, ::Float64, ::getfield(Main, Symbol("##15#17")), ::Float64)
Closest candidates are:
  play(::Function, ::Float64, ::Function) at /home/dabrowsa/lang/julia/mine/sines.jl:8
  play(::Function, ::Float64, ::Function, ::Int64) at /home/dabrowsa/lang/julia/mine/sines.jl:8
  play(::Function, ::Float64) at /home/dabrowsa/lang/julia/mine/sines.jl:8
Stacktrace:
 [1] play(::Function, ::Float64) at /home/dabrowsa/lang/julia/mine/sines.jl:8
 [2] top-level scope at util.jl:156

Surely it shoufd match play(::Function, ::Float64)?

It did, as shown by the stacktrace. The next call isn’t matching because the last argument is Float64, but your method is restricted to Int64.

Oh - my last argument is 44100/4, that’s not an integer?

Got it, thanks.

Right, division of Ints always produces a Float64 in Julia (this is like Python3 but unlike Python2).

1 Like
julia> 44100/4
11025.0

julia> 44100÷4
11025

÷ == \div <TAB> == div(44100,4) # Integer division
2 Likes