-
Notifications
You must be signed in to change notification settings - Fork 371
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
Hy models have wrong equality #1363
Comments
The fact that |
I'm honestly not a fan of how
I've been playing with a branch that makes |
Having have started to implement this change, I agree with vodik. There's a lot of obtuse implicit conversions going on in the code base which this rightfully gets rid of. There is one issue though when it comes to quoting. Currently |
That a macro can return an |
what would you suggest a user do to test tree equality if we're going to keep auto promotion? |
Use the interface I just mentioned; if there was some function |
so |
Yes. More precisely, it would recursively promote objects to their respective models. |
handily enough, |
Maybe a better name could be thought of, but I like |
maybe |
Hold on, on latest master I have => (= `(a ~(+ 2 3)) '(a 5))
hy.models.Expression([] + [hy.models.Symbol('a')] + [2 + 3]) == hy.models.Expression([] + [hy.models.Symbol('a')] + [hy.models.Integer(5)])
True
=> (= 5 '5)
5 == hy.models.Integer(5)
True Is there some other edge case that makes this a problem? |
That's the current behavior of the code, yeah. We haven't fixed it yet; we're just talking about fixing it. |
what do we actually get by hy autoboxing/unboxing values in this way? Gonna have to write docs for the behavior at some point |
|
any thoughts on names? The pr to close this is done otherwise. maybe |
My vote's for |
Note also the pleasing symmetry between |
my only issue with |
Those sound fine. Or |
|
looking over this again, is the only complaint of this equality the fact that symbols are equal to strings and compound types are equal to other compund types? If that's the case why not just make symbols only equal to symbols, leaving the other literals with the same equality, and compound types only equal to themselves? Gilch's compound example |
It seems more consistent to me to make models only equal to other models of the same kind for all types, not just keywords, symbols, and
That's only because |
i should have been more specific. is there any reason that having equality hypothetically work like this (and (= 1 '1)
(= 1j '1j)
(= 1.5 '1.5)
(= b"1" 'b"1")
(= :key ':key)
(= [1 2] '[1 2])
(= {1 2} '{1 2})
(= #{1 2} '#{1 2})
(!= 'asym "asym")
(!= (, 1 2) '[1 2])
(!= '[1 2] '{1 2})
(!= '{1 2} '#{1 2})) is a bad thing? That models are only equal to models of the same kind or their equivalent python literal (if it exists, |
One problem is that |
how would they both be equal? the elements are different |
Because |
ahhh got it. Could we have |
Then Another source of trouble is that Syntax is not the same thing as the object represented by the syntax. A programmer who wants to test syntax according to what it represents can always |
dictionaries do kind of throw this whole thing out of wack and i don't see a way to handle that properly so i'll go ahead and finalize the PR to make them only equal to models of the same kind |
Hy models are equal to other types.
For atoms, maybe this is okay?
It might even be convenient for symbols to be equal to strings, because Python uses strings pervasively when referring to its identifiers at runtime (e.g.
getattr
), though symbol mangling might confuse things in some cases.But for compound types, it gets weird.
The text was updated successfully, but these errors were encountered: