mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-29 07:58:28 +00:00
* lisp/emacs-lisp/cl-macs.el: Add cl-type pattern
* lisp/emacs-lisp/cl-macs.el: ((pcase-defmacro type)): Add 'cl-type' pattern. * test/lisp/emacs-lisp/pcase-tests.el (pcase-tests-cl-type): Add test. * doc/lispref/control.texi (pcase Macro): Update manual. With thanks to Stefan Monnier and Eli Zaretskii for their guidance.
This commit is contained in:
parent
d9bc7dbefd
commit
44fe0043d3
@ -555,6 +555,16 @@ Two symbols to avoid are @code{t}, which behaves like @code{_}
|
||||
Likewise, it makes no sense to bind keyword symbols
|
||||
(@pxref{Constant Variables}).
|
||||
|
||||
@item (cl-type @var{type})
|
||||
Matches if @var{expval} is of type @var{type}, which is a type
|
||||
descriptor as accepted by @code{cl-typep} (@pxref{cl-typep,,,cl,Common
|
||||
Lisp Extensions}). Examples:
|
||||
|
||||
@lisp
|
||||
(cl-type integer)
|
||||
(cl-type (integer 0 10))
|
||||
@end lisp
|
||||
|
||||
@item (pred @var{function})
|
||||
Matches if the predicate @var{function} returns non-@code{nil}
|
||||
when called on @var{expval}. The test can be negated with the syntax
|
||||
|
5
etc/NEWS
5
etc/NEWS
@ -545,6 +545,11 @@ in better code.
|
||||
---
|
||||
*** New function 'pcase-compile-patterns' to write other macros.
|
||||
|
||||
*** Added 'cl-type' pattern.
|
||||
The new 'cl-type' pattern compares types using 'cl-typep', which allows
|
||||
comparing simple types like '(cl-type integer)', as well as forms like
|
||||
'(cl-type (integer 0 10))'.
|
||||
|
||||
+++
|
||||
** profiler.el
|
||||
The results displayed by 'profiler-report' now have the usage figures
|
||||
|
@ -3623,6 +3623,14 @@ STRUCT and SLOT-NAME are symbols. INST is a structure instance."
|
||||
"use `with-eval-after-load' instead." "28.1")
|
||||
(run-hooks 'cl-macs-load-hook)
|
||||
|
||||
;;; Pcase type pattern.
|
||||
|
||||
;;;###autoload
|
||||
(pcase-defmacro cl-type (type)
|
||||
"Pcase pattern that matches objects of TYPE.
|
||||
TYPE is a type descriptor as accepted by `cl-typep', which see."
|
||||
`(pred (pcase--flip cl-typep ',type)))
|
||||
|
||||
;; Local variables:
|
||||
;; generated-autoload-file: "cl-loaddefs.el"
|
||||
;; End:
|
||||
|
@ -100,4 +100,14 @@
|
||||
(should (equal (funcall f 'b1) '(4 5 nil nil)))
|
||||
(should (equal (funcall f 'b2) '(nil nil 8 9)))))
|
||||
|
||||
(ert-deftest pcase-tests-cl-type ()
|
||||
(should (equal (pcase 1
|
||||
((cl-type integer) 'integer))
|
||||
'integer))
|
||||
(should (equal (pcase 1
|
||||
((cl-type (integer 0 2)) 'integer-0<=n<=2))
|
||||
'integer-0<=n<=2))
|
||||
(should-error (pcase 1
|
||||
((cl-type notatype) 'integer))))
|
||||
|
||||
;;; pcase-tests.el ends here.
|
||||
|
Loading…
Reference in New Issue
Block a user