all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Christopher Baines <mail@cbaines.net>
Cc: 28274@debbugs.gnu.org
Subject: [bug#28274] [PATCH] gnu: Add fold-packages-in-modules.
Date: Thu, 31 Aug 2017 15:20:55 +0200	[thread overview]
Message-ID: <87r2vrrhzc.fsf@gnu.org> (raw)
In-Reply-To: <20170829070723.21727-1-mail@cbaines.net> (Christopher Baines's message of "Tue, 29 Aug 2017 08:07:23 +0100")

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

  reply	other threads:[~2017-08-31 13:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-29  7:07 [bug#28274] [PATCH] gnu: Add fold-packages-in-modules Christopher Baines
2017-08-31 13:20 ` Ludovic Courtès [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r2vrrhzc.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=28274@debbugs.gnu.org \
    --cc=mail@cbaines.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.