[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}
- [Emacs-diffs] fix/bug-31311-pcase-doc 5c3da48 01/18: (docstring) [2nd para] use ‘PATTERN’ as proper noun, (continued)
- [Emacs-diffs] fix/bug-31311-pcase-doc 5c3da48 01/18: (docstring) [2nd para] use ‘PATTERN’ as proper noun, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc 492dd6c 04/18: use address@hidden, address@hidden as proper noun, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc b3fb63e 05/18: zonk "Depending on the pattern" para (superseded by SYMBOL expansion), Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc 15378c3 08/18: do ‘s/predicate function/predicate/’, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc f2610c6 11/18: for ‘app’, refine comparison w/ ‘pred’, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc abf7e6a 03/18: zonk "side-effecting" Issue comment lines, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc c0f0f18 07/18: zonk later address@hidden introduction (superseded), Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc 0f1c170 06/18: settle on address@hidden pcase’ text, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc dc4b413 09/18: do ‘s/predfun/function/g’, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc 5e2eeee 17/18: transform ‘get-return-code’ example, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc e276ce7 13/18: transform ‘guard’ example,
Thien-Thi Nguyen <=
- [Emacs-diffs] fix/bug-31311-pcase-doc ff41db6 12/18: (docstring) quote ‘pcase’ in QPAT docstring, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc bd79b06 15/18: add anchor/heading to examples; fix typo, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc d5dfe0e 02/18: expand on SYMBOL, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc 0dffb69 10/18: (docstring) do s/predicate function/predicate/g, s/specified/formed/g, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc 4ede733 16/18: refine example header, grouping, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc 484c3ae 18/18: add xref to ‘(cl) Conditionals’, Thien-Thi Nguyen, 2018/05/15
- [Emacs-diffs] fix/bug-31311-pcase-doc 279d548 14/18: transform ‘let’ example, Thien-Thi Nguyen, 2018/05/15