-
Notifications
You must be signed in to change notification settings - Fork 368
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
Add |
quotes and \
escapes to Hy symbols and keywords.
#1117
Comments
Wouldn't it be better to have something like |
I don't think so. That particular syntax isn't going to work, since it already means We could perhaps do a reader macro on a string like Clojure does for regex, but I didn't pull this syntax out of my nose. It is how Common Lisp does it and Scheme too. I think we need a better reason than "kirby doesn't like it" to break established convention with some other syntax, or we're just making things harder on Hy's users who may already be familiar with it.
It's perfectly readable.
looks a lot nicer than escapes like
but maybe that's just me... |
Although the practical use for this is slim, it would definitely be nice to have for the sake of completeness. To be clear, you want this to not only prevent manging (e.g., hyphens to underscores), but also to allow things like spaces and parentheses in symbols, right? Then it's probably worth thinking about exactly what characters are allowed. For example, can ASCII nulls be quoted? And in the context of Unicode, does a backslash apply to a single character, a single glyph, a single byte, or what? |
What's allowed depends on Python. I especially want to be able to prevent manging (without giving up manging), but any "attr" that Python's => ((lambda [fo?o] fo?o) 42)
(lambda fo?o: fo?o)(42) ; not valid Python!! AST doesn't care.
42 Local names get optimized to integers in bytecode anyway. Python already lets you name classes anything:
If Python can have such names, Hy should be able to evaluate them as symbols. Backslashes should escape anything that would otherwise cause Hy's reader to end the token. We could also let Python handle any remaining backslashes with the same rules as a Unicode string. |
@Kodiologist pointed out in #1327 that we could implement this as another prefix to string literals. E.g. We can almost do this with tag macros. Something like
Instead of And if we want to use arbitrary symbols in the tag macros themselves, it's not good enough. Something like
But I don't think it could work at all with the
The |
Common Lisp lets you use arbitrary strings as symbols. If you include certain characters you have to escape them, either by quoting the whole string in
||
, or with a\
per character.Common Lisp's reader uppercases symbols by default, but valid symbols can have lower case characters as demonstrated above. Hy's reader does similar shenanigans with
*
,-
,?
, and!
, yet does allow them in symbols.I propose we add the Common lisp style symbol quotes and escape to Hy, so if you really want the symbol to contain a
-
or end in?
(etc.), you can, but most of the time it will get mangled to something Python can use more easily as now. This could make Hy easier to work with when these details matter.The text was updated successfully, but these errors were encountered: