I am confused here
julia> sum([1,2,3])
6
julia> sum([k for k = 1:3])
6
julia> sum(k for k = 1:3)
6
But when I expand out “k for k = 1:3” manually it does not work
julia> sum(1,2,3)
ERROR: MethodError: no method matching sum(::Int64, ::Int64, ::Int64)
Closest candidates are:
sum(::Any, ::Any) at reduce.jl:486
sum(::Any) at reduce.jl:503
sum(::Any, ::AbstractArray; dims) at reducedim.jl:653
Stacktrace:
[1] top-level scope at REPL[42]:1
julia> sum(1.0,2.0,3.0)
ERROR: MethodError: no method matching sum(::Float64, ::Float64, ::Float64)
Closest candidates are:
sum(::Any, ::Any) at reduce.jl:486
sum(::Any) at reduce.jl:503
sum(::Any, ::AbstractArray; dims) at reducedim.jl:653
Stacktrace:
[1] top-level scope at REPL[43]:1
Why doesn’t sum(1,2,3) give me 6?
6 posts - 4 participants