emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] fix/bug-31311-pcase-doc e276ce7 13/18: transform ‘guard’


From: Thien-Thi Nguyen
Subject: [Emacs-diffs] fix/bug-31311-pcase-doc e276ce7 13/18: transform ‘guard’ example
Date: Tue, 15 May 2018 05:45:54 -0400 (EDT)

branch: fix/bug-31311-pcase-doc
commit e276ce7ca2bbc35e7ba07dfcab64df31fec242e6
Author: Thien-Thi Nguyen <address@hidden>
Commit: Thien-Thi Nguyen <address@hidden>

    transform ‘guard’ example
    
    Bonus: This reduces both forward-reference and ‘U-pattern’
           counts by one (each), yay!
    
    - zonk text in table
    - add "A common idiom" para (split) + example
---
 doc/lispref/control.texi | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi
index 4f6498b..08fc8f1c 100644
--- a/doc/lispref/control.texi
+++ b/doc/lispref/control.texi
@@ -401,13 +401,7 @@ Unlike @code{pred}, however,
 rather than against a boolean truth value.
 
 @item (guard @var{boolean-expression})
-Matches if @var{boolean-expression} evaluates to address@hidden  This
-allows you to include in a U-pattern boolean conditions that refer to
-symbols bound to values (including @var{expval}) by
-previous U-patterns.  Typically used inside @code{and}, see
-below.  For example, @address@hidden(and x (guard (< x 10)))}} is a pattern
-which matches any number smaller than 10 and let-binds the variable
address@hidden to that number.
+Matches if @var{boolean-expression} evaluates to address@hidden
 
 @item (let @var{pattern} @var{expr})
 Evaluates @var{expr} to get @var{exprval}
@@ -427,6 +421,28 @@ should all bind the same symbols.
 Matches if all the argument U-patterns match.
 @end table
 
+A common idiom is to write a pattern starting with @code{and},
+with one or more @var{symbol} sub-patterns providing bindings
+to the sub-patterns that follow (as well as to the body forms).
+For example, the following pattern matches single-digit integers.
+
address@hidden
+(and
+  (pred integerp)
+  n                     ; @r{bind @code{n} to @var{expval}}
+  (guard (<= -9 n 9)))
address@hidden example
+
address@hidden
+First, @code{pred} matches if @address@hidden(integerp @var{expval})}}
+evaluates to address@hidden
+Next, @code{n} is a @var{symbol} pattern that matches
+anything and binds @code{n} to @var{expval}.
+Lastly, @code{guard} matches if the boolean expression
address@hidden@code{(<= -9 n 9)}} (note the reference to @code{n})
+evaluates to address@hidden
+If all these sub-patterns match, @code{and} matches.
+
 @anchor{pcase-symbol-caveats}
 @heading Caveats for @var{symbol} in @var{bigpat}
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]