-
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
clean up rules for ?
#1115
Comments
Wow I didn't even realize this was a thing. Personally, I prefer either option 1 or 2. |
Yup, you can see all the conversions here. Note also that a Automagic really should be documented. Another trick--since it happens at the parser level, it is possible to keep the question mark: => 'query?
from hy import HySymbol
HySymbol('is_query')
'is_query'
=> (HySymbol "query?")
HySymbol('query?')
'query?' This kind of automagic makes me uncomfortable (it causes headaches, like #1100, etc.), but it really does make common Hy method names easier to use from Python. But if it's not a suffix, it doesn't count: => 'fo?o
from hy import HySymbol
HySymbol('fo?o')
'fo?o' It's really awkward to use a method named like that in Python. |
On second thought, the first two options are no good. Neither is the status quo. Recall that underscore prefixes have meaning in Python.
-- From PEP-8
-- Python docs Hy behaves the same way, except when the identifier ends with This inconsistency is unacceptable. Option 3 still works. Option 4Take the Canadian approach and use an Option 5Take Clojure's approach and replace all |
You're right that that inconsistency is no good, but it can also be addressed by altering mangling rules as follows: the "generated" |
On third thought, |
Hy converts a trailing
?
to anis_
prefix. This means that you can use a more lispy style for common predicate methods:But due to an unfortunate inconsistency in Python's naming conventions, it doesn't always work:
There's no underscore in
islower
! This appears to be the case for all string predicate methods. It may also be true elsewhere in the Python standard library, and therefore in other Python libraries.We may be able to adjust the rules to make this more consistent.
option 1Make a prefixed
?
become a prefixis
.This way, we can leave the suffix case (and any code using it) as-
is_
. But now there's three ways to writeis_integer
,?-integer
, andinteger?
.option 2Make a suffix
?
become a prefixis
and suffix-?
become a prefixis_
.This can break existing Hy code, but we're doing that anyway.
option 3
Remove the special treatment of
?
. Use the same names in Hy as in Python. Hy becomes more consistent and less magical. Hy names ending in?
become as difficult to use in Python as Hy names with an embedded?
are now. But it's still possible withgetattr
.We could probably come up with more options, but in any case, it needs to be documented. I didn't see the current
?
rule in the docs either.The text was updated successfully, but these errors were encountered: