[Guile/Goops] Enforcing value restrictions in class c'tor
From alicetrillianosako@gmail.com@21:1/5 to All on Wed Jul 28 16:37:35 2021
As an experiment to better understand GOOPS, I am currently writing a program in Guile using Guile-SDL2 and GOOPS, and as part of this I am implementing a simple wrapper class for RGBA values. I was looking to see if there was any way in GOOPS to enforce
(via saturation) value boundaries of 0-255 for the individual color gradients. The simple wrapper class as I have it now is:
-------------------------------------------------------------------- (define-class <rgba-color>
(red #:accessor red-gradient
#:init-keyword #:r)
(green #:accessor green-gradient
#:init-keyword #:g)
(blue #:accessor blue-gradient
#:init-keyword #:b)
(alpha #:accessor alpha-gradient
#:init-keyword #:a)) --------------------------------------------------------------------
I know that this is a bit clumsy as it is, and I am not certain how useful this even will be, but I thought that it would make sense to wrap these values rather than dealing with the bare numerical values. I might switch to a simpler list or vector-based
approach instead of a class if there's no straightforward way to enforce this pre-req in GOOPS.