IRC channel logs

2021-11-14.log

back to list of logs

<avp>Guilers, I need your help. How do you downcast an object of a class <a> to its subclass <b> in GOOPS?
<avp>I'm struggling with this part of the documentation: https://www.gnu.org/software/guile/manual/html_node/Changing-the-Class-of-an-Instance.html
<avp>Here's the error I'm getting: https://paste.debian.net/1219453/
<avp>And here's the code: https://paste.debian.net/1219455/
<avp>It's a part of this project: https://github.com/artyom-poptsov/guile-png
<wkmanire>Does anyone have any examples of how to use sxpath to query an sxml document?
<robin>avp, classes aren't redefinable by default, unlike CLOS; you mark a class as redefinable by adding a #:metaclass <redefinable-class> class option after the list of slots in its definition, then change-class should work for its instances. the metaclass is inherited by subclasses, at least for single inheritance
<lampilelo>wkmanire: ((sxpath '(// (p (@ class (equal? "post_title"))) a)) dom) <- this will search the dom for 'p nodes with 'class attribute equal to "post_title" and return their direct children that are 'a nodes
<wkmanire>lampilelo: Thank you! You're a life saver. I've been reading and rereading sxpath.sml but I can't make heads or tails of that file. The documentation makes a lot of assumptions about the reader's knowledge of the topic.
<wkmanire>And I've been unable to find usage examples online.
<lampilelo>yeah, i mostly learned by trial and error
<robin>i got a similar goops error with a plain slotless class and a subclass (without any class options); no error when using <redefinable-class> as the metaclass
<wkmanire>lampilelo: Worked like a charm. I'm learning guile and trying to make a little podcast aggregator. First thing I'm doing is writing a module that can parse RSS 2.0 feeds.
<wkmanire>(read-rss rss-text) ;; should return an alist representing a channel, containing a list of items with all of their content, etc...
<lampilelo>wkmanire: you can do some custom stuff like this: https://paste.debian.net/1219459/
<lampilelo>there's no regex matcher by default
<wkmanire>That's neat
<wkmanire>How would I go about selecting the title node of the first channel node?
<wkmanire>lampilelo: ^
<wkmanire>I tried '(// (channel (title))) but that got me all of the title elements in the whole dom
<wkmanire>The dom looks something like <channel><title>foo</title><item><title>bar</title></item>... + n number of items. No <items> node though. They're all mixed in with the channel's child nodes.
<lampilelo>car of the result should be it? i'm not sure if there's a simple way of returning just the first result without parsing the whole thing and i don't know the hard way either
<wkmanire>That's what I ended up doing. Seems inefficient though.
<wkmanire>Also imprecise. If for whatever reason the items were sorted before the <title> element of the channel, the wrong channel title would be selected. I'll just have to fiddle with this and see what I come up with.
<lampilelo>wkmanire: what you want is '(// channel title)
<lampilelo>or '(// channel title *text*)
<wkmanire>Yep, that's it. I was trying to do something like ((sxpath '(// (title (filter (eq? (node-parent) channel))))) doc)
<wkmanire>(car ((sxpath '(// channel title *text*)) doc)) <-- that pulls just the string. And I tested it with the items in preceding the channel title and it still works.
<lilyp>sneek: later tell morganw there's save and load, but it's more or less re-executing everything until then. You can be clever and save some hefty computations by using inner scripts, which only do the first line. You can add custom state and load hooks to save variables that Tsukundere itself doesn't manage
<sneek>Got it.
<lilyp>sneek later tell morganw this might probably be too hefty for a generic game engine, but for visual novels – especially small ones – it's no big deal at all
<sneek>Got it.
<lilyp>sneek later tell morganw pull requests welcome if you want it to change, though :)
<sneek>Will do.
<xelxebar>Is there a library for handling swagger api calls generically?
<xelxebar>I'm just discovering openapi and am thinking it makes sense to autogen procedures from the api documentation.
<xelxebar>Not sure if this would actually be useful in practice though.
<mwette>wkmanire: I think you can just put a 1 in the path to get the first one.
<avp>robin: Oh, I didn't realise that I must add 'metaclass' _after_ the list of slots. Thanks!
<avp>But now I faced with the new problem: Guile says that a slot that is present in <b> sub-class is unbound after the object is downcasted from its parent <a> class.
<avp>robin: Okay, I fixed my code, but it turned out that I chased down a wrong problem. Thanks for help anyways!
<stis>tjaba guilers!
<ajarara>Does anyone have a screencast of someone using geiser (or just the guile debugger) effectively? Poking around myself, I find it difficult to inspect locals and before I get anywhere interesting sometimes it crashes.
<wkmanire>ajarara: I haven't tried yet. Just been using the REPL and print debugging.
<ajarara>wkmanire: print debugging certainly works for me
<ajarara>maybe another question: is there a way to macroexpand like emacs macroexpand?
<wkmanire>Yes, I believe so. Let me see if I can find the function.
<wkmanire>ajarara: guile > API Reference > Macros > Macro Expansion
<wkmanire>6.8.9 Macro Expansion. See the macroexpand function.
<ajarara>ah it's just called macroexpand, lol
<ajarara>wkmanire: thanks!
<wkmanire>np
<RhodiumToad>macroexpand does expand to tree-il rather than scheme though. there's a tree-il->scheme function to decompile back to scheme
<lilyp>I'm not sure about using geiser effectively, but you can use it pretty easily to just load up a simple module and calling commands on the other side without the trouble of switching to your shell
<wkmanire>Is there a function that can transform a string into a safe filename?
<wkmanire>Without hashing it to an MD5 or something.
<ajarara>RhodiumToad: thanks, this is what the geiser-guile impl does under the hood: https://gitlab.com/emacs-geiser/guile/blob/aab5226dfe937861c54729744e8add15d931f758/src/geiser/evaluation.scm#L131
<lilyp>what is a "safe filename"?
<wkmanire>One that doesn't scare the children.
<lilyp>Oh you mean like "porn" → "homework"?
<wkmanire>ha ha
<lilyp>I think the former would be less scary though
<wkmanire>Just kidding. I just want to replace slashes and punctuation with something else
<lilyp>you can do basename + random prefix/suffix
<wkmanire>I want to pass in a URL and get back something like "https___foobar.com_bar_baz
<lilyp>in that case look at regexp replacement
<wkmanire>I'm caching http-get responses to disk.
<lilyp>though beware of percent encoding
<wkmanire>And want to name to the file after the URL I fetched
<wkmanire>I could just hash it, but I want to be able to recognize the URL just by reading the filename
<wkmanire>Yeah, I'll look at regex replace. Thanks.
<lilyp>imho you could still do a folder layout tho
<lilyp>like drop the prefix, split the string on slashes and make sure there's no dots or dot-dots
<wkmanire>That's an interesting idea.
<RhodiumToad>do you need the encoding to be reversible?
<wkmanire>RhodiumToad: no
<wkmanire>Just repeatable
<RhodiumToad>a simple regex should be fine then
<wkmanire>Seems like regexp-substitute/global is my function. There isn't a function like this that works at the string level? Do I have to setup a port?
<wkmanire>nvm
<wkmanire>#f
<wkmanire>(regexp-substitute/global #f "/|:|\\." "https://feeds.fireside.fm/linuxactionnews/rss" 'pre "_" 'post) <-- yeah that works. "https___feeds_fireside_fm_linuxactionnews_rss"
<wkmanire>Not sure if I really care about URL entities. Probably won't hurt anything
<lilyp>you probs want to add $ and ? for safety
<wkmanire>yeah..
<RhodiumToad>overkill
<RhodiumToad>even : and . are overkill if you're not on windows
<lilyp>single dot is not
<lilyp>oh well, if you do slash then it might be
<lilyp>but still, preventing bash misinterpretation sounds like a good thing
<RhodiumToad>you might want to replace a leading dot, but it looks like that would not happen in this case
<wkmanire>Running Guix, and this is just for me. So I'm gonna run with it as is :)
<wkmanire>I'm thankful for the ideas though
<wkmanire>Yep, everything is working great. Getting the actual response body from http-get was an adventure.
<wkmanire>The Guile docs really need more example code snippets.
<lilyp>heh, I remember implementing my own http-get* for album cover snarfing
<lilyp>It's still nicer to do in Guile than in Elisp, trust me
<lilyp>(like seriously, wtf is wrong with the url package)
<wkmanire>lol
<wkmanire>Are the guile docs updated separately from guile releases? How would I go about adding code snippets?
<lilyp>Guile docs are texinfo in the source tree, so no
<wkmanire>I see
<darth-cheney>hey all, simple question here (google failing me completely)
<darth-cheney>In a guile script, how can I read the current value of stdin as a string?
<darth-cheney>I'm trying to "drain" current-input-port but that doesn't seem to be a real port?
<RhodiumToad>(current-input-port)
<darth-cheney>oh my god
<RhodiumToad>current-input-port is not a variable, it's effectively a function that returns the current input port
<darth-cheney>haha
<darth-cheney>there goes my confidence for the day!
<RhodiumToad>(I think there's actually a fluid or parameter underneath it somewhere, but I haven't looked at the exact implementation)
<darth-cheney>So is there a quick way to just get the contents of the input port as a string?
<darth-cheney>is it (drain-input (current-input-port))?
<cbaines>(ice-9 rdelim) contains a read-line proceudure
<RhodiumToad>get-string-all, I think
<RhodiumToad>from (ice-9 textual-ports)
<darth-cheney>yes that did the trick! thanks RhodiumToad and cbaines
<KE0VVT>Any GNOME apps written in Guile?
<KE0VVT>Hm, can't find any GUI apps written in Guile.