diff options
| author | Stefan Monnier | 2011-02-17 23:58:21 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2011-02-17 23:58:21 -0500 |
| commit | f9d554dd46f9fb76217023a359e8c7297b1dc1e0 (patch) | |
| tree | 4cc5be2011771761e4c7ded216f321cc02ad98cc | |
| parent | 5da16a864156ad03820d43cb36d5388373506bca (diff) | |
| download | emacs-f9d554dd46f9fb76217023a359e8c7297b1dc1e0.tar.gz emacs-f9d554dd46f9fb76217023a359e8c7297b1dc1e0.zip | |
* lisp/emacs-lisp/pcase.el (pcase--u1): Understand non-linear patterns.
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/emacs-lisp/pcase.el | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 139bd5e432e..8e850fb9409 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2011-02-18 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * emacs-lisp/pcase.el (pcase--u1): Understand non-linear patterns. | ||
| 4 | |||
| 1 | 2011-02-18 Christian Ohler <ohler@gnu.org> | 5 | 2011-02-18 Christian Ohler <ohler@gnu.org> |
| 2 | 6 | ||
| 3 | * emacs-lisp/ert.el (ert--setup-results-buffer) | 7 | * emacs-lisp/ert.el (ert--setup-results-buffer) |
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el index 24ea0a3e801..3179672a3ec 100644 --- a/lisp/emacs-lisp/pcase.el +++ b/lisp/emacs-lisp/pcase.el | |||
| @@ -61,6 +61,8 @@ UPatterns can take the following forms: | |||
| 61 | `QPAT matches if the QPattern QPAT matches. | 61 | `QPAT matches if the QPattern QPAT matches. |
| 62 | (pred PRED) matches if PRED applied to the object returns non-nil. | 62 | (pred PRED) matches if PRED applied to the object returns non-nil. |
| 63 | (guard BOOLEXP) matches if BOOLEXP evaluates to non-nil. | 63 | (guard BOOLEXP) matches if BOOLEXP evaluates to non-nil. |
| 64 | If a SYMBOL is used twice in the same pattern (i.e. the pattern is | ||
| 65 | \"non-linear\"), then the second occurrence is turned into an `eq'uality test. | ||
| 64 | 66 | ||
| 65 | QPatterns can take the following forms: | 67 | QPatterns can take the following forms: |
| 66 | (QPAT1 . QPAT2) matches if QPAT1 matches the car and QPAT2 the cdr. | 68 | (QPAT1 . QPAT2) matches if QPAT1 matches the car and QPAT2 the cdr. |
| @@ -457,7 +459,12 @@ and otherwise defers to REST which is a list of branches of the form | |||
| 457 | (pcase--u1 matches code vars then-rest) | 459 | (pcase--u1 matches code vars then-rest) |
| 458 | (pcase--u else-rest)))) | 460 | (pcase--u else-rest)))) |
| 459 | ((symbolp upat) | 461 | ((symbolp upat) |
| 460 | (pcase--u1 matches code (cons (cons upat sym) vars) rest)) | 462 | (if (not (assq upat vars)) |
| 463 | (pcase--u1 matches code (cons (cons upat sym) vars) rest) | ||
| 464 | ;; Non-linear pattern. Turn it into an `eq' test. | ||
| 465 | (pcase--u1 (cons `(match ,sym . (pred (eq ,(cdr (assq upat vars))))) | ||
| 466 | matches) | ||
| 467 | code vars rest))) | ||
| 461 | ((eq (car-safe upat) '\`) | 468 | ((eq (car-safe upat) '\`) |
| 462 | (pcase--q1 sym (cadr upat) matches code vars rest)) | 469 | (pcase--q1 sym (cadr upat) matches code vars rest)) |
| 463 | ((eq (car-safe upat) 'or) | 470 | ((eq (car-safe upat) 'or) |