elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.65k stars 299 forks source link

Move the `cmp` function into the `vals` package #1700

Closed krader1961 closed 1 year ago

krader1961 commented 1 year ago

This moves the value comparison logic into pkg/eval/vals so it can be used by packges other than eval. For example, the vals package repr implementation as well as other Elvish modules which may want to compare Elvish values. This is a baby step to augmenting all the code which order values, or might want to (e.g., the pprint command), to also handle ordering otherwise uncomparable types.

Related #1495

krader1961 commented 1 year ago

I'm going to open a new pull-request with the enhancement I discussed in PR #1698 to treat the values of types not explicitly recognized as being equal. Thus eliminating one source of unexpected exceptions when doing things like compare $nil $nil or put ?(fail y) ?(fail x) | order since the types or obviously comparable while the current behavior says they are not comparable.