IRC channel logs

2021-11-01.log

back to list of logs

<morganw>Ah, thanks, that does make sense.
<dadinn>hi all
<dadinn>I am trying to read and parse the output of a shell command. What is the best way to do this?
<lilyp>probably expect or PEGs
<lilyp>depends on your use case
<dadinn>I've tried this: https://termbin.com/w0ck
<dadinn>I assume the problem is either with read-string or close-pipe?
<dadinn>I mean the regex was meaningles, obviously I wanted to parse the version string instead: https://termbin.com/80ge
<dadinn>lilyp: what's PEGs?
<lampilelo>string-match takes at least 2 arguments
<lilyp>yep, you're not actually passing content to it
<dadinn>lampilelo: apologies, indeed that's a typo in my example, assume that content is the second argument there
<lampilelo>so what's the error?
<lampilelo>what doesn't work? zpool exits with non-zero code?
<lampilelo> https://www.gnu.org/software/guile/manual/html_node/PEG-Parsing.html
<dadinn>the exit status of the command is zero
<dadinn>I get a backtrace printed it complains that something is wrong in close-pipe. In procedure %port-property: Wrong type argumen in position 1 (expecting open port): #<closed: file 562671aca3f0>
<lampilelo>i think that's because you used "pipe" as a variable name
<lampilelo>on close-pipe it tries to close a pipe procedure instead of that variable
<lampilelo>i mean it works if pipe is used as a variable name everywhere, maybe you have a typo somewhere?
<lampilelo>lol no, i'm wrong
<lampilelo>i'm just very sleepy
<lampilelo>it looks like the pipe is already closed and close-pipe doesn't like that
<dadinn>lampilelo: you mean that I don't have to close it manually?
<lampilelo>idk, when i test it with ls it just works, maybe check with (port-closed? pipe) before trying to close
<dadinn>lampilelo: arrgh, sorry I was accidentally closing it twice!
<lampilelo>lol
<lampilelo>and i was wondering how and why would it close prematurely
<lampilelo>and that it didn't make sense
<dadinn>lampilelo: ok, everything seems to work, I fetch the correct content, but the match returns #f, which means the regex is wrong
<dadinn>argh! it seems string-match applies for the whole string, and I'm using ^ and $ symbols as line ending
<dadinn>I think I should be using regexp-exec instead with regexp/newline option
<lampilelo>dadinn: you can use dynamic-wind to run any cleanup code
<dadinn>lampilelo: not familiar with dinamic-wind, do you have some docs which describe how it works?
<dadinn>oh sorry, I see the guile docs have some examples too
<dadinn>was confused by the C-specific aspect of it in the first part
<lampilelo>it's kinda like try-catch-finally block from python, without the "catch" part
<lampilelo>so the out-guard will run on normal exit and on error
<lampilelo>and whatever else non-local exit
<lampilelo>(let ((pipe ...)) (dynamic-wind (const #t) thunk (lambda () (close-pipe pipe))))
<dadinn>what's that (const #t) part for?
<lampilelo>equivalent to (lambda _ #t), it's a placeholder for in-guard
<lampilelo>since it's not used
<dadinn>got it
<dadinn>awesome, I think I will need this a lot! I've been missing the finally blocks a lot recently
<dadinn>tried working around it with catch instead, but it was quite clumsy
***janneke_ is now known as janneke
***dekenevs is now known as kitzman
<dsmith-work>UGT Greetings, Guilers
<dsmith-work>!uptime
<sneek>I've been running for 20 days
<sneek>This system has been up 14 weeks, 5 days, 16 minutes
<rmrfchik>hi, I have guile-2.2 (raspberrypi). what's the best way to use C .a library?
<RhodiumToad>use it for what?
<rmrfchik>to call C functions from program
<lilyp>You can also use FFI if you feel like it.
<lilyp>You're only really missing (system foreign-library)
<lilyp>but dynamic-link etc. have existed in 2.2 as well
<rmrfchik>this lib isn't avail on my system :(
<rmrfchik>and I have no dynamic, only .a lib
<lilyp>oh, then you need to compile it to a shared object first
<rmrfchik>hmmm...
<RhodiumToad>if you only have a .a file and it wasn't compiled for PIC, then you're a bit stuck
<RhodiumToad>you'd have to build your own guild binary
<RhodiumToad>*guile binary
<lilyp>alternatively you can write a guile program that writes a c program, that links against your static library
<rmrfchik>oh, noes. will try to make .so
<rmrfchik>it's rather simple lib for neopixel
<rmrfchik>python just drives me crazy
<lloda>i'd like to merge https://debbugs.gnu.org/cgi/bugreport.cgi?bug=39601
<lloda>it isn't pretty but it's just internal and it fixes a recurrent issue
<lloda>wdyt?
<lloda>wingo