diff options
| author | Thien-Thi Nguyen | 2018-05-19 13:10:04 +0200 |
|---|---|---|
| committer | Thien-Thi Nguyen | 2018-05-19 13:10:04 +0200 |
| commit | 712f4d7d3892abafc542c9380459ff23003a4c74 (patch) | |
| tree | 9db0de3437e2129cfe8125025ad546bcd7d69676 | |
| parent | 9164317c9832986a645e4e0e6685ea3e0e686d41 (diff) | |
| download | emacs-712f4d7d3892abafc542c9380459ff23003a4c74.tar.gz emacs-712f4d7d3892abafc542c9380459ff23003a4c74.zip | |
formalize SEQPAT
- for @var{symbol}, do ‘s/compound/sequencing/’
- do ‘s/bigpat/seqpat/g’
- split table into two
- between ‘let’ and ‘and’
- add intro para for ‘and’, ‘or’
- define "sequence pattern"; add @cindex
- mention @var{seqpat}
- xref to "normal" ‘and’, ‘or’
- (pcase-symbol-caveats)
- use "Sequencing Patterns" in title
- snellify intro para
| -rw-r--r-- | doc/lispref/control.texi | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index dbc1fd4b456..6c8009a1c67 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi | |||
| @@ -393,9 +393,9 @@ Matches any @var{expval}, and additionally let-binds @var{symbol} to | |||
| 393 | @var{expval}, such that this binding is available to | 393 | @var{expval}, such that this binding is available to |
| 394 | @var{body-forms} (@pxref{Dynamic Binding}). | 394 | @var{body-forms} (@pxref{Dynamic Binding}). |
| 395 | 395 | ||
| 396 | If @var{symbol} is part of a compound pattern @var{bigpat} | 396 | If @var{symbol} is part of a sequencing pattern @var{seqpat} |
| 397 | (e.g., by using @code{and}, below), the binding is also available to | 397 | (e.g., by using @code{and}, below), the binding is also available to |
| 398 | the portion of @var{bigpat} following the appearance of @var{symbol}. | 398 | the portion of @var{seqpat} following the appearance of @var{symbol}. |
| 399 | This usage has some caveats (@pxref{pcase-symbol-caveats,,caveats}). | 399 | This usage has some caveats (@pxref{pcase-symbol-caveats,,caveats}). |
| 400 | 400 | ||
| 401 | Two symbols to avoid are @code{t}, which behaves like @code{_} | 401 | Two symbols to avoid are @code{t}, which behaves like @code{_} |
| @@ -447,7 +447,17 @@ Evaluates @var{expr} to get @var{exprval} | |||
| 447 | and matches if @var{exprval} matches @var{pattern}. | 447 | and matches if @var{exprval} matches @var{pattern}. |
| 448 | (It is called @code{let} because | 448 | (It is called @code{let} because |
| 449 | @var{pattern} can bind symbols to values using @var{symbol}.) | 449 | @var{pattern} can bind symbols to values using @var{symbol}.) |
| 450 | @end table | ||
| 451 | |||
| 452 | @cindex sequencing pattern | ||
| 453 | A @dfn{sequencing pattern} (also known as @var{seqpat}) is a | ||
| 454 | pattern that processes its sub-pattern arguments in sequence. | ||
| 455 | There are two for @code{pcase}: @code{and} and @code{or}. | ||
| 456 | They behave in a similar manner to the special forms | ||
| 457 | that share their name (@pxref{Combining Conditions}), | ||
| 458 | but instead of processing values, they process sub-patterns. | ||
| 450 | 459 | ||
| 460 | @table @code | ||
| 451 | @item (and @var{pattern1}@dots{}) | 461 | @item (and @var{pattern1}@dots{}) |
| 452 | Attempts to match @var{pattern1}@dots{}, in order, | 462 | Attempts to match @var{pattern1}@dots{}, in order, |
| 453 | until one of them fails to match. | 463 | until one of them fails to match. |
| @@ -637,21 +647,20 @@ Because that is the last body form in a successfully matched | |||
| 637 | the return value of @code{grok/pcase} (@pxref{What Is a Function}). | 647 | the return value of @code{grok/pcase} (@pxref{What Is a Function}). |
| 638 | 648 | ||
| 639 | @anchor{pcase-symbol-caveats} | 649 | @anchor{pcase-symbol-caveats} |
| 640 | @subheading Caveats for @var{symbol} in @var{bigpat} | 650 | @subheading Caveats for @var{symbol} in Sequencing Patterns |
| 641 | 651 | ||
| 642 | The preceding examples all use compound patterns sequenced | 652 | The preceding examples all use sequencing patterns |
| 643 | by either @code{and} or @code{or} (also known as @var{bigpat} | 653 | which include the @var{symbol} |
| 644 | in this manual) which include the @var{symbol} | ||
| 645 | sub-pattern in some way. | 654 | sub-pattern in some way. |
| 646 | Here are some important details about that usage. | 655 | Here are some important details about that usage. |
| 647 | 656 | ||
| 648 | @enumerate | 657 | @enumerate |
| 649 | @item When @var{symbol} occurs more than once in @var{bigpat}, | 658 | @item When @var{symbol} occurs more than once in @var{seqpat}, |
| 650 | the second and subsequent occurances do not expand to re-binding, | 659 | the second and subsequent occurances do not expand to re-binding, |
| 651 | but instead expand to an equality test using @code{eq}. | 660 | but instead expand to an equality test using @code{eq}. |
| 652 | 661 | ||
| 653 | The following example features a @code{pcase} form | 662 | The following example features a @code{pcase} form |
| 654 | with two clauses and two @var{bigpat}, A and B. | 663 | with two clauses and two @var{seqpat}, A and B. |
| 655 | Both A and B first check that @var{expval} is a | 664 | Both A and B first check that @var{expval} is a |
| 656 | pair (using @code{pred}), | 665 | pair (using @code{pred}), |
| 657 | and then bind symbols to the @code{car} and @code{cdr} | 666 | and then bind symbols to the @code{car} and @code{cdr} |
| @@ -665,11 +674,11 @@ On the other hand, B uses two separate symbols, @code{s1} and | |||
| 665 | @example | 674 | @example |
| 666 | (defun grok (object) | 675 | (defun grok (object) |
| 667 | (pcase object | 676 | (pcase object |
| 668 | ((and (pred consp) ; bigpat A | 677 | ((and (pred consp) ; seqpat A |
| 669 | (app car st) ; first mention: st | 678 | (app car st) ; first mention: st |
| 670 | (app cdr st)) ; second mention: st | 679 | (app cdr st)) ; second mention: st |
| 671 | (list 'eq st)) | 680 | (list 'eq st)) |
| 672 | ((and (pred consp) ; bigpat B | 681 | ((and (pred consp) ; seqpat B |
| 673 | (app car s1) ; first mention: s1 | 682 | (app car s1) ; first mention: s1 |
| 674 | (app cdr s2)) ; first mention: s2 | 683 | (app cdr s2)) ; first mention: s2 |
| 675 | (list 'not-eq s1 s2)))) | 684 | (list 'not-eq s1 s2)))) |
| @@ -761,12 +770,12 @@ and @var{function} (in @code{pred} and @code{app}). | |||
| 761 | 770 | ||
| 762 | @item On match, the clause's body forms can reference the set | 771 | @item On match, the clause's body forms can reference the set |
| 763 | of symbols the pattern let-binds. | 772 | of symbols the pattern let-binds. |
| 764 | When @var{bigpat} is @code{and}, this set is | 773 | When @var{seqpat} is @code{and}, this set is |
| 765 | the union of all the symbols each of its sub-patterns let-binds. | 774 | the union of all the symbols each of its sub-patterns let-binds. |
| 766 | This makes sense because, for @code{and} to match, | 775 | This makes sense because, for @code{and} to match, |
| 767 | all the sub-patterns must match. | 776 | all the sub-patterns must match. |
| 768 | 777 | ||
| 769 | When @var{bigpat} is @code{or}, things are different: | 778 | When @var{seqpat} is @code{or}, things are different: |
| 770 | @code{or} matches at the first sub-pattern that matches; | 779 | @code{or} matches at the first sub-pattern that matches; |
| 771 | the rest of the sub-patterns are ignored. | 780 | the rest of the sub-patterns are ignored. |
| 772 | It makes no sense for each sub-pattern to let-bind a different | 781 | It makes no sense for each sub-pattern to let-bind a different |