IRC channel logs


back to list of logs

<wingo>manumanumanu: historical garbage :)
<ATuin>any idea where should i start looking at to be able to use non blocking io on custom ports?
<ArneBab>ATuin: I think that’s a question for wingo
<ATuin>yeah, i'm reading the code to try to get used to how it's implemented. I could try to redefine how (web response) get's the body but it would be really nice if the code could be reused
<wingo>sneek: later tell ATuin how would you know that the port is readable or writable? i guess we'd need to make it so that custom ports can return an FD to poll on
<sneek>Got it.
<wingo>sneek: later tell ATuin otherwise i think you arrange so that the port's read or write functions return -1 when EWOULDBLOCK
<sneek>Will do.
<wingo>i think that's all you would need, after having installed suspendable ports
<spk121>who drew the logos for guile on its main webpage?
<rlb>spk121: debian at least, should version guild, i.e. guile-2.2, but it also provides an unversioned name which is controlled by update-alternatives (i.e. defaults to on X.Y, but can be overridden locally).
<rlb>And may be well known, but if you have say guile-2.2-dev and guile-3.0-dev installed, then you should be able to pick one via the guile macros when building another project via "GUILE_EFFECTIVE_VERSION=X.Y ./configure ...". At least that's worked for me in some cases.
<rlb>daviid: your paste expired before I could see it.
<rlb>I'll also note that if you have a locally installed guile (at some --prefix), then I suspect GUILE_EFFECTIVE_VERSION may not work, and/or you'll need a number of other envt var settings to use it. I had someone report that, and I was planning to investigate more carefully. I know with homebrew, someone said for lokke, at least, they had to set PATH, PKG_CONFIG_PATH, and ACLOCAL_PATH. Not sure if that's relevant to your situation.
<rlb>(The homebrew info fwiw is at the end here )
<rlb>(Oh, and lokke uses guile's autoconf/automake stuff in a fairly pedestrian way I think, so suppose might apply elsewhere...)
<rlb>wingo: also wondered how cpu load comares between the scheme and C readers...
***leoprikler_ is now known as leoprikler
***daviid is now known as Guest95794
***Guest95794 is now known as daviid
<wingo>rlb: similar GC overhead; the overhead is on main thread
<wingo>when guile's native codegen is better things will improve
<rlb>Ahh, right, I also wondered about overall "instruction cost", since of course one might have a fast enough cpu to give similar runtimes for something like that, even if one is more expensive cpu-wise.
<rlb>(depending on the io)
<rlb>wasjust curious
<rlb>...though I suppose if all the input files are cached, then maybe that wouldn't be a question.
<wingo>my tests were effectively with all input files cached
<wingo>well. cached by the OS
<roptat>is this a bug: ?
<roptat>I used the same match, but the second one, inside the catch throws 'match-error
<roptat>have I done something wrong, or is my use of match breaking some sort of assumption?
<rekado>spk121: the illustrations were drawn by Luis Felipe López Acevedo (aka sirgazil),
<ATuin>wingo: I'm playing with fibers and the module (web client) but seems at some point i reach a continuation barrier when reading the response body. What do you think is better as an attempt to get an async web client using fibers, rewrite the client from scratch or try to use guile's one?
<sneek>Welcome back ATuin, you have 2 messages!
<sneek>ATuin, wingo says: how would you know that the port is readable or writable? i guess we'd need to make it so that custom ports can return an FD to poll on
<sneek>ATuin, wingo says: otherwise i think you arrange so that the port's read or write functions return -1 when EWOULDBLOCK
<spk121>rekado: thanks
<ATuin>ahhh sorry i see you replied to me before
<wingo>roptat: not a bug, oddly
<wingo>roptat: the intervening _ binding from the body thunk shadows the _ that the match macro recognizes
<roptat>ok, thanks for the explanation
<wingo>ATuin: yeah i am going to vanish shortly but looking into this again -- have you seen ports-internal.h ?
<wingo>basically describes the abstract interface that ports implement
<ATuin>i was looking at the code implementing the make-custom-*-port
<wingo>suspendable ports need the scm_read / scm_write functions to be present -- that's what suspendable-ports calls to fill/flush the guile-side buffers
<ATuin>anyway i tried fibers with a dummy custom port (aborting the continuation) and it did work, probably blocking ofc
<wingo>then i see we have read_wait_fd and write_wait_fd port type methods, which is good
<wingo>means a custom port can plumb those through somehow
<ATuin>ok, so then the only problem with custom ports is to know when we are blocking, i guess the continuation barrier problem i got it's not even related to custom ports
<wingo>yeah i don't recall, am looking into this
<wingo>you are referring to make-custom-binary-*-port ?
<ATuin>my poc is very hacky (using `(set! (@@ (web response) symbol) my-symbol)` I guess at some points it's not using the suspendable port calls
<ATuin>wingo: yes
<ATuin>`(web response)` uses then when reading the body from responses
<wingo>ok i see
<wingo>so the intention is that (port-read port) returns the read procedure for the port
<wingo>if it's implemented in scheme, there will be no problem if that custom port ends up reading from another port and suspending
<ATuin>i think so at least, it's scheme yes
<wingo>right now i see that the port_type->scm_read member seems to never be overridden
<wingo>it is always a subr that trampolines through the read function implemented in C
<wingo>which would prevent suspend & resume
<wingo>so even for custom binary input ports, we don't manage to hit the good suspendable path
<wingo>does that match what you are seeing?
<ATuin>yes, looks like
<ATuin>i got `Attempt to suspend fiber within continuation barrier` from `read-bytes`
<ATuin>the `read-bytes` implemented by suspendable-ports, and that code is inside the custom-binary-port used to read the exact len of the body response
<wingo>so you have two options :) one is somehow to make those functions be scheme for the custom binary ports. you don't have to worry about the read_wait_fd methods of scm_t_port_type because it won't be the generic custom port that causes a wait -- it may be the read function though, and we would be suspending then
<wingo>ATuin: yeah and it's calling ((port-read port) ...)
<ATuin>yes, the web code is calling that
<wingo>and (port-read port) on your port is returning a C subr instead of a scheme function
<ATuin>let me check the line
<wingo>the (port-read port) call is in suspendable-ports.scm
<ATuin>ahhh yes, right
<wingo>so your other option is to do something gnarly, make a new web server, make a new ports implementation, dunno
<wingo>i just mention that because it may be expedient
<wingo>but the right solution is to make it so that (port-read port) and (port-write port) for custom ports returns a scheme function, not a subr
<wingo>subr == scheme function implemented in C
<ATuin>so it's not a problem as long as the read/write function is the defined in scheme
<ATuin>even it's it's later created using the make-custom-binary-*-port (which seems to be implemented in c)
<wingo>so it's scm_set_port_scm_read, which needs to be called on the port type (not the port)
<wingo>so it's something to implement in r6rs-ports.c, where the custom binary port type is defined
<ATuin>that's the code i was reading this morning
<ATuin>ok, I will get confident with that code and with fibers and let's see if i can do something
<wingo>that needs to be passed some kind of scheme function, which would then dispatch to the specific reader for the specific port
<wingo>good luck :) if more questions, tag my name & i will answer sometime tomorrow. happy hacking :)
<ATuin>ok, thanks for your time :D
<derelict>is there a way to do something like this? (apply or '(#t #f #t)) basically, I want to "or" a list.
<derelict>I just started learning scheme a few days ago...
<RhodiumToad>(or) is a special form because it doesn't evaluate all its args, that's why apply won't work on it
<derelict>I though it must be something like that
<RhodiumToad>if you already have a list, you can think of it this way: the result of or is true if the list contains any element which is not #f
<derelict>So, what you are saying is I need to write a proc to do it?
<rekado>derelict: srfi-1 has “every”
<rekado>and “any”
<derelict>I'll check it out
<rekado>(any identity '(#t #f #t))
<RhodiumToad>(any identity yourlist)
<chrislck>took me a while to understand or-map = any, and-map = every
<RhodiumToad>btw when considering which of (any) or (every) to use in cases like this, always bear in mind that (any) is always false on an empty list and (every) is always true on one
<derelict>Works perfectly!
<derelict>I don't quite understand the identity part
<RhodiumToad>identity is a function that just returns its arg unchanged
<chrislck>(define (identity x) x)
<RhodiumToad>another subtlety is that using (any) that way actually returns the first value that isn't #f,
<RhodiumToad>but you could instead do (not (every not yourlist)) which will return #t or #f
<RhodiumToad>(any identity '(#f 1 2)) => 1 whereas (not (every not '(#f 1))) => #t
<derelict>Ok, I think I get it. Makes my head hurt a little.
<derelict>Thanks for the help!