IRC channel logs

2020-10-31.log

back to list of logs

***wxie1 is now known as wxie
***apteryx_ is now known as apteryx
***jonsger1 is now known as jonsger
<str1ngs>sneek later tell elliotpotts . Hello, you can also catch error/exceptions with C. see https://www.gnu.org/software/guile/manual/html_node/Exceptions-and-C.html
<sneek>Got it.
***jonsger1 is now known as jonsger
***maav is now known as miguel`
***miguel` is now known as maav_
***maav_ is now known as maav
***chrislck1 is now known as chrislck
<lampilelo>Is there an easy way of interfacing a c array with guile code? I found you can cast the c pointer to scm pointer with scm_from_pointer() and then scm_pointer_to_bytevector(). Is this the preferred way? scm_from_pointer takes a finalizer as an argument so i guess it takes ownership of the data, is there a way that doesn't do that?
<mwette>lampilelo: why not (pointer->bytevector (make-pointer addr) size); also, check out https://github.com/TaylanUB/scheme-bytestructures/
<lampilelo>the thing is i'm writing a wrapper for a c++ library so i'm not doing that from scheme
<mwette>lampilelo: I see, from C.
<leoprikler>lampilelo: it optionally takes ownership, but if you destroy the data from C you might have a dangling pointer from scheme, which would be bad
<mwette>Ah Maybe use guardians? Not sure that has a C interface.
<leoprikler>if you can ensure, that these scheme pointers will be invalidated in the destructor of your class, that should be fine
<lampilelo>leoprikler: that's not a problem, the pointer will live shorter than the data
<leoprikler>in that case just pass NULL as finalizer
<leoprikler>That should be a documented option
<lampilelo>yes, i found it after asking the question
<lampilelo>do you have any experiences with mixing guile and c++? will guile try to manage my c++ memory?
<leoprikler>Not exactly, but I did some Guile+Vala and it's very doable. Guile won't claim ownership until you instruct it to.
<lampilelo>hm, ok
<lampilelo>prepare for segfaults
***jonsger1 is now known as jonsger
<lampilelo>something's off, it's just working
<str1ngs>when you cringe but all the tests pass?
<lampilelo>when you write a lot of code and there are 0 problems with it
<lampilelo>when you finally run it, that is
<leoprikler>There are two stages of software development:
<leoprikler>1. It doesn't work, and I don't know why.
<leoprikler>2. It works and I don't know why.
<stis>Hi guilers!
<emys>hi, is it possible to somehow pass a specific environment to `macroexpand' ? I mean in common-lisp its an optional parameter, in guile there seems to be none..
<emys>is the something like (with-module-as-current-module (macroexpand '(let ((x 1)) x)))?
<mwette>maybe look at compile. Maybe like this: https://paste.debian.net/1169392/
<mwette>but replace (current-module) with your env
<emys>hmm, maybe its ok if I explain some more context. I am trying to compile s-expressions to tree-il for a language I am implementing. Since I read in the docs that the scheme->tree-il compilation is basically just macroexpansion, I wondered whether I could implement my compliation using macro definitions. But for that I would need some way to pass in a fairly clean environment I guess. Dunno if this is plausible actually for
<emys> a non-scheme language to use the macro system for this.
***jonsger1 is now known as jonsger
<leoprikler>If you already have s-expressions, wouldn't the natural thing be to perform some pattern matching on them, so that the result is Tree-IL?
<leoprikler>but regarding your question, you can (save-module-excursion (set-current-module my-module) ...)
<emys>leoprikler, yeah thats what I am doing right now, but I guess using syntax-case for hygienic transformations has some appeal
<leoprikler>oops, of course you'd need to wrap that in a lambda
<emys>I guess I'll figure that out, having the procedure names will help me tremendously
<leoprikler>Of course, you can just implement your own language as a set of syntax-cases on top of scheme, but that'd be a step higher on the compile tower if I'm not mistaken.
<mwette>did you look at language/scheme/compile-tree-il.scm ? It uses (set-current-module env) then calls macroexpand
<mwette>^ under (save-module-excursion ....)
<rekado>emys: if your language can be transformed to s-expressions you can build a simple compiler extension like leoprikler mentioned.
<rekado>that’s what guile-xcb does, and how guile-aws compiles JSON to .go
<mwette>but guile's scheme->tree-il is just calling macroexpand, so maybe emys has something there
<mwette>Also, (ice-9 match) may be useful.
<emys>ice-9 match is what I currently use in the procedural transformations that I do
<mwette>I have done several lang's in Guile and use: lang --[parser]--> sxml --[(sxml fold)+(sxml match)]--> tree-il
<emys>I guess looking at constructors like (let names gensyms vals exp) I do wonder how scheme implementation is capable of transforming into an expression that makes use of the original name of a symbol and the gensyms, a bit hard to tell when looking at psyntax.scm
<emys>mwette, that sounds like an interesting transformation path.
<mwette> https://git.savannah.nongnu.org/cgit/nyacc.git/tree/examples/nyacc/lang/javascript
<rekado>emys: here’s how guile-aws does it: https://git.elephly.net/?p=software/guile-aws.git;a=blob;f=language/aws/spec.scm;hb=HEAD
<rekado>during compilation of a JSON file it converts the JSON to Scheme modules.
<emys>thanks for these examples!
*civodul recommends the latest Foss & Crafts episode: https://fossandcrafts.org/episodes/14-digital-humanities-workshops.html
<civodul>rekado: ↑
<emys>rekado, I think your guile-aws code is fairly similar to the structure I have now.
<mwette>civodul: thanks for that link
<emys>I guess I found out how guile uses syntax transformations for let/letrec in the transformation to tree-il, its in psyntax-pp and to me it seems like the syntax transformations are hardcoded directly by providing a lambda function instead of using the syntax-case DSL