emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lexicographic list comparison


From: Stefan Monnier
Subject: Re: lexicographic list comparison
Date: Mon, 12 Sep 2022 14:31:33 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

>> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]