* Re: lexicographic list comparison
2022-09-10 9:07 ` Mattias Engdegård
@ 2022-09-10 9:22 ` Emanuel Berg
2022-09-10 9:26 ` tomas
2022-09-12 14:45 ` Sam Steingold
2 siblings, 0 replies; 10+ messages in thread
From: Emanuel Berg @ 2022-09-10 9:22 UTC (permalink / raw)
To: emacs-devel
Mattias Engdegård wrote:
>> Or maybe sorting lists of lists is just such a rare op that
>> no one has ever encountered it before me?
>
> It would be useful to have a total ordering on Lisp values:
> for heterogeneous ordered collections, for simplifying
> multi-key sorting, for normalising unordered
> collections, etc.
>
> The devil is in the details: are strings compared with our
> without properties? Do we observe the wonky IEEE rules for
> ordering floats? Is there a particularly useful ordering
> between elements of different types? Do we need to worry
> about circularity? How do we compare hash tables? And so on.
>
> Consistency with `equal` would be desirable (up to hash
> table identity, perhaps).
Interesting, what is this, type theory?
Sounds like something that is available in Haskell maybe ...
What is the benefit if you have it? Sort things recursively
and with no fear running into data of a type that would
wreck it?
It's easy to do, (order-pair a b) which accepts any an all
data and returns the list (a b) iff a < b. It could first
check types, then delegate the task to the existing
greater-than function for all cases that ... makes sense.
Making up rules that makes sense for everything that don't
make sense to compare is maybe more difficult ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lexicographic list comparison
2022-09-10 9:07 ` Mattias Engdegård
2022-09-10 9:22 ` Emanuel Berg
@ 2022-09-10 9:26 ` tomas
2022-09-12 14:45 ` Sam Steingold
2 siblings, 0 replies; 10+ messages in thread
From: tomas @ 2022-09-10 9:26 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1109 bytes --]
On Sat, Sep 10, 2022 at 11:07:49AM +0200, Mattias Engdegård wrote:
> 9 sep. 2022 kl. 21.27 skrev Sam Steingold <sds@gnu.org>:
>
> > What do you do when sorting a list of lists of numbers?
>
> Sigh deeply and write ad-hoc code for the nth time.
:-)
> It would be useful to have a total ordering on Lisp values: for heterogeneous ordered collections, for simplifying multi-key sorting, for normalising unordered collections, etc.
>
> The devil is in the details: are strings compared with our without properties? Do we observe the wonky IEEE rules for ordering floats? Is there a particularly useful ordering between elements of different types? Do we need to worry about circularity? How do we compare hash tables? And so on.
>
And language-dependent collation, and Unicode equivalence, and NaNs
and...
Details, indeed :-)
A look at the troubles and tribulations a DBMS goes through gives one
a rough idea on how interesting a general solution can become...
> Consistency with `equal` would be desirable (up to hash table identity, perhaps).
This, too :)
Cheers
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lexicographic list comparison
2022-09-10 9:07 ` Mattias Engdegård
2022-09-10 9:22 ` Emanuel Berg
2022-09-10 9:26 ` tomas
@ 2022-09-12 14:45 ` Sam Steingold
2022-09-12 17:53 ` mattiase
2 siblings, 1 reply; 10+ messages in thread
From: Sam Steingold @ 2022-09-12 14:45 UTC (permalink / raw)
To: emacs-devel, Mattias Engdegård
> * Mattias Engdegård <znggvnfr@npz.bet> [2022-09-10 11:07:49 +0200]:
>
> 9 sep. 2022 kl. 21.27 skrev Sam Steingold <sds@gnu.org>:
>
>> What do you do when sorting a list of lists of numbers?
>
> Sigh deeply and write ad-hoc code for the nth time.
okay, so, I suppose, you find the `lexicographic-compare-lists' from TS
useful, right?
>> Or maybe sorting lists of lists is just such a rare op that no one has
>> ever encountered it before me?
>
> It would be useful to have a total ordering on Lisp values: for
> heterogeneous ordered collections, for simplifying multi-key sorting,
> for normalising unordered collections, etc.
I certainly have no intention of comparing strings with numbers &c.
My question was about a list of _homogeneous_ lists, and comparing to,
say, lists of numbers, is done lexicographically based on number
comparison.
--
Sam Steingold (https://aphar.dreamwidth.org/) on darwin Ns 10.3.2113
https://lastingimpactpsychology.com https://steingoldpsychology.com
https://www.peaceandtolerance.org/ https://www.memritv.org
When C++ is your hammer, everything looks like a thumb.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lexicographic list comparison
2022-09-12 14:45 ` Sam Steingold
@ 2022-09-12 17:53 ` mattiase
2022-09-12 18:31 ` Stefan Monnier
2022-09-12 18:35 ` Sam Steingold
0 siblings, 2 replies; 10+ messages in thread
From: mattiase @ 2022-09-12 17:53 UTC (permalink / raw)
To: sds; +Cc: emacs-devel
12 sep. 2022 kl. 16.45 skrev Sam Steingold <sds@gnu.org>:
> okay, so, I suppose, you find the `lexicographic-compare-lists' from TS
> useful, right?
(What is TS in this context?)
I usually just copy-paste code from an older project of mine (who doesn't?) because that way I know that it works, how it works, what its performance is like, etc.
> I certainly have no intention of comparing strings with numbers &c.
> My question was about a list of _homogeneous_ lists, and comparing to,
> say, lists of numbers, is done lexicographically based on number
> comparison.
We could certainly add comparison functions for lists, then ones for arrays, then for hash tables, and so on. Or just write one that works for all built-in types and impose an ordering between objects of distinct types. It would be more useful (if harder to write).
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lexicographic list comparison
2022-09-12 17:53 ` mattiase
@ 2022-09-12 18:31 ` Stefan Monnier
2022-09-12 18:41 ` Sam Steingold
2022-09-12 18:35 ` Sam Steingold
1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2022-09-12 18:31 UTC (permalink / raw)
To: mattiase; +Cc: sds, emacs-devel
>> I certainly have no intention of comparing strings with numbers &c.
>> My question was about a list of _homogeneous_ lists, and comparing to,
>> say, lists of numbers, is done lexicographically based on number
>> comparison.
>
> We could certainly add comparison functions for lists, then ones for arrays,
> then for hash tables, and so on. Or just write one that works for all
> built-in types and impose an ordering between objects of distinct types. It
> would be more useful (if harder to write).
We could write a `cl-defgeneric` with a few basic instances.
Another option is to provide combinators: e.g. provide a `list-compare`
function which takes the comparison function to use for the elements and
return a comparison function that works of lists of such elements, so
you can do things like:
(sort foo (list-compare (list-compare #'<)))
[ Tho I suspect you'll want those comparison functions to return
a -1/0/1 result rather than just a boolean, so you'd need an extra
combinator to turn such a comparison function into the kind expected
by `sort`. ]
-- Stefan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lexicographic list comparison
2022-09-12 17:53 ` mattiase
2022-09-12 18:31 ` Stefan Monnier
@ 2022-09-12 18:35 ` Sam Steingold
1 sibling, 0 replies; 10+ messages in thread
From: Sam Steingold @ 2022-09-12 18:35 UTC (permalink / raw)
To: emacs-devel, mattiase
> * <znggvnfr@npz.bet> [2022-09-12 19:53:42 +0200]:
>
> 12 sep. 2022 kl. 16.45 skrev Sam Steingold <sds@gnu.org>:
>
>> okay, so, I suppose, you find the `lexicographic-compare-lists' from TS
>> useful, right?
>
> (What is TS in this context?)
TS=topic start (the initial message in the thread)
> I usually just copy-paste code from an older project of mine (who
> doesn't?) because that way I know that it works, how it works, what
> its performance is like, etc.
I abhor code copying.
If I find that I reuse a function, I put it into a library.
>> I certainly have no intention of comparing strings with numbers &c.
>> My question was about a list of _homogeneous_ lists, and comparing to,
>> say, lists of numbers, is done lexicographically based on number
>> comparison.
>
> We could certainly add comparison functions for lists, then ones for
> arrays,
nah, all sequences are compared the same way.
> then for hash tables, and so on.
> Or just write one that works for all built-in types and impose an
> ordering between objects of distinct types. It would be more useful
> (if harder to write).
I seriously doubt this could be useful.
--
Sam Steingold (https://aphar.dreamwidth.org/) on darwin Ns 10.3.2113
https://lastingimpactpsychology.com https://steingoldpsychology.com
https://iris.org.il https://ij.org/ https://jij.org https://camera.org
Calculus has its limits.
^ permalink raw reply [flat|nested] 10+ messages in thread