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

  • Done
  • quality assurance status badge
Details
2 participants
  • Ludovic Courtès
  • Christopher Baines
Owner
unassigned
Submitted by
Christopher Baines
Severity
normal

Debbugs page

Christopher Baines wrote 8 years ago
(address . guix-patches@gnu.org)
20170829070723.21727-1-mail@cbaines.net
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(-)

Toggle diff (37 lines)
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
Ludovic Courtès wrote 8 years ago
(name . Christopher Baines)(address . mail@cbaines.net)(address . 28274@debbugs.gnu.org)
87r2vrrhzc.fsf@gnu.org
Christopher Baines <mail@cbaines.net> skribis:

Toggle quote (10 lines)
> 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.

[...]

Toggle quote (13 lines)
> +(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:
Toggle diff (29 lines)
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
?
Ludo’.
Christopher Baines wrote 8 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 28274@debbugs.gnu.org)
20170831224433.07d6cea7@cbaines.net
On Thu, 31 Aug 2017 15:20:55 +0200
ludo@gnu.org (Ludovic Courtès) wrote:

Toggle quote (38 lines)
> 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
-----BEGIN PGP SIGNATURE-----

iQKTBAEBCgB9FiEEPonu50WOcg2XVOCyXiijOwuE9XcFAlmog0FfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcACgkQXiijOwuE
9XeZ9xAAtXKdELZxEjZRJLDB7Bxn+TllgupG0u2OEk9Pf6V3ibAAK8OzxBOjJxCy
hgmyKPYSGd3pLWJ2nvZWw02GeKqFJgqWH//ZUgjmv6kP/ZUHHGo6duRrd1seeS9X
hTspotXPiJDNzA42J4E/oesKk5nShcc7BkSwGnoExp7RYhqG0/OLm6dTLSCxhwV3
2LWoUtmSPInDGAL62uS8bbzoECbizy+gGg/NbGeGG4593JvvV9bI03A5TCG3LDvQ
KK8AZg7vuYAWmcJdzSi1zV5zXCUl4wzzRUV8ZaewNTNdIv7lkI8WYeqQ03ukinHJ
kQ9TsVYWxOH3go/YIhox4rDQxqEiAQsoj25xQC43ktPJ3O/Eu+yT4RsLFMPNmFq7
fXgYyj9CWd2UFBWvAbWpELC/WBMzYmElR/SV8ehkU14/C38QK3BWzyHrlR/IoJHI
t8Vtlz4YEF6exFBUlzWi2TfzvPzVGRUtnWewK//iDCwr8V9PZ1690Le3flqDToUW
z+sj8Y1zkMtP6hXzSn8dugOvSIsqi83iM3z+zvUm5fAz3yeJgyEvHLi4ojFZpOfG
NfAe7ik/Qx6wcXW7yaVLjEYJYv/4EBru+XChqB7oPcWNzOCnyodeI8OQrTi7io/S
hZVeeC7elWd7QIJvQGvJO/KrvyFhbBNFDHKI155morysm5YgbMs=
=01Vu
-----END PGP SIGNATURE-----


Ludovic Courtès wrote 8 years ago
(name . Christopher Baines)(address . mail@cbaines.net)(address . 28274-done@debbugs.gnu.org)
878thy7plj.fsf@gnu.org
Christopher Baines <mail@cbaines.net> skribis:

Toggle quote (43 lines)
> 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'.
Closed
Christopher Baines wrote 8 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 28274@debbugs.gnu.org)
20170901192026.42c484e7@cbaines.net
On Fri, 01 Sep 2017 11:08:56 +0200
ludo@gnu.org (Ludovic Courtès) wrote:

Toggle quote (47 lines)
> 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 :)
-----BEGIN PGP SIGNATURE-----

iQKTBAEBCgB9FiEEPonu50WOcg2XVOCyXiijOwuE9XcFAlmppOpfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcACgkQXiijOwuE
9Xc3nA//eexqSk7y7Mdb3lRKXS+q+KY3x/UBquC7SuVOc+RE501x8uH56iGsmxPd
FqxkFM43Yd1InIuz6IE5tp8TWFFoAr5nbJdniJc9yC1MG04BysRFfrjMhHjI8ESo
4a2/URSz2H2Vt3GQQnM9HP0YRAh66P4nVVQtXAO2+LkmS6itog9V9+uMQQ3krjDX
8tFwWOhWYK0u3nZEF/99eqbr3aQ+e8zLwDShfr0bveDmyv0MrJFrc+Uli6ErcfNC
DEaaIWwhtEo9nsNSdbFf0S5jPrLy7824fF9OSOLFQp1iiodHnao3rDQFEI93Ignw
Q3cZpT7lA1Cv2x4w77Zbr+kTAmHt1acNkH3YdbgGkmmrqVPjhhaDzuLsv/DBaxUH
ZpES+0qKt/tJ4iZJgCzFJewLmWG/oeijLoQiJUDB53PH/2QTriN7zunPunLSyYFz
k40chWBB02x4a9DGK8htb6z1cOCas9qb+JbMBCZ5D7U/0ixpzgfy7IY6BilGA+Sk
l7kfPld/j3LXFC17okL4lrDMp56Znuh5fEUOgnvC/MlQSKVqYOxJu9Y0bL9sMH8d
GyC2aWsqpfcYTtWK8Gj/2TMy9ojZkoHI9raC5qnz5RmSc8kfjuOdxD6hzXgEwf3T
CPsyuwCTraqC1FKcokBhV2dSKrUjpvfXqow8/D3+hx94NzKiLuw=
=ak2u
-----END PGP SIGNATURE-----


?
Your comment

This issue is archived.

To comment on this conversation send an email to 28274@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 28274
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help