Giter VIP home page Giter VIP logo

Comments (5)

baiango avatar baiango commented on August 28, 2024

I tried to write complement_range(), but then got distracted by a squirrel and left it in this state.

from julia.

baiango avatar baiango commented on August 28, 2024

Updated Minimal Reproducible Example

mutable struct MutRange
	start::Int
	finish::Int
end

struct Range # has to be mutable
	start::Int
	finish::Int
end

println(MutRange(1, 3) == MutRange(1, 3)) # false

println(Range(1, 3) == Range(1, 3)) # true

println((1, 3) == (1, 3)) # true

Julia REPL

   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.4 (2024-06-04)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> mutable struct MutRange
           start::Int
           finish::Int
       end

julia>

julia> struct Range # has to be mutable
           start::Int
           finish::Int
       end

julia>

julia> println(MutRange(1, 3) == MutRange(1, 3)) # false
false

julia>

julia> println(Range(1, 3) == Range(1, 3)) # true
true

julia>

julia> println((1, 3) == (1, 3)) # true
true

julia>

from julia.

fredrikekre avatar fredrikekre commented on August 28, 2024

See https://docs.julialang.org/en/v1/base/math/#Base.:==. In particular

Falls back to ===.

from julia.

baiango avatar baiango commented on August 28, 2024

I have encountered an issue where the comparison of mutable structs with identical field values returns false, even when using the == and === operators.

Here's a minimal reproducible example:

mutable struct MutRange
	start::UInt32
	finish::UInt32
end

println(MutRange(1, 3) == MutRange(1, 3)) # false
println(MutRange(1, 3) === MutRange(1, 3)) # false

Based on the documentation at https://docs.julialang.org/en/v1/base/math/#Base.:==, the == operator falls back to === for structs. However, in this case, both comparisons return false.

Could you please investigate this issue and provide guidance on how to correctly compare mutable structs with identical field values?

from julia.

fredrikekre avatar fredrikekre commented on August 28, 2024

the == operator falls back to === for structs. However, in this case, both comparisons return false.

Yes, == calls === so they return the same value.

provide guidance on how to correctly compare mutable structs

The forum at https://discourse.julialang.org/ is better suited for discussion and questions like this.

from julia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.