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] doc: Document (ice-9 match) macros. Date: Wed, 17 Jan 2018 17:55:04 +0530 Message-ID: <20180117122504.25583-1-arunisaac@systemreboot.net> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1516191881 13293 195.159.176.226 (17 Jan 2018 12:24:41 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 17 Jan 2018 12:24:41 +0000 (UTC) To: 30144@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Wed Jan 17 13:24:36 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 1ebmlM-00024V-A2 for guile-bugs@m.gmane.org; Wed, 17 Jan 2018 13:24:16 +0100 Original-Received: from localhost ([::1]:60013 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebmnM-0000X3-2b for guile-bugs@m.gmane.org; Wed, 17 Jan 2018 07:26:20 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebmn9-0000T0-6R for bug-guile@gnu.org; Wed, 17 Jan 2018 07:26:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebmn4-0004J3-88 for bug-guile@gnu.org; Wed, 17 Jan 2018 07:26:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebmn4-0004Ii-4p for bug-guile@gnu.org; Wed, 17 Jan 2018 07:26:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ebmn3-00063J-U8 for bug-guile@gnu.org; Wed, 17 Jan 2018 07:26:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 17 Jan 2018 12:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 30144 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.151619195723252 (code B ref -1); Wed, 17 Jan 2018 12:26:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 17 Jan 2018 12:25:57 +0000 Original-Received: from localhost ([127.0.0.1]:59513 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ebmmy-00062y-MV for submit@debbugs.gnu.org; Wed, 17 Jan 2018 07:25:56 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:53909) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ebmmw-00062g-V2 for submit@debbugs.gnu.org; Wed, 17 Jan 2018 07:25:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebmmm-00044n-QQ for submit@debbugs.gnu.org; Wed, 17 Jan 2018 07:25:49 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:37950) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebmmm-00044O-N6 for submit@debbugs.gnu.org; Wed, 17 Jan 2018 07:25:44 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebmmf-0000C1-Im for bug-guile@gnu.org; Wed, 17 Jan 2018 07:25:44 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebmma-0003x3-Jn for bug-guile@gnu.org; Wed, 17 Jan 2018 07:25:37 -0500 Original-Received: from vultr.systemreboot.net ([45.77.148.100]:49876) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebmma-0003tv-0t for bug-guile@gnu.org; Wed, 17 Jan 2018 07:25:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=FZPf1faRhaQrjzDRLgiCVjEfWeOL441M9rAfg6oSaWc=; b=K8LLeKwKXskKmQLO/r/KWFwOi4 5cRaRPMtyJctuzHJs9yO5KYrEwjB0qJQYapZagnPeaOEmaGNTpTHh0MLZH5ILNMlJCof/qn+y+2OY NvkcNRbvDx3yZ5mulZmVlgIB4/h+4rsfKCfhz/Jpd4Ot2tTaaU8qJPfqlitIq2LgWyOY=; Original-Received: from [117.192.107.9] (helo=localhost.localdomain) by systemreboot.net with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90) (envelope-from ) id 1ebmmH-0006aQ-Np; Wed, 17 Jan 2018 17:55:13 +0530 X-Mailer: git-send-email 2.15.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:8969 Archived-At: * 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