From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnPQ7-0005qy-57 for guix-patches@gnu.org; Thu, 31 Aug 2017 09:22:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnPQ3-0003Pd-6C for guix-patches@gnu.org; Thu, 31 Aug 2017 09:22:07 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:56083) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dnPQ3-0003PY-2h for guix-patches@gnu.org; Thu, 31 Aug 2017 09:22:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dnPQ2-0000ls-TH for guix-patches@gnu.org; Thu, 31 Aug 2017 09:22:02 -0400 Subject: [bug#28274] [PATCH] gnu: Add fold-packages-in-modules. Resent-Message-ID: From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <20170829070723.21727-1-mail@cbaines.net> Date: Thu, 31 Aug 2017 15:20:55 +0200 In-Reply-To: <20170829070723.21727-1-mail@cbaines.net> (Christopher Baines's message of "Tue, 29 Aug 2017 08:07:23 +0100") Message-ID: <87r2vrrhzc.fsf@gnu.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Christopher Baines Cc: 28274@debbugs.gnu.org --=-=-= Content-Type: text/plain Christopher Baines 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: --=-=-= Content-Type: text/x-patch Content-Disposition: inline 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 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 DQo/DQoNCkx1ZG/igJkuDQo= --=-=-=--