From 9ede36f0ed2ea3c2a6a020b52e51b741b07cbc1f Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Tue, 12 Feb 2013 20:29:30 -0500 Subject: Inhibit duplicates in fold-packages. * gnu/packages.scm (fold2): New procedure. (fold-packages): Rework to suppress duplicates. --- gnu/packages.scm | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/gnu/packages.scm b/gnu/packages.scm index 792fe44efa..f2f98de476 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2012, 2013 Ludovic Courtès +;;; Copyright © 2013 Mark H Weaver ;;; ;;; This file is part of GNU Guix. ;;; @@ -20,6 +21,7 @@ #:use-module (guix packages) #:use-module (guix utils) #:use-module (ice-9 ftw) + #:use-module (ice-9 vlist) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (srfi srfi-39) @@ -106,20 +108,34 @@ (false-if-exception (resolve-interface name)))) (package-files))) +(define (fold2 f seed1 seed2 lst) + (if (null? lst) + (values seed1 seed2) + (call-with-values + (lambda () (f (car lst) seed1 seed2)) + (lambda (seed1 seed2) + (fold2 f seed1 seed2 (cdr lst)))))) + (define (fold-packages proc init) "Call (PROC PACKAGE RESULT) for each available package, using INIT as -the initial value of RESULT." - (fold (lambda (module result) - (fold (lambda (var result) - (if (package? var) - (proc var result) - result)) - result - (module-map (lambda (sym var) - (false-if-exception (variable-ref var))) - module))) - init - (package-modules))) +the initial value of RESULT. It is guaranteed to never traverse the +same package twice." + (identity ; discard second return value + (fold2 (lambda (module result seen) + (fold2 (lambda (var result seen) + (if (and (package? var) + (not (vhash-assq var seen))) + (values (proc var result) + (vhash-consq var #t seen)) + (values result seen))) + result + seen + (module-map (lambda (sym var) + (false-if-exception (variable-ref var))) + module))) + init + vlist-null + (package-modules)))) (define* (find-packages-by-name name #:optional version) "Return the list of packages with the given NAME. If VERSION is not #f, -- cgit v1.2.3 -17gnu: Use PACKAGE/INHERIT in more places....Mark H Weaver 2021-03-06gnu: epson-inkjet-printer-escpr: Update to 1.7.9....Tobias Geerinckx-Rice 2021-03-06gnu: hplip: Update to 3.21.2....Tobias Geerinckx-Rice 2021-01-10gnu: Move brlaser to (gnu packages cups)....Tobias Geerinckx-Rice 2020-12-15gnu: foo2zjs: Fix installation....Boris A. Dekshteyn 2020-12-06gnu: hplip: Update to 3.20.11....Tobias Geerinckx-Rice 2020-11-29gnu: hplip: Install PPDs into a separate output....Tobias Geerinckx-Rice 2020-11-21gnu: Rename escpr to epson-inkjet-printer-escpr....Tobias Geerinckx-Rice 2020-11-21gnu: escpr: Omit static library....Tobias Geerinckx-Rice 2020-11-19gnu: escpr: Compress PPDs....Tobias Geerinckx-Rice 2020-11-19gnu: escpr: Use HTTPS, more relevant home page....Tobias Geerinckx-Rice 2020-11-19gnu: escpr: Update to 1.7.8....Tobias Geerinckx-Rice 2020-11-18gnu: splix: Compress PPDs....Tobias Geerinckx-Rice 2020-11-18gnu: splix: Update to 2.0.0-315.76268c4....Tobias Geerinckx-Rice