Mercurial > hg > xemacs-beta
annotate lisp/cl-compat.el @ 4843:715b15990d0a
add more foo_checking_assert macros
lisp.h: Add structure_checking_assert(), gc_checking_assert(), etc. for
all types of error-checking. Also FOO_checking_assert_with_message()
and inline_FOO_checking_assert() -- the latter for use in an inline
function where you want the calling function's line/file to be reported
(requires some conspiracy with the function itself).
Add disabled_assert(), disabled_assert_at_line(),
disabled_assert_with_message(), for what to do when an assert is
disabled. Formerly, we used to do ((void) 0), but now we do
((void) x), so the variable appears used and any side effects of the
expression do get done. In Unicode-internal, the standard assert()
uses this, but not yet in this workspace.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 13 Jan 2010 03:01:43 -0600 |
parents | 8b50bee3c88c |
children | 2a54dfbe434f 308d34e9f07d |
rev | line source |
---|---|
613 | 1 ;;; cl-compat.el --- Common Lisp extensions for XEmacs Lisp (compatibility) |
209 | 2 |
3 ;; Copyright (C) 1993 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Dave Gillespie <daveg@synaptics.com> | |
6 ;; Version: 2.02 | |
7 ;; Keywords: extensions | |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
11 ;; XEmacs is free software; you can redistribute it and/or modify it | |
12 ;; under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; XEmacs is distributed in the hope that it will be useful, but | |
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 ;; General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
24 ;; 02111-1307, USA. | |
25 | |
2153 | 26 ;;; Synched up with: FSF 21.3. |
209 | 27 |
28 ;;; Commentary: | |
29 | |
30 ;; These are extensions to Emacs Lisp that provide a degree of | |
31 ;; Common Lisp compatibility, beyond what is already built-in | |
32 ;; in Emacs Lisp. | |
33 ;; | |
34 ;; This package was written by Dave Gillespie; it is a complete | |
35 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986. | |
36 ;; | |
37 ;; This package works with Emacs 18, Emacs 19, and XEmacs/Lucid Emacs 19. | |
38 ;; | |
39 ;; Bug reports, comments, and suggestions are welcome! | |
40 | |
41 ;; This file contains emulations of internal routines of the older | |
42 ;; CL package which users may have called directly from their code. | |
43 ;; Use (require 'cl-compat) to get these routines. | |
44 | |
45 ;; See cl.el for Change Log. | |
46 | |
47 | |
48 ;;; Code: | |
49 | |
50 ;; Require at load-time, but not when compiling cl-compat. | |
51 (or (featurep 'cl) (require 'cl)) | |
52 | |
53 | |
54 ;;; Keyword routines not supported by new package. | |
55 | |
56 (defmacro defkeyword (x &optional doc) | |
57 (list* 'defconst x (list 'quote x) (and doc (list doc)))) | |
58 | |
59 (defun keyword-of (sym) | |
4793
8b50bee3c88c
Remove attempted support for 1996-era emacs without self-quoting keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4678
diff
changeset
|
60 (or (keywordp sym) (keywordp (read (format ":%s" sym))))) |
209 | 61 |
62 ;;; Routines for parsing keyword arguments. | |
63 | |
64 (defun build-klist (arglist keys &optional allow-others) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
2153
diff
changeset
|
65 (let ((res (multiple-value-call 'mapcar* 'cons (unzip-lists arglist)))) |
209 | 66 (or allow-others |
67 (let ((bad (set-difference (mapcar 'car res) keys))) | |
68 (if bad (error "Bad keywords: %s not in %s" bad keys)))) | |
69 res)) | |
70 | |
71 (defun extract-from-klist (klist key &optional def) | |
72 (let ((res (assq key klist))) (if res (cdr res) def))) | |
73 | |
74 (defun keyword-argument-supplied-p (klist key) | |
75 (assq key klist)) | |
76 | |
77 (defun elt-satisfies-test-p (item elt klist) | |
78 (let ((test-not (cdr (assq ':test-not klist))) | |
79 (test (cdr (assq ':test klist))) | |
80 (key (cdr (assq ':key klist)))) | |
81 (if key (setq elt (funcall key elt))) | |
82 (if test-not (not (funcall test-not item elt)) | |
83 (funcall (or test 'eql) item elt)))) | |
84 | |
4678
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
85 ;; The rounding functions in C now have all the functionality this package |
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
86 ;; used to: |
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
87 (loop |
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
88 for symbol in '(floor ceiling round truncate) |
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
89 do (defalias (intern (format "cl-%s" symbol)) symbol)) |
209 | 90 |
91 (defun safe-idiv (a b) | |
92 (let* ((q (/ (abs a) (abs b))) | |
93 (s (* (signum a) (signum b)))) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
2153
diff
changeset
|
94 (values q (- a (* s q b)) s))) |
209 | 95 |
96 ;; Internal routines. | |
97 | |
98 (defun pair-with-newsyms (oldforms) | |
99 (let ((newsyms (mapcar (function (lambda (x) (gensym))) oldforms))) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
2153
diff
changeset
|
100 (values (mapcar* 'list newsyms oldforms) newsyms))) |
209 | 101 |
102 (defun zip-lists (evens odds) | |
103 (mapcan 'list evens odds)) | |
104 | |
105 (defun unzip-lists (list) | |
106 (let ((e nil) (o nil)) | |
107 (while list | |
108 (setq e (cons (car list) e) o (cons (cadr list) o) list (cddr list))) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
2153
diff
changeset
|
109 (values (nreverse e) (nreverse o)))) |
209 | 110 |
111 (defun reassemble-argslists (list) | |
112 (let ((n (apply 'min (mapcar 'length list))) (res nil)) | |
113 (while (>= (setq n (1- n)) 0) | |
114 (setq res (cons (mapcar (function (lambda (x) (elt x n))) list) res))) | |
115 res)) | |
116 | |
117 (defun duplicate-symbols-p (list) | |
118 (let ((res nil)) | |
119 (while list | |
120 (if (memq (car list) (cdr list)) (setq res (cons (car list) res))) | |
121 (setq list (cdr list))) | |
122 res)) | |
123 | |
124 | |
125 ;;; Setf internals. | |
126 | |
127 (defun setnth (n list x) | |
128 (setcar (nthcdr n list) x)) | |
129 | |
130 (defun setnthcdr (n list x) | |
131 (setcdr (nthcdr (1- n) list) x)) | |
132 | |
133 (defun setelt (seq n x) | |
134 (if (consp seq) (setcar (nthcdr n seq) x) (aset seq n x))) | |
135 | |
136 | |
137 ;;; Functions omitted: case-clausify, check-do-stepforms, check-do-endforms, | |
138 ;;; extract-do-inits, extract-do[*]-steps, select-stepping-forms, | |
139 ;;; elt-satisfies-if[-not]-p, with-keyword-args, mv-bind-clausify, | |
140 ;;; all names with embedded `$'. | |
141 | |
142 | |
143 (provide 'cl-compat) | |
144 | |
2153 | 145 ;;; arch-tag: 9996bb4f-aaf5-4592-b436-bf64759a3163 |
209 | 146 ;;; cl-compat.el ends here |