* [PATCH] Remove duplicated code in `(oop goops util)'
@ 2008-03-13 14:39 Ludovic Courtès
2008-03-17 23:22 ` Neil Jerram
0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2008-03-13 14:39 UTC (permalink / raw)
To: guile-devel
[-- Attachment #1: Type: text/plain, Size: 384 bytes --]
Hi,
Would there be any objections to the patch below?
It removes code that duplicates SRFI-1. For `mapappend', the substitute
uses a (slightly) more efficient algorithm AFAICS. Given N M-element
lists, I think we have:
old `mapappend' -> O(M * 3N)
`append-map' -> O(M * (1 + N))
Checking whether this is correct is left as an exercise to the reader...
Thanks,
Ludovic.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: The patch --]
[-- Type: text/x-patch, Size: 2430 bytes --]
--- /home/ludo/src/guile/1.8/guile-core/oop/goops/util.scm.~1.8.2.1.~ 2006-02-12 14:42:52.000000000 +0100
+++ /home/ludo/src/guile/1.8/guile-core/oop/goops/util.scm 2008-03-12 18:12:06.000000000 +0100
@@ -1,4 +1,4 @@
-;;;; Copyright (C) 1999, 2000, 2001, 2003, 2006 Free Software Foundation, Inc.
+;;;; Copyright (C) 1999, 2000, 2001, 2003, 2006, 2008 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -17,9 +17,10 @@
\f
(define-module (oop goops util)
- :export (any every
- mapappend find-duplicate top-level-env top-level-env?
+ :export (mapappend find-duplicate top-level-env top-level-env?
map* for-each* length* improper->proper)
+ :use-module (srfi srfi-1)
+ :re-export (any every)
:no-backtrace
)
@@ -28,43 +29,7 @@
;;; {Utilities}
;;;
-(define (any pred lst . rest)
- (if (null? rest) ;fast path
- (and (not (null? lst))
- (let loop ((head (car lst)) (tail (cdr lst)))
- (if (null? tail)
- (pred head)
- (or (pred head)
- (loop (car tail) (cdr tail))))))
- (let ((lsts (cons lst rest)))
- (and (not (any null? lsts))
- (let loop ((heads (map car lsts)) (tails (map cdr lsts)))
- (if (any null? tails)
- (apply pred heads)
- (or (apply pred heads)
- (loop (map car tails) (map cdr tails)))))))))
-
-(define (every pred lst . rest)
- (if (null? rest) ;fast path
- (or (null? lst)
- (let loop ((head (car lst)) (tail (cdr lst)))
- (if (null? tail)
- (pred head)
- (and (pred head)
- (loop (car tail) (cdr tail))))))
- (let ((lsts (cons lst rest)))
- (or (any null? lsts)
- (let loop ((heads (map car lsts)) (tails (map cdr lsts)))
- (if (any null? tails)
- (apply pred heads)
- (and (apply pred heads)
- (loop (map car tails) (map cdr tails)))))))))
-
-(define (mapappend func . args)
- (if (memv '() args)
- '()
- (append (apply func (map car args))
- (apply mapappend func (map cdr args)))))
+(define mapappend append-map)
(define (find-duplicate l) ; find a duplicate in a list; #f otherwise
(cond
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Remove duplicated code in `(oop goops util)'
2008-03-13 14:39 [PATCH] Remove duplicated code in `(oop goops util)' Ludovic Courtès
@ 2008-03-17 23:22 ` Neil Jerram
2008-03-18 9:11 ` Ludovic Courtès
0 siblings, 1 reply; 3+ messages in thread
From: Neil Jerram @ 2008-03-17 23:22 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-devel
ludo@gnu.org (Ludovic Courtès) writes:
> Hi,
>
> Would there be any objections to the patch below?
Looks good to me.
Neil
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Remove duplicated code in `(oop goops util)'
2008-03-17 23:22 ` Neil Jerram
@ 2008-03-18 9:11 ` Ludovic Courtès
0 siblings, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2008-03-18 9:11 UTC (permalink / raw)
To: guile-devel
Hi,
Neil Jerram <neil@ossau.uklinux.net> writes:
> Looks good to me.
Thanks, applied.
Ludo'.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-03-18 9:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-13 14:39 [PATCH] Remove duplicated code in `(oop goops util)' Ludovic Courtès
2008-03-17 23:22 ` Neil Jerram
2008-03-18 9:11 ` Ludovic Courtès
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).