aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThien-Thi Nguyen2018-05-19 13:10:04 +0200
committerThien-Thi Nguyen2018-05-19 13:10:04 +0200
commit712f4d7d3892abafc542c9380459ff23003a4c74 (patch)
tree9db0de3437e2129cfe8125025ad546bcd7d69676
parent9164317c9832986a645e4e0e6685ea3e0e686d41 (diff)
downloademacs-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.texi33
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
396If @var{symbol} is part of a compound pattern @var{bigpat} 396If @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
398the portion of @var{bigpat} following the appearance of @var{symbol}. 398the portion of @var{seqpat} following the appearance of @var{symbol}.
399This usage has some caveats (@pxref{pcase-symbol-caveats,,caveats}). 399This usage has some caveats (@pxref{pcase-symbol-caveats,,caveats}).
400 400
401Two symbols to avoid are @code{t}, which behaves like @code{_} 401Two symbols to avoid are @code{t}, which behaves like @code{_}
@@ -447,7 +447,17 @@ Evaluates @var{expr} to get @var{exprval}
447and matches if @var{exprval} matches @var{pattern}. 447and 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
453A @dfn{sequencing pattern} (also known as @var{seqpat}) is a
454pattern that processes its sub-pattern arguments in sequence.
455There are two for @code{pcase}: @code{and} and @code{or}.
456They behave in a similar manner to the special forms
457that share their name (@pxref{Combining Conditions}),
458but 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{})
452Attempts to match @var{pattern1}@dots{}, in order, 462Attempts to match @var{pattern1}@dots{}, in order,
453until one of them fails to match. 463until one of them fails to match.
@@ -637,21 +647,20 @@ Because that is the last body form in a successfully matched
637the return value of @code{grok/pcase} (@pxref{What Is a Function}). 647the 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
642The preceding examples all use compound patterns sequenced 652The preceding examples all use sequencing patterns
643by either @code{and} or @code{or} (also known as @var{bigpat} 653which include the @var{symbol}
644in this manual) which include the @var{symbol}
645sub-pattern in some way. 654sub-pattern in some way.
646Here are some important details about that usage. 655Here 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},
650the second and subsequent occurances do not expand to re-binding, 659the second and subsequent occurances do not expand to re-binding,
651but instead expand to an equality test using @code{eq}. 660but instead expand to an equality test using @code{eq}.
652 661
653The following example features a @code{pcase} form 662The following example features a @code{pcase} form
654with two clauses and two @var{bigpat}, A and B. 663with two clauses and two @var{seqpat}, A and B.
655Both A and B first check that @var{expval} is a 664Both A and B first check that @var{expval} is a
656pair (using @code{pred}), 665pair (using @code{pred}),
657and then bind symbols to the @code{car} and @code{cdr} 666and 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
763of symbols the pattern let-binds. 772of symbols the pattern let-binds.
764When @var{bigpat} is @code{and}, this set is 773When @var{seqpat} is @code{and}, this set is
765the union of all the symbols each of its sub-patterns let-binds. 774the union of all the symbols each of its sub-patterns let-binds.
766This makes sense because, for @code{and} to match, 775This makes sense because, for @code{and} to match,
767all the sub-patterns must match. 776all the sub-patterns must match.
768 777
769When @var{bigpat} is @code{or}, things are different: 778When @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;
771the rest of the sub-patterns are ignored. 780the rest of the sub-patterns are ignored.
772It makes no sense for each sub-pattern to let-bind a different 781It makes no sense for each sub-pattern to let-bind a different