# 2 functions, same name, one with scalar and one with list arguments

**URL:** https://discourse.julialang.org/t/2-functions-same-name-one-with-scalar-and-one-with-list-arguments/781
**Category:** New to Julia
**Tags:** question
**Created:** [December 7, 2016, 3:17pm UTC](https://discourse.julialang.org/t/2-functions-same-name-one-with-scalar-and-one-with-list-arguments/781 "2016-12-07T15:17:54Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [December 7, 2016, 3:17pm UTC](https://discourse.julialang.org/t/2-functions-same-name-one-with-scalar-and-one-with-list-arguments/781/1 "2016-12-07T15:17:54Z")

</div>

Hello, what I understood is that multiple dispatch allows to write the same function with different arguments, and then the compiler transforms the different functions in different methods.  
I am trying to use this feature for a ods to dictionary converter, where the first function works with an array of sheet names or positions (and returns a dictionary of dictionaries) and, for user’s convenience, a second function that works with a single sheet name/pos and call the first function.

The first function is defined as:  
`function ods2dic(filename;sheetsNames=[],sheetsPos=[],ranges=[])`  
The second one is defined as:  
`function ods2dic(filename;sheetName::String=nothing,sheetPos::Int64=nothing,range=())`

The problem is that when I write my calls as:  
`outDic1 = OdsIO.ods2dic("spreadsheet.ods";sheetsPos=[1,3],ranges=[((1,1),(3,3)),((2,2),(6,4))])`  
Julia tries to call the second function, and obviously throws an error because different keyword arguments (note the s)… …but the second function should be called only when a single String or Integer is given,  
Why (she?) does that ?  
(if I comment out the second function, the call is correctly dispatched to the first function)

---

<div class="post-metadata">

### Author: ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)
#### Post date: [December 7, 2016, 3:32pm UTC](https://discourse.julialang.org/t/2-functions-same-name-one-with-scalar-and-one-with-list-arguments/781/2 "2016-12-07T15:32:50Z")

</div>

Julia (“it”!, see community guidelines for why) does not specialize on keyword arguments. so you’d need to change the sheetName/sheetNames argument to be positional so that Julia can distinguish between the two methods.

```nohighlight
function ods2dic(filename::AbstractString, sheets::String="";sheetpos=0, range=())
function ods2dic(filename::AbstractString, sheets::AbstractVector;sheetpos=[],ranges=[])

```

Also, you shouldn’t be assigning `nothing` to an `Int64` typed variable.

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [December 7, 2016, 3:33pm UTC](https://discourse.julialang.org/t/2-functions-same-name-one-with-scalar-and-one-with-list-arguments/781/3 "2016-12-07T15:33:01Z")

</div>

I guess the relevant answer is:

> Methods are dispatched based only on positional arguments, with keyword arguments processed after the matching method is identified.  
> (from [http://docs.julialang.org/en/release-0.5/manual/methods/](http://docs.julialang.org/en/release-0.5/manual/methods/))

…I’ll have to revise my functions! ☹

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [December 7, 2016, 3:51pm UTC](https://discourse.julialang.org/t/2-functions-same-name-one-with-scalar-and-one-with-list-arguments/781/4 "2016-12-07T15:51:10Z")

</div>

> [@ScottPJones](#):
>
> function ods2dic(filename::AbstractString, sheets::AbstractVector;sheetpos=,ranges=)

Thank you. The problem is that sheetsNames, sheetsPos and ranges are all optional and better handled as keyword arguments. I am better off choosing an other name for the scalar function!

---

<div class="post-metadata">

### Author: ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)
#### Post date: [December 7, 2016, 3:53pm UTC](https://discourse.julialang.org/t/2-functions-same-name-one-with-scalar-and-one-with-list-arguments/781/5 "2016-12-07T15:53:58Z")

</div>

OK, that’s why I put the =“” for the scalar method, so that if you just called with the filename, and maybe some of the optional keyword arguments, it would pick the scalar version with “” for the name.
