source: trunk/j/src/org/armedbear/lisp/map1.lisp @ 9266

Last change on this file since 9266 was 6351, checked in by piso, 17 years ago

(in-package "COMMON-LISP") => (in-package "SYSTEM")

File size: 2.0 KB
Line 
1;;; map1.lisp
2;;;
3;;; Copyright (C) 2003-2004 Peter Graves
4;;; $Id: map1.lisp,v 1.2 2004-03-24 01:32:41 piso Exp $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20(in-package "SYSTEM")
21
22;;; Mapping functions (from CMUCL)
23
24(defun map1 (function original-arglists accumulate take-car)
25  (let* ((arglists (copy-list original-arglists))
26   (ret-list (list nil))
27   (temp ret-list))
28    (do ((res nil)
29   (args '() '()))
30        ((dolist (x arglists nil) (if (null x) (return t)))
31         (if accumulate
32             (cdr ret-list)
33             (car original-arglists)))
34      (do ((l arglists (cdr l)))
35          ((null l))
36  (push (if take-car (caar l) (car l)) args)
37  (setf (car l) (cdar l)))
38      (setq res (apply function (nreverse args)))
39      (case accumulate
40  (:nconc (setq temp (last (nconc temp res))))
41  (:list (rplacd temp (list res))
42         (setq temp (cdr temp)))))))
43
44
45(defun mapc (function list &rest more-lists)
46  (map1 function (cons list more-lists) nil t))
47
48(defun mapcan (function list &rest more-lists)
49  (map1 function (cons list more-lists) :nconc t))
50
51(defun mapl (function list &rest more-lists)
52  (map1 function (cons list more-lists) nil nil))
53
54(defun maplist (function list &rest more-lists)
55  (map1 function (cons list more-lists) :list nil))
56
57(defun mapcon (function list &rest more-lists)
58  (map1 function (cons list more-lists) :nconc nil))
Note: See TracBrowser for help on using the repository browser.