* [PATCH] Inhibit duplicates in fold-packages
@ 2013-02-13 1:50 Mark H Weaver
2013-02-13 11:06 ` Mark H Weaver
2013-02-13 21:35 ` Ludovic Courtès
0 siblings, 2 replies; 3+ messages in thread
From: Mark H Weaver @ 2013-02-13 1:50 UTC (permalink / raw
To: bug-guix
[-- Attachment #1: Type: text/plain, Size: 728 bytes --]
Here's a patch to inhibit the same package (in the sense of eq?) from
being traversed more than once by fold-packages. One example where this
helps is the guile-2.0 package in (gnu packages guile), which is
exported in two different variables: guile-2.0 and guile-2.0/fixed.
Note that even after applying this patch, there are still cases where
"guix-package -A ." produces the same output twice, but that's a
different problem. In the remaining cases, there are actually two
distinct package objects being printed the same way because the
'location' field is inherited from one package to another. For example
this happens with the 'gcc-boot0' and 'gcc-4.7' packages in (gnu
packages base).
What do you think?
Mark
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Inhibit duplicates in fold-packages --]
[-- Type: text/x-diff, Size: 2508 bytes --]
From 1d30931a28af4ed6aa747a05bc3540e335ce1b32 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
Date: Tue, 12 Feb 2013 20:29:30 -0500
Subject: [PATCH] Inhibit duplicates in fold-packages.
* gnu/packages.scm (fold2): New procedure.
(fold-packages): Rework to suppress duplicates.
---
gnu/packages.scm | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/gnu/packages.scm b/gnu/packages.scm
index 6a5496e..d783e4c 100644
--- a/gnu/packages.scm
+++ b/gnu/packages.scm
@@ -21,6 +21,7 @@
#:use-module (guix utils)
#:use-module (ice-9 ftw)
#:use-module (ice-9 vlist)
+ #:use-module (ice-9 match)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-39)
@@ -108,20 +109,33 @@
(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)))
+ (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,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Inhibit duplicates in fold-packages
2013-02-13 1:50 [PATCH] Inhibit duplicates in fold-packages Mark H Weaver
@ 2013-02-13 11:06 ` Mark H Weaver
2013-02-13 21:35 ` Ludovic Courtès
1 sibling, 0 replies; 3+ messages in thread
From: Mark H Weaver @ 2013-02-13 11:06 UTC (permalink / raw
To: bug-guix
[-- Attachment #1: Type: text/plain, Size: 626 bytes --]
I wrote:
> Here's a patch to inhibit the same package (in the sense of eq?) from
> being traversed more than once by fold-packages. One example where this
> helps is the guile-2.0 package in (gnu packages guile), which is
> exported in two different variables: guile-2.0 and guile-2.0/fixed.
>
> Note that even after applying this patch, there are still cases where
> "guix-package -A ." produces the same output twice, but that's a
> different problem. [...]
Sorry, the patch I posted did not apply cleanly, because it was layered
on top of a preliminary version of my upgrade patch. Here's a fixed
version.
Mark
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Inhibit duplicates in fold-packages --]
[-- Type: text/x-diff, Size: 2510 bytes --]
From fcb78e4af6d4f7304582fa2ad44eb99236b6ae23 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
Date: Tue, 12 Feb 2013 20:29:30 -0500
Subject: [PATCH] Inhibit duplicates in fold-packages.
* gnu/packages.scm (fold2): New procedure.
(fold-packages): Rework to suppress duplicates.
---
gnu/packages.scm | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/gnu/packages.scm b/gnu/packages.scm
index 792fe44..ee661d7 100644
--- a/gnu/packages.scm
+++ b/gnu/packages.scm
@@ -20,6 +20,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 +107,33 @@
(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)))
+ (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,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Inhibit duplicates in fold-packages
2013-02-13 1:50 [PATCH] Inhibit duplicates in fold-packages Mark H Weaver
2013-02-13 11:06 ` Mark H Weaver
@ 2013-02-13 21:35 ` Ludovic Courtès
1 sibling, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2013-02-13 21:35 UTC (permalink / raw
To: Mark H Weaver; +Cc: bug-guix
Mark H Weaver <mhw@netris.org> skribis:
> Here's a patch to inhibit the same package (in the sense of eq?) from
> being traversed more than once by fold-packages. One example where this
> helps is the guile-2.0 package in (gnu packages guile), which is
> exported in two different variables: guile-2.0 and guile-2.0/fixed.
Looks good to me; can you update the docstring to mention that each
package is traversed only once? Then feel free to push.
BTW, I think ‘guile-2.0/fixed’ is the only case where this happens
actually, no?
BTW2, when doing non-trivial changes like this one, make sure to add a
copyright line under your name.
Thanks!
Ludo’.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-02-13 21:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-13 1:50 [PATCH] Inhibit duplicates in fold-packages Mark H Weaver
2013-02-13 11:06 ` Mark H Weaver
2013-02-13 21:35 ` Ludovic Courtès
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).