unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#30144: [PATCH] doc: Document (ice-9 match) macros.
@ 2018-01-17 12:25 Arun Isaac
  2018-01-21 16:16 ` Mark H Weaver
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Arun Isaac @ 2018-01-17 12:25 UTC (permalink / raw)
  To: 30144

* doc/ref/match.texi: Document match-lambda, match-lambda*, match-let,
  match-let* and match-letrec.
---
 doc/ref/match.texi | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 63 insertions(+), 2 deletions(-)

diff --git a/doc/ref/match.texi b/doc/ref/match.texi
index 12e3814ae..4d85fe3f9 100644
--- a/doc/ref/match.texi
+++ b/doc/ref/match.texi
@@ -213,8 +213,69 @@ any @var{person} whose second slot is a promise that evaluates to a
 one-element list containing a @var{person} whose first slot is
 @code{"Bob"}.
 
-Please refer to the @code{ice-9/match.upstream.scm} file in your Guile
-installation for more details.
+The @code{(ice-9 match)} module also provides the following convenient
+syntactic sugar macros wrapping around @code{match}.
+
+@deffn {Scheme Syntax} match-lambda exp clause1 clause2 @dots{}
+Create a procedure of one argument that matches its argument against
+each clause.
+
+@example
+(match-lambda clause1 clause2 @dots{})
+@equiv{}
+(lambda (arg) (match arg clause1 clause2 @dots{}))
+@end example
+@end deffn
+
+@deffn {Scheme Syntax} match-lambda* exp clause1 clause2 @dots{}
+Create a procedure of any number of arguments that matches its argument
+list against each clause.
+
+Equivalent to
+@example
+(match-lambda* clause1 clause2 @dots{})
+@equiv{}
+(lambda args (match args clause1 clause2 @dots{}))
+@end example
+@end deffn
+
+@deffn {Scheme Syntax} match-let ((variable expression) @dots{}) body
+Match each variable to the corresponding expression, and evaluate the
+body with all matched variables in scope.  Raise an error if any of the
+expressions fail to match.  @code{match-let} is analogous to named let
+and can also be used for recursive functions which match on their
+arguments as in @code{match-lambda*}.
+
+@example
+(match-let (((x y) (list 1 2))
+	    ((a b) (list 3 4)))
+  (list a b x y))
+@result{}
+(3 4 1 2)
+@end example
+@end deffn
+
+@deffn {Scheme Syntax} match-let* ((variable expression) @dots{}) body
+Similar to @code{match-let}, but analogously to @code{let*}, match and
+bind the variables in sequence, with preceding match variables in scope.
+
+@example
+(match-let* (((x y) (list 1 2))
+	     ((a b) (list x 4)))
+  (list a b x y))
+@equiv{}
+(match-let (((x y) (list 1 2)))
+  (match-let (((a b) (list x 4)))
+    (list a b x y)))
+@result{}
+(1 4 1 2)
+@end example
+@end deffn
+
+@deffn {Scheme Syntax} match-letrec ((variable expression) @dots{}) body
+Similar to @code{match-let}, but analogously to @code{letrec}, match and
+bind the variables with all match variables in scope.
+@end deffn
 
 Guile also comes with a pattern matcher specifically tailored to SXML
 trees, @xref{sxml-match}.
-- 
2.15.1






^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-06-18 12:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-17 12:25 bug#30144: [PATCH] doc: Document (ice-9 match) macros Arun Isaac
2018-01-21 16:16 ` Mark H Weaver
2018-01-21 18:14   ` Arun Isaac
2018-02-21 22:22   ` Ludovic Courtès
2018-03-16  4:05 ` Mark H Weaver
2018-03-16  4:33   ` Mark H Weaver
2018-03-16 23:27   ` Arun Isaac
2018-03-20  0:32     ` Mark H Weaver
2018-03-23 14:22 ` bug#30144: [PATCH 0/1] " Arun Isaac
2018-03-23 14:22   ` bug#30144: [PATCH 1/1] doc: " Arun Isaac
2018-06-18 12:08     ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).