unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#28274] [PATCH] gnu: Add fold-packages-in-modules.
@ 2017-08-29  7:07 Christopher Baines
  2017-08-31 13:20 ` Ludovic Courtès
  0 siblings, 1 reply; 5+ messages in thread
From: Christopher Baines @ 2017-08-29  7:07 UTC (permalink / raw)
  To: 28274

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [bug#28274] [PATCH] gnu: Add fold-packages-in-modules.
  2017-08-29  7:07 [bug#28274] [PATCH] gnu: Add fold-packages-in-modules Christopher Baines
@ 2017-08-31 13:20 ` Ludovic Courtès
  2017-08-31 21:44   ` Christopher Baines
  0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2017-08-31 13:20 UTC (permalink / raw)
  To: Christopher Baines; +Cc: 28274

[-- Attachment #1: Type: text/plain, Size: 1329 bytes --]

Christopher Baines <mail@cbaines.net> skribis:

> 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.

[...]

> +(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))

Instead of introducing a new procedure, what about simply:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1271 bytes --]

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

[-- Attachment #3: Type: text/plain, Size: 17 bytes --]


?

Ludo’.

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [bug#28274] [PATCH] gnu: Add fold-packages-in-modules.
  2017-08-31 13:20 ` Ludovic Courtès
@ 2017-08-31 21:44   ` Christopher Baines
  2017-09-01  9:08     ` bug#28274: " Ludovic Courtès
  0 siblings, 1 reply; 5+ messages in thread
From: Christopher Baines @ 2017-08-31 21:44 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 28274

[-- Attachment #1: Type: text/plain, Size: 1566 bytes --]

On Thu, 31 Aug 2017 15:20:55 +0200
ludo@gnu.org (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?

Thanks,

Chris

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 963 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#28274: [PATCH] gnu: Add fold-packages-in-modules.
  2017-08-31 21:44   ` Christopher Baines
@ 2017-09-01  9:08     ` Ludovic Courtès
  2017-09-01 18:20       ` [bug#28274] " Christopher Baines
  0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2017-09-01  9:08 UTC (permalink / raw)
  To: Christopher Baines; +Cc: 28274-done

Christopher Baines <mail@cbaines.net> skribis:

> On Thu, 31 Aug 2017 15:20:55 +0200
> ludo@gnu.org (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'.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#28274] [PATCH] gnu: Add fold-packages-in-modules.
  2017-09-01  9:08     ` bug#28274: " Ludovic Courtès
@ 2017-09-01 18:20       ` Christopher Baines
  0 siblings, 0 replies; 5+ messages in thread
From: Christopher Baines @ 2017-09-01 18:20 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 28274

[-- Attachment #1: Type: text/plain, Size: 1863 bytes --]

On Fri, 01 Sep 2017 11:08:56 +0200
ludo@gnu.org (Ludovic Courtès) wrote:

> Christopher Baines <mail@cbaines.net> skribis:
> 
> > On Thu, 31 Aug 2017 15:20:55 +0200
> > ludo@gnu.org (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!

Awesome, thanks Ludo :)

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 963 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-09-01 18:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-29  7:07 [bug#28274] [PATCH] gnu: Add fold-packages-in-modules Christopher Baines
2017-08-31 13:20 ` Ludovic Courtès
2017-08-31 21:44   ` Christopher Baines
2017-09-01  9:08     ` bug#28274: " Ludovic Courtès
2017-09-01 18:20       ` [bug#28274] " Christopher Baines

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).