GNU bug report logs -
#70800
[PATCH] scripts: style: Add 'order' option to alphabetically order file.
Previous Next
Reported by: Herman Rimm <herman <at> rimm.ee>
Date: Mon, 6 May 2024 10:52:02 UTC
Severity: normal
Tags: patch
Done: Ludovic Courtès <ludo <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
Message #11 received at 70800 <at> debbugs.gnu.org (full text, mbox):
Hi,
On Sat, 25 May 2024 at 16:14, Ludovic Courtès <ludo <at> 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
This bug report was last modified 315 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.