You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Slice implements the equality operator == as structural equality, i.e. two instances are considered equal if they have equivalent content.
Two instances are considered equal if they have the same values: Slice[1, 2, 3] == Slice[1, 2, 3] (or even just values expressing the same concept in different types: Slice[1.0, 2.0, 3.0] == Slice[1, 2, 3]).
There is no method for referential equality, i.e. if two instances pointing to the same memory. Slice is a struct type but it wraps a pointer, so it has semantics similar to a reference type.
Referential equality would be similar to equality of the pointers, but checking size as well - Slice is a pointer plus size.
Usually this is implemented as #same? and I think this would work well for Slice.
Related to referential equality and the implementation of same? is also #object_id. For example Set is a struct type but behaves like a reference because it's a wrapper of an reference type. It implements both #same? and #object_id (which just delegate to the wrapped reference). This doesn't work for Slice because the wrapped pointer is not the only defining characteristic. Size is relevant as well.
So I don't think #object_id makes sense for Slice because the pointer address is not unique. Two Slice instances can share the same pointer address, but with different sizes they would still be referentially unequal.
The text was updated successfully, but these errors were encountered:
Slice
implements the equality operator==
as structural equality, i.e. two instances are considered equal if they have equivalent content.Two instances are considered equal if they have the same values:
Slice[1, 2, 3] == Slice[1, 2, 3]
(or even just values expressing the same concept in different types:Slice[1.0, 2.0, 3.0] == Slice[1, 2, 3]
).There is no method for referential equality, i.e. if two instances pointing to the same memory.
Slice
is a struct type but it wraps a pointer, so it has semantics similar to a reference type.Referential equality would be similar to equality of the pointers, but checking
size
as well -Slice
is a pointer plus size.Usually this is implemented as
#same?
and I think this would work well forSlice
.Related to referential equality and the implementation of
same?
is also#object_id
. For exampleSet
is a struct type but behaves like a reference because it's a wrapper of an reference type. It implements both#same?
and#object_id
(which just delegate to the wrapped reference). This doesn't work forSlice
because the wrapped pointer is not the only defining characteristic. Size is relevant as well.So I don't think
#object_id
makes sense forSlice
because the pointer address is not unique. TwoSlice
instances can share the same pointer address, but with different sizes they would still be referentially unequal.The text was updated successfully, but these errors were encountered: