Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference equality on numbers that aren't non-small integers #23

Open
ltratt opened this issue Sep 27, 2019 · 2 comments
Open

Reference equality on numbers that aren't non-small integers #23

ltratt opened this issue Sep 27, 2019 · 2 comments
Labels
spec Needs specification, or is specification related.

Comments

@ltratt
Copy link

ltratt commented Sep 27, 2019

AIUI, = means "perform equality check on an object's data" and == means "pointer equality". However the latter is overriden for small integers, but not big integers or doubles. So, given this program:

obj1 = (
    run = (
        (1 == 1) println.
        (100 == 100) println.
        ((1 << 200) == (1 << 200)) println.
        (1.0 == 1.0) println.
    )
)

the output in java-som is:

true
true
false
false

In the interests of consistency, I tend to think those should all be true or all be false. If they should all be false, then one has trickier cases like 1 == 1.0 and so on. Perhaps reference equality should always return false for numbers?

ltratt added a commit to ltratt/yksom that referenced this issue Sep 27, 2019
This is roughly equivalent to the `is` operator in Python, although the precise
semantics in the face of numbers is muddy (see
SOM-st/SOM#23).
@smarr smarr added the spec Needs specification, or is specification related. label Sep 27, 2019
@smarr
Copy link
Member

smarr commented Sep 27, 2019

For integers, the test suite prefers that == works on all value ranges:
https://github.com/SOM-st/SOM/blob/master/TestSuite/IntegerTest.som#L30-L53

Thus, I'd consider this "specified", and (1 << 200) == (1 << 200) should be true.

Though for Double, there aren't any tests.

Historically, pointer equality was always a point where one was able to observe implementation strategy.
Form a language design perspective, I'd argue, one wants to avoid such leaky abstractions, and 1.0 == 1.0 should be true.

For 1 == 1.0, I actually argue that it should be false. These are clearly not the same objects.
Returning always false seems like a legal but lazy hack.

Unrelated, there is a strong precedence and preference for class names alway to start with a capital letter. obj1 really needs to be Obj1.

@ltratt
Copy link
Author

ltratt commented Sep 27, 2019

Thus, I'd consider this "specified", and (1 << 200) == (1 << 200) should be true.

Makes sense.

For 1 == 1.0, I actually argue that it should be false. These are clearly not the same objects.

OK, fair enough, I can certainly live with that.

I'll adjust yksom accordingly.

ltratt added a commit to ltratt/yksom that referenced this issue Sep 28, 2019
This is roughly equivalent to the `is` operator in Python in that it checks
normal objects for pointer equality, but numbers are checked for value equality.
Note that SOM (or, at least, java-som) doesn't define/implement the latter cases
properly yet (see SOM-st/SOM#23) so this commit makes
us diverge slightly.
ltratt added a commit to ltratt/yksom that referenced this issue Oct 8, 2019
This is roughly equivalent to the `is` operator in Python in that it checks
normal objects for pointer equality, but numbers are checked for value equality.
Note that SOM (or, at least, java-som) doesn't define/implement the latter cases
properly yet (see SOM-st/SOM#23) so this commit makes
us diverge slightly.
bors bot added a commit to softdevteam/yksom that referenced this issue Oct 9, 2019
55: More comparisons r=ptersilie a=ltratt

This PR adds more comparisons to yksom: reference equality (1dca2bc) and various comparisons for doubles (82d35c5). Notice that the former commit means that we diverge slightly from SOM's current semantics (see SOM-st/SOM#23) although I think it's fair to say that @smarr thinks the approach we're taking in this PR is the right one (and if I've got that wrong, hopefully he'll shout!).

Co-authored-by: Laurence Tratt <[email protected]>
bors bot added a commit to softdevteam/yksom that referenced this issue Oct 9, 2019
55: More comparisons r=vext01 a=ltratt

This PR adds more comparisons to yksom: reference equality (1dca2bc) and various comparisons for doubles (82d35c5). Notice that the former commit means that we diverge slightly from SOM's current semantics (see SOM-st/SOM#23) although I think it's fair to say that @smarr thinks the approach we're taking in this PR is the right one (and if I've got that wrong, hopefully he'll shout!).

Co-authored-by: Laurence Tratt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec Needs specification, or is specification related.
Projects
None yet
Development

No branches or pull requests

2 participants