* Validating an entire record-type* at value creation
@ 2024-05-05 17:01 Richard Sent
0 siblings, 0 replies; only message in thread
From: Richard Sent @ 2024-05-05 17:01 UTC (permalink / raw)
To: help-guix
Hi Guix!
Does define-record-type* support creating a validator/sanitzer that
validates the entire record during creation? I know you can create
sanitzers for individual fields (example below from the docstring).
--8<---------------cut here---------------start------------->8---
A field can also have an associated \"sanitizer\", which is a procedure that
takes a user-supplied field value and returns a \"sanitized\" value for the
field:
(define-record-type* <thing> thing make-thing
thing?
this-thing
(name thing-name
(sanitize (lambda (value)
(cond ((string? value) value)
((symbol? value) (symbol->string value))
(else (throw 'bad! value)))))))
--8<---------------cut here---------------end--------------->8---
I think it would be valuable to validate fields in relation to each
other. For example, verifying that mutually exclusive fields aren't all
set to #t.
However before I actually open this as a bug or post about it on
guix-devel I want to check if such a thing already exists. Or if there's
an equivalent method to achieve a similar result that's already used in
the code.
I imagine in general we don't want too many records that can have
mutually exclusive fields. However, (I believe) that already exists in
the current code base. For example, the file-system record has both
needed-for-boot? and dependencies, but if mount-at-boot? is set
dependencies is ignored.
--
Take it easy,
Richard Sent
Making my computer weirder one commit at a time.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-05-05 17:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-05 17:01 Validating an entire record-type* at value creation Richard Sent
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.