IRC channel logs

2021-02-21.log

back to list of logs

<Formbi>isn't there a command-line switch?
<Formbi>ah, nevermind
<Formbi>for some reason root owned my ~/.cache/guile and auto-compile of course couldn't write there
<apteryx>how can I access the element following a symbol in a tagged list?
<chrislck>whats a tagged lst
<RhodiumToad>you mean like (#:foo 123 #:bar 456) ?
<RhodiumToad>or ('foo 123 'bar 456)
<RhodiumToad>if you know that the symbol will not appear as a value, (and=> (memq 'bar lst) cadr) but that's a bit sloppy
<RhodiumToad>goops has a function for doing it with keywords, it uses a loop and match
<apteryx>Hmm in my current example the former (an args list)
<apteryx>ah, memq. Thanks.
<apteryx>chrislck: I think it's synonym with plist or property list
<apteryx>e.g., (list 'some-tag some-value 'some-other-tag some-other-value ...)
<chrislck>(let lp ((plist plist)) (match plist (('sym elt . _) elt) ((_ _ . rest) (lp rest))))
<apteryx>that's a bit more involved than I'd like; I was hopping for primitive similar to assoc-ref ;-) but thanks
<apteryx>I guess: (cadr (memq #:ta '(#:bo 1 #:ta 3))) -> 3 is the simplest so far
<chrislck>you'd want some handling for such things like '(#:foo 1 #:bar)
<apteryx>in my specific case, I can rely on the specific arg of interest always being passed and initialized to a default value
<daviid>apteryx: fwiw, (use-modules ((oop goops) #:select (get-keyword))), then (get-keyword #:ta '(#:bo 1 #:ta 3))
<apteryx>daviid: oh, neat!
<RhodiumToad>I did say goops has a function for it :-)
<daviid>RhodiumToad: indeed, i should have added 'as suggested by ....' tx
<daviid>rekado_: (or other musician) do you happen to know of a free s/w lib that displays a (lilypond) score (one line at least), plays it according to a user defined tempo, instrument 'timbre' and user feedback (a progress vertical bar that 'follows' the playback - and that could be embedded in a gtk widget?
***spk121_ is now known as spk121
<fnstudio>hi :) there's this procedure that returns multiple values and i think i'm interested in one (and only one) of them
<fnstudio>i can use `receive` to collect the returned values
<fnstudio>eg (receive (first-value second-value third-value) ...)
<fnstudio>is there a convention for how to name the variables i'm not interested in
<fnstudio>(in Python that'd be an underscore `_`, i suppose)
***rekado_ is now known as rekado
<rekado>daviid: frescobaldi has a GUI that also supports playback; not sure about following notes in the score.
<leoprikler>fnstudio: _ should work, but I'm not sure if you can list it twice
<leoprikler>if not, you can do (match (compose list your-function) ((v1 _ v3 ...) your code here))
<leoprikler>or even (compose (match-lambda ((v1 _ v3 ...) your code here)) mv-function)
<fnstudio>super leoprikler, very helpful, as usual
<fnstudio>hi :) i have this html page that contains a certain number of entries that i want to parse and save in a list; i think i can start by using html->sxml but i'm a bit lost at that point
<fnstudio>i see there's something called make-parser in the sxml library but i don't seem to be able to find a simple example
<chrislck>,use (sxml xpath) ,use (sxml simple)
<chrislck>(define xpath '(// td // *text*)) (define html "<html><table><td>bla</td><td>foo</td></table></html>") ((sxpath xpath) (xml->sxml html))
<spk121>wingo: question. For a guile app's stack which is a mix of scm and gsubr frames... Is a stack of scm->c->scm->c->scm->c in some sense worse than a stack that is scm->c->c->c->scm->scm. Do I gain anything by grouping C and scheme layers in a mixed app
<fnstudio>chrislck: amazing, thanks, let me try
<rekado>fnstudio: sxpath takes an XPath (represented as a list) as its argument and returns a procedure. Applying that procedure to an SXML tree returns the filtered result.
<rekado>the XPath in chrislck’s example begins with “//”, which effectively flattens the tree – it takes the root and all its decendents as the starting point
<rekado>from there it looks for elements with tag name “td”, (the following “//” is not needed) and then extracts the text node inside of each “td” node.
<rekado>there are fancy things you can do with this, e.g. to dynamically select nodes (not just nodes with a tag name that is known in advance), but this quickly becomes unwieldy
<rekado>luckily you can compose XPaths
<leoprikler>dynamic sxpaths sounds like a beast from the eight layer of hell
<leoprikler>s/eight/eighth/
<taw10>Conjure (https://github.com/Olical/conjure) now has a Guile client, if anyone is interested in trying it out, check out branch "develop" from the repo
<fnstudio>rekado: hey that's a very clear explanation, thanks! yes, i got things work in a minimum example, but it doesn't seem to work in the actual HTML, currently debugging that
<fnstudio>so... i'm trying to match all entries from the (minimum) example: https://paste.debian.net/1186333/
<fnstudio>using this sxpath: ((sxpath '(// (div (@ class (equal? "entry"))))) html-above)
<fnstudio>what puzzles me is that sxpath does find the entries
<fnstudio>but it doesn't seem to take the inner content
<fnstudio>that might be a bit obscure, let me add some more context :)
<fnstudio>the result of the sxpath procedure above is something along the lines of `(div (@ (class entry)))` (repeated as many times as the num of entries)
<fnstudio>no mention of the inner content, eg `Lorem Ipsum 0`
<fnstudio>i'd have expected all the node children to be matched
<fnstudio>weird, it seems to be an issue with paragraphs... `<p>...</p>`
<fnstudio>hm there seems to be a problem with the initial sxml
<fnstudio>the html looks fine to me, but when i convert it to sxml (via `html->sxml`) it then looks broken
<fnstudio>divs seem to be truncated whenever a paragraph `p` is used
<daviid>rekado: frescobaldi won't work - i'm really looking for a lib that would have a widget that display a score/staff, allows a few parameter settings foor timbres, tempo ... let the user start/stop/pause/resume while offering a vertical cursor feedback ... let's forget about lilypond, any format ... if yu happen to know, ping me ...
<fnstudio>ok, here's a minimum (non-)working example of my problem, in case someone has any idea https://paste.debian.net/1186340/
<fnstudio>this is a slightly improved version: https://paste.debian.net/1186341/
<fnstudio>with some more context in terms of the result i get on my machine vs what would be expected
<fnstudio>ah found it! it seems to be a known bug? http://gnu-guile.7481.n7.nabble.com/guile-lib-lt-p-gt-handling-td26828.html#a26829
<leoprikler>You probably want to go up a few steps using a parent function.
<fnstudio>oh ouch, so i swapped html->sxml (from htmlparg) with xml->sxml (from sxml simple), but unfortunately it seems my xhtml file doesn't seem to be fully compliant and xml->xsml throws an error related to a & char
<leoprikler>Don't worry, htmlprag produces sxml as well, so that's not an issue
<fnstudio>leoprikler: parent function of html->sxml, you mean?
<leoprikler>no, from xpath
<fnstudio>ok, let me try
<leoprikler>For instance, once as a part of finding album covers from musicbrainz, I used the following:
<leoprikler>(compose ... parent (xpath:sxpath `(mmd:metadata mmd:release-list mmd:release (equal? mmd:title ,album)))))
<leoprikler>where parent is defined as (xpath:node-parent sxml)
<RhodiumToad>fnstudio: what error exactly?
<leoprikler>since you dig into @ class, you probably need parent twice
<fnstudio>RhodiumToad: this error https://paste.debian.net/1186349/
<RhodiumToad>ok, so the input looks like it has an & which isn't an entity
<RhodiumToad>I asked because the bug I found in sxml still has not been fixed anywhere that matters, as far as I know
<fnstudio>RhodiumToad: yeah true, frustrating though as there's little i can do to fix the page upstream :(
<RhodiumToad>but that only applies to CDATA, which isn't involved here
<fnstudio>leoprikler: thanks for that, i'll look into that as an alternative in a min
*wingo has an implementation of read-syntax
<wingo>whee, source info for symbols & numbers...
<ATuin>hi
<ATuin>wingo: I have been looking at the code and I think now i understand how it works and why/where it fails (the async web client)
<ATuin>i could identify the (port-read ...) call that makes the fiber to fail (the one in the custom binary port). It uses the gsubr
<ATuin>but also before that the web code uses get-bytevector-all which is not wrapped by the suspendable-ports, so that also needs a fix
<ATuin>dunno why it's used since we should know the exact lenght for the body
<wingo>ah indeed
<ATuin>i guess it's to allow the weird case where we dont have that info but i guess that according to the protocol it should be known
<ATuin>anyway, that looks like a simple detail, the big change is that the custom port returns the gsubr instead of the scm
<ATuin>wingo: I saw this function in the API: trampoline_to_scm_read/write but it's not used anywhere
<ATuin>looks like the opposite to the c trampoline
<ATuin>just wrapping the c call into an SCM
<ATuin>ahh sorry the API call seems to be this one: scm_set_port_scm_read/write
<wingo>right
<ATuin> there is something i don't really understand well, maybe you can help. I can see in ports.c that there is a gsubr created call port-read on scm_init_ports (this one returns just the c trampoline) but I also see an SCM_DEFINE called also port-read that seems to return the (port)->scm_read
<ATuin>where (port) is the port-type
<ATuin>which one is used when doing (port-read port) in guile?
<ATuin>they have different signature :D 1 vs 4
<wingo>yeah
<ATuin>desc->scm_read = read ? trampoline_to_c_read_subr : SCM_BOOL_F;
<ATuin>seems that's the default
<ATuin>when the custom port is created, so by default it will return the subr
<wingo>ok so a subr is a function defined in c. can be bound to a name or not. also called a gsubr
<wingo>the gsubr named port-read implements a Scheme function that just calls the C read function
<wingo>and it is the default value of port->scm_read
<wingo>er
<wingo>port_type->scm_read
<ATuin>yeah, i was getting confused with port-type and port
<wingo>understandable
<wingo>right i was sloppy even above: when i said "the gsubr named port-read", well there are two of those
<wingo>the one i was talking about was trampoline_to_c_read_subr
<ATuin>yes, that gets 4 args and calls the c code so no suspendable
<wingo>then there is the Scheme function "port-read", also a gsubr, though implemented via SCM_DEFINE; that returns the scm_read of the port's type
<ATuin>i guess we need a c function that calls eval or something like that right?
<ATuin>ok i see
<wingo>you mean for custom binary ports?
<ATuin>in general
<ATuin>i see that for custom ones the read_scm just points the trampoline c code
<wingo>right that is the wrong thing
<ATuin>so i understand why it can not be used by fibers
<ATuin>what i dont see is the magic part that happens with other ports, where the scm one is returned
<ATuin>at some point the scm_read field should be changed in the code if i understand it correctly
<ATuin>then i could try something similar in the custom port, for the web client code is fine since it just wraps a real socket
<wingo>for custom binary ports (r6rs-ports.c) instead the port type should have scm_read be a (lambda (port dst start count) ((%custom-reader port) port dst start count)) or something
<wingo>i.e. a little closure in scheme that just calls the custom read procedure to fill the port's buffer
<ATuin>yeah, how are the fields of the port type exposed in guile?
***seepel1 is now known as seepel
<wingo>i think you don't have access to custom port internals from scheme; would need to expose that somehow
<ATuin>can i use someting like set! to set that field? or needs to be done in c code when the port is created
<ATuin>aha
<wingo>you would use scm_set_port_scm_read when the port type is defined
<wingo>i.e. once for all custom ports
<ATuin>yeah i was thinking that
<ATuin>since aactually some other set_port stuff is called
<ATuin>and the funciton is there
<wingo>then that trampoline in scheme would somehow invoke the specific port reader
<ATuin>would be nice to have that in guile though
<wingo>in a first patch, you can just make a new accessor on custom ports defined in whatever the default environment is, to get the read function
<ATuin>aha
<ATuin>well at least now i think i know enough about the port internals to try something, if it's not good enough it can be fixed later
<ATuin>i also needed to patch the fibers server to be able to reproduce the client block :D
<ATuin>so i forced it to send the body in 2 steps with a sleep in the middle, hacky but functional
<ATuin>thanks again for the help
<wingo>:0
<wingo>er
<wingo>:)
<rlb>wingo: be curious to see what you've done with read-syntax (when I get some time freed up again) -- wondering if it might indicate better ways to handle some things I just hacked to get started...
<wingo>still some bugs
<wingo>works fine until you get to quoted data; dunno how that should work
<wingo>right now 'foo is compiling as '#<syntax foo>
<wingo>which ain't right ;)
<rlb>I might actually need "something more", unless you can sublass syntax objects to add fields :)
<rlb>(or types)
<rlb>i.e. the fundamental thing I needed was the ability to add new "literals" i.e. for hash-maps, sets, vectors, and so I cheated, but being able to teach the syntax pattern matcher how to handle them somehow would be brilliant.
<rlb>e.g. [1 2 3] {:foo 1 :bar 2} and #{1 2 3} (vector, map, set)
<rlb>Need to be able to work with them directly during compilation.
<wingo>syntax objects for me are about two things -- source location info, and lexical info for the expander
<rlb>(better example of the issue I guess #{(foo ...) (bar ...)})
<wingo>dual-purpose
<wingo>usually applied to the "container" and the "elements" -- e.g. vector and elements, list and elements (or pair and head and tail), etc
<rlb>The key issue is of course just that I need the macroexpander to "look inside" (traverse) those collections, just as it does for lists.
<wingo>i pushed my broken read-syntax
<rlb>which kind of lexical-info do you mean?
<wingo>will fix up later
<rlb>right
<wingo>rlb: wraps and marks for hygienic expansion
<wingo>gnarly stuff
<wingo>could switch to scope sets like racket does, in some future
<rlb>Hmm, not sure I'm up to speed there atm :)
<wingo>anyway
<wingo>yeah i page it in every couple years but am currently not up to speed either :)
<rlb>heh
<wingo>night!
<rlb>night
<terpri>i like cl's readtables but they're not a perfect fit for scheme's syntax anymore, mainly because #random-word is used for a lot of things