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
next prev parent reply other threads:[~2024-05-31 16:38 UTC|newest]
Thread overview: 8+ 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
2024-07-04 15:55 ` [bug#70800] [PATCH v2] scripts: style: Add 'alphabetical-sort' option Herman Rimm via Guix-patches via
2024-07-18 15:12 ` Ludovic Courtès
2024-09-02 18:58 ` [bug#70800] [PATCH] " Herman Rimm via Guix-patches via
2024-09-03 9:50 ` bug#70800: " 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
List information: https://guix.gnu.org/
* 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 public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).