all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Simon Tournier <zimon.toutoune@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>, "Herman Rimm" <herman@rimm.ee>
Cc: 70800@debbugs.gnu.org, Josselin Poiret <dev@jpoiret.xyz>,
	Mathieu Othacehe <othacehe@gnu.org>,
	Tobias Geerinckx-Rice <me@tobias.gr>,
	Ricardo Wurmus <rekado@elephly.net>,
	Christopher Baines <guix@cbaines.net>
Subject: [bug#70800] [PATCH] scripts: style: Add 'order' option to alphabetically order file.
Date: Fri, 31 May 2024 17:36:09 +0200	[thread overview]
Message-ID: <87ed9i3seu.fsf@gmail.com> (raw)
In-Reply-To: <875xv20yhq.fsf@gnu.org>

Hi,

On Sat, 25 May 2024 at 16:14, Ludovic Courtès <ludo@gnu.org> wrote:

>> I managed to create a procedure which alphabetically sorts top-level
>> package definitions.  Sort is not stable as I understand it, so versions
>> of packages get swapped.  It works well enough in small package modules,
>> and should not be a problem once package versions are used in sorting.
>
> Maybe use ‘stable-sort’ instead of ‘sort’?

[...]

>> +         (lst (sort lst (lambda (lst1 lst2)
>> +                          (let ((name1 (package-name lst1))
>> +                                (name2 (package-name lst2)))
>> +                            (and name1 name2 (string> name1 name2)))))))
>> +    (reverse (concatenate lst))))
>
> Maybe replace ‘string>’ by ‘string<?’ and drop ‘reverse’.

I would suggest to use ’sort!’ for an in-place sort.  This would avoid
some GC cycles when internally copying since ’lst’ is inside ’let*’.

Moreover, yeah reverse the inequality would avoid the ’reverse’
call. :-)

About the stability, I would suggest something as:

--8<---------------cut here---------------start------------->8---
(sort! lst (lambda (lst1 lst2)
             (let ((name1 (package-name lst1))
                   (name2 (package-name lst2)))
               (and name1 name2 (or (string<? name1 name2)
                                    (eq? '< (version-compare
                                             (package-version lst1)
                                             (package-version lst2))))))))
--8<---------------cut here---------------end--------------->8---

with ’version-compare’ from (guix utils).  Well, something like
that. :-)


Cheers,
simon




  reply	other threads:[~2024-05-31 16:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-06 10:50 [bug#70800] [PATCH] scripts: style: Add 'order' option to alphabetically order file Herman Rimm via Guix-patches via
2024-05-25 14:14 ` Ludovic Courtès
2024-05-31 15:36   ` Simon Tournier [this message]
2024-06-26 21:32   ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ed9i3seu.fsf@gmail.com \
    --to=zimon.toutoune@gmail.com \
    --cc=70800@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=guix@cbaines.net \
    --cc=herman@rimm.ee \
    --cc=ludo@gnu.org \
    --cc=me@tobias.gr \
    --cc=othacehe@gnu.org \
    --cc=rekado@elephly.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.