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

Last change on this file since 9672 was 9672, checked in by piso, 16 years ago

Moved MAPC to Primitives.java.

File size: 1.9 KB
Line 
1;;; map1.lisp
2;;;
3;;; Copyright (C) 2003-2005 Peter Graves
4;;; $Id: map1.lisp,v 1.3 2005-07-16 18:06:32 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;;; Adapted from CMUCL.
21
22(in-package #:system)
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(defun mapcan (function list &rest more-lists)
45  (map1 function (cons list more-lists) :nconc t))
46
47(defun mapl (function list &rest more-lists)
48  (map1 function (cons list more-lists) nil nil))
49
50(defun maplist (function list &rest more-lists)
51  (map1 function (cons list more-lists) :list nil))
52
53(defun mapcon (function list &rest more-lists)
54  (map1 function (cons list more-lists) :nconc nil))
Note: See TracBrowser for help on using the repository browser.