IRC channel logs

2024-03-07.log

back to list of logs

<dthompson>civodul: the reason for needing a record is that we need something to encapsulate the bytevector and offset. whether or not to build a type hierarchy for strong typing could be up for debate. personally I see value in it and it's what ftypes do
<dthompson>civodul: but hey I'm glad you were able to try it so quickly and that you like it! can't think of a much better endorsement :)
<dthompson>you can also directly get/set into bytevectors without an intermediate record btw! bytestruct-pack and bytestruct-unpack do that
<civodul>oh, that’s excellent
<dthompson>yeah, it's a must-have for me for packing gpu buffers with vertex data
<dthompson>but the wrapper structs are nice when you want encapsulation
<dthompson>and to give someone an API that looks like a regular Scheme record
<dthompson>(bytestruct-unpack <vec2> ((y)) (f32vector 1.0 2.0) 0) would return 2.0
<civodul>very nice
<civodul>the best of both worlds!
<freakingpenguin>Hi all! Is the reason this snippet https://paste.debian.net/1309708/ fails because the define-syntax macro is hygienic?
<freakingpenguin>I have to define a public function with some shared logic in several different modules due to some other code and figured macros were the least code-dupe way to handle it.
<freakingpenguin>I should be able to cludge something together with functions but a (define-foo) macro feels like it would be cleaner.
<rlb>freakingpenguin: yes, I think more or less -- try (macroexpand '(test 'foo))
<rlb>But you can likely use syntax case, and break hygiene if you like, or you could (less safely, depending on the rest) use define-macro.
<rlb>freakingpenguin: perhaps related - https://www.gnu.org/software/guile//manual/html_node/Hygiene-and-the-Top_002dLevel.html
<rlb>And here with a syntax-case variant of your macro:
<rlb>scheme@(guile-user)> (macroexpand '(test 'foo))
<rlb>$1 = #<tree-il (define bar-46dea41ac6af4d9 (const foo))>
<freakingpenguin>rlb: Thanks a bunch! From what I've read of syntax-case in the manual it looks like datum->syntax is how I'd intentionally break hygiene, is that right?
<chrislck>sneek: botsnack
<sneek>:)
<rlb>freakingpenguin: yep
<rlb>Though note that you may not *need* it depending on what you're doing, i.e. here lokke creates the top-level binding for a clj protocol without it: https://codeberg.org/lokke/lokke/src/branch/main/mod/lokke/datatype.scm#L129-L132
<rlb>s/i.e./e.g./
<rlb>ACTION double-checks that name wasn't introduced some other way, now that he said that...
<rlb>Also, if your end-goal is a module, I'd probably work immediately with that, so you have the semantics (top-level and otherwise) you want from the start.
<rlb>Those define-generics just below the link are also "top level" defs, fwiw.
<freakingpenguin>Yeah, this is roughly what I'm going for if you're familiar with Guix and/or Cuirass: https://paste.debian.net/1309712/.
<rlb>I'm not, yet.
<freakingpenguin>Thanks for the example! Is... that project an implementation of Clojure in Guile?
<rlb>fsvo implementation -- it's intended to be heading in that direction :)
<freakingpenguin>"For a more Scheme oriented experience in Scheme" I love this community. Everywhere I look there's some cool new project.
<rlb>Yeah, up to a point I've tried to keep some bits that might also be useful to guile implemented first as mostly scheme-friendly, and then I've build the clj side on top.
<rlb>some of that's in here fwiw: https://codeberg.org/lokke/lokke/src/branch/main/mod/lokke/scm
<mwette>Due to the day job, I missed the entire struct conversation. bytestructures provides macros to generate offsets of struct-in-struct-...-in-structs.
<mwette>I have been using that in ffi-helper, but a little while ago I started looking at new form. My original interest was in supporting cross architecture access. (e.g., accessing data structures snarfed from microcontrollers).
<mwette>Also, I plan to parse C structures down to primitive types: u8, i16, f32, etc. so that equality predicates are doable.
<flatwhatson>bytestructs sound great, just need something like nyacc to autogen them from C headers
<old>mwette: I've had some syntax that does that
<mwette>does what?
<old>defining complex C-struct around a bytevector
<old>with accessors
<old>by complex I mean compound one, not just flat structure. With union and enum
<old>it is just very slow unfortunatelly
<old>I'm not sure if that's what you are refering to by bytestructures, I have not seen the conversation
<mwette>OK. nyacc will generate bytestructure descriptors for all structs inside include files. The bytestructures package provides accessors, but no in the flavor of scheme records.
<mwette>this is bytestructures: https://github.com/TaylanUB/scheme-bytestructures
<old>hm it looks similar to what I have
<old> https://git.sr.ht/~old/guile-ev/tree/master/item/ev/ffi.scm.in
<old>these are the bindings for libev I made, manually written
<old>using the following syntax mess: https://git.sr.ht/~old/guile-ev/tree/master/item/ev/foreign.scm
<old>but it is nice to see we can have something portable across Scheme with bytestructures
<mwette>nyacc autogenerates the scheme code. For glib gobject.h the file is ~13,000 lines of code; for gtk2.h it's 98k lines of code.
<mwette>example of gtk2 program using all scheme ffi code: https://git.savannah.nongnu.org/cgit/nyacc.git/tree/examples/nyacc/lang/ffi-help/gdk2-03.scm
<mwette>gtkgl example: https://git.savannah.nongnu.org/cgit/nyacc.git/tree/examples/nyacc/lang/ffi-help/gtkgl-01.scm
<mwette>mixing C and Scheme has its idiosyncrasies
<jmes>How do I make (file-exists? "$XDG_RUNTIME_DIR/frumble") understand the environment variable?
<jmes>Generally, how do "expand" strings with environment vars?
<jmes>how does one*
<mwette>(file-exists? (string-append (getenv "XDG_RUNTIME_DIR") "/frumble"))
<mwette>you could also use (format ...)
<jmes>mwette: Thanks a bunch. And the universe seems to be poking fun at me because as soon as I bother you about it I finally find the relevant docs online...
<mwette>no problem; glad to help
<ArneBab>Does anyone have a high performance implementation of skip lists for Guile?
<sneek>Yey! chrislck is back :)
<dsmith>sneek, botsnack
<sneek>:)
<dsmith>!uptime
<sneek>I've been serving for 10 days
<sneek>This system has been up 48 weeks, 4 days, 21 hours, 14 minutes
<freakingpenguin>Hi all! I'm trying to add a fender to a syntax-case macro to restrict input to only "list of X", but I can't seem to get it working. https://paste.debian.net/1309766/
<freakingpenguin>Pretty sure the problem is from wrapping the list in a syntax but I can't get rid of it.
<freakingpenguin>In this case I guess I could turn it into a datum but in my actual use case that list would contain variables, not constants, so I don't think that would work.
<mwette>maybe expand to (define foo (if (every ...) bar (error "")))
<old>freakingpenguin: fender is not what you want if the elements are not constant I think
<freakingpenguin>Alrighty, thanks! Do you know of any good resources on this topic? The manual is a bit hard to parse sometimes.
<old>On syntax fence?
<freakingpenguin>Huh, it does actually work with syntax->datum and an eval in the fender, it's just really ugly. https://paste.debian.net/1309776/
<old>freakingpenguin: right because the expander can deduce that hello is a constant number
<freakingpenguin>I did also try it cross-module with some records, seemed fine.
<old>try it inside a function that received some parameter
<old>on the parameter
<old>anyway, I would not mix eval and fence, you might encouter issue in the future
<freakingpenguin>You're right, it can't handle that. Putting in a conditional error clause is definitely cleaner, just wish I could understand all the finer points of macros. Guess that just comes with practice.
<dsmith>sneek, macros?
<sneek>I could be wrong, but macros is http://hipster.home.xs4all.nl/lib/scheme/gauche/define-syntax-primer.txt
<dsmith>freakingpenguin, ^^ Though that's only syntax-rules, not syntax-case