Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extending methods in a loop over functions results in misleading method table printing #10373

Closed
tkelman opened this issue Mar 1, 2015 · 3 comments

Comments

@tkelman
Copy link
Contributor

tkelman commented Mar 1, 2015

This seems to be just a printing issue, but there might be something else going on here. Looks more or less the same on latest master too.

  | | |_| | | | (_| |  |  Version 0.3.6 (2015-01-08 22:33 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org release
|__/                   |  x86_64-linux-gnu

julia> type newtype
       end
       for f in (cos, sin, tan)
           f(x::newtype) = println("$f")
       end

julia> methods(cos)
#12 methods for generic function "cos":
cos(a::Complex{Float16}) at float16.jl:141
cos(z::Complex{T<:Real}) at complex.jl:528
cos(x::Float64) at math.jl:122
cos(x::Float32) at math.jl:123
cos(a::Float16) at float16.jl:140
cos(x::BigFloat) at mpfr.jl:488
cos(x::Real) at math.jl:124
cos{Tv}(A::SparseMatrixCSC{Tv,Ti<:Integer}) at sparse/sparsematrix.jl:512
cos{T<:Number}(::AbstractArray{T<:Number,1}) at operators.jl:359
cos{T<:Number}(::AbstractArray{T<:Number,2}) at operators.jl:360
cos{T<:Number}(::AbstractArray{T<:Number,N}) at operators.jl:362
tan(x::newtype) at none:2

julia> methods(sin)
#12 methods for generic function "sin":
sin(a::Complex{Float16}) at float16.jl:141
sin(z::Complex{T<:Real}) at complex.jl:518
sin(x::Float64) at math.jl:122
sin(x::Float32) at math.jl:123
sin(a::Float16) at float16.jl:140
sin(x::BigFloat) at mpfr.jl:488
sin(x::Real) at math.jl:124
sin{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}) at sparse/sparsematrix.jl:448
sin{T<:Number}(::AbstractArray{T<:Number,1}) at operators.jl:359
sin{T<:Number}(::AbstractArray{T<:Number,2}) at operators.jl:360
sin{T<:Number}(::AbstractArray{T<:Number,N}) at operators.jl:362
tan(x::newtype) at none:2

julia> methods(tan)
#12 methods for generic function "tan":
tan(a::Complex{Float16}) at float16.jl:141
tan(z::Complex{T<:Real}) at complex.jl:544
tan(x::Float64) at math.jl:122
tan(x::Float32) at math.jl:123
tan(a::Float16) at float16.jl:140
tan(x::BigFloat) at mpfr.jl:488
tan(x::Real) at math.jl:124
tan{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}) at sparse/sparsematrix.jl:448
tan{T<:Number}(::AbstractArray{T<:Number,1}) at operators.jl:359
tan{T<:Number}(::AbstractArray{T<:Number,2}) at operators.jl:360
tan{T<:Number}(::AbstractArray{T<:Number,N}) at operators.jl:362
tan(x::newtype) at none:2

julia> sin(newtype())
sin

julia> cos(newtype())
cos

julia> tan(newtype())
tan
@JeffBezanson
Copy link
Member

I'm not sure this code pattern should be allowed. This is happening because the same code (with different closure environments) is being added to multiple generic functions.

@tkelman
Copy link
Contributor Author

tkelman commented Mar 3, 2015

Outside of a loop at the repl I get an error cannot define function f; it already has a value. I don't mind sprinkling eval in various places and using symbols, but I have an application where it's convenient to be saving the function instead of its name in the values of a Dict for evaluation purposes: functiondict[idx](x), and elsewhere define methods for a type by looping over values(functiondict).

@JeffBezanson
Copy link
Member

...yikes. Ok I guess I'll just fix this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants