IRC channel logs

2020-08-08.log

back to list of logs

<wklew>hi guilers, im back with another delimited continuation question
<wklew>while trying to implement control/prompt by following the racket implementation, i realized i need a multi-prompt version of call/cc
<wklew>does such a thing exist?
<mwette>a_v_p: are you looking for help?
<wklew>oof this connection
<mwette>a_v_p: if so, here is an approach I would use: https://paste.debian.net/1159585/
<jgart>how can I return a new list that collects the lists that have 1 as a common atom. Give the following list: ((0 1 2) (1 2 3) (2 3 4) (3 4 5) (4 5 6) (5 6 7) (6 7 8) (7 8 9) (8 9 10) (9 10 11) (10 11 0) (11 0 1))
<sneek>jgart, you have 2 messages!
<sneek>jgart, manumanumanu says: I am the srfi-171 author. If you have any questions you can ask me here, or even better PM me.
<sneek>jgart, manumanumanu says: but srfi-171 would be a bad choice. SRFI-158 would be a much better choice.
<jgart>I want to return: '((0 1 2) (1 2 3) (11 0 1))
<jgart>any hints or help are greatly appreciated
<justin_smith>jgart: sounds like a classic use for srfi-1 filter
<jgart>thanks, justin_smith
<jgart>I'll check that out
<justin_smith>jgart: in fact without even using srfi (filter (lambda (x) (memq 1 x)) ...) should work
<justin_smith>I forgot filter was in the base guile
***catonano_ is now known as catonano
<RhodiumToad>technically I think that should be memv but memq works for it in guile
<justin_smith>memv is faster for types (like numbers) that support it, right?
<RhodiumToad>no
<RhodiumToad>equal is slower than eqv which is slower than eq
<RhodiumToad>member uses equal, memv uses eqv, memq uses eq
<RhodiumToad>however, numbers of equal value are not necessarily eq
<RhodiumToad>correct usage is to use eq? (and memq, assq, etc.) only for comparing against special unique values and interned objects such as symbols or keywords
<RhodiumToad>eqv? etc. should be used for values without substructure (though iirc the real/imag parts of complex numbers don't count as substructure for this purpose)
<RhodiumToad>and for values with substructure, you need equal?
<RhodiumToad>so for example you can compare symbols with eq? but comparing strings requires equal?
<RhodiumToad>guile, as an implementation artifact, happens to allow eq? to work with characters and small fixnums
<RhodiumToad>oh, also, sometimes eq? has a use for comparing whether two things are in fact the same pair.
*chrislck has defeated SASL. +1 EXP
<chrislck>is there a SRFI or module which can convert relative to full file paths? eg. "~/folder1/../folder2/x.txt" to "/home/chris/folder2/x.txt"
<jackhill>chrislck: the tilda expansion might be hard, otherwise guile had canonicalize-path
<jackhill>*tilde
<jackhill>I might use the shell to get the tilde expanded. It it authoratative on all the rules.
<jackhill>otherwise, I might look to see if scsh has anything
<chrislck>thanks... looks like a very OS-specific problem
***apteryx is now known as Guest37609
***apteryx_ is now known as apteryx
<leoprikler>for the record, you could just use (getenv "HOME") unless you need other users as well
<chrislck>the idea is to try convert strings without writing code... there's https://stackoverflow.com/questions/51520/how-to-get-an-absolute-file-path-in-python?rq=1 in python but guile needs one too
<leoprikler>that'd be (string-append (getcwd) "/" dir)
<leoprikler>note that python needs expanduser and expandvars to handle stuff like ~/ and $HOME
<leoprikler>you could write those on your own using regular expressions, but I'm pretty sure most use cases are very trivial in the end
<chrislck>maybe guile needs (ice-9 path) or something
<leoprikler>I think there is a filesystem library out there, but I don't know if it does everything you want it to
<leoprikler>Perhaps try out guile-file-names
<str1ngs>(passwd:dir (getpwnam (getlogin))) will also get home without using environment variables
<str1ngs>err $HOME
<leoprikler>oh, nice, one can actually use that for ~user too
<leoprikler>extending guile-file-names with that might be nice, but is it portable? might be unix only
<str1ngs>the main question I guess does it work on windows. not sure
<leoprikler>then again do people use that syntax on windows? :P
<str1ngs>people that are forced to use windows :)
<leoprikler>I think my question was unclear. I was wondering whether people using Windows (whether forced at gunpoint or otherwise 'convinced') enjoy the luxury of having tilde expand to anything in the first place.
<RhodiumToad>chrislck: you can call realpath() via the FFI on posix-like platforms
<RhodiumToad>really guile should have its own wrapper for that
<RhodiumToad>str1ngs: ~/foo uses $HOME and _not_ whatever is in the passwd file
<RhodiumToad>str1ngs: which means that ~ and ~myuser aren't necessarily the same
<str1ngs>leoprikler: what I was trying to imply was if a unix user is forced to use windows. then globing ans expansion would indeed be usesful.
<str1ngs>$HOME not being ~$USER seems kinda broken. all the more reason to use passwd
<RhodiumToad>Windows does have its own concept of a home directory but obviously it doesn't work the same way as on unix
<leoprikler>well, during guix builds $HOME is not /var/empty
<RhodiumToad>str1ngs: not only is it not broken, it's always been the traditional behaviour and is required by the standards
<RhodiumToad> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_01
<str1ngs>I don't see anywhere where is says the passwd and HOME can be different.
<str1ngs>it only says if login is NULL assuming it means the passwd entry then $HOME is used. so 'passwd:dir is preferred over HOME which is why I suggested it.
<RhodiumToad>HOME is just an env var, nothing forces it to be the same as the value in the passwd entry
<RhodiumToad>no, you read it wrong
<RhodiumToad>"login is null" means that you used ~/foo rather than ~somelogin/foo
<str1ngs>right I did read it wrong that was imply the postfix
<str1ngs>wait this is for a POSIX shell which might make sense. this might not work the same as glob
<RhodiumToad>globbing is a separate operation
<RhodiumToad>tilde expansion is done before pathname expansion
<str1ngs>so unless you are writing a POSIX shell. personally I would use globing. I might have made an assumption here.
<dsmith>dsmith@debmetrix:~$ pwd
<dsmith>/home/dsmith
<dsmith>dsmith@debmetrix:~$ HOME=$HOME/src
<dsmith>dsmith@debmetrix:/home/dsmith$ cd
<dsmith>dsmith@debmetrix:~$ pwd
<dsmith>/home/dsmith/src
<RhodiumToad>yes, cd without args also uses $HOME
<dsmith>And you can change (in the current process) HOME to whatever.
<RhodiumToad>str1ngs: nobody asked for globbing that I can see. the question was how to resolve a path that might contain ~ and ..
*RhodiumToad wonders why guile doesn't already have a (realpath), maybe a historical oversight?
<leoprikler>guile is not alone in this regard tho
<leoprikler>see the various python solutions
<pkill9>it has canonical-path though
<str1ngs>right I've already mentioned that before
*RhodiumToad doesn't like python
<dsmith>RhodiumToad: I would thing oversight. Most things are in because someone wanted/needed them at some point.
<RhodiumToad>what has canonical-path?
<str1ngs>check the manual?
<RhodiumToad>I just did?
<str1ngs>it's documented there!
<RhodiumToad>where?
<leoprikler>Nowhere as far as I can see
<leoprikler>but you can ,describe canonicalize-path
<RhodiumToad>also, python does have realpath()
<str1ngs>guile is not posix. some functions adhere to scheme standards
<str1ngs>though I'm not sure if canonicalize-path. but some procedures/functions do.
<str1ngs>Again probably realpath is not required since canonicalize-path exists. you can though if it's important to you. provide a patch to the posix module.
<RhodiumToad>hm
<RhodiumToad>so canonicalize-path exists, but is not in the docs?
<str1ngs>it is in the docs
<str1ngs>see https://www.gnu.org/software/guile/manual/html_node/File-System.html
<RhodiumToad>ah
<RhodiumToad>looks like it was added recently
<RhodiumToad>2020-05-30 in fact
<RhodiumToad>anyway, canonicalize-path is just a realpath() call on platforms where that exists
<RhodiumToad>added recently to the docs, that is, the function has been there a long time
<dsmith>2009-06-19
<dsmith>commit 25b82b3
*dsmith recently learned how to search in gitk
<leoprikler>it's missing from the 3.0.2 docs, so that's probably why no one knows about it yet ;)
<RhodiumToad>yes, the copy of the docs I was searching happened to be from 3.0.2
<dsmith>OT Question: Is it possible after writing to a socket, clear/reset the socket of any untransmitted data?
<dsmith>Talking kernel buffers here, not userland buffering.
<dsmith>Hmm. There is the SIOCOUTQ ioctl that undent data in the socket send queue..
<RhodiumToad>not on my system there isn't
<RhodiumToad>but the real problem is, what does it mean for data to be untransmitted?
<RhodiumToad>(and what possible good would it do?)
<dsmith>Right.
<dsmith>Was just going over the HiSLIP spec: https://www.ivifoundation.org/downloads/Protocol%20Specifications/IVI-6.1_HiSLIP-2.0-2020-04-23.pdf#page=51
<dsmith>Talks about clearing messages. "Clear messages on the synchronous and asynchronous channels with the exception of {..}"
<dsmith>Must be userland unsent messages.
<dsmith>Oftentimes, the people that write these specs don't have a real understanding of how things are implemented.
<RhodiumToad>that sounds like "clear" in the sense of "read and discard incoming messages"
<dsmith>Yes you are right: "To send a device clear, theclient will..."
<str1ngs>using FFI is it possible to represent an array of strings? I need to pass something like char *argv[] to a foreign function.
<mwette>I would think so. Check out string->pointer pointer-address and uint-list->bytevector. You want to make a bytevector of an array of integers which are pointers to the strings.
<mwette>Then pass to the function, declared to take '*, via bytevector->pointer.
<str1ngs>mwette: great. I will read up on these thank you.
<leoprikler>str1ngs: I just hacked together https://paste.debian.net/1159661/
<leoprikler>if it's for wordexp, it'll be fine just passing a significantly large null struct, will it not?
<leoprikler>parsing the struct back into something meaningful is where your problem lies, so you need to reverse all the arrows ;)
<leoprikler>and the program flow too
<str1ngs>the term argv was probalby not the best but the principle is the same. let me take a look at this.
<leoprikler>well, passing an argv to a function is different from accepting an argv from a function
<str1ngs>right as far as I can see wordexp_t *p is . char string_list[2][10] = { "tom", "jerry" };
<str1ngs>so it does need to be memory created then passed as an argument where it is the filled.
<str1ngs>or **char p
<str1ngs>here's what it looks like in C http://paste.debian.net/1159662
<str1ngs>I just notice p.we_wordc which means this is a struct. so I don't know where wordexp_t is defined.
<leoprikler>I think this might need an SCM_DEFINE'd wrapper function
<leoprikler>otherwise you risk ABI weirdness breaking your code
<str1ngs>that I can do. I was just trying to avoid using C
<leoprikler>If you want to use as little C as possible, you can just pass the arguments in unchecked and return the wordexp_t in a controlled manner
<leoprikler>I do think that writing the whole blob in C would be more safe though in some manner
<str1ngs>I can pass SCM I've done that before no problem. I'll play with FFI some more though. This was mainly to expose myself to FFI anyways.
<str1ngs>if not SCM_DEFINE as a last resort.
<leoprikler>you can do parse-c-struct to get the contents of the wordexp_t
<str1ngs>I found the definition for worexp_t it's not what I thought it was so that's an improvement :)
<str1ngs>afk for a few
<leoprikler>yeah, it's size_t, pointer, size_t
<leoprikler>exactly as in the manual
<str1ngs>right, so should be able to use make-c-struct hard part will be char **we_wordv;
<leoprikler>well, you start with bytevector->uint-list
<leoprikler>then map (compose pointer->string make-pointer)
<str1ngs>thing is it starts with an empty list I would assume.
<leoprikler>on which end are you right now? passing to or reading from?
<str1ngs>right now I'm just researching
<leoprikler>passing to is simply three zeroes
<str1ngs>then you think parse-c-struct would be enough?
<leoprikler>not quite
<leoprikler>with parse-c-struct you get argc as an integer and argv as a pointer
<leoprikler>you convert argv to a bytevector using argc
<leoprikler>then to an uint-list
<leoprikler>than to a bunch of pointers/strings
<str1ngs>right but for wordexp it takes a wordexp_t p. I confused things using argv as an example.
<str1ngs>char **we_wordv; is like argv which is what I thought wordexp_t. sorry for the confusion
<str1ngs>possible wordexp does initializing as long as you use wordfree when you are done. in which case this might be easier than I thought.
<str1ngs>so I just need to reverse your example.
*str1ngs cross's fingers
<str1ngs>really AFK for a awhile :)
<a_v_p>Guilers, is there a way to create an empty list from the C world? I have read the manual and the header files, but found nothing similar. Maybe I overlooked something?
<mwette>sneek: later tell str1ngs, nyacc's ffi-helper generated, from (define-ffi-module (wordexp) #:include '("wordexp.h")), this: https://paste.debian.net/1159665/
<sneek>Okay.
<a_v_p>Oh wait. 'scm_make_list' seems to be what I need.
<str1ngs>mwette: maybe I should use that instead :)
<sneek>Welcome back str1ngs, you have 1 message!
<sneek>str1ngs, mwette says: nyacc's ffi-helper generated, from (define-ffi-module (wordexp) #:include '("wordexp.h")), this: https://paste.debian.net/1159665/
<str1ngs>is size_t uint64 I'm not sure this is a safe assumption on my part.
<str1ngs>that could be platform dependent maybe?
<mwette>yes- the intention is that you compile ffi->scm on the host to be used. If another host defines size_t to be 32 bits, it should do the right thing.
<mwette>The command "guild compile-ffi wordexp.ffi" generates "wordexp.scm"
<mwette>when you have nyacc available
<mwette>the contents of wordexp.ffi I used is just (define-ffi-module (wordexp) #:include '("wordexp.h"))
<str1ngs>thank you mwette
<leoprikler>that's surprisingly much boilerplate for little gain
<str1ngs>I think I almost got it. http://paste.debian.net/1159679 . though I'm not sure how to handle cadr of the parse-c-struct. this should be SCM pointer of char **we_wordv
<str1ngs>more correct version. http://paste.debian.net/1159680
<str1ngs>I have some weird hacks for my distro don't mind them :)
<mwette>Do you mean lots of boiler plate for simple header file? Yes, it would be easy to do by hand. But that's not what I am after. I have auto-converted glib.h + gobject.h + pango.h + gdk.h + gtk2.h and then been able to write a hello world gtk+-2 demo. That just can't be done by hand in the same time. The idea is to be able to talk to C libraries quickly.
<str1ngs>mwette: I can see ffi-helper being quite useful. :)
<mwette>str1ngs: you don't need to dynamic-link lib's that are already bound into the guile run-time
<str1ngs>oh wow I did not know that
<leoprikler>let me expand your let* chain
<leoprikler>(real-results (parse-c-struct results wordexp-type))
<leoprikler>(wordc (car real-results))
<leoprikler>(wordv (cadr real-results))
<str1ngs>right looks good
<leoprikler>(wordbv (pointer->bytevector wordv (* wordc (sizeof '*))))
<leoprikler>(words* (bytevector->uint-list wordbv (native-endianness) (sizeof '*)))
<leoprikler>finally (map (compose pointer->string make-pointer) words*)
<str1ngs>awww yeah!
<str1ngs>leoprikler: that's the missing special sauce thanks. now I need to getting better grasp of bytevector->uint-list. the rest kinda makes sense.
<leoprikler>bytevector->[u]int-list "reinterprets" a bytevector as a list of integers given a particular endianness and integer size
<leoprikler>for instance, you can unpack a series of big-endian 16bit integers if you're working with low level protocols that use them a lot
<leoprikler>or an array of native-endian FFI data
<str1ngs>this is not bad, it's actually easier then C. doesn't not help I don't grok map and compose like for-each. imperative has tainted me!
<leoprikler>mwette I kinda see the point, but I wish it needed less helpers and had more raw guile code
<leoprikler>e.g. instead of symbols-tab a (define WRDE_SYNTAX 5) or something like that
<str1ngs>nice thing about wordexp is it can glob as well. but I need to set some enumb. I won't want program expansion
<str1ngs>enum*
<str1ngs>aka command substitution
<leoprikler>well, i think passing flags should not be too difficult for a manually written FFI to handle ;)
<mwette>leoprikler: I struggle with code bloat. If you define everything then the namespace will get quite polluted. Conversion of gtk2.scm generates 91k lines of scm code.
<mwette>the gtk2.scm symbol-tag has ~2300 items
<leoprikler>yeah, that's definitively too much to handle in any normal way
<leoprikler>hence why guile-gi and g-golf both have filtering
<mwette>So I usually define a procedure (gtk2-val 'GTK_CTREE_ExPANSION_TOGGLE) -> 4
<leoprikler>I feel that's a bit too general though
<mwette>guile does not have the size developer community to hand-wrap c libraries like the python community does
<leoprikler>can nyacc handle specific enums?
<leoprikler>you could do something like (define %gtk-ctree-table '((expansion-toggle . 4) ...))
<mwette>yes. If the header declares a c function that takes an enum then you can just pass the symbol value. e.g., my cariso example uses (cairo_image_surface_crate 'CAIRO_FORMAT_ARGB32 200 200)
<mwette>s/symbol value/quoted symbol name/
<mwette>leoprikler: when you define a ffi module via define-ffi-module you can add scheme code to add helper's. I also have partial hooks for a re-namer so one will be able to convert _ to -, but the thinking is that the generated scm code is really C-in-scheme and serious use should put a more scheme-like wrapper on the front.
<leoprikler>hmm, does nyacc's ffi-helper use any parsing on top of parse-c99?
<leoprikler>if not, it should probably be easy enough to alter the front end to fit my needs