Comments (5)
I tried to write complement_range()
, but then got distracted by a squirrel and left it in this state.
from julia.
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.
See https://docs.julialang.org/en/v1/base/math/#Base.:==. In particular
Falls back to ===.
from julia.
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.
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)
- Ambiguous behavior of Tuple constructor with mismatched array length HOT 2
- RetentionParameterEstimator hits incorrect assert in emit_masked_bits_compare
- Monorepo Packages via Submodules/Subpackages: Support in Pkg and Julia Compiler HOT 14
- Circular dependency detected for Symbolics.jl on Julia 1.11.0-rc2 HOT 7
- [REPL] Autocompletion of `ModuleName.@macro_name` is broken
- [REPL] Autocompletion of `@benchmark A .= A setup=(A=` is broken
- Deadlock doing I/O on a foreign thread while the main thread is blocked HOT 5
- `Conditional` lattice element is semantically broken in the presence of SSAValues HOT 1
- `Base.summarysize(::Symbol)` returns zero
- Mention accuracy of `Base.summarysize` in docstring
- `__init__` side effects order is not defined, such that any global effects from `__init__` are a data race HOT 3
- Extension cycles are problematic (long `precompile` times, difficult to understand/resolve) HOT 4
- Add tests about layout of Int128
- Defining `sum(f, ::MyArray; dims)` breaks `sum(::MyArray)`
- Choose number of OpenBLAS threads based on process affinity HOT 6
- `Iterators.rest` gives wrong result for `AbstractRange` HOT 4
- `define_editor` should default to `wait=true` HOT 1
- Type instability when using intrinsics as higher order functions HOT 7
- Can't sum partially initialized non-isbits Hermitian or Symmetric matrix with Diagonal or SymTridiagonal HOT 2
- `--project=@script` is broken or NEWS entry is incorrect (Julia 1.11.0-rc3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia.