From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Arun Isaac Newsgroups: gmane.lisp.guile.bugs Subject: bug#30920: doc: Inconsistent parentheses in "(guile) sxml-match" Date: Tue, 24 Mar 2020 02:00:05 +0530 Message-ID: References: <87d095xuhg.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="21408"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 30920@debbugs.gnu.org To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Mon Mar 23 21:31:16 2020 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jGTj9-0005St-IT for guile-bugs@m.gmane-mx.org; Mon, 23 Mar 2020 21:31:15 +0100 Original-Received: from localhost ([::1]:39490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGTj8-0005tT-DY for guile-bugs@m.gmane-mx.org; Mon, 23 Mar 2020 16:31:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57564) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGTix-0005hi-R9 for bug-guile@gnu.org; Mon, 23 Mar 2020 16:31:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGTiw-0000aM-4Z for bug-guile@gnu.org; Mon, 23 Mar 2020 16:31:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47628) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGTiw-0000aG-13 for bug-guile@gnu.org; Mon, 23 Mar 2020 16:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jGTiv-0006OK-RW for bug-guile@gnu.org; Mon, 23 Mar 2020 16:31:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Mon, 23 Mar 2020 20:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30920 X-GNU-PR-Package: guile Original-Received: via spool by 30920-submit@debbugs.gnu.org id=B30920.158499543324535 (code B ref 30920); Mon, 23 Mar 2020 20:31:01 +0000 Original-Received: (at 30920) by debbugs.gnu.org; 23 Mar 2020 20:30:33 +0000 Original-Received: from localhost ([127.0.0.1]:53601 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jGTiS-0006Nc-Tu for submit@debbugs.gnu.org; Mon, 23 Mar 2020 16:30:33 -0400 Original-Received: from mugam.systemreboot.net ([139.59.75.54]:51270) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jGTiO-0006NP-FH for 30920@debbugs.gnu.org; Mon, 23 Mar 2020 16:30:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=Content-Type:MIME-Version:Message-ID:Date: References:In-Reply-To:Subject:Cc:To:From:Sender:Reply-To: 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=iGiXLcIv9L60d988l77rmKRBGM85jodrC0IPeuf2ahg=; b=fL+rl3uFQ1ztn5yaJaN/pGjq/ 80RRknhmHPcHKUZqxiWWkJKMX3vpNhU5MRRYp9if5HFAhI2XZsgD6ebuyjXhpAOiN3SdLOB0BEqfU 0K+1dUD3M8giJVCKynf7FOhGJegPWlYpJ2D0mC/U760FXoltk+eZ70CM+1l5L1IrPO2Ws=; Original-Received: from [192.168.2.1] (helo=steel) by systemreboot.net with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jGTiK-003pcM-RB; Tue, 24 Mar 2020 02:00:24 +0530 In-Reply-To: <87d095xuhg.fsf@gnu.org> 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: 209.51.188.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-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:9688 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Hi, > I agree with you that consistency would be nice and a patch in that > direction would be welcome! Please find attached a patch. While working on this patch, I found that two of the code snippets don't work. They work neither with square brackets nor with round brackets. The two snippets are * The first snippet in the "Matching the Unmatched Attributes" subsection @lisp (sxml-match '(a (@@ (z 1) (y 2) (x 3)) 4 5 6) ((a (@@ (y ,www) . ,qqq) ,t ,u ,v) (list www qqq t u v))) @end lisp * The snippet in the "Default Values in Attribute Patterns" subsection @lisp (sxml-match '(e 3 4 5) ((e (@@ (z (,d 1))) ,a ,b ,c) (list d a b c))) @end lisp These snippets fail to evaluate. Could you check? Thanks! --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-doc-Replace-square-brackets-with-round-brackets.patch Content-Transfer-Encoding: quoted-printable From=206e31e3fe1fd2b537d4a02dbcfccbb03e0d20e804 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Tue, 24 Mar 2020 01:45:32 +0530 Subject: [PATCH] doc: Replace square brackets with round brackets. * doc/ref/sxml-match.texi: Replace all square brackets with round brackets in order to be consistent with the rest of the documentation. =2D-- doc/ref/sxml-match.texi | 90 ++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/doc/ref/sxml-match.texi b/doc/ref/sxml-match.texi index 3adf34751..9b5f1dbd4 100644 =2D-- a/doc/ref/sxml-match.texi +++ b/doc/ref/sxml-match.texi @@ -30,9 +30,9 @@ illustration, transforming a music album catalog language= into HTML. @lisp (define (album->html x) (sxml-match x =2D [(album (@@ (title ,t)) (catalog (num ,n) (fmt ,f)) ...) + ((album (@@ (title ,t)) (catalog (num ,n) (fmt ,f)) ...) `(ul (li ,t) =2D (li (b ,n) (i ,f)) ...)])) + (li (b ,n) (i ,f)) ...)))) @end lisp =20 Three macros are provided: @code{sxml-match}, @code{sxml-match-let}, and @@ -138,8 +138,8 @@ The example below illustrates the pattern matching of a= n XML element: =20 @lisp (sxml-match '(e (@@ (i 1)) 3 4 5) =2D [(e (@@ (i ,d)) ,a ,b ,c) (list d a b c)] =2D [,otherwise #f]) + ((e (@@ (i ,d)) ,a ,b ,c) (list d a b c)) + (,otherwise #f)) @end lisp =20 Each clause in @code{sxml-match} contains two parts: a pattern and one or = more @@ -165,8 +165,8 @@ where nested ellipses are used to match the children of= repeated instances of an (define x '(d (a 1 2 3) (a 4 5) (a 6 7 8) (a 9 10))) =20 (sxml-match x =2D [(d (a ,b ...) ...) =2D (list (list b ...) ...)]) + ((d (a ,b ...) ...) + (list (list b ...) ...))) @end lisp =20 The above expression returns a value of @code{((1 2 3) (4 5) (6 7 8) (9 10= ))}. @@ -179,8 +179,8 @@ in the example below. =20 @lisp (sxml-match '(e 3 4 5 6 7) =2D [(e ,i ... 6 7) `("start" ,(list 'wrap i) ... "end")] =2D [,otherwise #f]) + ((e ,i ... 6 7) `("start" ,(list 'wrap i) ... "end")) + (,otherwise #f)) @end lisp =20 The general pattern is that @code{`(something ,i ...)} is rewritten as @@ -193,8 +193,8 @@ identifier list. The example below illustrates matchin= g a nodeset. =20 @lisp (sxml-match '("i" "j" "k" "l" "m") =2D [(list ,a ,b ,c ,d ,e) =2D `((p ,a) (p ,b) (p ,c) (p ,d) (p ,e))]) + ((list ,a ,b ,c ,d ,e) + `((p ,a) (p ,b) (p ,c) (p ,d) (p ,e)))) @end lisp =20 This example wraps each nodeset item in an HTML paragraph element. This e= xample @@ -202,8 +202,8 @@ can be rewritten and simplified through using ellipsis: =20 @lisp (sxml-match '("i" "j" "k" "l" "m") =2D [(list ,i ...) =2D `((p ,i) ...)]) + ((list ,i ...) + `((p ,i) ...))) @end lisp =20 This version will match nodesets of any length, and wrap each item in the @@ -218,8 +218,8 @@ This is illustrated in the example below: =20 @lisp (sxml-match '(e 3 (f 4 5 6) 7) =2D [(e ,a (f . ,y) ,d) =2D (list a y d)]) + ((e ,a (f . ,y) ,d) + (list a y d))) @end lisp =20 The above expression returns @code{(3 (4 5 6) 7)}. @@ -233,8 +233,8 @@ illustrated in the example below: =20 @lisp (sxml-match '(a (@@ (z 1) (y 2) (x 3)) 4 5 6) =2D [(a (@@ (y ,www) . ,qqq) ,t ,u ,v) =2D (list www qqq t u v)]) + ((a (@@ (y ,www) . ,qqq) ,t ,u ,v) + (list www qqq t u v))) @end lisp =20 The above expression matches the attribute @code{y} and binds a list of the @@ -245,8 +245,8 @@ This type of pattern also allows the binding of all att= ributes: =20 @lisp (sxml-match '(a (@@ (z 1) (y 2) (x 3))) =2D [(a (@@ . ,qqq)) =2D qqq]) + ((a (@@ . ,qqq)) + qqq)) @end lisp =20 @unnumberedsubsec Default Values in Attribute Patterns @@ -257,7 +257,7 @@ the following example: =20 @lisp (sxml-match '(e 3 4 5) =2D [(e (@@ (z (,d 1))) ,a ,b ,c) (list d a b c)]) + ((e (@@ (z (,d 1))) ,a ,b ,c) (list d a b c))) @end lisp =20 The value @code{1} is used when the attribute @code{z} is absent from the @@ -289,35 +289,35 @@ basic arithmetic operations, which are represented by= the XML elements (define simple-eval (lambda (x) (sxml-match x =2D [,i (guard (integer? i)) i] =2D [(plus ,x ,y) (+ (simple-eval x) (simple-eval y))] =2D [(times ,x ,y) (* (simple-eval x) (simple-eval y))] =2D [(minus ,x ,y) (- (simple-eval x) (simple-eval y))] =2D [(div ,x ,y) (/ (simple-eval x) (simple-eval y))] =2D [,otherwise (error "simple-eval: invalid expression" x)]))) + (,i (guard (integer? i)) i) + ((plus ,x ,y) (+ (simple-eval x) (simple-eval y))) + ((times ,x ,y) (* (simple-eval x) (simple-eval y))) + ((minus ,x ,y) (- (simple-eval x) (simple-eval y))) + ((div ,x ,y) (/ (simple-eval x) (simple-eval y))) + (,otherwise (error "simple-eval: invalid expression" x))))) @end lisp =20 Using the catamorphism feature of @code{sxml-match}, a more concise versio= n of =2D@code{simple-eval} can be written. The pattern @code{,[x]} recursively = invokes +@code{simple-eval} can be written. The pattern @code{,(x)} recursively in= vokes the pattern matcher on the value bound in this position. =20 @lisp (define simple-eval (lambda (x) (sxml-match x =2D [,i (guard (integer? i)) i] =2D [(plus ,[x] ,[y]) (+ x y)] =2D [(times ,[x] ,[y]) (* x y)] =2D [(minus ,[x] ,[y]) (- x y)] =2D [(div ,[x] ,[y]) (/ x y)] =2D [,otherwise (error "simple-eval: invalid expression" x)]))) + (,i (guard (integer? i)) i) + ((plus ,(x) ,(y)) (+ x y)) + ((times ,(x) ,(y)) (* x y)) + ((minus ,(x) ,(y)) (- x y)) + ((div ,(x) ,(y)) (/ x y)) + (,otherwise (error "simple-eval: invalid expression" x))))) @end lisp =20 @unnumberedsubsec Named-Catamorphisms =20 It is also possible to explicitly name the operator in the ``cata'' positi= on. =2DWhere @code{,[id*]} recurs to the top of the current @code{sxml-match}, =2D@code{,[cata -> id*]} recurs to @code{cata}. @code{cata} must evaluate = to a +Where @code{,(id*)} recurs to the top of the current @code{sxml-match}, +@code{,(cata -> id*)} recurs to @code{cata}. @code{cata} must evaluate to= a procedure which takes one argument, and returns as many values as there are identifiers following @code{->}. =20 @@ -329,29 +329,29 @@ transformation that formats a ``TV Guide'' into HTML. (define (tv-guide->html g) (define (cast-list cl) (sxml-match cl =2D [(CastList (CastMember (Character (Name ,ch)) (Actor (Name ,a))) .= ..) =2D `(div (ul (li ,ch ": " ,a) ...))])) + ((CastList (CastMember (Character (Name ,ch)) (Actor (Name ,a))) ...) + `(div (ul (li ,ch ": " ,a) ...))))) (define (prog p) (sxml-match p =2D [(Program (Start ,start-time) (Duration ,dur) (Series ,series-titl= e) + ((Program (Start ,start-time) (Duration ,dur) (Series ,series-title) (Description ,desc ...)) `(div (p ,start-time (br) ,series-title =2D (br) ,desc ...))] =2D [(Program (Start ,start-time) (Duration ,dur) (Series ,series-titl= e) + (br) ,desc ...))) + ((Program (Start ,start-time) (Duration ,dur) (Series ,series-title) (Description ,desc ...) =2D ,[cast-list -> cl]) + ,(cast-list -> cl)) `(div (p ,start-time (br) ,series-title (br) ,desc ...) =2D ,cl)])) + ,cl)))) (sxml-match g =2D [(TVGuide (@@ (start ,start-date) + ((TVGuide (@@ (start ,start-date) (end ,end-date)) =2D (Channel (Name ,nm) ,[prog -> p] ...) ...) + (Channel (Name ,nm) ,(prog -> p) ...) ...) `(html (head (title "TV Guide")) (body (h1 "TV Guide") =2D (div (h2 ,nm) ,p ...) ...))])) + (div (h2 ,nm) ,p ...) ...))))) @end lisp =20 @unnumberedsubsec @code{sxml-match-let} and @code{sxml-match-let*} @@ -365,7 +365,7 @@ an XML pattern in the binding position, rather than a s= imple variable. For example, the expression below: =20 @lisp =2D(sxml-match-let ([(a ,i ,j) '(a 1 2)]) +(sxml-match-let (((a ,i ,j) '(a 1 2))) (+ i j)) @end lisp =20 =2D-=20 2.25.1 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEf3MDQ/Lwnzx3v3nTLiXui2GAK7MFAl55HE0ACgkQLiXui2GA K7Ms2wgAnG6r5RMPW7dO84qDLkpSM+k6jWbOMVabrbnOBTebKz4CrW4DueHSysmH ihHYQDG0LDWlKiyxaa2ijDzLzwO3DM0JNQNzi3jREzSzVeq/B22mzums/crx/vtZ XjB9NnZXq7c8YbGhbk4za0hKFO7ZdVgCBIjgX0No+Yp1w3Yw1lXSjP66DEEAHjGB 6eEN4+acgiO+wK8AFKxtCCf9HEaWrNAKj9StbKwtGKoXomkINaGI47MutmJO7NLl Lu1m2/7w2muC29FE0up0wdq5Ewt7leu7zyAkNgtden4cP/6S65CP+Dg/M/8v0m3G 4GMvxOXp/WJQPDXSRLgsX3b/tcRPfw== =0W0i -----END PGP SIGNATURE----- --==-=-=--