Den 2024-09-22 kl. 04:34, skrev Nala Ginrut:
@Linus!
I think it's similar to a getter/setter, but I think making it a
function will be safer.
I think a box is a good idea, since that is more or less what happens
behind the scenes when you start mutating values outside contexts where
automatic unboxing occurs. You will also not have to deal with the
performance penalty of the dynamic environment, nor any unexpected
thread things (apart from threads being able to mutate the value at the
same time). It is what you would have gotten if guile had not introduced
declarative modules.
Guile has both regular boxes (srfi 111?) and atomic boxes.
My suggestion about identifier macros means you can make the boxing
primitives invisible to the user. Ie using (+ the-var 5) turns into (+
(unbox the-var) 5) and (set! the-var 12)=> (set-box! the-var 12). I have
done some voodoo using make-variable-transformer, but I believe the
shorthand _identifier-syntax_ could be what you are looking for.
Best regards
Linus