# How to delete method for call functions?

**URL:** <https://discourse.julialang.org/t/how-to-delete-method-for-call-functions/21697>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 10, 2019, 9:22am UTC](https://discourse.julialang.org/t/how-to-delete-method-for-call-functions/21697 "2019-03-10T09:22:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [March 10, 2019, 9:22am UTC](https://discourse.julialang.org/t/how-to-delete-method-for-call-functions/21697/1 "2019-03-10T09:22:00Z")

</div>

Lets define call syntax for Int

```julia
(i::Int)(n::Number) = i*n
3(4) # 12

```

now I can list the methods by using `Int.name.mt` which will output

```julia
# 1 method for generic function "(::Int64)":
[1] (i::Int64)(n::Number) in Main at none:1

```

The goal is to delete this again, however I fail trying so. Best guess is just calling `empty!()` on it, but that is not defined… Next guess is using `Base.delete_method`, however that does not work either…

```julia
Base.delete_method(collect(Base.MethodList(Int.name.mt))[1])
3(4) # 12

```

Does anyone know how I can empty the methodtable of a Type, i.e. getting `Int.name.mt` empty again?

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [March 10, 2019, 9:38am UTC](https://discourse.julialang.org/t/how-to-delete-method-for-call-functions/21697/2 "2019-03-10T09:38:20Z")

</div>

another try… also failing

```julia
for m ∈ methods(1)
  Base.delete_method(m)
end
3(4) # 12

```

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [March 10, 2019, 9:38am UTC](https://discourse.julialang.org/t/how-to-delete-method-for-call-functions/21697/3 "2019-03-10T09:38:56Z")

</div>

`delete_method` works fine:

```julia
julia> sin("asd")
ERROR: MethodError: no method matching sin(::String)
Closest candidates are:
  sin(::BigFloat) at mpfr.jl:683
  sin(::Missing) at math.jl:1056
  sin(::Complex{Float16}) at math.jl:1005
  ...
Stacktrace:
 [1] top-level scope at none:0

julia> Base.sin(::String) = "ha"

julia> sin("asd")
"ha"

julia> Base.delete_method(which(sin, (String,)))

julia> sin("asd")
ERROR: MethodError: no method matching sin(::String)
Closest candidates are:
  sin(::BigFloat) at mpfr.jl:683
  sin(::Missing) at math.jl:1056
  sin(::Complex{Float16}) at math.jl:1005
  ...
Stacktrace:
 [1] top-level scope at none:0

```

What you’re seeing is normal behaviour – a number (e.g. `3`) juxtaposed with an expression (e.g. `(4)`) is defined as multiplication. Your overload didn’t actually take effect at all:

```julia
julia> (i::Int)(n::Number) = i+n

julia> 3(4)
12 # should be 7 if the method above was called

```

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [March 10, 2019, 9:39am UTC](https://discourse.julialang.org/t/how-to-delete-method-for-call-functions/21697/4 "2019-03-10T09:39:59Z")

</div>

what a coincidence :'D

thanks for pointing that out!

an adapted example indeed works. Thanks a lot!

```julia
julia> "hi"("ho")
ERROR: MethodError: objects of type String are not callable
Stacktrace:
 [1] top-level scope at none:0

julia> (i::String)(n::String) = i * n

julia> "hi"("ho")
"hiho"

julia> for m ∈ Base.MethodList(String.name.mt)
       Base.delete_method(m)
       end

julia> "hi"("ho")
ERROR: MethodError: objects of type String are not callable
Stacktrace:
 [1] top-level scope at none:0

```
