IRC channel logs

2021-09-08.log

back to list of logs

<theruran>has anyone used guile-log? the logic programming framework
<stis>i'm the author of that
<theruran>stis: that's awesome! I wanted to try it out but I don't see it in guix
<stis>k
<stis>not fmailiar with guix
<theruran>ok. I can probably get it to work in a guix ad-hoc environment
<stis>make sure to take out a tag, also it is not tested against recent guile versions
<theruran>I can't even get autoconf to finish :/
<theruran>probably needs an old autoconf too
<stis>darn, havent worked on it for so9me time. recent year has bin into guile-python
<stis>or python-on-guile as it is called
<theruran>:O
<theruran>I am wondering about building a compiler using guile-log
<stis>prolog is nice for that indeed
<stis>I use stis-parser when I make compilers
<stis>nowdays tough
<theruran>wow so that can make parsers for LR(1) grammars? looking at parsing Ada
<theruran>there is a complete BNF grammar for Ada in the standard, so it seemed best to me to try to parse that to generate an Ada parser
<stis>should be able to do that, not fast, but in my experience the compilatioin still takes longer. but chunking large set of source code semantics you probably need something else
<theruran>do you mean some finer control would be needed to parse a source file properly? not only quickly.
<theruran>I've never written a compiler before
<stis>the fastes is to use a parser generator if these are applicable, like yacc or guile versions. But if you want more power I would use something else like stis-parser ot the guile PEG parser
<stis>the parser generators usuale can take BNF like inputs.
<stis>there are an example of a complete python parser in stis-parser
<stis>and a few other examples
<stis>I think that I should document it better though
<theruran>awesome! well I got stis-parser to build, anyway
<stis>goot to here
<stis>good to here
<theruran>thanks - I will try to learn from these examples
***sneek_ is now known as sneek
<theruran>so Guile doesn't have design-by-contract or data schemas?
<theruran>just use quickcheck?
<lilyp>theruran: You could add contracts add runtime by wrapping functions in pre- and postconditions.
<lilyp>but otherwise yeah, quickcheck is fun
<theruran>I saw a Guix thing that can convert CHICKEN eggs for Guile? there is a design-by-contract egg
<theruran>not sure that's what I want though
<muradm>hi guile, is there path join function in library? can't find..
<muradm>like (path-join "/some/dir" "some-file") => "/some/dir/some-file"
<muradm>that will take care of necessary trailing slashes etc. (not a guix :) )
<xd1le>muradm: maybe can use canonicalize-path and system-file-name-convention as starting points to implement it
<xd1le>from here https://www.gnu.org/software/guile/manual/guile.html#File-System
<muradm>xd1le: canonicalize-path raises exception, i suppose it is doing (stat.. under the hood
<muradm>for now i decided to go like this, seems like working, but need to look at edge cases may be https://paste.rs/T8h
<xd1le>muradm: ah hmm
<xd1le>well i found this: https://notabug.org/ZelphirKaltstahl/guile-examples/src/master/web-development/example-03-serve-static-assets/path-handling.scm
<xd1le>i have not used or tested it
<xd1le>but the path-join function looks like it is using string-trim-right instead of canonicalize-path
<muradm>xd1le: thanks! great source. may be you can shed a light: https://paste.rs/GdV
<muradm>this is from guile manual "Web Server" section
<muradm>it says "... or it can return a procedure ..."
<muradm>whole request handler? so i have to write response/headers my self?
<muradm>i can't figure it out (define (static-send-file file size) (lambda (outer) ...))
<muradm> https://paste.rs/90V
<muradm>both cases raise: Too few values returned to continuation
<dsmith-work>Hey Hi Howdy, Guilers
<xd1le>muradm: sorry I'm going to sleep now
<xd1le>but your code seems to be in the right direction
<xd1le>and also I found this: https://notabug.org/ZelphirKaltstahl/guile-examples/src/master/web-development/example-03-serve-static-assets/response-utils.scm
<xd1le>the respond-static-asset function might interest you
<xd1le>anyway time zz, good luck!
<muradm>xd1le: thanks, will check, gn
<xd1le>oh and to answer you question, yeah it does seem like you have to write this yourself from reading the web server section
<xd1le>maybe search if someone made a higher level web framework, I have not used web servers in guile myself
<xd1le>ah yes there is artanis btw
<xd1le>gn!
<muradm>yes, i'm staring at it whole day, but it is complex to understand for now :)
<muradm>Zelphirkaltstahl too simple :D
<muradm>what does "Too few values returned to continuation" means?
<maximed>muradm: (receive (x y) 'z SOMETHING) --> too few values
<maximed>because the expression 'z evaluates to a szingle value
<maximed>but two were expected (to be named 'x' and 'y')
<rlb>civodul: I'm confused again with respect to the gmp settings we should have in debian. It looks like mini-gmp is disabled by default and that disables scm_install_gmp_memory_functions, so things should be safe by default? In which case we don't have to have --enable-mini-gmp in debian, and I'm not sure we could for 3.0, even if we wanted to, since we've been shipping 3.0 for a while without it, and it breaks the abi?
<rlb>i.e. 3.0's been in testing for a while and has now shipped in stable (bullseye), so I suspect we might have to wait until a soname change to change that in debian.
<muradm>maximed: thanks, figured that out now!
<muradm>suppose i have out string port, and file to write to it, now i do like open-input-file, get-string-all, write out
<muradm>is there more simple/efficient way of doing that, or i have to follow this way
<maximed>muradm: what are you trying to do exactly?
<maximed>Copy from one port to another?
<maximed>If so, maybe get-bytevector-some and put-bytevector are useful
<maximed>(in a loop)
<muradm>maximed: trying to make simple static file web server https://paste.rs/vlC :)
<muradm>for now don't want loop, at least want to see it working
<muradm>then i can do loops etc.. :)
<muradm> https://paste.rs/WbV some progress, still again getting "too few values" for (apply writer ...
<RhodiumToad>with what value for writer?
<RhodiumToad>(I don't think you actually need apply there, (writer out read-in) should suffice, but that's probably not your problem)
<muradm>i tried many ways, now simplified even more https://paste.rs/chC
<muradm>still i get that "Too few.." (face palm)
<RhodiumToad>you didn't answer the question, what actual procedure is the value of "writer" when the error occurs?
<muradm>here is more simplified https://paste.rs/c76
<muradm>there is no writer reader any more
<muradm>in before it was either get-string-n or get-bytevector-n for text and binary respectively
<RhodiumToad>so what expression generates the error now?
<muradm>now i don't even pass the procedure to web server, i read in one shot and give it plain data
<muradm> https://paste.rs/VwZ
<muradm>here is output
<muradm>it happens after my handler returns
<maximed>muradm: I wonder if 'static-file' is allowed to return a single value?
<maximed>Maybe replace #f with (values #f #f)?
<maximed>(I'm guessing here)
<muradm> https://paste.rs/Jfx line 279 is one with (with-stack-and-prompt
<RhodiumToad>muradm: in the handler you pass to run-server, you're returning only one of static-file's two results
<RhodiumToad>you need to use a let-values or receive or one of the other multi-value binding syntaxes in place of let
<muradm>maximed: that return value is used only in if, but i tried your guess, same thing
<maximed>muradm: (receive (x y) (static-file ...) (if x (values x y) (not-found ...)))
<maximed>(to bind multiple values, as RhodiumToad suggests)
<muradm>RhodiumToad: (static-file ...) returns either (values ...) or #f, this is not allowed?
<muradm>why do i need to unpack and pack (values if i don't need them
<RhodiumToad>but you do need them
<RhodiumToad>(let ((res (foo))) ...) binds res to only the first result of (foo) and discards the rest
<RhodiumToad>a less obvious way to do it would be something like,
<RhodiumToad>(cond ((static-file ...) (lambda (res . _) res) => values) (else (not-found ...)))
<rndd>hi everyone!
<rndd>i have problem with compiling an example of using libguile
<rndd>i found that header files are located in /usr/include/guile/3.0/ (on ubuntu)
<rndd>but where are actual .so files?
<RhodiumToad>you should be using the pkgconf info to find them
<rndd>RhodiumToad: i tried pkg-config --libs guile-3.0
<RhodiumToad>and?
<muradm>RhodiumToad, maximed: https://paste.rs/naT this worked... (face palm).. thanks :)
<rndd>but i got "no package guile-3.0 found"
<rndd>but i installed it
<muradm>but it is very unintuitive..
<rndd>-dev
<rndd>guile-3.0-dev
<RhodiumToad>did that not install a .pc file?
<RhodiumToad>muradm: dealing with multiple values always seems to involve some amount of friction
<muradm>now i have to something like this https://paste.rs/tWw
<muradm>which feels very uncomfortable, what if tomorrow 3 or 4 values, which one would mean what? :)
<RhodiumToad>muradm: why the or?
<RhodiumToad>muradm: the version I showed with cond doesn't assume any number of values
<muradm>both should be false to signal failure
<RhodiumToad>ah
<RhodiumToad>then (cond ((static-file ...) (lambda (res body . _) (or res body)) => values) (else (not-found ...)))
<RhodiumToad>(that's srfi-61 syntax for (cond), but in guile it's available by default)
<rndd>RhodiumToad: i dont know
<RhodiumToad>rndd: there should be a way to see the files installed by the package
*RhodiumToad not linux user, doesn't know the commands offhand
<muradm>i can return "string/record/list/vector/etc. or #f" but cant "values or #f" very unintuitive, killed like 3 hours to get that .. :D
<muradm>rndd: there is guile-config
<muradm>tool for that
<tohoyn> rndd: try to run "dpkg -L guile-3.0-dev | grep .so"
<tohoyn>rndd: and rndd: try to run "dpkg -L guile-3.0-dev | grep .pc"
<muradm>RhodiumToad: yeah, cond looks better of course, thanks :)
<muradm>rndd: "guile-config link" "guile-config compile" ..
<muradm>will give you flags
<muradm>and your libs should be in standard place of your distro
<muradm>there are 2 of them guile-3.0 and gc
<muradm>rndd: under guix it looks like: https://paste.rs/Git but i suppose you are not guix
<muradm>then you can use guile-config tool in your build tool (Makefile, CMakeLists.txt etc.)
<rndd>muradm: ohhh
<rndd>it helped
<rndd>thank you
<muradm>welcome :)
<RhodiumToad>it's kind of unfortunate that you can't do (cond ((foo) or => values) ...)
<RhodiumToad>(it doesn't work because (or) is syntax and not a function)
<muradm>values feel heart breaking.. :)
<RhodiumToad>the main thing that annoys me with multiple values is that it's often not possible to avoid converting them to lists and back
<muradm>RhodiumToad: twice heart breaking then... as far as i see from (web server) code it was not revised for long time...
<muradm>first time i saw (values ...) here in (web server)
<RhodiumToad>unfortunately the alternatives are usually worse
<RhodiumToad>returning a single list rather than multiple values can lead to more consing
<muradm>can't even properly serve binary file, as it only seems to support bytevector for it
<RhodiumToad>what else would you expect it to support?
<muradm>at least i want to do this https://paste.rs/TJh
<muradm>but i always get this: In procedure sendfile: Wrong type argument in position 1 (expecting open file port): #<output: string 7f69a26eacb0>
<muradm>it provides only string output
<muradm>RhodiumToad: regarding returning multiple values, for me it is at most tuple, where '(val1 . val2) works pretty well
<muradm>(match exp ((v1 . v2) ... ) does good job
<RhodiumToad>returning a pair like that is an allocation
<RhodiumToad>whereas returning multiple values usually is not
<muradm>hmm.. good to learn the difference
<muradm>thanks
<muradm>may be i have to look at call-with-with-values, as (web server) code is full of them
<muradm>to understand the pattern for (values ...) usage
<RhodiumToad>call-with-values is the underlying primitive, you need to know how it works but usually you can avoid using it
<RhodiumToad>(call-with-values a b) calls a with no args, and then the return values of a become the args passed to b
<muradm>as far as i understand values cannot be matched either with (ice-9 match)...
<RhodiumToad>there are things you can do with match-lambda
<RhodiumToad>er, match-lambda*
<RhodiumToad>but again, that's forcing the construction of a list of the values
<muradm>yes, there is no code path to output binary with port
<muradm> https://paste.rs/XPI now this works
<muradm>but (stat:size ...) reported size is not matching to what (get-bytevector-n ...) returns
<muradm>gave up with port https://paste.rs/8DH :)
<muradm>more compact https://paste.rs/tO8, to solve mime type lookup and local path :)
*muradm zzz...