summaryrefslogtreecommitdiff
path: root/list-functions-2.lisp
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-07-30 19:56:54 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-07-30 19:56:54 +0200
commitbae90539e72d2d52d48ccf6f70560bf42af2e546 (patch)
tree39b5d45d13d4bc02d12a6ec6a6688b9bf433d501 /list-functions-2.lisp
parenta9fc2993478ba50558492bd250d17cac7c2a657c (diff)
Add MAPCAN, MAPCAR, and MAPCON.
Diffstat (limited to 'list-functions-2.lisp')
-rw-r--r--list-functions-2.lisp33
1 files changed, 32 insertions, 1 deletions
diff --git a/list-functions-2.lisp b/list-functions-2.lisp
index 0bae5f3..c8d4ccd 100644
--- a/list-functions-2.lisp
+++ b/list-functions-2.lisp
@@ -1,5 +1,5 @@
(export '(copy-tree assoc assoc-if assoc-if-not rassoc rassoc-if
- rassoc-if-not sublis nsublis))
+ rassoc-if-not sublis nsublis mapcar mapcan mapcon))
(defun copy-tree (tree)
@@ -58,3 +58,34 @@
(defun nsublis (alist tree &key key test test-not)
(sublvs alist tree :key key :test test :test-not test-not))
+
+
+(defun some1 (function list)
+ (and (not (null list))
+ (or (funcall function (first list))
+ (some1 function (rest list)))))
+
+(defun every1 (function list)
+ (or (null list)
+ (and (funcall function (first list))
+ (every1 function (rest list)))))
+
+(defun mapcar1 (function list)
+ (when list
+ (cons (funcall function (first list))
+ (mapcar1 function (rest list)))))
+
+(defun mapcan1 (function list)
+ (%append (mapcar1 function list)))
+
+(defun mapcar (function list &rest more-lists)
+ (let ((lists (list* list more-lists)))
+ (when (every1 'identity lists)
+ (cons (apply function (mapcar1 'car lists))
+ (apply 'mapcar (list* function (mapcar1 'cdr lists)))))))
+
+(defun mapcan (function list &rest more-lists)
+ (%append (apply 'mapcar (list* function list more-lists))))
+
+(defun mapcon (function list &rest more-lists)
+ (apply (function mapcan) (list* function list more-lists)))