IRC channel logs

2021-09-15.log

back to list of logs

<lispmacs[work]>hi, when we use one of the bytevector ref functions, is the "index" the raw number of bytes into the bytevector, or bytes multiplied by the unit size (u16, etc.)?
<vijaymarupudi>Raw byte index
<lispmacs[work]>okay
<lispmacs[work]>do we have some trick with macros or something to compile the results of a calculation into the definition of a word? E.g., to put (/ 1 180) into the source code but not have to recalculate that each time?
***Guest7621 is now known as chrislck
<lispmacs[work]>My scheme is a bit rusty
<chrislck>1/180 is valid guile
<chrislck>(this may not be what you mean :-P)
<lispmacs[work]>chrislck: right, but any arbitrary calculation
<lispmacs[work]>I'm thinking like in FORTH where you use brackets to go out of compiling mode temporarily and then afterwards compile the result into your definition
<lispmacs[work]>something like the backtick operator...?
*chrislck has no idea
<adhoc>lispmacs[work]: why ?
<adhoc>you want to pre-compute to a constant ?
<lispmacs[work]>I think so, depending on what you mean
<lispmacs[work]>like, e.g., if you had a function that made a bytevector of a certain length based on certain dimensions you had in mind
<lispmacs[work]>you could do (make-bytevector (* 100 200)), since you had in mind 100 rows and 200 columns
<lispmacs[work]>of course, you could just do (make-bytevector 20000), but then you would have to separately document why you picked that number
<chrislck>I think wingo's compiler does some optimizing automagically
<chrislck> https://wingolog.org/archives/2011/10/11/partial-evaluation-in-guile
<chrislck>(all hail wingo)
<lispmacs[work]>yeah, but my question is, is there some kind of operator I can apply to (* 100 200) so that it explicitly is interpreted in some first pass compile phase or something
<lispmacs[work]>like macros are pre-expanded...?
<lispmacs[work]>like quasiquote...?
<lispmacs[work]>yeah, like unquote in a quasiquote, but unquoting in a definition
<lispmacs[work]>this works, but looks a little funny:
<lispmacs[work]>(define foo (eval `(lambda (n) (+ n (unquote (* 10 2)))) (interaction-environment)))
<lispmacs[work]>so result of (* 10 2) is pre-calculated into the compiled definition
<lispmacs[work]>maybe I just need a new syntax to make that look a little nicer, with a special operator. Sounds like something that would have been thought of already, though
*lispmacs[work] goes home
<flatwhatson>lispmacs[work]: that's a worse way to write (define foo (let ((c (* 10 2))) (lambda (n) (+ n c))))
<flatwhatson>neither are happening at "compile time" (ignoring optimizations which will definitely evaluate this at compile time)
<flatwhatson>the multiplication would be evaluated on the first pass through the module when it is loaded
<tohoyn>apteryx: In a module system where interfaces and implementations of modules are separate it is possible to the module bodies to import arbitrary interfaces. Theme-D has this kind of module system and AFAIK Turbo Pascal did that, too.
<muradm>interesting i'm calling (http-request ...) from (web client), per docs return should be (values response . body) but what i get is (response? ret-val) => #t
<muradm>i would expect (response? (car ret-val)) to be #t
<muradm>(car above is to signify first of values, i don't remember how to fetch first and (let-values ...) is long to write)
<muradm>looking at source i see (values ...) returned from (http-request ...)
<muradm>yes and (call-with-values (http-request ...) (lambda (res body) ...)) fails with wrong type to apply
<muradm>why this does not work? https://paste.rs/DfD
<muradm>figured out, both problems
<muradm>(ice-9 regex) such a pain
<muradm>i have string with plain html
<muradm>i want to match "<img.*>"
<muradm>every character i use throws some error :)
<muradm>why (regexp-substitute/global "<img*>" ...) throws error while (regexp-sustitute/global "<img*\\>" ...) does not?
<muradm>can't find any place in manual saying that ">" is special
<muradm>and no non-greedy support
<chrislck>muradm: https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags
<muradm>chrislck: thanks, i saw this.. :) yes i'm trying to use (xml->sxml ...) but it seems that html I get is not getting parsed due to not very compliant xml. like <img ...> is not closed with />, and there is some cryptic error which i still not understand, so i decided to pre-fix what i get from http result and then feed it to (xml->sxml ..)
<muradm>this is last error i'm stuck with https://paste.rs/1Zy
<pottsy>I think I may have asked this before, but how do I call guile procedures from c?
<pottsy>the best I can find is gh_call0(SCM proc) and gh_call1(SCM proc, SCM arg0) etc. from guile 1.8
<pottsy>I can't find the equivalent in guile 3
<pottsy>ah I think it's just scm_apply_0
<chrislck>or scm_call_[0-9]
<chrislck>muradm: see htmlprag
<chrislck>sneek: botsnack
<sneek>:)
<pottsy>I think I've asked this before too, but one last time for good measure. Is there some way to pass userdata to scm_c_make_gsubr?
<tohoyn>pottsy: add user data as an extra argument to the procedure and define a wrapper procedure in Scheme
<muradm>chrislck: thanks, will try it some time, will require packaging effort from me.. nongnu and not in guix packages.. :)
<pottsy>tohoyn: I see, thanks
<pottsy>that's how I'm doing it now but it's suboptimal IMO :(
***chris is now known as Guest8595
***Guest8595 is now known as chrislck
<stis>Cheers guilers!
<lloda>if i have (define a 'x), what is (??? a) that gives me (syntax 'x) ?
<tohoyn>has anyone considered writing optimized versions of car and cdr in Guile JIT?
<tohoyn>I could try that
<tohoyn>lloda: `(syntax ,a) gives (syntax x)
<tohoyn>lloda: `(syntax (quote ,a)) gives (syntax (quote x))
<tohoyn>lloda: but (syntax 'x) is a different thing
<lloda>yes
<lloda>i want to insert a value in a macro. maybe it doesn't make sense. The way i do it now is by having a list of - #'things #'to #'insert -. Instead I could look up a list that gives me - things to insert - instead. But I can insert the first with #,x and the second i don't know how.
<lloda>too many insteads
<dsmith-work>Wednesday Greetings, Guilers
<dsmith-work>flatwhatson: Guile does do pretty good at compiling constant expresions. Happens even before the JIT compiler.
<dsmith-work>flatwhatson: But there are times when you need to evaluate something at macro or load time or something.
<dsmith-work>flatwhatson: So there is eval-when. See https://www.gnu.org/software/guile/manual/html_node/Eval-When.html
<dsmith-work>flatwhatson: But be careful with using that if you have a cat.
<dsmith-work>flatwhatson: Doh! Sorry! That all was meant for lispmacs[work]
<dsmith-work>lispmacs[work]: ^^
<dsmith-work>sneek: later tell lispmacs[work] See eval-when: https://www.gnu.org/software/guile/manual/html_node/Eval-When.html
<sneek>Will do.
<dsmith-work>sneek: botsnack
<sneek>:)
<dsmith-work>!uptime
<sneek>I've been running for 8 days
<sneek>This system has been up 8 weeks, 1 hour, 11 minutes
<dsmith-work>goodbot
*sneek wags
<lispmacs[work]>dsmith-work: thanks
<sneek>Welcome back lispmacs[work], you have 1 message!
<sneek>lispmacs[work], dsmith-work says: See eval-when: https://www.gnu.org/software/guile/manual/html_node/Eval-When.html
<dsmith-work>lispmacs[work]: Looks like peval (partial evaluator), which does constant folding and other stuff, first appeared in 2.0.3
<stis>sneek: where is bugs
<stis>sneek where bugs
<stis>sneek bugs
<sneek>Someone once said bugs is Send reports to bug-guile@gnu.org, and see bug reports at https://bugs.gnu.org/guile
<geex3>is sneek made with guile?
<dsmith-work>geex3: Yes, to a degree. It's a bobot++ with the guile extension.
<dsmith-work>geex3: Original code was sarahbot in #scheme, mildly ported over.
<geex3>cool :)
<dsmith-work>sneek: version
<sneek>Sneeky bot running on Guile version 3.0.3 using bobot++ release.2.3.1-6-a463-dirty
<geex3>we have the technology