On Mon, Dec 09, 2024 at 07:32:09PM +0100, Mikael Djurfeldt wrote: > On Mon, Dec 9, 2024 at 2:11 PM <to...@tuxteam.de> wrote: > > > On Mon, Dec 09, 2024 at 01:58:08PM +0100, Mikael Djurfeldt wrote: > > > > [...] > > > > > No problem---I'm too. > > > > > > Think about it this way: > > > > > > How would you sort this list of numbers: 7 1 3 8 2 1 4 ? > > > > > > It's 1 1 2 3 4 7 8, right? That is what we want (sort '(7 1 3 8 2 1 4)) > > to > > > output (+ the parentheses of course). > > > > > > Now, `sorted?' returns true if its input is what `sort' would have > > produced > > > as output, otherwise false. > > > > Hmmm. Perhaps, what throws me off the rails is that you can pass > > a "less" predicate to sorted?. > > > > To behave like it does, it has to have some notion of equality, > > which seems to be implicit and doesn't necessarily harmonize with > > the less predicate you pass to it. > > > > (= 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)? > 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? [...] > There is actually to kinds of `sort'. Ordinary sort and stable sort. Yes, I know that -- but this wasn't my issue (or at least I think it isn't). Thanks for your patience :) Cheers -- t
signature.asc
Description: PGP signature