IRC channel logs

2024-02-10.log

back to list of logs

<teddd>How would you get the text in a shtml tree ? Like not all the strings, but just the actual html text
<rekado>teddd: I’d use sxpath to get all *text* nodes
<rekado>example:
<rekado>(import (sxml xpath) (sxml simple))
<rekado>(define x (xml->sxml "<hello><a>hello</a><b>world</b>done</hello>"))
<rekado>((sxpath '(// *text*)) x)
<rekado>this returns a list of strings: '("done" "hello" "world")
<rekado>the order may not be what you expect due to the way the tree is traversed.
<teddd>rekado: Looks good !
<teddd>I'll try that out, thanks
<rekado>XPath is specified here: https://www.w3.org/TR/1999/REC-xpath-19991116/
<rekado>but I wouldn’t bother attempting to read it in one sitting
<rekado>in other languages, xpath is usually specified as a big string (much like regexps are)
<rekado>sxpath is a little different; the path is a list and the sxpath procedure returns a procedure that can be applied to a tree.
<rekado>“//” roughly means “from anywhere”, and “*text*” is the special symbol matching XML text nodes.
<rekado>without “//” you’d have to specify an uninterrupted path to the target element of interest
<rekado>e.g. ((sxpath '(hello b *text*)) x) => '("world")
<rekado>sxpath support a few extra tricks (you can use procedures in the path!), but even though I’ve done this many times I can’t trust myself to ever use it without a REPL to iterate over the path expression.
<rekado>the Guile manual has a whole chapter dedicated to SXPath, but it’s short on examples
<rekado>if you crave examples you can find them in the Guile code at module/sxml/upstream/SXPath-old.scm
<teddd>Nice, thanks for the explanation. I had a quick look at the manual but I felt overwhelmed. I think with your hints I can get started
<teddd>Is there an equivalent to bash's `which` command in guile ?
<teddd>Or maybe a way to find if a program is available
<jpoiret>teddd: you'll just want to iterate over possible programs in the PATH
<rlb>I think /bin/sh -c 'command -v SOMETHING' via open-pipe* should also be portable, if tedious to get exactly right wrt quoting... Though I seem to recall someone mentioning a scheme fn for this -- not sure if it was in guile itself, or maybe guix?
<singpolyma>guix has a (which) I dont know how it's implemented
<mwette>just looked: guix which is just (search-path (search-path-as-string->list (getenv "PATH")) program) where search-path is in guile
<jpoiret>mwette: hmmm, it doesn't check that the file is +x?
<old>teddd: you can check the `define-simple-finder' syntax I made here: https://paste.sr.ht/~old/a98ab75184531aba9d87edf87dc24d30ba652de9
<old>there's noise in this (like progression) because it is from a project of mine. But yeah the idea is to iterate over path in PATH and try to canonicalize-path on the concatenation of the path and the desired binary
<rlb>civodul: ok, I may have a possible solution, if I'm still comfortable with it after I clean up. It works, but it's not completely trivial -- though we do also have non-trivial constraints wrt threads, joins, and fork.
<avp>sneek: later tell civodul: Hello! Any updates on <https://notabug.org/guile-zlib/guile-zlib/issues/4> ? It's been a month since I provided an updated version of the patch; I'd love to see if there any issues left with my solution. Thanks!
<sneek>Okay.
<avp>Or maybe I should address this question to Zelphir Kaltstahl...
<civodul>avp: thanks for the heads-up, i had forgotten
<sneek>civodul, you have 1 message!
<sneek>civodul, avp says: Hello! Any updates on <https://notabug.org/guile-zlib/guile-zlib/issues/4> ? It's been a month since I provided an updated version of the patch; I'd love to see if there any issues left with my solution. Thanks!
<civodul>merged!