-
Notifications
You must be signed in to change notification settings - Fork 372
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 implicit tuples to . DSL #1481
Comments
Looks pretty cool. It is a bit weird that square brackets, which are usually used to define a list, end up defining a tuple here. But the same criticism applies to Python, so that's not our fault. |
Technically, it's the comma that makes a tuple in Python, not the parentheses (with the single exception of the empty tuple). It's just that syntactically, you often need them. Inside a subscript operator is one of the cases where you don't. But |
Somewhat related - how do you all feel about implementing |
I just demonstrated that in #541. In the context of the tag macro, it's an alias. But dots do weird things to Hy expressions, since they interfere with our syntax for dotted lists. You can't just |
I managed to get hy to support Ellipsis:
Its actually a very small patch, I'll put up a PR shortly. |
is this still relevant with the addition of |
Probably not. |
Something I mentioned in #911, Python code often passes tuples to the subscript operator
[]
, in numpy code especially (for multidimensional slices), and now in the typing module's generics. Currently you can write things like,But since we're already declaring a list, the tuple seems redundant. So we could simplify it to.
So a single item would be passed to the subscript as-is, but multiple items would implicitly have a tuple wrapped around them. In the rare case you actually want a single-item tuple, you can still do that explicitly, since it's a single item passed as-is.
In fact, the old syntax would still work as-is, even if the tuple had multiple items, since it would be a single item, passed as-is.
With more compact notation for slice objects, #541 we could improve the slice sytanx further.
I'm reluctant to propose anything that complicates the compiler. But there's really no reason the
.
DSL couldn't be a macro, provided a more basic.*
special form for attribute access only. We could also add calls to the chain #1108.The text was updated successfully, but these errors were encountered: