[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] fix/bug-3133-pcase-doc c3d1896 12/13: (docstring) rework m
From: |
Thien-Thi Nguyen |
Subject: |
[Emacs-diffs] fix/bug-3133-pcase-doc c3d1896 12/13: (docstring) rework middle |
Date: |
Fri, 11 May 2018 12:50:53 -0400 (EDT) |
branch: fix/bug-3133-pcase-doc
commit c3d1896c7c48e15ff5dce350e044446dd246dc69
Author: Thien-Thi Nguyen <address@hidden>
Commit: Thien-Thi Nguyen <address@hidden>
(docstring) rework middle
- zonk ‘cl-destructuring-bind’ info (interesting, but...)
- use "two categories: logical and structural"
- describe logical first
- mention "expands" and "predicate function"
- move table after logical description
- describe structural second
- quote ‘backquote’ (to build on reader familiarity)
- add example (from ~/.signature :-D)
- mention "congruent"
---
lisp/emacs-lisp/pcase.el | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el
index ab80aea..b84f8ba 100644
--- a/lisp/emacs-lisp/pcase.el
+++ b/lisp/emacs-lisp/pcase.el
@@ -114,28 +114,11 @@ For the first CASE whose PATTERN \"matches\" EXPVAL,
evaluate its CODE..., and return the value of the last form.
If no CASE has a PATTERN that matches, return nil.
-A structural PATTERN describes a template that identifies a class
-of values. For example, the pattern \\=`(,foo ,bar) matches any
-two element list, binding its elements to symbols named `foo' and
-`bar' -- in much the same way that `cl-destructuring-bind' would.
+The two catagories of patterns are logical and structural.
-A significant difference from `cl-destructuring-bind' is that, if
-a pattern match fails, the next case is tried until either a
-successful match is found or there are no more cases. The CODE
-expression corresponding to the matching pattern determines the
-return value. If there is no match the returned value is nil.
-
-Another difference is that pattern elements may be quoted,
-meaning they must match exactly: The pattern \\='(foo bar)
-matches only against two element lists containing the symbols
-`foo' and `bar' in that order.
-
-Lastly, a pattern can be logical, such as (pred numberp), that
-matches any number-like element; or the symbol `_', that matches
-anything. Also, when patterns are backquoted, a comma may be
-used to introduce logical patterns inside backquoted patterns.
-
-The complete list of standard patterns is as follows:
+A logical pattern expands, in essence, to a predicate function
+to call on EXPVAL. When the return value of that call is non-nil,
+the pattern matches. A logical pattern can take one of the forms:
_ matches anything.
\\='VAL matches if EXPVAL is `equal' to VAL.
@@ -152,6 +135,23 @@ The complete list of standard patterns is as follows:
(let PAT EXP) matches if EXP matches PAT.
(app FUN PAT) matches if FUN applied to EXPVAL matches PAT.
+On the other hand, a structural pattern specifies a template,
+and allows for elements of that template to be either constants
+or sub-patterns (of either category). A structural pattern
+begins with `backquote' and logical sub-pattern elements are
+introduced by a comma. For example:
+
+ \\=`(technical ,ml)
+
+The predicate function specified by a structural pattern is a
+combination of those specified by any sub-patterns, wrapped in a
+top-level condition: EXPVAL must be \"congruent\" with the template.
+In the above example, the predicate is the logical-AND of:
+ - Is EXPVAL a list of two elements?
+ - Is the first element the symbol `technical'?
+ - True! (The second element can be anything, and for the sake
+ of CODE..., its value is bound to the symbol `ml'.)
+
Additional patterns can be defined using `pcase-defmacro'.
The FUN argument in the `app' pattern may have the following forms:
- [Emacs-diffs] branch fix/bug-3133-pcase-doc created (now 82791b1), Thien-Thi Nguyen, 2018/05/11
- [Emacs-diffs] fix/bug-3133-pcase-doc 7b00deb 02/13: add @cindex entry for ‘backquote’, Thien-Thi Nguyen, 2018/05/11
- [Emacs-diffs] fix/bug-3133-pcase-doc 0f42499 03/13: refine "value being matched" note, Thien-Thi Nguyen, 2018/05/11
- [Emacs-diffs] fix/bug-3133-pcase-doc edae74f 09/13: (docstring) update elisp.info ref, Thien-Thi Nguyen, 2018/05/11
- [Emacs-diffs] fix/bug-3133-pcase-doc dcb6d91 04/13: further refinement: introduce @var{expval}; GSR, Thien-Thi Nguyen, 2018/05/11
- [Emacs-diffs] fix/bug-3133-pcase-doc 80ed201 07/13: (docstring) explode "ATOM"; flatten; zonk "match themselves" sentence, Thien-Thi Nguyen, 2018/05/11
- [Emacs-diffs] fix/bug-3133-pcase-doc f927f6a 10/13: (docstring) move { 'VAL, KEYWORD, INTEGER, STRING } prior to SYMBOL, Thien-Thi Nguyen, 2018/05/11
- [Emacs-diffs] fix/bug-3133-pcase-doc 82791b1 13/13: (docstring) move ‘FUN’ para after after logical pattern table; refine, Thien-Thi Nguyen, 2018/05/11
- [Emacs-diffs] fix/bug-3133-pcase-doc c3d1896 12/13: (docstring) rework middle,
Thien-Thi Nguyen <=
- [Emacs-diffs] fix/bug-3133-pcase-doc fdbdb64 05/13: more @var{expval} insinuation, Thien-Thi Nguyen, 2018/05/11
- [Emacs-diffs] fix/bug-3133-pcase-doc fa03d3a 06/13: (docstring) rewrite first para, Thien-Thi Nguyen, 2018/05/11
- [Emacs-diffs] fix/bug-3133-pcase-doc dc67ead 08/13: (docstring) use ‘EXPVAL’ more, Thien-Thi Nguyen, 2018/05/11
- [Emacs-diffs] fix/bug-3133-pcase-doc 1181796 01/13: do ‘s/UPattern/U-pattern/g’, ‘s/QPattern/Q-pattern/g’, Thien-Thi Nguyen, 2018/05/11
- [Emacs-diffs] fix/bug-3133-pcase-doc 9449c39 11/13: pxref ‘Lambda Expressions’, Thien-Thi Nguyen, 2018/05/11