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

Last change on this file since 2275 was 2275, checked in by piso, 18 years ago

Initial checkin.

File size: 2.0 KB
Line 
1;;; map1.lisp
2;;;
3;;; Copyright (C) 2003 Peter Graves
4;;; $Id: map1.lisp,v 1.1 2003-06-11 00:04:02 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 "COMMON-LISP")
21
22(export '(mapc mapcan mapl maplist mapcon))
23
24;;; Mapping functions (from CMUCL)
25
26(defun map1 (function original-arglists accumulate take-car)
27  (let* ((arglists (copy-list original-arglists))
28   (ret-list (list nil))
29   (temp ret-list))
30    (do ((res nil)
31   (args '() '()))
32        ((dolist (x arglists nil) (if (null x) (return t)))
33         (if accumulate
34             (cdr ret-list)
35             (car original-arglists)))
36      (do ((l arglists (cdr l)))
37          ((null l))
38  (push (if take-car (caar l) (car l)) args)
39  (setf (car l) (cdar l)))
40      (setq res (apply function (nreverse args)))
41      (case accumulate
42  (:nconc (setq temp (last (nconc temp res))))
43  (:list (rplacd temp (list res))
44         (setq temp (cdr temp)))))))
45
46
47(defun mapc (function list &rest more-lists)
48  (map1 function (cons list more-lists) nil t))
49
50(defun mapcan (function list &rest more-lists)
51  (map1 function (cons list more-lists) :nconc t))
52
53(defun mapl (function list &rest more-lists)
54  (map1 function (cons list more-lists) nil nil))
55
56(defun maplist (function list &rest more-lists)
57  (map1 function (cons list more-lists) :list nil))
58
59(defun mapcon (function list &rest more-lists)
60  (map1 function (cons list more-lists) :nconc nil))
Note: See TracBrowser for help on using the repository browser.