1 ;;;; Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
3 ;;;; This library is free software; you can redistribute it and/or
4 ;;;; modify it under the terms of the GNU Lesser General Public
5 ;;;; License as published by the Free Software Foundation; either
6 ;;;; version 2.1 of the License, or (at your option) any later version.
8 ;;;; This library is distributed in the hope that it will be useful,
9 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ;;;; Lesser General Public License for more details.
13 ;;;; You should have received a copy of the GNU Lesser General Public
14 ;;;; License along with this library; if not, write to the Free Software
15 ;;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 (define-module (oop goops util)
21 mapappend find-duplicate top-level-env top-level-env?
22 map* for-each* length* improper->proper)
31 (define (any pred lst . rest)
32 (if (null? rest) ;fast path
33 (and (not (null? lst))
34 (let loop ((head (car lst)) (tail (cdr lst)))
38 (loop (car tail) (cdr tail))))))
39 (let ((lsts (cons lst rest)))
40 (and (not (any null? lsts))
41 (let loop ((heads (map car lsts)) (tails (map cdr lsts)))
44 (or (apply pred heads)
45 (loop (map car tails) (map cdr tails)))))))))
47 (define (every pred lst . rest)
48 (if (null? rest) ;fast path
50 (let loop ((head (car lst)) (tail (cdr lst)))
54 (loop (car tail) (cdr tail))))))
55 (let ((lsts (cons lst rest)))
57 (let loop ((heads (map car lsts)) (tails (map cdr lsts)))
60 (and (apply pred heads)
61 (loop (map car tails) (map cdr tails)))))))))
63 (define (mapappend func . args)
66 (append (apply func (map car args))
67 (apply mapappend func (map cdr args)))))
69 (define (find-duplicate l) ; find a duplicate in a list; #f otherwise
72 ((memv (car l) (cdr l)) (car l))
73 (else (find-duplicate (cdr l)))))
75 (define (top-level-env)
76 (let ((mod (current-module)))
78 (module-eval-closure mod)
81 (define (top-level-env? env)
83 (procedure? (car env))))
85 (define (map* fn . l) ; A map which accepts dotted lists (arg lists
86 (cond ; must be "isomorph"
88 ((pair? (car l)) (cons (apply fn (map car l))
89 (apply map* fn (map cdr l))))
92 (define (for-each* fn . l) ; A for-each which accepts dotted lists (arg lists
93 (cond ; must be "isomorph"
95 ((pair? (car l)) (apply fn (map car l)) (apply for-each* fn (map cdr l)))
101 ((not (pair? ls)) n)))
103 (define (improper->proper ls)
105 (cons (car ls) (improper->proper (cdr ls)))