[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] fix/bug-31311-pcase-doc 5e2eeee 17/18: transform ‘get-ret
From: |
Thien-Thi Nguyen |
Subject: |
[Emacs-diffs] fix/bug-31311-pcase-doc 5e2eeee 17/18: transform ‘get-return-code’ example |
Date: |
Tue, 15 May 2018 05:45:55 -0400 (EDT) |
branch: fix/bug-31311-pcase-doc
commit 5e2eeeee075342b1b03fc9269e05c863f21840c3
Author: Thien-Thi Nguyen <address@hidden>
Commit: Thien-Thi Nguyen <address@hidden>
transform ‘get-return-code’ example
- move before other examples
- add anchor/subheading
- expand to compare against ‘cl-case’
- add pre- and post- paras
- remove FIXME comment (coverage now shared by all examples)
---
doc/lispref/control.texi | 40 ++++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 14 deletions(-)
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi
index 3439916..95d5777 100644
--- a/doc/lispref/control.texi
+++ b/doc/lispref/control.texi
@@ -419,6 +419,32 @@ should all bind the same symbols.
Matches if all the argument U-patterns match.
@end table
address@hidden
address@hidden Example: Advantage Over @code{cl-case}
+
+Here's an example that highlights some advantages @code{pcase}
+has over @code{cl-case}.
+
address@hidden
+(pcase (get-return-code x)
+ ;; string
+ ((and (pred stringp) msg)
+ (message "%s" msg))
+ ;; symbol
+ ('success (message "Done!"))
+ ('would-block (message "Sorry, can't do it now"))
+ ('read-only (message "The shmliblick is read-only"))
+ ('access-denied (message "You do not have the needed rights"))
+ ;; default
+ (code (message "Unknown return code %S" code)))
address@hidden example
+
address@hidden
+With @code{cl-case}, you would need to explicitly declare a local
+variable @code{code} to hold the return value of @code{get-return-code}.
+Also @code{cl-case} is difficult to use with strings because it
+uses @code{eql} for comparison.
+
@anchor{pcase-example-1}
@subheading Example: Using @code{and}
@@ -607,20 +633,6 @@ Avoid.
@c (what does it mean?)
@end enumerate
address@hidden
-Here's an example of using U-patterns:
-
address@hidden FIXME: This example should use every one of the U-patterns
described
address@hidden above at least once.
address@hidden
-(pcase (get-return-code x)
- ('success (message "Done!"))
- ('would-block (message "Sorry, can't do it now"))
- ('read-only (message "The shmliblick is read-only"))
- ('access-denied (message "You do not have the needed rights"))
- (code (message "Unknown return code %S" code)))
address@hidden example
-
In addition, you can use backquoted patterns that are more powerful.
They allow matching @var{expval} against specifications of its
@emph{structure}. For example, you can specify that the value must be
- [Emacs-diffs] fix/bug-31311-pcase-doc updated (2eb044b -> 484c3ae), Thien-Thi Nguyen, 2018/05/15
- [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 <=
- [Emacs-diffs] fix/bug-31311-pcase-doc e276ce7 13/18: transform ‘guard’ example, Thien-Thi Nguyen, 2018/05/15
- [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