# Function overloading instead of dot syntax

**URL:** <https://discourse.julialang.org/t/function-overloading-instead-of-dot-syntax/75321>\
**Category:** Data\
**Tags:** question\
**Created:** [January 27, 2022, 8:22pm UTC](https://discourse.julialang.org/t/function-overloading-instead-of-dot-syntax/75321 "2022-01-27T20:22:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leticia-maria](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leticia-maria/32/30981_2.png) [@Leticia-maria](https://discourse.julialang.org/u/Leticia-maria)\
**Post date:** [January 27, 2022, 8:22pm UTC](https://discourse.julialang.org/t/function-overloading-instead-of-dot-syntax/75321/1 "2022-01-27T20:22:34Z")

</div>

Hey, i have created this function and I would like to overload the last function (`vdw_radius`) instead of using `.@` macro. Any help?

````julia
 ​_vdw_radius_crc ​=​ [ 
 ​ ​110.0​, 
 ​ ​140.0​, 
 ​ ​182.0​, 
 ​ ​153.0​, 
 ​ ​192.0​, 
 ​ ​170.0​, 
 ​ ​155.0​, 
 ​ ​152.0​, 
 ​ ​147.0​, 
 ​ ​154.0​, 
 ​ ​227.0​, 
 ​ ​173.0​, 
 ​ ​184.0​, 
 ​ ​210.0​, 
 ​ ​180.0​, 
 ​ ​180.0​, 
 ​ ​175.0​, 
 ​ ​188.0​, 
 ​ ​275.0​, 
 ​ ​231.0​, 
 ​ ​215.0​, 
 ​ ​211.0​, 
 ​ ​207.0​, 
 ​ ​206.0​, 
 ​ ​205.0​, 
 ​ ​204.0​, 
 ​ ​200.0​, 
 ​ ​197.0​, 
 ​ ​196.0​, 
 ​ ​201.0​, 
 ​ ​187.0​, 
 ​ ​211.0​, 
 ​ ​185.0​, 
 ​ ​190.0​, 
 ​ ​185.0​, 
 ​ ​202.0​, 
 ​ ​303.0​, 
 ​ ​249.0​, 
 ​ ​232.0​, 
 ​ ​223.0​, 
 ​ ​218.0​, 
 ​ ​217.0​, 
 ​ ​216.0​, 
 ​ ​213.0​, 
 ​ ​210.0​, 
 ​ ​210.0​, 
 ​ ​211.0​, 
 ​ ​218.0​, 
 ​ ​193.0​, 
 ​ ​217.0​, 
 ​ ​206.0​, 
 ​ ​206.0​, 
 ​ ​198.0​, 
 ​ ​216.0​, 
 ​ ​343.0​, 
 ​ ​268.0​, 
 ​ ​243.0​, 
 ​ ​242.0​, 
 ​ ​240.0​, 
 ​ ​239.0​, 
 ​ ​238.0​, 
 ​ ​236.0​, 
 ​ ​235.0​, 
 ​ ​234.0​, 
 ​ ​233.0​, 
 ​ ​231.0​, 
 ​ ​230.0​, 
 ​ ​229.0​, 
 ​ ​227.0​, 
 ​ ​226.0​, 
 ​ ​224.0​, 
 ​ ​223.0​, 
 ​ ​222.0​, 
 ​ ​218.0​, 
 ​ ​216.0​, 
 ​ ​216.0​, 
 ​ ​213.0​, 
 ​ ​213.0​, 
 ​ ​214.0​, 
 ​ ​223.0​, 
 ​ ​196.0​, 
 ​ ​202.0​, 
 ​ ​207.0​, 
 ​ ​197.0​, 
 ​ ​202.0​, 
 ​ ​220.0​, 
 ​ ​348.0​, 
 ​ ​283.0​, 
 ​ ​247.0​, 
 ​ ​245.0​, 
 ​ ​243.0​, 
 ​ ​241.0​, 
 ​ ​239.0​, 
 ​ ​243.0​, 
 ​ ​244.0​, 
 ​ ​245.0​, 
 ​ ​244.0​, 
 ​ ​245.0​, 
 ​ ​245.0​, 
 ​ ​245.0​, 
 ​ ​246.0​, 
 ​ ​246.0​, 
 ​ ​246.0​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​ ​nothing​, 
 ​] 
  
 ​function​ ​_vdw_radius​(atomno) 
 ​     
 ​ radius ​=​ _vdw_radius_crc[atomno] 
 ​     
 ​ ​if​ ​isnothing​(radius)  
 ​ ​return​ ​2.0 
 ​ ​end 
 ​     
 ​ ​return​ radius ​*​ consts​.​centi 
 ​end 
  
 ​""" 
 ​Select reasonable estimates for the van der Waals radii. 
 ​This function returns van der Waals radii as recommended in the 95th 
 ​edition of the "CRC Handbook of Chemistry and Physics" (2014). This 
 ​consists of Bondi radii (A. Bondi. "van der Waals Volumes and Radii". J. 
 ​Phys. Chem. 1964, 68, 3, 441-451. DOI:10.1021/j100785a001) together with 
 ​the values recommended by Truhlar (M. Mantina et al. "Consistent van der 
 ​Waals Radii for the Whole Main Group". J. Phys. Chem. A 2009, 113, 19, 
 ​5806-5812. DOI:10.1021/jp8111556). For hydrogen, the value recommended by 
 ​Taylor is employed (R. Rowland et al. "Intermolecular Nonbonded Contact 
 ​Distances in Organic Crystal Structures: Comparison with Distances Expected 
 ​from van der Waals Radii". J. Phys. Chem. 1996, 100, 18, 7384-7391. 
 ​DOI:10.1021/jp953141+). Other elements receive values recommended by either 
 ​Hu (S.-Z., Hu. Kristallogr. 224, 375, 2009) or Guzei (Guzei, I. A. and 
 ​Wendt, M., Dalton Trans., 2006, 3991, 2006). If neither are defined, we use 
 ​2.0 Å as default. 
 ​Parameters 
 ​---------- 
 ​atomno : array-like 
 ​Returns 
 ​------- 
 ​array-like 
  
 ​Examples 
 ​-------- 
  
 ​```julia-repl 
 ​julia> vdw_radius(1) 
 ​1.1 
 ​``` 
  
 ​```julia-repl 
 ​julia> vdw_radius([1,2,3]) 
 ​1.1 
 ​1.4000000000000001 
 ​1.82 
 ​``` 
  
 ​```julia-repl 
 ​julia> vdw_radius(range(1,3)) 
 ​1.1 
 ​1.4000000000000001 
 ​1.82 
 ​``` 
 ​""" 
 ​@.​ ​function​ ​vdw_radius​(atomno) 
 ​     
 ​ ​return​ ​_vdw_radius​(atomno) 
 ​end

````

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [January 27, 2022, 8:47pm UTC](https://discourse.julialang.org/t/function-overloading-instead-of-dot-syntax/75321/2 "2022-01-27T20:47:07Z")

</div>

Overloading works as follows

```julia
julia> function foo(x)
           println("The most general method")
       end;

julia> function foo(x::AbstractArray)
           println("The array method")
       end;

julia> foo(1)
The most general method

julia> foo([1, 2])
The array method

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [January 27, 2022, 9:07pm UTC](https://discourse.julialang.org/t/function-overloading-instead-of-dot-syntax/75321/3 "2022-01-27T21:07:58Z")

</div>

You probably want something like this there:

```julia
julia> const vdw_radius_crc = [1.0, 2.0, 3.0, nothing];

julia> vdw_radius(i::Integer) = isnothing(vdw_radius_crc[i]) ? 2.0 : vdw_radius_crc[i]
vdw_radius (generic function with 1 method)

julia> vdw_radius(a::AbstractVector{<:Integer}) = vdw_radius.(a)
vdw_radius (generic function with 2 methods)

julia> vdw_radius(1)
1.0

julia> vdw_radius([1,2,4])
3-element Vector{Float64}:
 1.0
 2.0
 2.0

julia> vdw_radius(1:3)
3-element Vector{Float64}:
 1.0
 2.0
 3.0

```
