-
Notifications
You must be signed in to change notification settings - Fork 373
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 reader macro for generator expressions #867
Comments
This is some proper hackery :) Interesting! I'm not huge on |
How about this? (defreader G [expr]
`(genexpr ~expr))
(tuple #G(x [x (range 12)] (even? x))) Yes, I know, no parens/braces saved. But still shorter... Can't put my finger on why, but The reason the "alias"-like reader macro feels better to me is that in Python, the syntax makes the generator expression simpler. So does the macro. If we put the |
The character that says "generator expression" to a Python programmer isn't I know this dashes any hope of Hy eventually using that syntax for an equivalent of Clojure's If we do create a reader macro alias for |
|
@gilch Do you still want this, considering that the new name for |
Admittedly, |
I don't think An updated approach might be
This could be a macro in terms of And, of course, this could be a tag macro instead.
Note that we're not restricted to a single-character tag now. I think |
That seems pretty reasonable, yeah. |
For Python generator expressions, the parentheses can be omitted on calls with only one argument:
This happens pretty often in Python.
tuple
is just a simple example.Hy has no such shortcut:
Since we seem eager to add syntactic sugar if Python has it (e.g. #860 #829), what do you guys think of adding something similar for generator expressions?
We could come close with a reader macro:
I'm not really sure if 'G' (for Generator expression) is the appropriate character. Perhaps we want to reserve the alphabet for end users?
Alternatively, perhaps we could use an ordinary macro?
Not sure if this is better.
The text was updated successfully, but these errors were encountered: