Mercurial > hg > xemacs-beta
comparison lisp/cl-macs.el @ 5219:2d0937dc83cf
Tidying of CL files; make docstrings read better, remove commented-out code
2010-05-30 Aidan Kehoe <kehoea@parhasard.net>
* cl.el: Remove extraneous empty lines.
Remove the commented-out Lisp implementation of #'last,
#'copy-list.
Remove #'cl-maclisp-member.
(acons, pairlis): Have the argument list reflect the docstring for
these functions.
* cl-macs.el (defun*): Have the argument list reflect the
docstring.
Document the syntax of keywords in ARGLIST.
(defmacro*): Have the argument list reflect the docstring.
Document &body, &whole and &environment.
(function*): Have the argument list reflect the docstring.
(loop): Have the argument list reflect the docstring.
(eval-when, dolist, dotimes, do-symbols, flet, labels, macrolet,
symbol-macrolet):
Specify the argument list using the arguments: (...) syntax.
(define-setf-method, rotatef, defsubst*): Have the argument list
reflect the docstring.
(letf, letf*):
Specify the argument list using the arguments: (...) syntax.
(svref, acons, pairlis): Add compiler macros for these functions.
* cl-extra.el: Remove the commented-out Lisp implementation of
#'equalp. If we want to look at it, it's in version control.
(cl-expt): Remove this. The subr #'expt is always available.
Call #'cl-float-limits at dump time.
Remove the commented-out Lisp implementation of #'subseq.
(concatenate): Use (error 'invalid-argument ...) here, if TYPE is
not understood.
(list-length): Don't manually get the length of a list, call
#'length and return nil if the list is circular.
* byte-optimize.el (equalp): This needs
byte-optimize-binary-predicate as its optimizer, as do the other
equality predicates.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 30 May 2010 13:27:36 +0100 |
parents | 2e528066e2fc |
children | 7789ae555c45 |
comparison
equal
deleted
inserted
replaced
5218:ec2ddc82f10d | 5219:2d0937dc83cf |
---|---|
173 | 173 |
174 | 174 |
175 ;;; Program structure. | 175 ;;; Program structure. |
176 | 176 |
177 ;;;###autoload | 177 ;;;###autoload |
178 (defmacro defun* (name args &rest body) | 178 (defmacro defun* (name arglist &optional docstring &rest body) |
179 "(defun* NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function. | 179 "Define NAME as a function. |
180 Like normal `defun', except ARGLIST allows full Common Lisp conventions, | 180 Like normal `defun', except ARGLIST allows full Common Lisp conventions, |
181 and BODY is implicitly surrounded by (block NAME ...). | 181 and BODY is implicitly surrounded by (block NAME ...). |
182 | 182 |
183 \"Full Common Lisp conventions\" means that: | 183 \"Full Common Lisp conventions\" means that: |
184 | 184 |
191 INITFORM is omitted) and stored as VAR's value, and SVAR is bound to t. | 191 INITFORM is omitted) and stored as VAR's value, and SVAR is bound to t. |
192 If an arguent is available for VAR, and INITFORM is unused, SVAR is | 192 If an arguent is available for VAR, and INITFORM is unused, SVAR is |
193 bound to nil. | 193 bound to nil. |
194 | 194 |
195 -- &key specifies keyword arguments. The format of each argument is | 195 -- &key specifies keyword arguments. The format of each argument is |
196 VAR || ( { VAR || (KEYWORD VAR) } [INITFORM [SVAR]]) -- #### document me. | 196 VAR || ( { VAR || (KEYWORD VAR) } [INITFORM [SVAR]]). |
197 | |
198 If VAR is specified on its own, VAR is bound within BODY to the value | |
199 supplied by the caller for the corresponding keyword; for example, &key | |
200 my-value means callers write :my-value RUNTIME-EXPRESSION. | |
201 | |
202 If (VAR INITFORM) is specified, INITFORM is an expression evaluated at | |
203 runtime to determine a default value for VAR. | |
204 | |
205 If (VAR INITFORM SVAR) is specified, SVAR is variable available within | |
206 BODY that is non-nil if VAR was explicitly specified in the calling | |
207 expression. | |
208 | |
209 If ((KEYWORD VAR)) is specified, KEYWORD is the keyword to be used by | |
210 callers, and VAR is the corresponding variable binding within BODY. | |
211 | |
212 In calls to NAME, values for a given keyword may be supplied multiple | |
213 times. The first value is the only one used. | |
197 | 214 |
198 -- &allow-other-keys means that if other keyword arguments are given that are | 215 -- &allow-other-keys means that if other keyword arguments are given that are |
199 not specifically list in the arg list, they are allowed, rather than an | 216 not specifically list in the arg list, they are allowed, rather than an |
200 error being signalled. They can be retrieved with an &rest form. | 217 error being signalled. They can be retrieved with an &rest form. |
201 | 218 |
202 -- &aux specifies extra bindings, exactly like a `let*' enclosing the body. | 219 -- &aux specifies extra bindings, exactly like a `let*' enclosing the body. |
203 The format of each binding is VAR || (VAR [INITFORM]) -- exactly like the | 220 The format of each binding is VAR || (VAR [INITFORM]) -- exactly like the |
204 format of `let'/`let*' bindings. | 221 format of `let'/`let*' bindings. |
205 " | 222 " |
206 (let* ((res (cl-transform-lambda (cons args body) name)) | 223 (let* ((res (cl-transform-lambda (list* arglist docstring body) name)) |
207 (form (list* 'defun name (cdr res)))) | 224 (form (list* 'defun name (cdr res)))) |
208 (if (car res) (list 'progn (car res) form) form))) | 225 (if (car res) (list 'progn (car res) form) form))) |
209 | 226 |
210 ;;;###autoload | 227 ;;;###autoload |
211 (defmacro defmacro* (name args &rest body) | 228 (defmacro defmacro* (name arglist &optional docstring &rest body) |
212 "(defmacro* NAME ARGLIST [DOCSTRING] BODY...): define NAME as a macro. | 229 "Define NAME as a macro. |
213 Like normal `defmacro', except ARGLIST allows full Common Lisp conventions, | 230 Like normal `defmacro', except ARGLIST allows full Common Lisp conventions, |
214 and BODY is implicitly surrounded by (block NAME ...). | 231 and BODY is implicitly surrounded by (block NAME ...). |
215 | 232 |
216 \"Full Common Lisp conventions\" means that: | 233 \"Full Common Lisp conventions\" means that: |
217 | 234 |
218 -- The lambda-list keywords &optional, &rest, &key, &allow-other-keys, and | 235 -- The lambda-list keywords &optional, &rest, &key, &allow-other-keys, and |
219 &aux are allowed, as in `defun*'. | 236 &aux are allowed, as in `defun*'. |
220 | 237 |
221 -- Three additional lambda-list keywords are allowed: &body, &whole, and | 238 -- Three additional lambda-list keywords are allowed: &body, &whole, and |
222 &environment. #### Document me. | 239 &environment: |
240 | |
241 &body is equivalent to &rest, but is intended to indicate that the | |
242 following arguments are the body of some piece of code, and should be | |
243 indented as such. | |
244 | |
245 &whole must come first; it is followed by a single variable that, at | |
246 macro expansion time, reflects all the arguments supplied to the macro, | |
247 as if it had been declared with a single &rest argument. | |
248 | |
249 &environment specifies local semantics for various macros for use within | |
250 the expansion of BODY. See the ENVIRONMENT argument to `macroexpand'. | |
223 | 251 |
224 -- The macro arg list syntax allows for \"destructuring\" -- see also | 252 -- The macro arg list syntax allows for \"destructuring\" -- see also |
225 `destructuring-bind', which destructures exactly like `defmacro*', and | 253 `destructuring-bind', which destructures exactly like `defmacro*', and |
226 `loop', which does a rather different way of destructuring. Anywhere | 254 `loop', which does a rather different way of destructuring. Anywhere |
227 that a simple argument may appear, and (if following a lambda-list | 255 that a simple argument may appear, and (if following a lambda-list |
246 actual structure does not match the expected structure. On the | 274 actual structure does not match the expected structure. On the |
247 other hand, loop destructuring is lax -- extra arguments in a list | 275 other hand, loop destructuring is lax -- extra arguments in a list |
248 are ignored, not enough arguments cause the remaining parameters to | 276 are ignored, not enough arguments cause the remaining parameters to |
249 receive a value of nil, etc. | 277 receive a value of nil, etc. |
250 " | 278 " |
251 (let* ((res (cl-transform-lambda (cons args body) name)) | 279 (let* ((res (cl-transform-lambda (list* arglist docstring body) name)) |
252 (form (list* 'defmacro name (cdr res)))) | 280 (form (list* 'defmacro name (cdr res)))) |
253 (if (car res) (list 'progn (car res) form) form))) | 281 (if (car res) (list 'progn (car res) form) form))) |
254 | 282 |
255 ;;;###autoload | 283 ;;;###autoload |
256 (defmacro function* (func) | 284 (defmacro function* (symbol-or-lambda) |
257 "(function* SYMBOL-OR-LAMBDA): introduce a function. | 285 "Introduce a function. |
258 Like normal `function', except that if argument is a lambda form, its | 286 Like normal `function', except that if argument is a lambda form, its |
259 ARGLIST allows full Common Lisp conventions." | 287 ARGLIST allows full Common Lisp conventions." |
260 (if (eq (car-safe func) 'lambda) | 288 (if (eq (car-safe symbol-or-lambda) 'lambda) |
261 (let* ((res (cl-transform-lambda (cdr func) 'cl-none)) | 289 (let* ((res (cl-transform-lambda (cdr symbol-or-lambda) 'cl-none)) |
262 (form (list 'function (cons 'lambda (cdr res))))) | 290 (form (list 'function (cons 'lambda (cdr res))))) |
263 (if (car res) (list 'progn (car res) form) form)) | 291 (if (car res) (list 'progn (car res) form) form)) |
264 (list 'function func))) | 292 (list 'function symbol-or-lambda))) |
265 | 293 |
266 (defun cl-transform-function-property (func prop form) | 294 (defun cl-transform-function-property (func prop form) |
267 (let ((res (cl-transform-lambda form func))) | 295 (let ((res (cl-transform-lambda form func))) |
268 (append '(progn) (cdr (cdr (car res))) | 296 (append '(progn) (cdr (cdr (car res))) |
269 (list (list 'put (list 'quote func) (list 'quote prop) | 297 (list (list 'put (list 'quote func) (list 'quote prop) |
553 | 581 |
554 (defvar cl-not-toplevel nil) | 582 (defvar cl-not-toplevel nil) |
555 | 583 |
556 ;;;###autoload | 584 ;;;###autoload |
557 (defmacro eval-when (when &rest body) | 585 (defmacro eval-when (when &rest body) |
558 "(eval-when (WHEN...) BODY...): control when BODY is evaluated. | 586 "Control when BODY is evaluated. |
559 If `compile' is in WHEN, BODY is evaluated when compiled at top-level. | 587 If `compile' is in WHEN, BODY is evaluated when compiled at top-level. |
560 If `load' is in WHEN, BODY is evaluated when loaded after top-level compile. | 588 If `load' is in WHEN, BODY is evaluated when loaded after top-level compile. |
561 If `eval' is in WHEN, BODY is evaluated when interpreted or at non-top-level." | 589 If `eval' is in WHEN, BODY is evaluated when interpreted or at non-top-level. |
590 | |
591 arguments: ((&rest WHEN) &body BODY)" | |
562 (if (and (fboundp 'cl-compiling-file) (cl-compiling-file) | 592 (if (and (fboundp 'cl-compiling-file) (cl-compiling-file) |
563 (not cl-not-toplevel) (not (boundp 'for-effect))) ; horrible kludge | 593 (not cl-not-toplevel) (not (boundp 'for-effect))) ; horrible kludge |
564 (let ((comp (or (memq 'compile when) (memq :compile-toplevel when))) | 594 (let ((comp (or (memq 'compile when) (memq :compile-toplevel when))) |
565 (cl-not-toplevel t)) | 595 (cl-not-toplevel t)) |
566 (if (or (memq 'load when) (memq :load-toplevel when)) | 596 (if (or (memq 'load when) (memq :load-toplevel when)) |
766 (defvar loop-initially) (defvar loop-map-form) (defvar loop-name) | 796 (defvar loop-initially) (defvar loop-map-form) (defvar loop-name) |
767 (defvar loop-result) (defvar loop-result-explicit) | 797 (defvar loop-result) (defvar loop-result-explicit) |
768 (defvar loop-result-var) (defvar loop-steps) (defvar loop-symbol-macs) | 798 (defvar loop-result-var) (defvar loop-steps) (defvar loop-symbol-macs) |
769 | 799 |
770 ;;;###autoload | 800 ;;;###autoload |
771 (defmacro loop (&rest args) | 801 (defmacro loop (&rest clauses) |
772 "(loop CLAUSE...): The Common Lisp `loop' macro. | 802 "The Common Lisp `loop' macro. |
773 | 803 |
774 The loop macro consists of a series of clauses, which do things like | 804 The loop macro consists of a series of clauses, which do things like |
775 iterate variables, set conditions for exiting the loop, accumulating values | 805 iterate variables, set conditions for exiting the loop, accumulating values |
776 to be returned as the return value of the loop, and executing arbitrary | 806 to be returned as the return value of the loop, and executing arbitrary |
777 blocks of code. Each clause is processed in turn, and the loop executes its | 807 blocks of code. Each clause is processed in turn, and the loop executes its |
1048 | 1078 |
1049 named NAME | 1079 named NAME |
1050 Specify the name for block surrounding the loop, in place of nil. | 1080 Specify the name for block surrounding the loop, in place of nil. |
1051 (See `block'.) | 1081 (See `block'.) |
1052 " | 1082 " |
1053 (if (not (memq t (mapcar 'symbolp (delq nil (delq t (copy-list args)))))) | 1083 (if (not (memq t (mapcar 'symbolp (delq nil (delq t (copy-list clauses)))))) |
1054 (list 'block nil (list* 'while t args)) | 1084 (list 'block nil (list* 'while t clauses)) |
1055 (let ((loop-name nil) (loop-bindings nil) | 1085 (let ((loop-name nil) (loop-bindings nil) |
1056 (loop-body nil) (loop-steps nil) | 1086 (loop-body nil) (loop-steps nil) |
1057 (loop-result nil) (loop-result-explicit nil) | 1087 (loop-result nil) (loop-result-explicit nil) |
1058 (loop-result-var nil) (loop-finish-flag nil) | 1088 (loop-result-var nil) (loop-finish-flag nil) |
1059 (loop-accum-var nil) (loop-accum-vars nil) | 1089 (loop-accum-var nil) (loop-accum-vars nil) |
1060 (loop-initially nil) (loop-finally nil) | 1090 (loop-initially nil) (loop-finally nil) |
1061 (loop-map-form nil) (loop-first-flag nil) | 1091 (loop-map-form nil) (loop-first-flag nil) |
1062 (loop-destr-temps nil) (loop-symbol-macs nil)) | 1092 (loop-destr-temps nil) (loop-symbol-macs nil) |
1063 (setq args (append args '(cl-end-loop))) | 1093 (args (append clauses '(cl-end-loop)))) |
1064 (while (not (eq (car args) 'cl-end-loop)) (cl-parse-loop-clause)) | 1094 (while (not (eq (car args) 'cl-end-loop)) (cl-parse-loop-clause)) |
1065 (if loop-finish-flag | 1095 (if loop-finish-flag |
1066 (push (list (list loop-finish-flag t)) loop-bindings)) | 1096 (push (list (list loop-finish-flag t)) loop-bindings)) |
1067 (if loop-first-flag | 1097 (if loop-first-flag |
1068 (progn (push (list (list loop-first-flag t)) loop-bindings) | 1098 (progn (push (list (list loop-first-flag t)) loop-bindings) |
1644 (apply 'append sets))))))) | 1674 (apply 'append sets))))))) |
1645 (or (cdr endtest) '(nil))))) | 1675 (or (cdr endtest) '(nil))))) |
1646 | 1676 |
1647 ;;;###autoload | 1677 ;;;###autoload |
1648 (defmacro dolist (spec &rest body) | 1678 (defmacro dolist (spec &rest body) |
1649 "(dolist (VAR LIST [RESULT]) BODY...): loop over a list. | 1679 "Loop over a list. |
1650 Evaluate BODY with VAR bound to each `car' from LIST, in turn. | 1680 Evaluate BODY with VAR bound to each `car' from LIST, in turn. |
1651 Then evaluate RESULT to get return value, default nil." | 1681 Then evaluate RESULT to get return value, default nil. |
1682 | |
1683 arguments: ((VAR LIST &optional RESULT) &body BODY)" | |
1652 (let ((temp (gensym "--dolist-temp--"))) | 1684 (let ((temp (gensym "--dolist-temp--"))) |
1653 (list 'block nil | 1685 (list 'block nil |
1654 (list* 'let (list (list temp (nth 1 spec)) (car spec)) | 1686 (list* 'let (list (list temp (nth 1 spec)) (car spec)) |
1655 (list* 'while temp (list 'setq (car spec) (list 'car temp)) | 1687 (list* 'while temp (list 'setq (car spec) (list 'car temp)) |
1656 (append body (list (list 'setq temp | 1688 (append body (list (list 'setq temp |
1659 (cons (list 'setq (car spec) nil) (cdr (cdr spec))) | 1691 (cons (list 'setq (car spec) nil) (cdr (cdr spec))) |
1660 '(nil)))))) | 1692 '(nil)))))) |
1661 | 1693 |
1662 ;;;###autoload | 1694 ;;;###autoload |
1663 (defmacro dotimes (spec &rest body) | 1695 (defmacro dotimes (spec &rest body) |
1664 "(dotimes (VAR COUNT [RESULT]) BODY...): loop a certain number of times. | 1696 "Loop a certain number of times. |
1665 Evaluate BODY with VAR bound to successive integers from 0, inclusive, | 1697 Evaluate BODY with VAR bound to successive integers from 0, inclusive, |
1666 to COUNT, exclusive. Then evaluate RESULT to get return value, default | 1698 to COUNT, exclusive. Then evaluate RESULT to get return value, default |
1667 nil." | 1699 nil. |
1700 | |
1701 arguments: ((VAR COUNT &optional RESULT) &body BODY)" | |
1668 (let ((temp (gensym "--dotimes-temp--"))) | 1702 (let ((temp (gensym "--dotimes-temp--"))) |
1669 (list 'block nil | 1703 (list 'block nil |
1670 (list* 'let (list (list temp (nth 1 spec)) (list (car spec) 0)) | 1704 (list* 'let (list (list temp (nth 1 spec)) (list (car spec) 0)) |
1671 (list* 'while (list '< (car spec) temp) | 1705 (list* 'while (list '< (car spec) temp) |
1672 (append body (list (list 'incf (car spec))))) | 1706 (append body (list (list 'incf (car spec))))) |
1673 (or (cdr (cdr spec)) '(nil)))))) | 1707 (or (cdr (cdr spec)) '(nil)))))) |
1674 | 1708 |
1675 ;;;###autoload | 1709 ;;;###autoload |
1676 (defmacro do-symbols (spec &rest body) | 1710 (defmacro do-symbols (spec &rest body) |
1677 "(dosymbols (VAR [OBARRAY [RESULT]]) BODY...): loop over all symbols. | 1711 "Loop over all symbols. |
1678 Evaluate BODY with VAR bound to each interned symbol, or to each symbol | 1712 Evaluate BODY with VAR bound to each interned symbol, or to each symbol |
1679 from OBARRAY." | 1713 from OBARRAY. |
1714 | |
1715 arguments: ((VAR &optional OBARRAY RESULT) &body BODY)" | |
1680 ;; Apparently this doesn't have an implicit block. | 1716 ;; Apparently this doesn't have an implicit block. |
1681 (list 'block nil | 1717 (list 'block nil |
1682 (list 'let (list (car spec)) | 1718 (list 'let (list (car spec)) |
1683 (list* 'mapatoms | 1719 (list* 'mapatoms |
1684 (list 'function (list* 'lambda (list (car spec)) body)) | 1720 (list 'function (list* 'lambda (list (car spec)) body)) |
1716 '(cl-progv-after)))) | 1752 '(cl-progv-after)))) |
1717 | 1753 |
1718 ;;; This should really have some way to shadow 'byte-compile properties, etc. | 1754 ;;; This should really have some way to shadow 'byte-compile properties, etc. |
1719 ;;;###autoload | 1755 ;;;###autoload |
1720 (defmacro flet (bindings &rest body) | 1756 (defmacro flet (bindings &rest body) |
1721 "(flet ((FUNC ARGLIST BODY...) ...) FORM...): make temporary function defns. | 1757 "Make temporary function definitions. |
1722 This is an analogue of `let' that operates on the function cell of FUNC | 1758 This is an analogue of `let' that operates on the function cell of FUNC |
1723 rather than its value cell. The FORMs are evaluated with the specified | 1759 rather than its value cell. The FORMs are evaluated with the specified |
1724 function definitions in place, then the definitions are undone (the FUNCs | 1760 function definitions in place, then the definitions are undone (the FUNCs |
1725 go back to their previous definitions, or lack thereof)." | 1761 go back to their previous definitions, or lack thereof). |
1762 | |
1763 arguments: (((FUNC ARGLIST &body BODY) &rest FUNCTIONS) &body FORM)" | |
1726 (list* 'letf* | 1764 (list* 'letf* |
1727 (mapcar | 1765 (mapcar |
1728 #'(lambda (x) | 1766 #'(lambda (x) |
1729 (if (or (and (fboundp (car x)) | 1767 (if (or (and (fboundp (car x)) |
1730 (eq (car-safe (symbol-function (car x))) 'macro)) | 1768 (eq (car-safe (symbol-function (car x))) 'macro)) |
1741 bindings) | 1779 bindings) |
1742 body)) | 1780 body)) |
1743 | 1781 |
1744 ;;;###autoload | 1782 ;;;###autoload |
1745 (defmacro labels (bindings &rest body) | 1783 (defmacro labels (bindings &rest body) |
1746 "(labels ((FUNC ARGLIST BODY...) ...) FORM...): make temporary func bindings. | 1784 "Make temporary func bindings. |
1747 This is like `flet', except the bindings are lexical instead of dynamic. | 1785 This is like `flet', except the bindings are lexical instead of dynamic. |
1748 Unlike `flet', this macro is fully compliant with the Common Lisp standard." | 1786 Unlike `flet', this macro is fully compliant with the Common Lisp standard. |
1787 | |
1788 arguments: (((FUNC ARGLIST &body BODY) &rest FUNCTIONS) &body FORM)" | |
1749 (let ((vars nil) (sets nil) (cl-macro-environment cl-macro-environment)) | 1789 (let ((vars nil) (sets nil) (cl-macro-environment cl-macro-environment)) |
1750 (while bindings | 1790 (while bindings |
1751 (let ((var (gensym))) | 1791 (let ((var (gensym))) |
1752 (push var vars) | 1792 (push var vars) |
1753 (push (list 'function* (cons 'lambda (cdar bindings))) sets) | 1793 (push (list 'function* (cons 'lambda (cdar bindings))) sets) |
1761 | 1801 |
1762 ;; The following ought to have a better definition for use with newer | 1802 ;; The following ought to have a better definition for use with newer |
1763 ;; byte compilers. | 1803 ;; byte compilers. |
1764 ;;;###autoload | 1804 ;;;###autoload |
1765 (defmacro macrolet (bindings &rest body) | 1805 (defmacro macrolet (bindings &rest body) |
1766 "(macrolet ((NAME ARGLIST BODY...) ...) FORM...): make temporary macro defns. | 1806 "Make temporary macro definitions. |
1767 This is like `flet', but for macros instead of functions." | 1807 This is like `flet', but for macros instead of functions. |
1808 | |
1809 arguments: (((NAME ARGLIST &optional DOCSTRING &body body) &rest MACROS) &body FORM)" | |
1768 (if (cdr bindings) | 1810 (if (cdr bindings) |
1769 (list 'macrolet | 1811 (list 'macrolet |
1770 (list (car bindings)) (list* 'macrolet (cdr bindings) body)) | 1812 (list (car bindings)) (list* 'macrolet (cdr bindings) body)) |
1771 (if (null bindings) (cons 'progn body) | 1813 (if (null bindings) (cons 'progn body) |
1772 (let* ((name (caar bindings)) | 1814 (let* ((name (caar bindings)) |
1776 (cons (list* name 'lambda (cdr res)) | 1818 (cons (list* name 'lambda (cdr res)) |
1777 cl-macro-environment)))))) | 1819 cl-macro-environment)))))) |
1778 | 1820 |
1779 ;;;###autoload | 1821 ;;;###autoload |
1780 (defmacro symbol-macrolet (bindings &rest body) | 1822 (defmacro symbol-macrolet (bindings &rest body) |
1781 "(symbol-macrolet ((NAME EXPANSION) ...) FORM...): make symbol macro defns. | 1823 "Make symbol macro definitions. |
1782 Within the body FORMs, references to the variable NAME will be replaced | 1824 Within the body FORMs, references to the variable NAME will be replaced |
1783 by EXPANSION, and (setq NAME ...) will act like (setf EXPANSION ...)." | 1825 by EXPANSION, and (setq NAME ...) will act like (setf EXPANSION ...). |
1826 | |
1827 arguments: (((NAME EXPANSION) &rest SYMBOL-MACROS) &body FORM)" | |
1784 (if (cdr bindings) | 1828 (if (cdr bindings) |
1785 (list 'symbol-macrolet | 1829 (list 'symbol-macrolet |
1786 (list (car bindings)) (list* 'symbol-macrolet (cdr bindings) body)) | 1830 (list (car bindings)) (list* 'symbol-macrolet (cdr bindings) body)) |
1787 (if (null bindings) (cons 'progn body) | 1831 (if (null bindings) (cons 'progn body) |
1788 (cl-macroexpand-all (cons 'progn body) | 1832 (cl-macroexpand-all (cons 'progn body) |
1990 | 2034 |
1991 | 2035 |
1992 ;;; Generalized variables. | 2036 ;;; Generalized variables. |
1993 | 2037 |
1994 ;;;###autoload | 2038 ;;;###autoload |
1995 (defmacro define-setf-method (func args &rest body) | 2039 (defmacro define-setf-method (name arglist &rest body) |
1996 "(define-setf-method NAME ARGLIST BODY...): define a `setf' method. | 2040 "Define a `setf' method. |
1997 This method shows how to handle `setf's to places of the form (NAME ARGS...). | 2041 This method shows how to handle `setf's to places of the form (NAME ARGLIST...). |
1998 The argument forms ARGS are bound according to ARGLIST, as if NAME were | 2042 The argument forms are bound according to ARGLIST, as if NAME were |
1999 going to be expanded as a macro, then the BODY forms are executed and must | 2043 going to be expanded as a macro, then the BODY forms are executed and must |
2000 return a list of five elements: a temporary-variables list, a value-forms | 2044 return a list of five elements: a temporary-variables list, a value-forms |
2001 list, a store-variables list (of length one), a store-form, and an access- | 2045 list, a store-variables list (of length one), a store-form, and an access- |
2002 form. See `defsetf' for a simpler way to define most setf-methods." | 2046 form. See `defsetf' for a simpler way to define most setf-methods." |
2003 (append '(eval-when (compile load eval)) | 2047 (append '(eval-when (compile load eval)) |
2004 (if (stringp (car body)) | 2048 (if (stringp (car body)) |
2005 (list (list 'put (list 'quote func) '(quote setf-documentation) | 2049 (list (list 'put (list 'quote name) '(quote setf-documentation) |
2006 (pop body)))) | 2050 (pop body)))) |
2007 (list (cl-transform-function-property | 2051 (list (cl-transform-function-property |
2008 func 'setf-method (cons args body))))) | 2052 name 'setf-method (cons arglist body))))) |
2009 (defalias 'define-setf-expander 'define-setf-method) | 2053 (defalias 'define-setf-expander 'define-setf-method) |
2010 | 2054 |
2011 ;;;###autoload | 2055 ;;;###autoload |
2012 (defmacro defsetf (func arg1 &rest args) | 2056 (defmacro defsetf (func arg1 &rest args) |
2013 "(defsetf NAME FUNC): define a `setf' method. | 2057 "(defsetf NAME FUNC): define a `setf' method. |
2564 (list 'prog1 (nth 2 method) | 2608 (list 'prog1 (nth 2 method) |
2565 (cl-setf-do-store (nth 1 method) form)))))) | 2609 (cl-setf-do-store (nth 1 method) form)))))) |
2566 form))) | 2610 form))) |
2567 | 2611 |
2568 ;;;###autoload | 2612 ;;;###autoload |
2569 (defmacro rotatef (&rest args) | 2613 (defmacro rotatef (&rest places) |
2570 "(rotatef PLACE...): rotate left among PLACEs. | 2614 "Rotate left among PLACES. |
2571 Example: (rotatef A B C) sets A to B, B to C, and C to A. It returns nil. | 2615 Example: (rotatef A B C) sets A to B, B to C, and C to A. It returns nil. |
2572 Each PLACE may be a symbol, or any generalized variable allowed by `setf'." | 2616 Each PLACE may be a symbol, or any generalized variable allowed by `setf'." |
2573 (if (not (memq nil (mapcar 'symbolp args))) | 2617 (if (not (memq nil (mapcar 'symbolp places))) |
2574 (and (cdr args) | 2618 (and (cdr places) |
2575 (let ((sets nil) | 2619 (let ((sets nil) |
2576 (first (car args))) | 2620 (first (car places))) |
2577 (while (cdr args) | 2621 (while (cdr places) |
2578 (setq sets (nconc sets (list (pop args) (car args))))) | 2622 (setq sets (nconc sets (list (pop places) (car places))))) |
2579 (nconc (list 'psetf) sets (list (car args) first)))) | 2623 (nconc (list 'psetf) sets (list (car places) first)))) |
2580 (let* ((places (reverse args)) | 2624 (let* ((places (reverse places)) |
2581 (temp (gensym "--rotatef--")) | 2625 (temp (gensym "--rotatef--")) |
2582 (form temp)) | 2626 (form temp)) |
2583 (while (cdr places) | 2627 (while (cdr places) |
2584 (let ((method (cl-setf-do-modify (pop places) 'unsafe))) | 2628 (let ((method (cl-setf-do-modify (pop places) 'unsafe))) |
2585 (setq form (list 'let* (car method) | 2629 (setq form (list 'let* (car method) |
2611 ;; | 2655 ;; |
2612 ;; Aidan Kehoe, Fr Nov 13 16:12:21 GMT 2009 | 2656 ;; Aidan Kehoe, Fr Nov 13 16:12:21 GMT 2009 |
2613 | 2657 |
2614 ;;;###autoload | 2658 ;;;###autoload |
2615 (defmacro letf (bindings &rest body) | 2659 (defmacro letf (bindings &rest body) |
2616 "(letf ((PLACE VALUE) ...) BODY...): temporarily bind to PLACEs. | 2660 "Temporarily bind to PLACEs. |
2617 This is the analogue of `let', but with generalized variables (in the | 2661 This is the analogue of `let', but with generalized variables (in the |
2618 sense of `setf') for the PLACEs. Each PLACE is set to the corresponding | 2662 sense of `setf') for the PLACEs. Each PLACE is set to the corresponding |
2619 VALUE, then the BODY forms are executed. On exit, either normally or | 2663 VALUE, then the BODY forms are executed. On exit, either normally or |
2620 because of a `throw' or error, the PLACEs are set back to their original | 2664 because of a `throw' or error, the PLACEs are set back to their original |
2621 values. Note that this macro is *not* available in Common Lisp. | 2665 values. Note that this macro is *not* available in Common Lisp. |
2622 As a special case, if `(PLACE)' is used instead of `(PLACE VALUE)', | 2666 As a special case, if `(PLACE)' is used instead of `(PLACE VALUE)', |
2623 the PLACE is not modified before executing BODY." | 2667 the PLACE is not modified before executing BODY. |
2668 | |
2669 arguments: (((PLACE VALUE) &rest BINDINGS) &body BODY)" | |
2624 (if (and (not (cdr bindings)) (cdar bindings) (symbolp (caar bindings))) | 2670 (if (and (not (cdr bindings)) (cdar bindings) (symbolp (caar bindings))) |
2625 (list* 'let bindings body) | 2671 (list* 'let bindings body) |
2626 (let ((lets nil) | 2672 (let ((lets nil) |
2627 (rev (reverse bindings))) | 2673 (rev (reverse bindings))) |
2628 (while rev | 2674 (while rev |
2713 rev (cdr rev)))) | 2759 rev (cdr rev)))) |
2714 (list* 'let* lets body)))) | 2760 (list* 'let* lets body)))) |
2715 | 2761 |
2716 ;;;###autoload | 2762 ;;;###autoload |
2717 (defmacro letf* (bindings &rest body) | 2763 (defmacro letf* (bindings &rest body) |
2718 "(letf* ((PLACE VALUE) ...) BODY...): temporarily bind to PLACEs. | 2764 "Temporarily bind to PLACES. |
2719 This is the analogue of `let*', but with generalized variables (in the | 2765 This is the analogue of `let*', but with generalized variables (in the |
2720 sense of `setf') for the PLACEs. Each PLACE is set to the corresponding | 2766 sense of `setf') for the PLACEs. Each PLACE is set to the corresponding |
2721 VALUE, then the BODY forms are executed. On exit, either normally or | 2767 VALUE, then the BODY forms are executed. On exit, either normally or |
2722 because of a `throw' or error, the PLACEs are set back to their original | 2768 because of a `throw' or error, the PLACEs are set back to their original |
2723 values. Note that this macro is *not* available in Common Lisp. | 2769 values. Note that this macro is *not* available in Common Lisp. |
2724 As a special case, if `(PLACE)' is used instead of `(PLACE VALUE)', | 2770 As a special case, if `(PLACE)' is used instead of `(PLACE VALUE)', |
2725 the PLACE is not modified before executing BODY." | 2771 the PLACE is not modified before executing BODY. |
2772 | |
2773 arguments: (((PLACE VALUE) &rest BINDINGS) &body BODY)" | |
2726 (if (null bindings) | 2774 (if (null bindings) |
2727 (cons 'progn body) | 2775 (cons 'progn body) |
2728 (setq bindings (reverse bindings)) | 2776 (setq bindings (reverse bindings)) |
2729 (while bindings | 2777 (while bindings |
2730 (setq body (list (list* 'letf (list (pop bindings)) body)))) | 2778 (setq body (list (list* 'letf (list (pop bindings)) body)))) |
3161 (defun cl-byte-compile-compiler-macro (form) | 3209 (defun cl-byte-compile-compiler-macro (form) |
3162 (if (eq form (setq form (compiler-macroexpand form))) | 3210 (if (eq form (setq form (compiler-macroexpand form))) |
3163 (byte-compile-normal-call form) | 3211 (byte-compile-normal-call form) |
3164 (byte-compile-form form))) | 3212 (byte-compile-form form))) |
3165 | 3213 |
3166 (defmacro defsubst* (name args &rest body) | 3214 (defmacro defsubst* (name arglist &optional docstring &rest body) |
3167 "(defsubst* NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function. | 3215 "Define NAME as a function. |
3168 Like `defun', except the function is automatically declared `inline', | 3216 Like `defun', except the function is automatically declared `inline', |
3169 ARGLIST allows full Common Lisp conventions, and BODY is implicitly | 3217 ARGLIST allows full Common Lisp conventions, and BODY is implicitly |
3170 surrounded by (block NAME ...)." | 3218 surrounded by (block NAME ...)." |
3171 (let* ((argns (cl-arglist-args args)) (p argns) | 3219 (let* ((argns (cl-arglist-args arglist)) (p argns) |
3172 (pbody (cons 'progn body)) | 3220 (exec-body (if (or (stringp docstring) (null docstring)) |
3221 body | |
3222 (cons docstring body))) | |
3223 (pbody (cons 'progn exec-body)) | |
3173 (unsafe (not (cl-safe-expr-p pbody)))) | 3224 (unsafe (not (cl-safe-expr-p pbody)))) |
3174 (while (and p (eq (cl-expr-contains args (car p)) 1)) (pop p)) | 3225 (while (and p (eq (cl-expr-contains arglist (car p)) 1)) (pop p)) |
3175 (list 'progn | 3226 (list 'progn |
3176 (if p nil ; give up if defaults refer to earlier args | 3227 (if p nil ; give up if defaults refer to earlier args |
3177 (list 'define-compiler-macro name | 3228 (list 'define-compiler-macro name |
3178 (if (memq '&key args) | 3229 (if (memq '&key arglist) |
3179 (list* '&whole 'cl-whole '&cl-quote args) | 3230 (list* '&whole 'cl-whole '&cl-quote arglist) |
3180 (cons '&cl-quote args)) | 3231 (cons '&cl-quote arglist)) |
3181 (list* 'cl-defsubst-expand (list 'quote argns) | 3232 (list* 'cl-defsubst-expand (list 'quote argns) |
3182 (list 'quote (list* 'block name body)) | 3233 (list 'quote (list* 'block name exec-body)) |
3183 (not (or unsafe (cl-expr-access-order pbody argns))) | 3234 (not (or unsafe (cl-expr-access-order pbody argns))) |
3184 (and (memq '&key args) 'cl-whole) unsafe argns))) | 3235 (and (memq '&key arglist) 'cl-whole) unsafe argns))) |
3185 (list* 'defun* name args body)))) | 3236 (list* 'defun* name arglist docstring body)))) |
3186 | 3237 |
3187 (defun cl-defsubst-expand (argns body simple whole unsafe &rest argvs) | 3238 (defun cl-defsubst-expand (argns body simple whole unsafe &rest argvs) |
3188 (if (and whole (not (cl-safe-expr-p (cons 'progn argvs)))) whole | 3239 (if (and whole (not (cl-safe-expr-p (cons 'progn argvs)))) whole |
3189 (if (cl-simple-exprs-p argvs) (setq simple t)) | 3240 (if (cl-simple-exprs-p argvs) (setq simple t)) |
3190 (let ((lets (delq nil | 3241 (let ((lets (delq nil |
3650 ,(compiled-function-stack-depth compiled)))))) | 3701 ,(compiled-function-stack-depth compiled)))))) |
3651 | 3702 |
3652 (define-compiler-macro stable-sort (&whole form &rest cl-rest) | 3703 (define-compiler-macro stable-sort (&whole form &rest cl-rest) |
3653 (cons 'sort* (cdr form))) | 3704 (cons 'sort* (cdr form))) |
3654 | 3705 |
3706 (define-compiler-macro svref (&whole form) | |
3707 (cons 'aref (cdr form))) | |
3708 | |
3709 (define-compiler-macro acons (a b c) | |
3710 `(cons (cons ,a ,b) ,c)) | |
3711 | |
3712 (define-compiler-macro pairlis (a b &optional c) | |
3713 `(nconc (mapcar* #'cons ,a ,b) ,c)) | |
3714 | |
3655 (mapc | 3715 (mapc |
3656 #'(lambda (y) | 3716 #'(lambda (y) |
3657 (put (car y) 'side-effect-free t) | 3717 (put (car y) 'side-effect-free t) |
3658 (put (car y) 'byte-compile 'cl-byte-compile-compiler-macro) | 3718 (put (car y) 'byte-compile 'cl-byte-compile-compiler-macro) |
3659 (put (car y) 'cl-compiler-macro | 3719 (put (car y) 'cl-compiler-macro |