]> git.eshelyaron.com Git - emacs.git/commit
(pcase): New `_` syntax in pred/app functions
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 12 Feb 2024 03:00:44 +0000 (22:00 -0500)
committerEshel Yaron <me@eshelyaron.com>
Mon, 12 Feb 2024 07:02:42 +0000 (08:02 +0100)
commit33de1a40eab43892f5b84f2cdbbf4603eb1e47bc
tree110730b16640bdb9a00257cf31a183659d1f11a0
parent41b1d6ff5515321377445c4ec2758f868dd22278
(pcase): New `_` syntax in pred/app functions

The current syntax for functions in `app` and `pred` patterns
allows a shorthand (F ARGS) where the object being matched is
added as an extra last argument.  This is nice for things like
(pred (< 5)) but sometimes the object needs to be at
another position.
Until now you had to use (pred (lambda (x) (memq x my-list)))
or (pred (pcase--flip memq my-list)) in those cases.
So, introduce a new shorthand where `_` can be used to indicate
where the object should be passed: (pred (memq _ my-list))

* lisp/emacs-lisp/pcase.el (pcase--split-pred): Document new syntax
for pred/app functions.
(pcase--funcall): Support new syntax.
(pcase--flip): Declare obsolete.
(pcase--u1, \`): Use `_` instead.
(pcase--split-pred): Adjust accordingly.

* doc/lispref/control.texi (pcase Macro): Document new syntax
for pred/app functions.

* lisp/progmodes/opascal.el (pcase-defmacro):
* lisp/emacs-lisp/seq.el (seq--make-pcase-bindings):
* lisp/emacs-lisp/eieio.el (eieio):
* lisp/emacs-lisp/cl-macs.el (cl-struct, cl-type):
Use _ instead of `pcase--flip`.
(cl--pcase-mutually-exclusive-p): Adjust accordingly.

* lisp/emacs-lisp/map.el (map--pcase-map-elt): Declare obsolete.
(map--make-pcase-bindings): Use `_` instead.

(cherry picked from commit 806759dc0a6a3b049ce35d0497011464e5fc4dcb)
doc/lispref/control.texi
etc/NEWS
lisp/emacs-lisp/cl-macs.el
lisp/emacs-lisp/eieio.el
lisp/emacs-lisp/map.el
lisp/emacs-lisp/pcase.el
lisp/emacs-lisp/seq.el
lisp/progmodes/opascal.el