# Why is this code nondeterministic?

**URL:** <https://discourse.julialang.org/t/why-is-this-code-nondeterministic/6331>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 8, 2017, 9:06pm UTC](https://discourse.julialang.org/t/why-is-this-code-nondeterministic/6331 "2017-10-08T21:06:39Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [October 8, 2017, 9:06pm UTC](https://discourse.julialang.org/t/why-is-this-code-nondeterministic/6331/1 "2017-10-08T21:06:39Z")

</div>

I don’t understand what is going on with the code below (MWE): the first invocation of `isequal` is `false`, from then on it is `true`. Running `v0.6`.

```julia
struct MaybeParsed{T}
    pos::Int
    value::T
    MaybeParsed{T}(pos) where {T} = new{T}(pos)
    MaybeParsed{T}(pos, value::T) where {T} = new{T}(pos, value)
    MaybeParsed(pos, value::T) where {T} = new{T}(pos, value)
end

function Base.isequal(x::MaybeParsed{Tx}, y::MaybeParsed{Ty}) where {Tx,Ty}
    if isbits(Tx) && isbits(Ty)
        (x.pos == y.pos) & ifelse(x.pos > 0, isequal(x.value, y.value), true)
    else
        x.pos == y.pos && (x.pos > 0 ? isequal(x.value, y.value) : true)
    end
end

isequal(MaybeParsed{Int}(1), MaybeParsed{Int}(1)) # false

isequal(MaybeParsed{Int}(1), MaybeParsed{Int}(1)) # true

```

---

<div class="post-metadata">

**Author:** ![Evizero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evizero/32/10118_2.png) [@Evizero](https://discourse.julialang.org/u/Evizero)\
**Post date:** [October 8, 2017, 9:11pm UTC](https://discourse.julialang.org/t/why-is-this-code-nondeterministic/6331/2 "2017-10-08T21:11:26Z")

</div>

It doesn’t look like you initialize `value`, yet it is used for computing the result of `isequal`.

---

<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:** [October 8, 2017, 9:12pm UTC](https://discourse.julialang.org/t/why-is-this-code-nondeterministic/6331/3 "2017-10-08T21:12:17Z")

</div>

Indeed. Sorry, silly mistake after refactoring, forgot to switch signs.
