-
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
Leading -
should not get converted to underscores.
#1635
Comments
I have to admit that I never considered the possiblity of beginning a name with
That sounds reasonable.
But in that case, the user is no longer allowed to write a Python name that contains an internal underscore, like |
An important point, which makes the leading underscore problem something of a separate question from this. The tradeoff is that we don't get full invertiblity. I'd prefer there be one-- and preferably only one --obvious way to do it. That is--always use hyphens internally. Always write the dunder names the same way, like
I don't think idempotent functions can be invertible generally (except some trivial cases, like identity or singleton sets), since mapping the result back to itself when it started as something else means it can't be 1-to-1. We can't have both. So which property is more important? I thought it was invertiblity, since we're defining and using an inverse function, |
When I think about it, "idempotence" in this case is just a fancy way to say the earlier thing I said, "any Python name is also a valid Hy name with the same meaning"; i.e., every Python identifier mangles to itself. This property is equivalent to idempotence because So to answer your question, I would rather have Python names work unchanged as Hy names than have |
Welp, this is pretty much exactly what I proposed with #2005, I should have done my due diligence before creating a new issue. +1 to |
I went through and categorized all the issues and made a bit of an index for myself. I'll post it in discussions after i have the chance to clean it up some. |
If you define a converter function with a name like
Then it becomes module-private and you can't import it with
*
. (Unless you override this with__all__
.) This is a gotcha that Hy doesn't need.I propose we revise the mangling rules to distinguish leading
-
s from leading_
s. Any internal-
will continue to mangle to_
as now, but if they're in the lead, it becomesXhyphenHminusX
s, or preferably something shorter likeXsubX
s if we do the short names #1577. But leading_
won't change.We could also distinguish non-leading
_
s from-
s for full reversibility by converting them toXlow_lineX
(orXscoreX
).Dunder names would look weird if we had to write them like
__init--
, so trailing_
s will use the same rule as for the leading_
s. Then we'd write__init__
etc.Examples,
In summary, special characters get mangled to X-quoted forms except for leading
_
s, trailing_
s, and internal-
, which all convert to_
.The text was updated successfully, but these errors were encountered: