() <to...@tuxteam.de> () 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:
#!/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))
Maybe it's idiomatic. Feedback on how to improve it welcome! -- Thien-Thi Nguyen ----------------------------------------------- (defun responsep (query) ; (2021) Software Libero (pcase (context query) ; = Dissenso Etico (`(technical ,ml) (correctp ml)) ...)) 748E A0E8 1CB8 A748 9BFA --------------------------------------- 6CE4 6703 2224 4C80 7502
signature.asc
Description: PGP signature