Subject: bug#28274: closed (Re: [bug#28274] [PATCH] gnu: Add fold-packages-in-modules.)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 01 Sep 2017 09:10:02 +0000

Your bug report

#28274: [PATCH] gnu: Add fold-packages-in-modules.

which was filed against the guix-patches package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
28274: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=28274
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: [bug#28274] [PATCH] gnu: Add fold-packages-in-modules.
From: [email-masked] (Ludovic Courtès)
To: Christopher Baines <[email-masked]>
Cc: [email-masked]
Date: Fri, 01 Sep 2017 11:08:56 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Christopher Baines <[email-masked]> skribis:

> On Thu, 31 Aug 2017 15:20:55 +0200
> [email-masked] (Ludovic Courtès) wrote:
>
>> Instead of introducing a new procedure, what about simply:
>> 
>> 
>> diff --git a/gnu/packages.scm b/gnu/packages.scm
>> index 562906178..b4ac6661c 100644
>> --- a/gnu/packages.scm
>> +++ b/gnu/packages.scm
>> @@ -140,17 +140,19 @@ for system '~a'")
>>                directory))
>>          %load-path)))
>>  
>> -(define (fold-packages proc init)
>> -  "Call (PROC PACKAGE RESULT) for each available package, using INIT
>> as -the initial value of RESULT.  It is guaranteed to never traverse
>> the -same package twice."
>> +(define* (fold-packages proc init
>> +                        #:optional
>> +                        (modules (all-modules
>> (%package-module-path))))
>> +  "Call (PROC PACKAGE RESULT) for each available package defined in
>> one of +MODULES, using INIT as the initial value of RESULT.  It is
>> guaranteed to never +traverse the same package twice."
>>    (fold-module-public-variables (lambda (object result)
>>                                    (if (and (package? object)
>>                                             (not (hidden-package?
>> object))) (proc object result)
>>                                        result))
>>                                  init
>> -                                (all-modules
>> (%package-module-path))))
>> +                                modules))
>>  
>>  (define find-packages-by-name
>>    (let ((packages (delay
>> 
>> 
>> ?
>
> This looks great. Are you set to push it up, or shall I?

Pushed, thanks!

Ludo'.

Subject: [PATCH] gnu: Add fold-packages-in-modules.
From: Christopher Baines <[email-masked]>
To: [email-masked]
Date: Tue, 29 Aug 2017 08:07:23 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Add a more flexible variant of the fold-packages procedure, that takes a list
of the modules to work with. The existing fold-packages procedure then calls
fold-packages-in-modules with the result of the all-modules procedure.

I wrote this when looking at how to get the packages in a specific set of
modules, to create jobs for cuirass.

* gnu/packages.scm (fold-packages-in-modules): New procedure.
  (fold-packages): Change to use fold-packages-in-modules.
---
 gnu/packages.scm | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/gnu/packages.scm b/gnu/packages.scm
index 562906178..3f0ff56b8 100644
--- a/gnu/packages.scm
+++ b/gnu/packages.scm
@@ -47,6 +47,7 @@
             %bootstrap-binaries-path
             %package-module-path
 
+            fold-packages-in-modules
             fold-packages
 
             find-packages-by-name
@@ -144,13 +145,21 @@ for system '~a'")
   "Call (PROC PACKAGE RESULT) for each available package, using INIT as
 the initial value of RESULT.  It is guaranteed to never traverse the
 same package twice."
+  (fold-packages-in-modules (all-modules (%package-module-path))
+                            proc
+                            init))
+
+(define (fold-packages-in-modules modules proc init)
+  "Call (PROC PACKAGE RESULT) for each available package within any of the
+modules in MODULES, using INIT as the initial value of RESULT.  It is
+guaranteed to never traverse the same package twice."
   (fold-module-public-variables (lambda (object result)
                                   (if (and (package? object)
                                            (not (hidden-package? object)))
                                       (proc object result)
                                       result))
                                 init
-                                (all-modules (%package-module-path))))
+                                modules))
 
 (define find-packages-by-name
   (let ((packages (delay
-- 
2.14.1