IRC channel logs

2021-02-05.log

back to list of logs

<dongcarl>In a scheme file foo.scm, I did `(add-to-load-path (dirname (current-filename)))` at the top of the file, then in (use-modules) I started adding other files in the same directory as foo.scm, such as (use-modules (bar)), which should point to bar.scm, correct?
<dongcarl>Unfortunately I'm getting: ice-9/eval.scm:159:9: In procedure scm_to_utf8_stringn: Wrong type argument in position 1 (expecting string): #f
<tohoyn>dongcarl: try leaving add-to-load-path away and giving command "export GUILE_LOAD_PATH=." before running the guile code.
<xelxebar>Noob question. Say you're writing a guile script and have a ~10KB file that you need to know whether any of the lines beginning with "foo" contain the string "bar".
<tohoyn>xelxebar: grep ^foo myfile.txt | grep bar
<xelxebar>What are your preferred ways of going about this? If I was in shell, I'd just reach for sed/grep/awk.
<xelxebar>tohoyn: So you'd call out to an external tool for this?
<tohoyn>xelxebar: maybe not
<tohoyn>xelxebar: read all the lines with read-line and use string-match to do the match
<xelxebar>Yeah, I'm mainly interested if there is some sensible pure Guile approach to this problem space, in the spirit of replacing sed/grep/awk for general sysadmin tasks.
<tohoyn>xelxebar: have you ever heard about scsh?
<xelxebar>tohoyn: That's the naive approach I originally conjured! Just not sure whether it's considered non-idiomatic, overly naive, etc.
<xelxebar>Yes, have actually lightly played around with it.
<tohoyn>xelxebar: the last release of scsh seems to be from year 2006
<xelxebar>I actually have a concrete problem I'm working on, though. It needs to be in guile, and I'm currently just using sed to find whether there's a match. Would like to replace that sed line with pure Guile.
***rekado_ is now known as rekado
<rekado>xelxebar: here’s a definition for you: https://elephly.net/paste/1612514897.html
<rekado>it reads a file line by line, checking for every line if it starts with the given prefix.
<rekado>if it does then it escapes via “throw” and returns #true.
<rekado>if it does not it will eventually hit EOF and return #false
<rekado>actually, this can be simplified some more, removing the “if” and doing more in “match”
<xelxebar>rekado: Thanks. This is a very direct/naive approach. Since you are suggesting it, can I take that to mean that it's relatively idiomatic?
<rekado>or without match: https://elephly.net/paste/1612515162.html
<rekado>xelxebar: I don’t know if it’s idiomatic or idiotic. But in the truest sense of the word, I *am* an idiot and this is how I’d do it, so I guess with the right definitions this can be considered idiomatic :)
<xelxebar>The Haskell in me wants to do something like split-on-lines -> map regex on lines -> reduce.
<xelxebar>Haha. Nice verbal sleight of hand.
<rekado>you can do that, but Scheme is not lazy by default, so you will in fact compute all lines first.
<xelxebar>Thanks for the concrete code. It's really helpful!
<rekado>you can go the Haskellish route if you used streams, but that’s a lot of complexity for something done so simply.
<rekado>glad to be of help!
<rekado>note that this is not the *fastest* way of doing this
<xelxebar>Okay, that might be a fun problem to play around with :)
<rekado>it would likely be faster to implement one of the well-known string search algorithms instead; that would require reading chunks from the file port.
<rekado>s/likely/definitely/
<rekado>the question is just if it’s worth the hassle
<rekado>with read-line you’re going over the characters once until you hit a newline; then you go over the characters again to determine if there’s a match
<xelxebar>Yeah, that could also be a nice homework problem. I imagine that sed/grep are doing something in that regard. Might be fun to try translating their algorithms.
<rekado>this may be of interest: https://lists.freebsd.org/pipermail/freebsd-current/2010-August/019310.html
<xelxebar>Oh! Very nice!
***chrislck_ is now known as chrislck
***metro is now known as metreo
<civodul>has anyone considered writing a TLS 1.3 implementation in Scheme?
<wingo>i wonder what the constant-time story would be
<civodul>you could still call out to one of these C libraries for crypto
<dsmith-work>Happy Friday, Guilers!!
<civodul>happy Friday!
<civodul>wingo: continuing on this guile-gnutls theme, here's my "bench" with and without GMP/libgc hooks: https://web.fdn.fr/~lcourtes/pastebin/guile-without-gmp-memory-functions.html
<civodul>looks like scm_install_gmp_memory_functions = 0 is not an option
<wingo>well... i mean, when it comes to silent breakage of crypto libs, surely it is a better option?
<civodul>heh
<civodul>to me it's not a viable option
<civodul>which doesn't mean a broken GnuTLS is any better :-)
<wingo>hoo, i have a clear hierarchy for which is worse :)
<wingo>of course we need to fix the bignum issue :)
<rlb>civodul: is there a summary of the situation somewhere, i.e. what the problem/constraints are?
<rlb>Hmm, does PyUnicode_DecodeFSDefault hit the bug you found? I mean that's not a deal breaker, i.e. even if it does, perhaps fine to just require that people not install bup under too crazy a path until/unless python/libc fixes the issue, but just curious...
<rlb>oops wrong channel
<spk121>wingo: I'll take a stab at dlopen for MinGW this week. maybe. Then the 32-bit, single threaded, non JIT, MinGW guile will be ready to integrate
<wingo>great!!!!
<janneke>spk121: oh, great!
<civodul>rlb: i've just opened a bug on the Guix side: https://issues.guix.gnu.org/46330
<rlb>civodul: thanks
<rlb>civodul: I'm not sure I remember the relevant GC semantics correctly. Is the issue there that nettle is using malloc, and storing gc (libgmp) allocated pointers in the malloced blocks?
<dsmith-work>What's a current url for mini-gmp ?
<civodul>rlb: GnuTLS calls Nettle, which allocates via libgc; but GnuTLS stores pointers in malloc'd memory, which is not scanned by libgc
<spk121>dsmith-work: there is a mini-gmp in the main gmp tree
<rlb>Oh, ok, so the reverse, but still the underlying issue is just that it's storing gc pointers in malloced memory. Thanks.
<civodul>wingo: i realized we can do "scm_install_gmp_memory_functions = 0" in Guix's own 'guile' executable (yes, that exists)
<civodul>that looks like a reasonable workaround until we have Guile on mini-GMP
<rlb>And sounds like the main drawback to mini-gmp would be performance, but maybe that's something we could try to improve over time for the paths that affect us, I suppose...
<civodul>yeah, we'll have to check how it affects performance; i suspect it's not that bad
<dsmith-work>spk121: Thanks
<civodul>and few applications make heavy use of bignums
<rlb>(guessing, particularly now that 64-bit archs are so common...)
<civodul>was there initial work on adding mini-GMP support? Niels Möller maybe?
<spk121>civodul: I doubt it is more complicated than pulling the two files into the Guile tree, and adding the configure options. (If you're willing to pull the files in tree). GMP itself doesn't have the autoconfigury/make to build mini-gmp into a library
<spk121>(of course, when a software manager says things like "I doubt it is complicated..." it always goes wrong)
<Rovanion>I'm feeling incompetent but I can't wrangle split to work as I like. I want to read a file and split it into a list of lines.
<Rovanion>(string-split my-string #\n), but with newline instead.
<Rovanion>hyperpolyglot.org/lisp should have a guile column.
<spk121>Rovanion: try #\newline instead of #\n
<Rovanion>Thank you spk121!
<civodul>spk121: that'd be really nice
<civodul>are you giving a look already? :-)
<civodul>it'd be nice to add the mini-GMP option for 3.0.6, making it opt-in (because it'd be ABI-incompatible)
<spk121>civodul: well I did take a quick look. Haven't actually coded anything.
<rlb>hmm, so I guess it might not fix the debian gnutls problem, i.e. we can't change the abi, I think... We'd need a new libguile soname?
<rlb>Well, or just the next Y release, since we have libguile-X.Y.so...
<spk121>rlb: mini-gmp solves a specific problem in Guix, so they may want to enable such an option, but, if we do add mini-GMP, we can make full GMP as default for a while via ./configure
<rlb>right, but the current arrangement also breaks on the debian buildds.
<rlb>i.e. it's broken even outside guix
<rlb>I think?
<spk121>rlb: huh. I didn't know that. Was it something about also using libgmp in gnutls or something? Anyway, if you did enable such an option, I guess debian *would* need a new soname. It is probably complicated to really figure out how to do sonames with configure options
<rlb>It's gnutls itself, I believe, i.e. its test suite fails.
<rlb>sometimes
<rlb>i.e. if I understand it correctly, guile's just broken right now for programs that might use libgmp?
<rlb>(that's just not all that common, and we've been fairly lucky?)
<rlb>But that's just my current understanding - I might have misread the situation.
<civodul>rlb: yes, the problem was first identified in Debian
<civodul>and now we realize we're all suffering, Debian & Guix alike :-)
<rlb>So I think for debian at least, we'll probably have to wait for the >= 3.2 to make the switch.
<rlb>(of the setting)