IRC channel logs

2023-12-22.log

back to list of logs

<sneek>dsmith: Greetings :D
<dsmith>sneek, botsnack
<sneek>:)
<cow_2001>i don't get the (? predicate? ,a) match clause
<cow_2001>okay, i think i get it now
<apteryx>what's the most natural way to represent a timeval (C) value in Sheme? a pair?
<apteryx>Scheme*
<apteryx>perhaps a float :-)
<apteryx>I'll split the second/microseconds component apart in time to call the lower level C procedure
<apteryx>look like srfi 18 already worked a time datatype
<apteryx>srfi 18 uses a pair for reprenting time in second and microseconds units
<RavenJoad>This feels like something that is documented in the Guile manual, but I seem to be missing it. Is there an "rm -r dir" equivalent?
<RavenJoad>Or do I need to write my own wrapper using delete-file, rmdir, ftw/file-system-fold? The manual has an example, "Here is an example showing how to display all the entries in a directory", but I am not sure how performant it is.
<RavenJoad>Nevermind my question. I looked at how Guix implemented their delete-file-recursively, and is exactly what I was suggesting.
<isaneran>(define (foo x) (assert (integer? x)) (+ x x)) (foo "hello")
<isaneran>When running a program like this interactively and the assertion fails, I try to evaluate in the repl what x is, but there seems to be no way to retrieve it?
<isaneran>assert here being from r6rs
<isaneran>with ,locals I just get a closure for the exception
<isaneran>ah, wait if I do ,up and ,locals I can see x
<isaneran>there was some case I tried where I couldn't see it the other day which was frustrating cuz if that happens many levels deep you wanna be able to retrieve it
<isaneran>but I guess I either was mistaken or don't know a simple case to reproduce yet so nevermind!
<isaneran>actually with (define (bar n) (assert (= n 2)) 42) it seems like guile has deleted n when running ,locals
<isaneran>(if run with (bar 9) for example)
<sneek>tohoyn: Greetings
<tohoyn>sneek: botsnack
<sneek>:)
<chitochi>hi everyone! i am trying to get an expression to call a procedure when evaluated, so that for example in `(if x then else)`, the evaluation of x calls a procedure and evaluate to the return value of that procedure, is such a thing possible? :o
<chitochi>(probably a bad idea, but i am still trying xD)
<dsmith>chitochi, Why not just (if (x) then else) ?
<chitochi>honestly... not good reason at all
<chitochi>i just think i liked the idea of making it transparent, but the more i think about it the more it's not really a good idea
<guileHacker4000>Hello. I'm learning scheme with guile
<guileHacker4000>chitochi, I wonder if defining a macro is what you want to do
<jdlugosz963>Hi Guilers! How can i downlaod some file? For example i want to fetch http://localhost/some_file.tar.gz to /tmp directory.
<chitochi>the thing is that `x` come from a procedure, and so i can't know to what name it'll be bound, so i don't think a macro can handle that?
<euouae>Hello can I print all exports of a module somehow?
<euouae>hm, nevermind :)
<apteryx>I see the scm_select implementation in Guile accepts both time values as long or double; why is this so?
<apteryx>the underling select (2) accepts only long, as far as I can see
<euouae>apteryx: probably because it converts fractional seconds to integral usec
<euouae>it says usec has to be integral and sec can be either integral or fractional
<apteryx>so the Guile select is more lenient on the input type than select itself, right?
<euouae>yes, it just augments the interface with additional convenience features
<euouae>generally that's all you can do with the kernel interface, add conveniences, you can't add real features on top
<euouae>that's why usec is not double
<euouae>you can't select(2) on a sub-usec interval
<apteryx>actually digging deeper the usec part of a timeval struct in C is an int64
<apteryx>on 64bits systems
<euouae>what's your point though?
<apteryx>yeah, none, nevermind :-)
<apteryx>I thought int64 was a float for a second
<euouae>no kernel sources are more explicit about bit size
<euouae>they won't use int/long
<apteryx>I see: typesizes.h:67:#define __SUSECONDS64_T_TYPE __SQUAD_TYPE, and # define __SQUAD_TYPE __int64_t
<euouae>Ther'es no reason to touch kernel sources
<apteryx>and __suseconds64_t tv_usec; /* Microseconds. */ in struct_timeval.h
<euouae>the user API is documented in POSIX or man pages
<apteryx>yes, documented as suseconds_t tv_usec; /* microseconds */
<apteryx>doesn't tell me what suseconds_t is
<apteryx>(man 2 select)
<euouae>you don't need to know
<euouae>it tells you it's microseconds
<apteryx>I see. microseconds being capped at 999999
<apteryx>thanks!
<euouae>you're welcome
<apteryx>I think the complications stem from guile-udev using bare select (2) instead of scm_select in its C wrappers.
<apteryx>I'll use scm_select and leave the existing abstractions do their job
<apteryx>then I don't need to wrestle with timeval struct myself
<euouae>I think using bare select is the right approach
<euouae>you don't want cascading effects for changing one public wrapper
<apteryx>for more context, I'm looking at: https://github.com/artyom-poptsov/guile-udev/blob/c9c85b06c73e52ef31f49d3a3e6ddacffb63b866/libguile-udev/udev-monitor-func.c#L223
<apteryx>using bare select means I must reimplement argument validation myself instead of reusing that of scm_select
<euouae>hm?
<euouae>oh this is a different library
<euouae>in this case it could use scm_ version instead yeah
<apteryx>good, I'll try that
<apteryx>a thunk is a procedure of zero argument, right?
<euouae>yeah
<euouae>a closure
<apteryx>how do I define a closure in C ?
<apteryx>I want to use scm_catch, and it wants a thunk, which should capture things from the current scope
<euouae>you mean, how do you define a scheme closure in C?
<apteryx>yes
<euouae>why?
<euouae>what are you trying to do?
<euouae>from C you typically want to make C functions available to Guile, not define Guile functions to make available to Guile
<apteryx>replace the bare select (with its C error handling) by scm_select (and scm_catch for error handling) in the code linked earlier (udev-monitor-func.c:223)
<apteryx>I want to use the C-usable Scheme procedures from libguile in C, e.g. scm_select, to hopefully simplify the problem
<euouae>I wonder if "Exceptions and C" is what you want
<apteryx>does select block when used without a timeout?
<apteryx>I think it does
<apteryx>any idea how I'd convert a C file descriptor (int) to a Scheme one?
<apteryx>I guess scm_from_int, since it appears to be just a number?
<euouae>7.2.2 Ports and File Descriptors
<euouae>scm_fdopen
<euouae>and yes to pass the file descriptor to scm_fdopen you need to convert to SCM from int
<apteryx>select accept raw file descriptor (rather than ports), IIUC; so I don't need to use scm_fdopen, no?
<apteryx>"with each member a port or file descriptor"
<apteryx>another question: how do I create an empty Scheme list in C?
<apteryx>I don't see scm_list_0 (it starts at 1)
<euouae>it might be scm_list_1(SCM_UNDEFINED)
<apteryx>ah, SCM_EOL, the scheme empty list object
<apteryx>oh, gcc has a nested function extension for C
<apteryx>that should make using scm_catch easier from C
<apteryx>does clang implements this GNU C extension?
<civodul>apteryx: Clang does not implemented nested functions
<civodul>libguile doesn’t have nested functions though
<euouae>I think apteryx wants to define a scheme closure (thunk) from C to pass to scm_catch
<euouae>I couldn't figure out how to do that, it doesn't sound right to me because such a closure should be defined on the scheme side in my opinion
<apteryx>civodul: does libgulie needs to have nested function? it's implemented by GCC
<apteryx>need*
<apteryx>euouae: yes, that's what I'm after
<apteryx>ACTION wonders if SCM_DEFINE would work to define a nested function
<apteryx>I guess not, but haven't tried
<apteryx>if it doesn't work I'll have to fallback to nested functions + scm_internal_catch
<civodul>i think using nested functions in libguile at this point would hinder portability for little in return
<apteryx>right, seems I can use scm_internal_catch and pass the args via a struct pointer, which removes the need
<apteryx>I'm not working in libguile though, I'm working in guile-udev
<civodul>ah ok