Generate curved quotes in pseudo-info nodes
[emacs.git] / lisp / obsolete / cl-compat.el
blobd6918da3e568b2adab95d4b967dfc13ca4d6badf
1 ;;; cl-compat.el --- Common Lisp extensions for GNU Emacs Lisp (compatibility)
3 ;; Copyright (C) 1993, 2001-2015 Free Software Foundation, Inc.
5 ;; Author: Dave Gillespie <daveg@synaptics.com>
6 ;; Version: 2.02
7 ;; Keywords: extensions
8 ;; Obsolete-since: 23.3
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; This file has been obsolete since Emacs 23.3.
29 ;; These are extensions to Emacs Lisp that provide a degree of
30 ;; Common Lisp compatibility, beyond what is already built-in
31 ;; in Emacs Lisp.
33 ;; This package was written by Dave Gillespie; it is a complete
34 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986.
36 ;; This package works with Emacs 18, Emacs 19, and Lucid Emacs 19.
38 ;; Bug reports, comments, and suggestions are welcome!
40 ;; This file contains emulations of internal routines of the older
41 ;; CL package which users may have called directly from their code.
42 ;; Use (require 'cl-compat) to get these routines.
44 ;; See cl.el for Change Log.
47 ;;; Code:
49 ;; This used to be:
50 ;; (or (featurep 'cl) (require 'cl))
51 ;; which just has the effect of fooling the byte-compiler into not
52 ;; loading cl when compiling. However, that leads to some bogus
53 ;; compiler warnings. Loading cl when compiling cannot do any harm,
54 ;; because for a long time bootstrap-emacs contained 'cl, due to being
55 ;; dumped from uncompiled files that eval-when-compile'd cl. So every
56 ;; file was compiled with 'cl loaded.
57 (require 'cl)
60 ;;; Keyword routines not supported by new package.
62 (defmacro defkeyword (x &optional doc)
63 (list* 'defconst x (list 'quote x) (and doc (list doc))))
65 (defun keyword-of (sym)
66 (or (keywordp sym) (keywordp (intern (format ":%s" sym)))))
69 ;;; Multiple values. Note that the new package uses a different
70 ;;; convention for multiple values. The following definitions
71 ;;; emulate the old convention; all function names have been changed
72 ;;; by capitalizing the first letter: Values, Multiple-value-*,
73 ;;; to avoid conflict with the new-style definitions in cl-macs.
75 (defvar *mvalues-values* nil)
77 (defun Values (&rest val-forms)
78 (setq *mvalues-values* val-forms)
79 (car val-forms))
81 (defun Values-list (val-forms)
82 (apply 'values val-forms))
84 (defmacro Multiple-value-list (form)
85 (list 'let* (list '(*mvalues-values* nil) (list '*mvalues-temp* form))
86 '(or (and (eq *mvalues-temp* (car *mvalues-values*)) *mvalues-values*)
87 (list *mvalues-temp*))))
89 (defmacro Multiple-value-call (function &rest args)
90 (declare (indent 1))
91 (list 'apply function
92 (cons 'append
93 (mapcar (function (lambda (x) (list 'Multiple-value-list x)))
94 args))))
96 (defmacro Multiple-value-bind (vars form &rest body)
97 (declare (indent 2))
98 (list* 'multiple-value-bind vars (list 'Multiple-value-list form) body))
100 (defmacro Multiple-value-setq (vars form)
101 (declare (indent 2))
102 (list 'multiple-value-setq vars (list 'Multiple-value-list form)))
104 (defmacro Multiple-value-prog1 (form &rest body)
105 (declare (indent 1))
106 (list 'prog1 form (list* 'let '((*mvalues-values* nil)) body)))
109 ;;; Routines for parsing keyword arguments.
111 (defun build-klist (arglist keys &optional allow-others)
112 (let ((res (Multiple-value-call 'mapcar* 'cons (unzip-lists arglist))))
113 (or allow-others
114 (let ((bad (set-difference (mapcar 'car res) keys)))
115 (if bad (error "Bad keywords: %s not in %s" bad keys))))
116 res))
118 (defun extract-from-klist (klist key &optional def)
119 (let ((res (assq key klist))) (if res (cdr res) def)))
121 (defun keyword-argument-supplied-p (klist key)
122 (assq key klist))
124 (defun elt-satisfies-test-p (item elt klist)
125 (let ((test-not (cdr (assq ':test-not klist)))
126 (test (cdr (assq ':test klist)))
127 (key (cdr (assq ':key klist))))
128 (if key (setq elt (funcall key elt)))
129 (if test-not (not (funcall test-not item elt))
130 (funcall (or test 'eql) item elt))))
132 (defun safe-idiv (a b)
133 (let* ((q (/ (abs a) (abs b)))
134 (s (* (signum a) (signum b))))
135 (Values q (- a (* s q b)) s)))
138 ;; Internal routines.
140 (defun pair-with-newsyms (oldforms)
141 (let ((newsyms (mapcar (lambda (x) (make-symbol "--cl-var--")) oldforms)))
142 (Values (mapcar* 'list newsyms oldforms) newsyms)))
144 (defun zip-lists (evens odds)
145 (mapcan 'list evens odds))
147 (defun unzip-lists (list)
148 (let ((e nil) (o nil))
149 (while list
150 (setq e (cons (car list) e) o (cons (cadr list) o) list (cddr list)))
151 (Values (nreverse e) (nreverse o))))
153 (defun reassemble-argslists (list)
154 (let ((n (apply 'min (mapcar 'length list))) (res nil))
155 (while (>= (setq n (1- n)) 0)
156 (setq res (cons (mapcar (function (lambda (x) (elt x n))) list) res)))
157 res))
159 (defun duplicate-symbols-p (list)
160 (let ((res nil))
161 (while list
162 (if (memq (car list) (cdr list)) (setq res (cons (car list) res)))
163 (setq list (cdr list)))
164 res))
167 ;;; Setf internals.
169 (defun setnth (n list x)
170 (setcar (nthcdr n list) x))
172 (defun setnthcdr (n list x)
173 (setcdr (nthcdr (1- n) list) x))
175 (defun setelt (seq n x)
176 (if (consp seq) (setcar (nthcdr n seq) x) (aset seq n x)))
179 ;;; Functions omitted: case-clausify, check-do-stepforms, check-do-endforms,
180 ;;; extract-do-inits, extract-do[*]-steps, select-stepping-forms,
181 ;;; elt-satisfies-if[-not]-p, with-keyword-args, mv-bind-clausify,
182 ;;; all names with embedded `$'.
185 (provide 'cl-compat)
187 ;; Local variables:
188 ;; byte-compile-warnings: (not cl-functions)
189 ;; End:
191 ;;; cl-compat.el ends here