(I’m reposting this from a message I sent on the mailing list)
This is actually not much of a proposal, since I’m just bringing up a bunch of previous art.
A couple of other languages like C#, Rust, D and a few others have a “dialect” embedded within their language for “unsafe” operations.
Rust has “unsafe”, C# also calls it unsafe, and I think D calls it @system
It would be nice to have similar functionality in Guile so you could do a lot more low level stuff. It would be fun to be able to use as little C as possible while still creating stuff that’s super close to the metal!
There was actually a similar proposal/project a while back that I was following along quite closely called PreScheme
This was a scheme-inspired language that did low level memory management and pointers and stuff, used to implement Scheme-48.
It was revived for a bit, but the author seemed to have vanished off the internet.
Still, there’s a lot of good work here, so I’m wondering if it would somehow be possible to turn all of this stuff into a SFRI of sorts?
The only problem is that something like PreScheme breaks a lot of the assumptions Guile has, so I’m not sure if it would be able to fit a SFRI
There’s also Crunch (https://wiki.call-cc.org/eggref/6/crunch), which is a similar idea by the guys who do Chicken scheme. However, that still uses reference counting, whereas I’m interested in something low-level that can compete with C/Odin/Zig/Hare/etc.
How I imagine that this would work
;; scheme code
(unsafe
;; write PreScheme/Unsafe-Guile/Whatever you want to call it
)
;; continue writing scheme code
Actually, crunch does something very similar, so there is prior art in this:
(import crunch (chicken bitwise) (chicken fixnum))
(crunch
(define (popcount32 x) ; From "Hacker's Delight"
(let ((x (fx- x (bitwise-and (arithmetic-shift x -1) #x55555555))))
(let ((x (fx+ (bitwise-and x #x33333333)
(bitwise-and (arithmetic-shift x -2) #x33333333))))
(let ((x (bitwise-and (fx+ x (arithmetic-shift x -4)) #x0F0F0F0F)))
(let ((x (fx+ x (arithmetic-shift x -8))))
(let ((x (fx+ x (arithmetic-shift x -16))))
(bitwise-and x #x0000003F)))))))))
But yeah, IDK, I’d be interested in what y’all think.