1 ;;; gnus-clfns.el --- compiler macros for emulating cl functions
2 ;; Copyright (C) 2000, 2001 Free Software Foundation, Inc.
4 ;; Author: Kastsumi Yamaoka <yamaoka@jpl.org>
5 ;; Keywords: cl, compile
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; Avoid cl runtime functions for FSF Emacsen.
30 (if (featurep 'xemacs)
34 (define-compiler-macro butlast (&whole form x &optional n)
35 (if (and (fboundp 'butlast)
36 (subrp (symbol-function 'butlast)))
47 (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
53 (setcdr (nthcdr (- m 2) x) nil)
56 (define-compiler-macro coerce (&whole form x type)
57 (if (and (fboundp 'coerce)
58 (subrp (symbol-function 'coerce)))
62 (cond ((eq type 'list) (if (listp x) x (append x nil)))
63 ((eq type 'vector) (if (vectorp x) x (vconcat x)))
64 ((eq type 'string) (if (stringp x) x (concat x)))
65 ((eq type 'array) (if (arrayp x) x (vconcat x)))
66 ((and (eq type 'character) (stringp x) (= (length x) 1))
68 ((and (eq type 'character) (symbolp x)
69 (= (length (symbol-name x)) 1))
70 (aref (symbol-name x) 0))
71 ((eq type 'float) (float x))
73 (t (error "Can't coerce %s to type %s" x type))))))
75 (define-compiler-macro last (&whole form x &optional n)
76 (if (and (fboundp 'last)
77 (subrp (symbol-function 'last)))
93 (while (consp (cdr x))
97 (define-compiler-macro merge (&whole form type seq1 seq2 pred &rest keys)
98 (if (and (fboundp 'merge)
99 (subrp (symbol-function 'merge)))
105 (or (listp seq1) (setq seq1 (append seq1 nil)))
106 (or (listp seq2) (setq seq2 (append seq2 nil)))
108 (while (and seq1 seq2)
109 (if (funcall pred (car seq2) (car seq1))
110 (push (pop seq2) res)
111 (push (pop seq1) res)))
112 (coerce (nconc (nreverse res) seq1 seq2) type)))))
114 (define-compiler-macro string (&whole form &rest args)
115 (if (and (fboundp 'string)
116 (subrp (symbol-function 'string)))
118 (list 'concat (cons 'list args))))
120 (define-compiler-macro subseq (&whole form seq start &optional end)
121 (if (and (fboundp 'subseq)
122 (subrp (symbol-function 'subseq)))
129 (substring seq start end)
132 (setq end (+ end (setq len (length seq)))))
134 (setq start (+ start (or len (setq len (length seq))))))
137 (setq seq (nthcdr start seq)))
139 (while (>= (setq end (1- end)) start)
140 (push (pop seq) res))
143 (let ((res (make-vector (max (- end start) 0) nil))
146 (aset res i (aref seq start))
153 (substring seq start)
156 (setq start (+ start (or len (setq len (length seq))))))
159 (setq seq (nthcdr start seq)))
162 (let* ((end (or len (length seq)))
163 (res (make-vector (max (- end start) 0) nil))
166 (aset res i (aref seq start))
172 (provide 'gnus-clfns)
174 ;;; gnus-clfns.el ends here