What exactly does “with # methods” mean? Here are some results that really confuse me.

```
function sayhi(x,y)
x+y
end
```

Result: sayhi (generic function with 3 methods)

```
function f(x,y)
x+y
end
```

Result: f (generic function with 1 method)

What exactly does “with # methods” mean? Here are some results that really confuse me.

```
function sayhi(x,y)
x+y
end
```

Result: sayhi (generic function with 3 methods)

```
function f(x,y)
x+y
end
```

Result: f (generic function with 1 method)

The number of methods is the number different possible places you end up when calling a function. This is because with multiple dispatch some functions (like +) are defined in many different ways for different type combinations.

Try to restart Julia. You may have some old definitions lying around.

5 Likes

You can use `methods()`

to see a list of the methods for a given function:

```
julia> function f(x, y)
x + y
end
f (generic function with 1 method)
julia> methods(f)
# 1 method for generic function "f":
[1] f(x, y) in Main at REPL[1]:2
julia> function f(x)
x + 2
end
f (generic function with 2 methods)
julia> methods(f)
# 2 methods for generic function "f":
[1] f(x) in Main at REPL[3]:2
[2] f(x, y) in Main at REPL[1]:2
```

1 Like