diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2011-02-21 17:34:51 -0500 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2011-02-21 17:34:51 -0500 |
commit | f619ad4ca2ce943d53589469c010e451afab97dd (patch) | |
tree | e1b71f79518372ecab4c677ae948504450d8bf5d /lisp/emacs-lisp/pcase.el | |
parent | a647cb26b695a542e3a546104afdf4c7c47eb061 (diff) | |
parent | 9f8370e63f65f76887b319ab6a0368d4a332777c (diff) | |
download | emacs-f619ad4ca2ce943d53589469c010e451afab97dd.tar.gz |
Merge from trunk
Diffstat (limited to 'lisp/emacs-lisp/pcase.el')
-rw-r--r-- | lisp/emacs-lisp/pcase.el | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el index c8a07738fe5..d795dbd390c 100644 --- a/lisp/emacs-lisp/pcase.el +++ b/lisp/emacs-lisp/pcase.el @@ -59,6 +59,8 @@ UPatterns can take the following forms: `QPAT matches if the QPattern QPAT matches. (pred PRED) matches if PRED applied to the object returns non-nil. (guard BOOLEXP) matches if BOOLEXP evaluates to non-nil. +If a SYMBOL is used twice in the same pattern (i.e. the pattern is +\"non-linear\"), then the second occurrence is turned into an `eq'uality test. QPatterns can take the following forms: (QPAT1 . QPAT2) matches if QPAT1 matches the car and QPAT2 the cdr. @@ -465,7 +467,12 @@ and otherwise defers to REST which is a list of branches of the form (pcase--u1 matches code vars then-rest) (pcase--u else-rest)))) ((symbolp upat) - (pcase--u1 matches code (cons (cons upat sym) vars) rest)) + (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))))) + matches) + code vars rest))) ((eq (car-safe upat) '\`) (pcase--q1 sym (cadr upat) matches code vars rest)) ((eq (car-safe upat) 'or) |