-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
WIP: Use (::Symbol) as curried getproperty #60271
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
base: master
Are you sure you want to change the base?
Conversation
This implements the suggestion in #53946 (comment) and defined `(s::Symbol)(x) = getproperty(x, s)`. In addition, we defined `getproperty(::Symbol, ::Symbol)` to return the lens object I suggested in #53946. Together this satisfies the requirements I had for #53946 while not requiring any parser changes.
|
I've played around with this a little bit and I like it. Examples: |
| curried form of `getproperty` (equivalently `Fix1(getproperty, s)`). | ||
| !!! compat "Julia 1.14" | ||
| This behavior feature at least Julia 1.14. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| This behavior feature at least Julia 1.14. | |
| This feature requires at least Julia 1.14. |
| Constructs a curried accessor for the `s`.`a`.`b` property of some future struct | ||
| `s`. This essentially extends the currying-behavior of symbols into nested | ||
| hieararchies. See also `(s::Symbol)(obj)`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| hieararchies. See also `(s::Symbol)(obj)`. | |
| hierarchies. See also `(s::Symbol)(obj)`. |
To me this seems like an extremely odd pun on what Does this mean To be honest, I'm not a fan. The syntax looks very subtle and easy to skip when reading code. The distinction between property access on |
|
One could extend on the single-argument @Seelengrab, what do you think about this? |
|
@jonas-schulze please see #53946 and the discussions within for proposing more variations on syntax for this feature. |
I did. My subscription to that issue has brought me here. I simply meant to address your concern by an epsilon modification of what Keno did here. Mind giving feedback (or a mere 👍 / 😕 / 👎 reaction) on my question? |
That is the proposal, yes. |
To be clear, while I think this variant is fine, it does not meet my requirements. The whole point is that there needs to be a very short syntax for this, because i want to use it as an accessor. |
|
FWIW, I do agree that it is not necessarily intuitive that Symbol has this call overload, but it does pass my general criteria in that:
|
This implements the suggestion in #53946 (comment) and defines
(s::Symbol)(x) = getproperty(x, s). In addition, we definegetproperty(::Symbol, ::Symbol)to return the lens object I suggested in #53946. Together this satisfies the requirements I had for #53946 while not requiring any parser changes.