-
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
Comparisons for number, string, array, and record #1985
Conversation
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.
Thanks a lot for taking this on! It looks pretty good, beside a few secondary comments.
core/stdlib/std.ncl
Outdated
@@ -2761,6 +2810,23 @@ | |||
|> std.array.filter (fun { field, value } => f field value) | |||
|> from_array, | |||
|
|||
on |
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 feel like the name of this function is not very descriptive of what it does. I don't have a great inspiration right now, and it is a bit hard to describe as it's pretty abstract. We'll bikeshed that in the weekly meeting tomorrow and I'll report back here.
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.
Yeah, it's not obvious to me what to call this. For what it's worth, Haskell has a function on
that is very similar:
(b -> b -> c) -> (a -> b) -> a -> a -> c
The Nickel function here is the same as Haskell's on
except:
- the arguments are flipped
a
is specialized to{ _ : b }
(a -> b)
is specialized to accessing a named field
Curious to hear how the bikeshedding goes.
use std::cmp::Ordering; | ||
Ok(Closure::atomic_closure(RichTerm::new( | ||
Term::Enum(LocIdent::new_with_pos( | ||
match s1.cmp(s2) { |
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.
At first I thought we would need to do something unicode-aware, because Nickel uses everywhere grapheme clusters as its unit of string characters. However, the Rust comparison is just comparing byte by byte lexicographically. I guess doing that, or first splitting by grapheme clusters, and then comparing cluster by cluster (using the normal string comparison) is entirely equivalent, so this is fine.
Thanks @yannham! I made the changes you suggested. |
With 4th of July and unrelated stuff, the weekly was rather empty, so let's bikeshed a bit here. I think
|
I've been thinking about these names for an embarrassingly long amount of time and I'm starting to get semantic satiation 😅 Variants of I considered
I kind of like That leaves my top choices as The use case that motivated me to open this PR in the first place was sorting an array of records by name. Here's how that looks with these options:
I'm not committed to those, though, and I'm happy for you to unilaterally make a call. You have a lot more invested in nickel than I do. |
Thanks for your input. I think I like |
@yannham Done. |
Great. Thanks again for contributing! |
Hello! This is my first PR to Nickel.
I was writing some Nickel configuration today and found myself wanting string comparisons. I found this open issue, and decided to take a shot at it.
Resolves #1030