From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Arun Isaac Newsgroups: gmane.lisp.guile.bugs Subject: bug#30144: [PATCH 1/1] doc: Document (ice-9 match) macros. Date: Fri, 23 Mar 2018 19:52:04 +0530 Message-ID: <20180323142204.23420-2-arunisaac@systemreboot.net> References: <20180323142204.23420-1-arunisaac@systemreboot.net> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1521814879 17664 195.159.176.226 (23 Mar 2018 14:21:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 23 Mar 2018 14:21:19 +0000 (UTC) To: 30144@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Fri Mar 23 15:21:15 2018 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ezNZC-0004Sd-Mv for guile-bugs@m.gmane.org; Fri, 23 Mar 2018 15:21:15 +0100 Original-Received: from localhost ([::1]:38301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezNbE-0007zc-7u for guile-bugs@m.gmane.org; Fri, 23 Mar 2018 10:23:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34119) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezNb1-0007xh-F5 for bug-guile@gnu.org; Fri, 23 Mar 2018 10:23:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezNaw-0004lG-Up for bug-guile@gnu.org; Fri, 23 Mar 2018 10:23:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41940) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ezNaw-0004l2-Qw for bug-guile@gnu.org; Fri, 23 Mar 2018 10:23:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ezNaw-0005Gc-LU for bug-guile@gnu.org; Fri, 23 Mar 2018 10:23:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 23 Mar 2018 14:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30144 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch Original-Received: via spool by 30144-submit@debbugs.gnu.org id=B30144.152181496620196 (code B ref 30144); Fri, 23 Mar 2018 14:23:02 +0000 Original-Received: (at 30144) by debbugs.gnu.org; 23 Mar 2018 14:22:46 +0000 Original-Received: from localhost ([127.0.0.1]:49835 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ezNag-0005Fg-8P for submit@debbugs.gnu.org; Fri, 23 Mar 2018 10:22:46 -0400 Original-Received: from vultr.systemreboot.net ([45.77.148.100]:59998) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ezNae-0005FR-6Z for 30144@debbugs.gnu.org; Fri, 23 Mar 2018 10:22:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=JL3BSAGhHWXbCgNjP2YFatP4zfhKJZ6vEWBt1QCpevY=; b=QednUtFzoiX7uvsv8tUcoEA67 V2rYlIKntX86CDDfQjdI9tU/4lRZOumOuPTrVf8Z7zgm+GheAQw/DDnsraqBjlEkTXEBm2lLOl6jE LkSVH0qVtmlTw/CmfyQhB9yWvAkwFPpmwq70sJBHhTupxuMkpBoWj0QRWFlG1f6L4Msuk=; Original-Received: from [117.192.124.137] (helo=localhost.localdomain) by systemreboot.net with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ezNaW-0007f4-Rc; Fri, 23 Mar 2018 19:52:36 +0530 X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180323142204.23420-1-arunisaac@systemreboot.net> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:9032 Archived-At: * doc/ref/match.texi: Document match-lambda, match-lambda*, match-let, match-let* and match-letrec. --- doc/ref/match.texi | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/doc/ref/match.texi b/doc/ref/match.texi index 12e3814ae..0fc5105d1 100644 --- a/doc/ref/match.texi +++ b/doc/ref/match.texi @@ -213,8 +213,96 @@ 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, and returns the result of evaluating the corresponding +expressions. + +@example +(match-lambda clause1 clause2 @dots{}) +@equiv{} +(lambda (arg) (match arg clause1 clause2 @dots{})) +@end example +@end deffn + +@example +((match-lambda + (('hello (who)) + who)) + '(hello (world))) +@result{} world +@end example + +@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, and returns the result of evaluating the +corresponding expressions. + +@example +(match-lambda* clause1 clause2 @dots{}) +@equiv{} +(lambda args (match args clause1 clause2 @dots{})) +@end example +@end deffn + +@example +((match-lambda* + (('hello (who)) + who)) + 'hello '(world)) +@result{} world +@end example + +@deffn {Scheme Syntax} match-let ((pattern expression) @dots{}) body +Match each pattern 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 ((pattern init) @dots{}) body +Similar to @code{match-let}, but analogously to @dfn{named let}, locally +bind VARIABLE to a new procedure which accepts as many arguments as +there are INIT expressions. The procedure is initially applied to the +results of evaluating the INIT expressions. When called, the procedure +matches each argument against the corresponding PATTERN, and returns the +result(s) of evaluating the BODY expressions. @xref{while do, +Iteration}, for more on @dfn{named let}. +@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