From: Richard Sent <richard@freakingpenguin.com>
To: help-guix@gnu.org
Subject: Validating an entire record-type* at value creation
Date: Sun, 05 May 2024 13:01:50 -0400 [thread overview]
Message-ID: <871q6gw5tt.fsf@freakingpenguin.com> (raw)
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.
reply other threads:[~2024-05-05 17:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871q6gw5tt.fsf@freakingpenguin.com \
--to=richard@freakingpenguin.com \
--cc=help-guix@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).