[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#68271] [PATCH 1/3] guix: utils: Add delete-duplicates/sort.
From: |
Ludovic Courtès |
Subject: |
[bug#68271] [PATCH 1/3] guix: utils: Add delete-duplicates/sort. |
Date: |
Fri, 12 Jan 2024 14:53:43 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Christopher Baines <mail@cbaines.net> skribis:
> Similar to delete-duplicates, but sorts the list first and then compares the
> pairs in the list. This is faster than delete-duplicates for larger lists.
We’re dealing with small lists here though (derivation inputs). Did you
try to time the benefit?
There’s a complexity/benefit tradeoff and I wonder if it cuts it.
> +(define* (delete-duplicates/sort unsorted-lst less #:optional (equal? eq?))
> + (if (null? unsorted-lst)
> + unsorted-lst
This ‘if’ is unnecessary.
> + (let ((sorted-lst (sort unsorted-lst
> + ;; Sort in the reverse order
> + (lambda (a b) (eq? #f (less a b))))))
Just: (negate less).
> + (let loop ((lst (cdr sorted-lst))
> + (last-element (car sorted-lst))
> + (result (list (car sorted-lst))))
> + (if (null? lst)
> + result
> + (let ((current-element (car lst)))
Please follow the convention of using ‘match’ rather than car caddr
caddddar (info "(guix) Data Types and Pattern Matching"):
(match lst
(()
result)
((head . tail)
…))
Ludo’.