-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Add @get! #1764
RFC: Add @get! #1764
Conversation
I like |
This pull request should also include an update to the documentation, so that one knows which |
In Toivo, you can use |
All good points. About doing the lookup twice: It didn't feel sane to provide a Anyways, I have now eliminated the second lookup for Once we have specialization on function arguments, I think a cleaner implementation would be with a method
where |
I found a mutation version of |
How about having some syntax for |
My original pull request included |
Bump. Personally I prefer this to the operator idea. |
Unsurprisingly, I prefer the operator proposal – just the original bit. Using macros for something as basic as this seems really ugly to me. |
Please keep It seems much less confusing to the user to have all the forms than to have one of the four arbitrarily missing. "Too many gets" is much less annoying than "all the gets except the one you want." The manual could make it really obvious with a simple table:
|
Since we added the higher-order method for get, I think we can close this. I still favor adding some syntax for default assignment – i.e. |
Yes, we should keep track of the operator somewhere. |
As per this discussion.
Already,
get(d::Associative, key, default)
returns the value atkey
if one exists, ordefault
otherwise.This patch adds
get!
,@get
, and@get!
:get!
and@get!
assigndefault
tod[key]
if it's not present.They return
d[key]
(i.e. the converted value).@get
and@get!
evaluatedefault
only ifkey
is missing.Thoughts? I think that at least
@get!
would provide a useful addition toBase
.Edit: I removed everything but
@get!
(and made it avoid the extra lookup when applied to aDict
)