From bae90539e72d2d52d48ccf6f70560bf42af2e546 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Wed, 30 Jul 2008 19:56:54 +0200 Subject: Add MAPCAN, MAPCAR, and MAPCON. --- list-functions-2.lisp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'list-functions-2.lisp') 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))) -- cgit v1.2.3