IRC channel logs

2021-10-20.log

back to list of logs

<cwebber>hi!
<RhodiumToad>good evening
<drakonis>hey
<drakonis>so, what's the goods
<RhodiumToad>lilyp: it does look a bit over-engineered
<RhodiumToad>including all the functions from (rnrs enums (6)) is probably overkill
*RhodiumToad mumbles in annoyance of the fact that there's no clear convention on whether (with-foo ...) is syntax or a procedure that calls a thunk
<spk121>.
<RhodiumToad>
<RhodiumToad>anyone know a good way to map '(a b c) into '((a . 1) (b . 2) (c . 3)) ?
<RhodiumToad>I mean it can be done with map-in-order or pair-for-each and a mutable counter, but that's not very clean
<rgherdt>RhodiumToad: something like this? (define (map-to-numbers lst) (map (lambda (x i) (cons x (+ i 1))) lst (iota (length lst))))
<lloda>you can do (iota n 1)
<RhodiumToad>ah of course
<lloda>but that builds a list and runs over the lst first, neither of which is really necessary
<RhodiumToad>forgot about map with multiple lists
<rgherdt>lloda: nice
<RhodiumToad>these wouldn't be long lists
<lloda>then yeah that is the shortest way to put it i think
<lloda>i think reducing map ... iota to some kind of let loop ((i 0) ...) ... (loop (+ 1 i) ...) is something that a compiler should be able to do :-\
<rgherdt>(map cons lst (iota (length lst) 1))
<rgherdt>:)
***nckx_ is now known as nckx
<lloda>i kinda like srfi-5, seems more natural than the standard named let syntax
<RhodiumToad>is there a better way for a goops class to have a pre-processed #:each-subclass slot than overriding compute-get-n-set in a metaclass?
<RhodiumToad>I suppose the other way would be to process it on the first instance creation, but that seems ... ugh
***robin_ is now known as robin
<chrislck>sneek: botsnack
<sneek>:)
<dadinn>hi all
<dadinn>Is there a way in Guile to somehow convert a input-output port into a terminal device?
<dadinn>I am trying to ran a qemu process, and would like to use (ice-9 expect) to interact with it :/
<wingo>moo
<lampilelo>dadinn: i don't know anything about terminal devices, but it's definitely possible with some hacking, you can make a port out of anything with make-custom-binary-input-port and ffi, or not even custom ports, you can use fdopen to wrap an fd with a port
<dsmith-work>Hey Hi Howdy, Guilers
<dsmith-work>!uptime
<sneek>I've been running for 8 days
<sneek>This system has been up 13 weeks, 4 hours, 48 minutes
<dsmith-work>Goodbot
<Zelphir>Hi! Question about pattern matching using (ice-9 match): I get an error, when I try to put 2 times triple dot on the same level of nesting in the matched expression. Probably because that would not be something unambiguous to match against. However, how can I elegantly pattern match, when I have for example a structure like the following:
<Zelphir>'((attr1 123) (attr2 123) (attr3 123) (attr4 123))
<Zelphir>But the order of attributes is arbitrary and I want to match against 1 attribute, do something for that attribute and then continue matching again against the list with all the other attributes, and the one I already matched removed?
<Zelphir>So for example, a match could be: (others1 ... (attr1 123) others2 ...) and then I want to do something with (attr1 123).
<Zelphir>What I am doing to far is to bail out and call a normal function for handling this arbitrarily ordered list. But I wonder, if there is some elegant way using pattern matching.
<lampilelo>can't you loop over the list and dispatch with match on every element instead?
<Zelphir>Ah, I did not mention that: I am outputting strings for each matched part and the whole output string does need to follow some order. So I would like to first match some attribute, which has to be serialized first, then the next, and so on. But in the data structure (huge nested list of stuff, actually result of a PEG parsing), I have no guarantee, that the attributes appear in order.
<Zelphir>Ultimately, I could still write it all as `render-xyz` procedures, instead of pattern matching, but perhaps I am overlooking some good way.
<Zelphir>Thinking, that perhaps I can do better or more concise than writing lots of procedures.
<Zelphir>Or I could do a big `(cond ...)` possibly.
<lampilelo>i don't know if this can be done with pattern matching, but i'm no expert
<lampilelo>you could sort the list first
<Zelphir>Hmmm, that could work. And then wrap it, to tag it and know when matching again, that it is the sorted one.
<lampilelo>you could alternatively make a list of keys and loop over that, calling assoc on your input in order, it would be probably cleaner code but more complex in terms of computation cost
<Zelphir>So whatever order I get, I would run a loop in the consequence of matching any order of elements, which goes through that sorted list of keys and picks out the items from the matched list?
<Zelphir>I think that might be equivalent to making a procedure call and handling that special part in there.
<lampilelo>like this: https://paste.debian.net/1216192/
<Zelphir>Oh I see!
<Zelphir>That is sort of sorting.
<Zelphir>But quite readable.
<lampilelo>you can always define a function that takes keyword arguments instead of playing with these kinds of things, instead of making a list of ((attr1 n) ...) you'd make a list of (#:attr1 n #:attr2 m) and apply that to the function
<lampilelo>i don't know if that makes any sense, just throwing some ideas, i'm very sleepy and will be going to bed soon