# Starting with julia's functions

**URL:** https://discourse.julialang.org/t/starting-with-julias-functions/1308
**Category:** New to Julia
**Created:** [January 5, 2017, 5:45pm UTC](https://discourse.julialang.org/t/starting-with-julias-functions/1308 "2017-01-05T17:45:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![vincent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vincent/32/380_2.png) [@vincent](https://discourse.julialang.org/u/vincent)
#### Post date: [January 5, 2017, 5:45pm UTC](https://discourse.julialang.org/t/starting-with-julias-functions/1308/1 "2017-01-05T17:45:41Z")

</div>

hi  
i follow Julia-'s help on [http://docs.julialang.org/en/stable/manual/functions/](http://docs.julialang.org/en/stable/manual/functions/) and i try to inderstand how functions work in Julia  
i type this in a file that i run with an `include` in the RPPL :

```julia
function f(x,y)
        x + y
end
f(2,3)

```

it seems to work but Julia says :

> WARNING: Method definition f(Any, Any) in module Main at /Users/vincentdouce/Desktop/Julia/vademecum\_Julia.jl:16 overwritten at /Users/vincentdouce/Desktop/Julia/vademecum\_Julia.jl:16.

i must admit i do not undestand at all what it means, and i pain to find any explanation on `http://docs.julialang.org` about this point.

morehowever, i type this :

```julia
function f(x)
  x*2
end
f(2,3)

```

and the result is 5.  
i am ok that my script is wrong according to the number of variables of f, but why 5 ?

de plus je ne parviens pas du tout à comprendre comment tracer une famille de fonctions. Par exemple si je veux tracer les courbes f(x)=a.cos(x) pour a variant  
j’ai essayé :

```julia
1 function f(x,y)
2 return(x*cos(y))
3 end
4 
5 tvec = linspace(-π,π , 100)
6 for i=-5:5
7 plot!(tvec, f(i,tvec))
8 end

```

but the result is :  
`WARNING: Method definition f(Any, Any) in module Main at [line 2] overwritten at [line 2]`

???

thanks for your help

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [January 5, 2017, 6:16pm UTC](https://discourse.julialang.org/t/starting-with-julias-functions/1308/2 "2017-01-05T18:16:55Z")

</div>

Julia is rereading the file, so the method definition is overwritten, hence the warning.

It is possible that you have a definition `f(x)` in your global scope. Try `workspace()` to clear it.

Finally (sorry, my French is very basic so I am not sure I understand), there is no “standard” plotting library in Julia. Many people like `Plots.jl`, which has plenty of examples.  
[https://github.com/tbreloff/Plots.jl](https://github.com/tbreloff/Plots.jl)

---

<div class="post-metadata">

### Author: ![shorty66](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shorty66/32/3254_2.png) [@shorty66](https://discourse.julialang.org/u/shorty66)
#### Post date: [January 5, 2017, 6:18pm UTC](https://discourse.julialang.org/t/starting-with-julias-functions/1308/3 "2017-01-05T18:18:36Z")

</div>

Every time you include your files, julia also creates the functions again which are defined in the files. This leads to the `method definition warning` as julia already knows a function with the same name and argument types and warns you, that it will be overridden.

Your second problem comes from multiple dispatch: a function with the same name, but different number or types of arguments is a new method. Julia decides which method to use by the types of the arguments. In your case `f(2,3)` evaluates to `5` because the version of `f`with two arguments is called - this is `f(x,y) = x+y`.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [January 5, 2017, 8:14pm UTC](https://discourse.julialang.org/t/starting-with-julias-functions/1308/4 "2017-01-05T20:14:32Z")

</div>

Here’s an answer with work arounds which I gave a new Julia user before:

[https://github.com/JuliaDiffEq/DifferentialEquations.jl/issues/119#issuecomment-267654207](https://github.com/JuliaDiffEq/DifferentialEquations.jl/issues/119#issuecomment-267654207)
