diff options
author | Andrea Corallo <akrl@sdf.org> | 2021-02-10 21:56:55 +0100 |
---|---|---|
committer | Andrea Corallo <akrl@sdf.org> | 2021-02-10 21:56:55 +0100 |
commit | 2fcb85c3e780f1f2871ce0f300cfaffce9836eb0 (patch) | |
tree | a8857ccad8bff12080062a3edaad1a55a3eb8171 /lisp/emacs-lisp/pcase.el | |
parent | 1f626e9662d8120acd5a937f847123cc2b8c6e31 (diff) | |
parent | 6bfdfeed36fab4680c8db90c22da8f6611694186 (diff) | |
download | emacs-2fcb85c3e780f1f2871ce0f300cfaffce9836eb0.tar.gz emacs-2fcb85c3e780f1f2871ce0f300cfaffce9836eb0.tar.bz2 emacs-2fcb85c3e780f1f2871ce0f300cfaffce9836eb0.zip |
Merge remote-tracking branch 'savannah/master' into HEAD
Diffstat (limited to 'lisp/emacs-lisp/pcase.el')
-rw-r--r-- | lisp/emacs-lisp/pcase.el | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el index cf129c453ec..ec746fa4747 100644 --- a/lisp/emacs-lisp/pcase.el +++ b/lisp/emacs-lisp/pcase.el @@ -135,7 +135,6 @@ PATTERN matches. PATTERN can take one of the forms: (pred (not FUN)) matches if FUN called on EXPVAL returns nil. (app FUN PAT) matches if FUN called on EXPVAL matches PAT. (guard BOOLEXP) matches if BOOLEXP evaluates to non-nil. - (let PAT EXPR) matches if EXPR matches PAT. (and PAT...) matches if all the patterns match. (or PAT...) matches if any of the patterns matches. @@ -145,7 +144,7 @@ FUN in `pred' and `app' can take one of the forms: (F ARG1 .. ARGn) call F with ARG1..ARGn and EXPVAL as n+1'th argument -FUN, BOOLEXP, EXPR, and subsequent PAT can refer to variables +FUN, BOOLEXP, and subsequent PAT can refer to variables bound earlier in the pattern by a SYMBOL pattern. Additional patterns can be defined using `pcase-defmacro'. @@ -426,7 +425,6 @@ of the elements of LIST is performed as if by `pcase-let'. (if (pcase--self-quoting-p pat) `',pat pat)) ((memq head '(pred guard quote)) pat) ((memq head '(or and)) `(,head ,@(mapcar #'pcase--macroexpand (cdr pat)))) - ((eq head 'let) `(let ,(pcase--macroexpand (cadr pat)) ,@(cddr pat))) ((eq head 'app) `(app ,(nth 1 pat) ,(pcase--macroexpand (nth 2 pat)))) (t (let* ((expander (pcase--get-macroexpander head)) @@ -888,18 +886,9 @@ Otherwise, it defers to REST which is a list of branches of the form (if (not (assq upat vars)) (pcase--u1 matches code (cons (cons upat sym) vars) rest) ;; Non-linear pattern. Turn it into an `eq' test. - (pcase--u1 (cons `(match ,sym . (pred (eq ,(cdr (assq upat vars))))) + (pcase--u1 (cons `(match ,sym . (pred (eql ,(cdr (assq upat vars))))) matches) code vars rest))) - ((eq (car-safe upat) 'let) - ;; A upat of the form (let VAR EXP). - ;; (pcase--u1 matches code - ;; (cons (cons (nth 1 upat) (nth 2 upat)) vars) rest) - (macroexp-let2 - macroexp-copyable-p sym - (pcase--eval (nth 2 upat) vars) - (pcase--u1 (cons (pcase--match sym (nth 1 upat)) matches) - code vars rest))) ((eq (car-safe upat) 'app) ;; A upat of the form (app FUN PAT) (pcase--mark-used sym) @@ -1011,5 +1000,9 @@ The predicate is the logical-AND of: ;; compounded values that are not `consp' (t (error "Unknown QPAT: %S" qpat)))) +(pcase-defmacro let (pat expr) + "Matches if EXPR matches PAT." + `(app (lambda (_) ,expr) ,pat)) + (provide 'pcase) ;;; pcase.el ends here |