From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.lisp.guile.user Subject: Re: sxml-match bad pattern syntax Date: Tue, 28 Dec 2021 02:58:56 -0500 Message-ID: <87a6gldutb.fsf@gnuvola.org> References: <87h7atdzbo.fsf@gnuvola.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2652"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Dec 28 08:59:45 2021 Return-path: Envelope-to: guile-user@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 1n27Ob-0000Wy-01 for guile-user@m.gmane-mx.org; Tue, 28 Dec 2021 08:59:45 +0100 Original-Received: from localhost ([::1]:37072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n27OZ-0003O6-Tn for guile-user@m.gmane-mx.org; Tue, 28 Dec 2021 02:59:43 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n27OA-0003Ny-NO for guile-user@gnu.org; Tue, 28 Dec 2021 02:59:18 -0500 Original-Received: from delivery.mailspamprotection.com ([185.56.84.9]:41907) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n27O8-0004NA-K2 for guile-user@gnu.org; Tue, 28 Dec 2021 02:59:18 -0500 Original-Received: from 241.110.209.35.bc.googleusercontent.com ([35.209.110.241] helo=giow1035.siteground.us) by se18.mailspamprotection.com with esmtps (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1n27O4-0009TW-FT for guile-user@gnu.org; Tue, 28 Dec 2021 01:59:14 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnuvola.org ; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:To:From:Sender:Reply-To:Cc: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=vs7rqu2KeaKqG2eB9eIOn8pgoLKl8BkNgd9rws+a+G4=; b=rww2vDdpD/Qj+eRr/dRqnyLqCB DetjxCkt3wR9LWDT1g8JZNb8l7um2XnJhvMFE2pnITchqyvioyyx78+UPOZnaMNUFuDJkH5CSgCc2 2iR7G39zOVAj4o34eKFV+EBgWj3ooAJLMQU/h2P2jSUGqtAoOCkoenHPFc1sbj6njTxk=; Original-Received: from [50.89.166.226] (port=39326 helo=abolire) by giow1035.siteground.us with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.90-.1) (envelope-from ) id 1n27O4-0009KW-7v for guile-user@gnu.org; Tue, 28 Dec 2021 07:59:12 +0000 Mail-Followup-To: guile-user@gnu.org In-Reply-To: (tomas@tuxteam.de's message of "Tue, 28 Dec 2021 08:19:04 +0100") X-Originating-IP: 35.209.110.241 X-SpamExperts-Domain: giow1035.siteground.us X-SpamExperts-Username: 35.209.110.241 Authentication-Results: mailspamprotection.com; auth=pass smtp.auth=35.209.110.241@giow1035.siteground.us X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.20) X-Recommended-Action: accept X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT84I7aRIg1xPjLjrnb1NuZ9PUtbdvnXkggZ 3YnVId/Y5jcf0yeVQAvfjHznO7+bT5wLhre8Rs9A7VGcCqK8bn0qbA/nwrcN5XO9vX75jP2nU+1H PKyKjZVYKvnmCdbCKdnilbHtbFYVmmyNP/jzd7CCzPgfBgZM0FjuQW6Y55dUiQZmnW/XN+tohdLu D74c7RIjp6w6C9uhW4b49q7wR4OIg8CBO1Snvm6qXHQp7O9kdXEVHK8ms3KD3usLgF5hop6WBs2x H2ECFB9jy+mqDrXyzO11BRKqT8B4uLrn7iz8uvLBMzbIQcSG8L0jOzL80Q1MxDcqDeEvahfPkDkT lH91LgaQnmF8H6pa6B8MTK1lii9jyCbkXtEuyOnFV02lgfrmIJFSU6hi7nfgXGmjAulQMgrYfgAZ Zb04/OubpB2EQv2o1X92Cn4UU9JJ17dQkS7izDj4VfLGYhV5rU4pWppWNkfi8i3qCVlWxapaS/oL VM7UZB5DjZsjTnYAKJBt0QYHqlOp8L8bz1V+J+CU4gJ92+mjZSBX08/Qa05JAIPdanoSKlHMxVnk urBPHtW+f1JZBGKGpZFwJprvIwY1weIqdADEgzRHsT0YO1C0kjJqTNEVJ8oJVpjpfPYvOSq1gBWN qSSmQg5ci8DoVX3KIYHskDzLsegeIf5jR5PNTlF6RW+yRxkmeaL6EFcZnyRV4RDujwN5vAr2fQEN gxhN/KmvgWDJyQhGvT8x+8ZryF6sGWKvFVT8sOEeyl3l/+Pi0yQ9nWPDJiphAOkUAkv9H/DmUQWD 8ZUl6W6GbLVSRWNFEr/SVY5/aOEWx X-Report-Abuse-To: spam@quarantine1.mailspamprotection.com Received-SPF: pass client-ip=185.56.84.9; envelope-from=ttn@gnuvola.org; helo=delivery.mailspamprotection.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17918 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain () () Tue, 28 Dec 2021 08:19:04 +0100 I /think/ the ellipsis is at a wrong place there. Note that I'm coming from "traditional" match, and I just have wrapped half of my brain around that (which, BTW, is somewhat painful :-) Haha, i know exactly how you feel. So take this with a grain of salt. * Phenomenology (aka: I barely know what I'm doing): If you replace your ellipses above by ". ,rest", things seem to work: (define (unbogus x) (sxml-match x ((a (@ . ,attrs) . ,rest) `(a (@ ,@(delete '(shape "rect") attrs)) . ,rest)))) (unbogus '(a (@ (shape "rect") (href "foo.html")) "kid")) => (a (@ (href "foo.html")) "kid") Cool. I guest the ". ,rest" is a shortcut for the ellipses. * Philosophy (aka blah, blah) If those ellipses resemble what match do, I think they are wrong there: (@ . ,attrs) ... would mean zero or more times the shape "(@ . ,attrs)". I think this isn't what you want. Ah, right! The ellipses are a tail that need to follow a head. I guess i was confused by the documentation's use of ellipses in the conventional sense rather than the literal sense: (define (album->html x) (sxml-match x [(album (@ (title ,t)) (catalog (num ,n) (fmt ,f)) ...) `(ul (li ,t) (li (b ,n) (i ,f)) ...)])) Anyway, thanks to your help, i've managed to cobble together the following code, attached here for the benefit of future self: --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=UNBOGUS #!/usr/bin/guile -s !# (use-modules (ice-9 pretty-print) (sxml match)) (define (pp x) (pretty-print x) (newline)) (define (unbogus x) (sxml-match x ((a (@ . ,attrs) . ,rest) `(a (@ ,@(delete '(shape "rect") attrs)) . ,rest)) (,otherwise (if (string? x) x `(,(car x) ,(cadr x) ,@(map unbogus (cddr x))))))) (define one '(a (@ (shape "rect") (href "foo.html")) "kid")) (newline) (pp one) (pp (unbogus one)) (define bad `(p (@) "some text and " ,one " and " ,one)) (newline) (pp bad) (pp (unbogus bad)) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Maybe it's idiomatic. Feedback on how to improve it welcome! =2D-=20 Thien-Thi Nguyen ----------------------------------------------- (defun responsep (query) ; (2021) Software Libero (pcase (context query) ; =3D Dissenso Etico (`(technical ,ml) (correctp ml)) ...)) 748E A0E8 1CB8 A748 9BFA =2D-------------------------------------- 6CE4 6703 2224 4C80 7502 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iG4EARECAC4WIQR0jqDoHLinSJv6bORnAyIkTIB1AgUCYcrDwhAcdHRuQGdudXZv bGEub3JnAAoJEGcDIiRMgHUCNl0AoJToFGkEEnDwxCyk4H7hLLUJOaW+AKCrv3SI lNOjNa9RIUeY4HcjJWB1hg== =RMRM -----END PGP SIGNATURE----- --==-=-=--