Mercurial > hg > xemacs-beta
diff lisp/cl-extra.el @ 4996:c17c857e20bf
Merge.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 03 Feb 2010 20:18:53 +0000 |
parents | 6ef8256a020a 8431b52e43b1 |
children | 8800b5350a13 |
line wrap: on
line diff
--- a/lisp/cl-extra.el Wed Feb 03 09:43:16 2010 -0700 +++ b/lisp/cl-extra.el Wed Feb 03 20:18:53 2010 +0000 @@ -75,14 +75,27 @@ (memq type '(integer ratio bigfloat)) (coerce-number x type))) ;; XEmacs addition: bit-vector coercion - ((eq type 'bit-vector) (if (bit-vector-p x) x - (apply 'bit-vector (append x nil)))) + ((or (eq type 'bit-vector) + (eq type 'simple-bit-vector)) + (if (bit-vector-p x) x (apply 'bit-vector (append x nil)))) ;; XEmacs addition: weak-list coercion ((eq type 'weak-list) (if (weak-list-p x) x (let ((wl (make-weak-list))) (set-weak-list-list wl (if (listp x) x (append x nil))) wl))) + ((and + (consp type) + (or (eq (car type) 'vector) + (eq (car type) 'simple-array) + (eq (car type) 'simple-vector)) + (cond + ((equal (cdr-safe type) '(*)) + (coerce x 'vector)) + ((equal (cdr-safe type) '(bit)) + (coerce x 'bit-vector)) + ((equal (cdr-safe type) '(character)) + (coerce x 'string))))) ((typep x type) x) (t (error "Can't coerce %s to type %s" x type)))) @@ -212,94 +225,8 @@ ;; (and (equal "" y) (equal #* x))))) ;; (t (equal x y))))))) -;;; Control structures. - -(defun cl-mapcar-many (cl-func cl-seqs) - (if (cdr (cdr cl-seqs)) - (let* ((cl-res nil) - (cl-n (apply 'min (mapcar 'length cl-seqs))) - (cl-i 0) - (cl-args (copy-sequence cl-seqs)) - cl-p1 cl-p2) - (setq cl-seqs (copy-sequence cl-seqs)) - (while (< cl-i cl-n) - (setq cl-p1 cl-seqs cl-p2 cl-args) - (while cl-p1 - (setcar cl-p2 - (if (consp (car cl-p1)) - (prog1 (car (car cl-p1)) - (setcar cl-p1 (cdr (car cl-p1)))) - (aref (car cl-p1) cl-i))) - (setq cl-p1 (cdr cl-p1) cl-p2 (cdr cl-p2))) - (push (apply cl-func cl-args) cl-res) - (setq cl-i (1+ cl-i))) - (nreverse cl-res)) - (let ((cl-res nil) - (cl-x (car cl-seqs)) - (cl-y (nth 1 cl-seqs))) - (let ((cl-n (min (length cl-x) (length cl-y))) - (cl-i -1)) - (while (< (setq cl-i (1+ cl-i)) cl-n) - (push (funcall cl-func - (if (consp cl-x) (pop cl-x) (aref cl-x cl-i)) - (if (consp cl-y) (pop cl-y) (aref cl-y cl-i))) - cl-res))) - (nreverse cl-res)))) - -(defun map (cl-type cl-func cl-seq &rest cl-rest) - "Map a function across one or more sequences, returning a sequence. -TYPE is the sequence type to return, FUNC is the function, and SEQS -are the argument sequences." - (let ((cl-res (apply 'mapcar* cl-func cl-seq cl-rest))) - (and cl-type (coerce cl-res cl-type)))) - -(defun maplist (cl-func cl-list &rest cl-rest) - "Map FUNC to each sublist of LIST or LISTS. -Like `mapcar', except applies to lists and their cdr's rather than to -the elements themselves." - (if cl-rest - (let ((cl-res nil) - (cl-args (cons cl-list (copy-sequence cl-rest))) - cl-p) - (while (not (memq nil cl-args)) - (push (apply cl-func cl-args) cl-res) - (setq cl-p cl-args) - (while cl-p (setcar cl-p (cdr (pop cl-p)) ))) - (nreverse cl-res)) - (let ((cl-res nil)) - (while cl-list - (push (funcall cl-func cl-list) cl-res) - (setq cl-list (cdr cl-list))) - (nreverse cl-res)))) - -;; XEmacs change: in Emacs, this function is named cl-mapc. -(defun mapc (cl-func cl-seq &rest cl-rest) - "Like `mapcar', but does not accumulate values returned by the function." - (if cl-rest - (apply 'map nil cl-func cl-seq cl-rest) - ;; XEmacs change: in the simplest case we call mapc-internal, - ;; which really doesn't accumulate any results. - (mapc-internal cl-func cl-seq)) - cl-seq) - -;; XEmacs addition: FSF compatibility -(defalias 'cl-mapc 'mapc) - -(defun mapl (cl-func cl-list &rest cl-rest) - "Like `maplist', but does not accumulate values returned by the function." - (if cl-rest - (apply 'maplist cl-func cl-list cl-rest) - (let ((cl-p cl-list)) - (while cl-p (funcall cl-func cl-p) (setq cl-p (cdr cl-p))))) - cl-list) - -(defun mapcan (cl-func cl-seq &rest cl-rest) - "Like `mapcar', but nconc's together the values returned by the function." - (apply 'nconc (apply 'mapcar* cl-func cl-seq cl-rest))) - -(defun mapcon (cl-func cl-list &rest cl-rest) - "Like `maplist', but nconc's together the values returned by the function." - (apply 'nconc (apply 'maplist cl-func cl-list cl-rest))) +;; XEmacs; #'map, #'mapc, #'mapl, #'maplist, #'mapcon are now in C, together +;; with #'map-into, which was never in this file. (defun some (cl-pred cl-seq &rest cl-rest) "Return true if PREDICATE is true of any element of SEQ or SEQs.