guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/6] emacs: Add 'guix-packages-by-location' command.


From: Alex Kost
Subject: Re: [PATCH 1/6] emacs: Add 'guix-packages-by-location' command.
Date: Sun, 17 Apr 2016 10:29:10 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Ludovic Courtès (2016-04-16 01:23 +0300) wrote:

> Alex Kost <address@hidden> skribis:
[...]
>> The problem (well, not really a problem) is: along with this procedure
>> (to get packages by location file), I need another one (to get a list
>> of location files).
>
> Right, I had forgotten about that second use.
>
> We could do something to have both lookup procedures close over the same
> promise, for instance:
>
>   (define-values (lookup1 lookup2)
>     (let ((table (delay (fold-packages …))))
>       (values (lambda (x) …)
>               (lambda (y) …))))
>
> This way there’s still only one ‘fold-packages’ call.

Oh, very interesting; I didn't know about 'define-values' (shame on me),
thanks for pointing!

>>> That is, I would rather write:
>>>
>>>   (define packages-in-source-file
>>
>> And again, I don't like the name 'packages-in-source-file', what about
>> 'packages-by-location-file'?  (I prefer "by" over "in" as it is already
>> used in other procedure names: by-regexp, by-name, by-license, etc.)
>
> Fine with me, or ‘package-by-source-file’?

Since the package field as named 'location' I prefer
'packages-by-location-file'.

>> So, as far as I see it, another "lookup procedure" will be:
>>
>>   (define package-location-files
>>     (memoize
>>      (lambda ()
>>        "Return the list of file names of all package locations."
>>        (fold-packages
>>         (lambda (package result)
>>           (let ((file (location-file (package-location package))))
>>             (if (member file result)
>>                 result
>>                 (cons file result))))
>>         '()))))
>>
>> OK?  Or is there a better way to write it?
>
> This is fine.
>
> If you choose to take the ‘define-values’ approach above, I think you
> can just list they keys already in the vhash:
>
>   (define-values (package-by-something-file package-something-files)
>     (let* ((table (delay …))
>            (files (delay
>                     (delete-duplicates
>                       (vhash-fold (lambda (file _ result)
>                                     (cons file result))
>                                   '()
>                                   (force table))))))
>       (values …
>               (lambda () (force files)))))

Great, thanks!  I'm going to use this variant.  Is there a preference
for 'delete-duplicates' over this?:

  (vhash-fold (lambda (file _ result)
                (if (member file result)
                    result
                  (cons file result)))
              '()
              (force table))

-- 
Alex



reply via email to

[Prev in Thread] Current Thread [Next in Thread]