Re: sorted?

Mikael Djurfeldt <[email protected]>
Newsgroups gmane.lisp.guile.user
Message-ID <CAA2XvwKf54Ep74wpRJGRG9xXN0n9-LwejaD9+8bkKo_PfQephQ@mail.gmail.com>
On Mon, Dec 9, 2024 at 7:59 PM <[email protected]> wrote:

> > (= a b) is equivalent to (not (or (< a b) (> a b)))
>
> Yes, but for that, you have to know what "=" is. Is it eq? Is it
> eqv? Is it equal? (yeah, lame pun with question marks). Or is it
> (see below)?
>

It's equal in the sense of (not (or (< a b) (> a b)). If < is Scheme <
(i.e. comparing numbers), then this is completely equivalent with Scheme =.


> > The reason why you need to pass less to sort is that sort needs a way to
> > determine when an object should go before another one. Let's for example
> > take the example of a list of neuronal spike events. Each event is (TIME
> .
> > ID). It could be unsorted because the data might come from different
> > detectors. To sort the list in time, we would call sort like this:
> >
> > (sort '((0.73 . 7) (0.23 . 3) (0.54 . 17) (0.27 . 98)) (lambda (x y) (<
> > (car x) (car y))))
>
> So here you'd need your equal to be (eq (car x) (car y)), right?
>

As I've tried to convey, you don't need equal when sorting using `sort'.
But the equal corresponding to < is = in Scheme.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.