-
Notifications
You must be signed in to change notification settings - Fork 90
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 get value from record with supplying default #1920
Conversation
a6bc2a2
to
ce7f775
Compare
Or maybe would be better to have dedicated syntax for that? |
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.
I originally wrote a comment but it's probably been lost in draft state, on the topic of having a dedicated syntax for that. I'm personally not a fan of making the syntax more complex just for a little convenience - especially in Nickel which we want to remain mostly readable to non-experts. Additionally, whether we add a new syntax or not at some point, it's still useful to have the function version, for example to pass to higher-order functions like array.map
or record.map
.
Beside the previous suggestions, looks good to me! The tests are currently failing because of my bogus suggestion, see the corresponding comment (it's r."%{field}"
, not field."%{r}"
). We can merge once it's fixed.
🤦 actually I haven't time to just property analyse it... Just applied your suggestions... |
7700474
to
ea41f82
Compare
Maybe also would be sensible to add |
core/stdlib/std.ncl
Outdated
"default" | ||
``` | ||
"% | ||
= fun n default_value l => |
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.
= fun n default_value l => | |
= fun n default_value array => |
core/stdlib/std.ncl
Outdated
``` | ||
"% | ||
= fun n default_value l => | ||
if n < %length% then |
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 primop is missing an argument.
if n < %length% then | |
if n < %length% array then |
Thanks for next review with obvious findings:) those %s misleads, and also I am used to According to names as you propose name "array" I'll do the same for "record". |
e224f7e
to
fa7e379
Compare
OK, it seems that I should update those tests snapshots, as there are different line numbers in some cases... Am I right, @yannham ? |
fa7e379
to
fc14523
Compare
Ah, yes, we have a test which checks all the snippets in the manual, including their output, by actually running the code and capturing the result. Which means some error needs to be updated when they point to inside the stdlib and the line numbers in stdlib have changed. It's a bit annoying (but those tests are still very useful to make sure we keep the examples in the manual up to date). It seems this is what's failing in the CI. You can trigger those tests with |
fc14523
to
7d7fc5a
Compare
@yannham Hmm, I got some strange errors after adding |
I'm always fine with smaller changes 🙂 we can do |
Of course, only if you feel it valuable I can do next MR with |
As I see there is lacking the function in stdlib for getting values from the record with assumed default in case field is lacking. Or maybe there is another idiomatic method for that, which I miss?
The name of the function could be discussed...Personally for me
get
would be the best, but it is reserved already;-> do you have better ideas?Here also documentation should be extended...
What do you, @yannham think about it?