Subject: Re: [bug#57460] [PATCH 00/19] Refresh to specific version

From: Maxime Devos <[email-masked]>
Date: Sat, 24 Sep 2022 12:25:28 +0200

On 24-09-2022 11:29, Ludovic Courtès wrote:
> Hartmut Goebel <[email-masked]> skribis:
> 
>> * guix/import/gnome.scm(latest-gnome-release): Rename
>>    to (import-gnome-release), add keyword-argument 'version'. If version is
>>    given, try to find the respective version
>>    [find-latest-release]: New function, based on former code.
>>    [find-version-release]: New function.
> 
> [...]
> 
>> +  (define (find-latest-release releases)
>> +    (fold (match-lambda*
>> +           (((key . value) result)
>> +            (cond ((even-minor-version? key)
>> +                   (match result
>> +                          (#f
>> +                           (cons key value))
>> +                          ((newest . _)
>> +                           (if (version>? key newest)
>> +                               (cons key value)
>> +                               result))))
> 
> Please reindent ‘match’ as it was.

"guix style" is IMO not usable here 
(<https://issues.guix.gnu.org/58040>: "guix style" puts closing 
parentheses on the wrong line").

>> +  (define (find-version-release releases version)
>> +    (fold (match-lambda*
>> +           (((key . value) result)
>> +            (if (string=? key version)
>> +                (cons key value)
>> +                result)))
>> +          #f
>> +          releases))
> 
> I guess we could start at the first match instead of traversing all the
> list, no?  How about:
> 
>    (define (find-version-release releases version)
>      (find (match-lambda
>              ((key . value)
>               (string=? key version)))
>            releases))
> 
> ?

(1) according to "guix style", this should be

(define (find-version-release releases version)
   (find (match-lambda
           ((key . value) (string=? key version))) releases))

(2)  Isn't this an inline definition of 'assoc' (except for replacing 
equal? by string=?)?

(use-modules (srfi srfi-1)) ; the third argument is only documented in 
SRFI-1 Asosciation Lists
(define (find-version-release releases version)
   (assoc version releases string=?)

Some code duplication can be avoided here.

Greetings,
Maxime.