Mercurial > hg > xemacs-beta
comparison lisp/cl-extra.el @ 5056:6aba0daedb7c
Add #'constantly, as specified by ANSI Common Lisp.
2010-02-22 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (constantly):
Add this function, from ANSI Common Lisp, using the SBCL extension
that extra arguments to it are passed back as multiple values in
the constructed function.
* cl-macs.el (constantly):
In the compiler macro for #'constantly, construct a
compiled-function object almost every time, at compile time when
all arguments are constant, and at runtime when they vary.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Mon, 22 Feb 2010 20:08:51 +0000 |
parents | 8800b5350a13 |
children | 868a9ffcc37b |
comparison
equal
deleted
inserted
replaced
5036:9624523604c5 | 5056:6aba0daedb7c |
---|---|
610 (cond ((atom (cdr plst)) | 610 (cond ((atom (cdr plst)) |
611 (error "Malformed property list: %S." plist)) | 611 (error "Malformed property list: %S." plist)) |
612 ((memq (car plst) indicator-list) | 612 ((memq (car plst) indicator-list) |
613 (return (values (car plst) (cadr plst) plst)))))) | 613 (return (values (car plst) (cadr plst) plst)))))) |
614 | 614 |
615 ;; See our compiler macro in cl-macs.el, we will only pass back the | |
616 ;; actual lambda list in interpreted code or if we've been funcalled | |
617 ;; (from #'apply or #'mapcar or whatever). | |
618 (defun constantly (value &rest more-values) | |
619 "Construct a function always returning VALUE, and possibly MORE-VALUES. | |
620 | |
621 The constructed function accepts any number of arguments, and ignores them. | |
622 | |
623 Members of MORE-VALUES, if provided, will be passed as multiple values; see | |
624 `multiple-value-bind' and `multiple-value-setq'." | |
625 `(lambda (&rest ignore) (values-list ',(cons value more-values)))) | |
615 | 626 |
616 ;;; Hash tables. | 627 ;;; Hash tables. |
617 | 628 |
618 ;; The `regular' Common Lisp hash-table stuff has been moved into C. | 629 ;; The `regular' Common Lisp hash-table stuff has been moved into C. |
619 ;; Only backward compatibility stuff remains here. | 630 ;; Only backward compatibility stuff remains here. |