# New dispatch for isless() does not work

**URL:** https://discourse.julialang.org/t/new-dispatch-for-isless-does-not-work/74025
**Category:** General Usage
**Tags:** question, numerics, function, multidispatch
**Created:** [January 4, 2022, 11:16am UTC](https://discourse.julialang.org/t/new-dispatch-for-isless-does-not-work/74025 "2022-01-04T11:16:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jafar.isbarov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jafar.isbarov/32/36130_2.png) [@jafar.isbarov](https://discourse.julialang.org/u/jafar.isbarov)
#### Post date: [January 4, 2022, 11:16am UTC](https://discourse.julialang.org/t/new-dispatch-for-isless-does-not-work/74025/1 "2022-01-04T11:16:58Z")

</div>

I need to be able to compare instances of a struct named `Hijri`, so I have defined a new method for the `isless()` function as follows:

```julia
function isless(a::Hijri, b::Hijri)
	tuple_a = datetuple(a)
	tuple_b = datetuple(b)
	
	return tuple_a < tuple_b
end

```

`datetuple()` returns values of the Hijri struct as a tuple.

This works fine:

```julia
@show isless(a, b)

```

However, this one

```julia
@show a < b

```

throws an error:

```julia
ERROR: LoadError: MethodError: no method matching isless(::Main.HijriConverter.Hijri, ::Main.HijriConverter.Hijri)
Closest candidates are:
  isless(::Any, ::Missing) at ~/Downloads/julia-1.7.0/share/julia/base/missing.jl:88
  isless(::Missing, ::Any) at ~/Downloads/julia-1.7.0/share/julia/base/missing.jl:87
Stacktrace:
 [1] <(x::Main.HijriConverter.Hijri, y::Main.HijriConverter.Hijri)
   @ Base ./operators.jl:352
 [2] top-level scope
   @ show.jl:1047
in expression starting at /home/jafar_isbarov/Documents/projects/hijri/HijriConverter.jl/src/HijriConverter.jl:1

```

What could be the reason?

---

<div class="post-metadata">

### Author: ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)
#### Post date: [January 4, 2022, 11:20am UTC](https://discourse.julialang.org/t/new-dispatch-for-isless-does-not-work/74025/2 "2022-01-04T11:20:34Z")

</div>

You may have forgotten to `import` `isless` from `Base` or you can use `Base.isless` in your function definition.

use this before `isless` definition

```julia

import Base: isless

```

or define the function as below to extend existing definition in Base

```julia

function Base.isless(...)

end

```

---

<div class="post-metadata">

### Author: ![jafar.isbarov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jafar.isbarov/32/36130_2.png) [@jafar.isbarov](https://discourse.julialang.org/u/jafar.isbarov)
#### Post date: [January 4, 2022, 11:23am UTC](https://discourse.julialang.org/t/new-dispatch-for-isless-does-not-work/74025/3 "2022-01-04T11:23:31Z")

</div>

Thanks!
