Mercurial > hg > xemacs-beta
annotate lisp/cl-compat.el @ 5603:2b2f37e84792
Fixes for building native windows setup kits
| author | Vin Shelton <acs@xemacs.org> |
|---|---|
| date | Tue, 29 Nov 2011 09:05:36 -0500 |
| parents | 0af042a0c116 |
| children |
| 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 | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4793
diff
changeset
|
11 ;; XEmacs is free software: you can redistribute it and/or modify it |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4793
diff
changeset
|
12 ;; under the terms of the GNU General Public License as published by the |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4793
diff
changeset
|
13 ;; Free Software Foundation, either version 3 of the License, or (at your |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4793
diff
changeset
|
14 ;; option) any later version. |
| 209 | 15 |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4793
diff
changeset
|
16 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4793
diff
changeset
|
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4793
diff
changeset
|
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4793
diff
changeset
|
19 ;; for more details. |
| 209 | 20 |
| 21 ;; You should have received a copy of the GNU General Public License | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4793
diff
changeset
|
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
| 209 | 23 |
| 2153 | 24 ;;; Synched up with: FSF 21.3. |
| 209 | 25 |
| 26 ;;; Commentary: | |
| 27 | |
| 28 ;; These are extensions to Emacs Lisp that provide a degree of | |
| 29 ;; Common Lisp compatibility, beyond what is already built-in | |
| 30 ;; in Emacs Lisp. | |
| 31 ;; | |
| 32 ;; This package was written by Dave Gillespie; it is a complete | |
| 33 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986. | |
| 34 ;; | |
| 35 ;; This package works with Emacs 18, Emacs 19, and XEmacs/Lucid Emacs 19. | |
| 36 ;; | |
| 37 ;; Bug reports, comments, and suggestions are welcome! | |
| 38 | |
| 39 ;; This file contains emulations of internal routines of the older | |
| 40 ;; CL package which users may have called directly from their code. | |
| 41 ;; Use (require 'cl-compat) to get these routines. | |
| 42 | |
| 43 ;; See cl.el for Change Log. | |
| 44 | |
| 45 | |
| 46 ;;; Code: | |
| 47 | |
| 48 ;; Require at load-time, but not when compiling cl-compat. | |
| 49 (or (featurep 'cl) (require 'cl)) | |
| 50 | |
| 51 | |
| 52 ;;; Keyword routines not supported by new package. | |
| 53 | |
| 54 (defmacro defkeyword (x &optional doc) | |
| 55 (list* 'defconst x (list 'quote x) (and doc (list doc)))) | |
| 56 | |
| 57 (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
|
58 (or (keywordp sym) (keywordp (read (format ":%s" sym))))) |
| 209 | 59 |
| 60 ;;; Routines for parsing keyword arguments. | |
| 61 | |
| 62 (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
|
63 (let ((res (multiple-value-call 'mapcar* 'cons (unzip-lists arglist)))) |
| 209 | 64 (or allow-others |
| 65 (let ((bad (set-difference (mapcar 'car res) keys))) | |
| 66 (if bad (error "Bad keywords: %s not in %s" bad keys)))) | |
| 67 res)) | |
| 68 | |
| 69 (defun extract-from-klist (klist key &optional def) | |
| 70 (let ((res (assq key klist))) (if res (cdr res) def))) | |
| 71 | |
| 72 (defun keyword-argument-supplied-p (klist key) | |
| 73 (assq key klist)) | |
| 74 | |
| 75 (defun elt-satisfies-test-p (item elt klist) | |
|
5344
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4793
diff
changeset
|
76 (let ((test-not (cdr (assq :test-not klist))) |
|
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4793
diff
changeset
|
77 (test (cdr (assq :test klist))) |
|
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4793
diff
changeset
|
78 (key (cdr (assq :key klist)))) |
| 209 | 79 (if key (setq elt (funcall key elt))) |
| 80 (if test-not (not (funcall test-not item elt)) | |
| 81 (funcall (or test 'eql) item elt)))) | |
| 82 | |
|
4678
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
83 ;; 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
|
84 ;; used to: |
|
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
85 (loop |
|
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
86 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
|
87 do (defalias (intern (format "cl-%s" symbol)) symbol)) |
| 209 | 88 |
| 89 (defun safe-idiv (a b) | |
| 90 (let* ((q (/ (abs a) (abs b))) | |
| 91 (s (* (signum a) (signum b)))) | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
2153
diff
changeset
|
92 (values q (- a (* s q b)) s))) |
| 209 | 93 |
| 94 ;; Internal routines. | |
| 95 | |
| 96 (defun pair-with-newsyms (oldforms) | |
| 97 (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
|
98 (values (mapcar* 'list newsyms oldforms) newsyms))) |
| 209 | 99 |
| 100 (defun zip-lists (evens odds) | |
| 101 (mapcan 'list evens odds)) | |
| 102 | |
| 103 (defun unzip-lists (list) | |
| 104 (let ((e nil) (o nil)) | |
| 105 (while list | |
| 106 (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
|
107 (values (nreverse e) (nreverse o)))) |
| 209 | 108 |
| 109 (defun reassemble-argslists (list) | |
| 110 (let ((n (apply 'min (mapcar 'length list))) (res nil)) | |
| 111 (while (>= (setq n (1- n)) 0) | |
| 112 (setq res (cons (mapcar (function (lambda (x) (elt x n))) list) res))) | |
| 113 res)) | |
| 114 | |
| 115 (defun duplicate-symbols-p (list) | |
| 116 (let ((res nil)) | |
| 117 (while list | |
| 118 (if (memq (car list) (cdr list)) (setq res (cons (car list) res))) | |
| 119 (setq list (cdr list))) | |
| 120 res)) | |
| 121 | |
| 122 | |
| 123 ;;; Setf internals. | |
| 124 | |
| 125 (defun setnth (n list x) | |
| 126 (setcar (nthcdr n list) x)) | |
| 127 | |
| 128 (defun setnthcdr (n list x) | |
| 129 (setcdr (nthcdr (1- n) list) x)) | |
| 130 | |
| 131 (defun setelt (seq n x) | |
| 132 (if (consp seq) (setcar (nthcdr n seq) x) (aset seq n x))) | |
| 133 | |
| 134 | |
| 135 ;;; Functions omitted: case-clausify, check-do-stepforms, check-do-endforms, | |
| 136 ;;; extract-do-inits, extract-do[*]-steps, select-stepping-forms, | |
| 137 ;;; elt-satisfies-if[-not]-p, with-keyword-args, mv-bind-clausify, | |
| 138 ;;; all names with embedded `$'. | |
| 139 | |
| 140 | |
| 141 (provide 'cl-compat) | |
| 142 | |
| 2153 | 143 ;;; arch-tag: 9996bb4f-aaf5-4592-b436-bf64759a3163 |
| 209 | 144 ;;; cl-compat.el ends here |
